Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8,768 changes: 8,768 additions & 0 deletions data/Cuernavaca_MEX_MOR.epw

Large diffs are not rendered by default.

Large diffs are not rendered by default.

166 changes: 166 additions & 0 deletions notebooks/.ipynb_checkpoints/005_epw_ReadEPW-checkpoint.ipynb

Large diffs are not rendered by default.

239 changes: 239 additions & 0 deletions notebooks/.ipynb_checkpoints/999_developement_tb-checkpoint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"# %load ../iertools/tb.py\n",
"import pandas as pd\n",
"import requests\n",
"import json\n",
"import datetime\n",
"from dateutil.parser import parse\n",
"import numpy as np\n",
"import time\n",
"\n",
"\n",
"\n",
"# def get_config(file=\"local.ini\", sec=\"DEFAULT\"):\n",
"# \"\"\"Reads a section of a configpareser INI file\"\"\"\n",
"# import configparser\n",
"# config = configparser.ConfigParser()\n",
"# config.read(file)\n",
"# section = config[sec]\n",
"# out = {}\n",
"# for i in section.items():\n",
"# out[i[0]] = i[1]\n",
"# return out\n",
"\n",
"\n",
"def unix_time_millis(dt):\n",
" return (dt - epoch).total_seconds() * 1000\n",
"\n",
"epoch = datetime.datetime.utcfromtimestamp(0)\n",
"class TB:\n",
" \"\"\"\n",
" Reads device data \n",
" TB(config_file='local.ini',device_name='DEFAULT')\n",
" config_file: Initialization file which cointains sections, each section is a device\n",
" in ThingsBoard, so each one has a token, device_id, tenant, password, host and port.\n",
" By default, TB class looks for local.ini and section to DEFAULT\n",
" section: By default DEFAULT is used and is used to specify the device\n",
"\n",
" \"\"\"\n",
" def __init__(self,config_file='local.ini',device_name='DEFAULT'):\n",
" \"\"\"\n",
" \n",
" \"\"\"\n",
" import pandas as pd\n",
" import requests\n",
" import json\n",
" from dateutil.parser import parse\n",
" import configparser\n",
" config = configparser.ConfigParser()\n",
" config.read(config_file)\n",
" section = config[device_name]\n",
" out = {}\n",
" for i in section.items():\n",
" out[i[0]] = i[1]\n",
" self.init = out\n",
" auth_url = \"http://{}:{}/api/auth/login\".format(self.init[\"host\"], self.init[\"port\"])\n",
" data = {\"username\": self.init[\"tenant\"], \"password\": self.init[\"password\"]}\n",
" headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}\n",
" r = requests.post(auth_url, data=json.dumps(data), headers=headers)\n",
" self.jwt_token = json.loads(r.text)['token']\n",
" timeseries = \"http://{}:{}/api/plugins/telemetry/DEVICE/{}/keys/timeseries\".format(self.init[\"host\"], self.init[\"port\"], self.init[\"device_id\"])\n",
" headers = {\"Content-Type\":\"application/json\", \"X-Authorization\": \"Bearer {}\".format(self.jwt_token)}\n",
" key = requests.get(timeseries, headers=headers)\n",
" self.key = list(key.text)\n",
" print(key.text)\n",
" \n",
"\n",
" epoch = datetime.datetime.utcfromtimestamp(0)\n",
" \n",
"# return self.key\n",
"\n",
" def unix_time_millis(dt):\n",
" return (dt - epoch).total_seconds() * 1000\n",
" \n",
" def request(self):\n",
" auth_url = \"http://{}:{}/api/auth/login\".format(self.init[\"host\"], self.init[\"port\"])\n",
" data = {\"username\": self.init[\"tenant\"], \"password\": self.init[\"password\"]}\n",
" headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}\n",
" r = requests.post(auth_url, data=json.dumps(data), headers=headers)\n",
" self.jwt_token = json.loads(r.text)['token']\n",
" timeseries = \"http://{}:{}/api/plugins/telemetry/DEVICE/{}/keys/timeseries\".format(self.init[\"host\"], self.init[\"port\"], self.init[\"device_id\"])\n",
" headers = {\"Content-Type\":\"application/json\", \"X-Authorization\": \"Bearer {}\".format(self.jwt_token)}\n",
" keys = requests.get(timeseries, headers=headers)\n",
" self.keys = list(keys.text)\n",
" print(keys.text)\n",
" def get_df(self,key=\"NONE\",\n",
" start_datetime=datetime.datetime.now()- pd.Timedelta('2Min'),\n",
" end_datetime =datetime.datetime.now(),\n",
" Lat=0):\n",
" try:\n",
" if type(start_datetime) == str:\n",
" start_datetime = parse(start_datetime)\n",
"\n",
" if type(end_datetime) == str:\n",
" end_datetime = parse(end_datetime)\n",
" auth_url = \"http://{}:{}/api/auth/login\".format(self.init[\"host\"], self.init[\"port\"])\n",
" data = {\"username\": self.init[\"tenant\"], \"password\": self.init[\"password\"]}\n",
" headers = {'Content-Type': 'application/json', 'Accept': 'application/json'}\n",
" r = requests.post(auth_url, data=json.dumps(data), headers=headers)\n",
" self.jwt_token = json.loads(r.text)['token']\n",
" timeseries = \"http://{}:{}/api/plugins/telemetry/DEVICE/{}/keys/timeseries\".format(self.init[\"host\"], self.init[\"port\"], self.init[\"device_id\"])\n",
" headers = {\"Content-Type\":\"application/json\", \"X-Authorization\": \"Bearer {}\".format(self.jwt_token)}\n",
" keys = requests.get(timeseries, headers=headers)\n",
"\n",
" self.key = key\n",
" start_m = int(unix_time_millis(start_datetime))\n",
" end_m = int(unix_time_millis(end_datetime))\n",
" interval= 20000\n",
" limit = 10000000\n",
" agg = \"NONE\"\n",
" timeseries = \"http://{}:{}/api/plugins/telemetry/DEVICE/{}/values/timeseries?keys={}&startTs={}&endTs={}&interval={}&limit={}&agg={}\".format(self.init[\"host\"],\n",
" self.init[\"port\"], \n",
" self.init[\"device_id\"], \n",
" self.key, \n",
" start_m, \n",
" end_m,\n",
" interval,\n",
" limit,\n",
" agg) \n",
"\n",
" # print(timeseries)\n",
" telemetry = requests.get(timeseries, headers=headers)\n",
" # time.sleep(10)\n",
" datos = pd.read_json(telemetry.text, orient=None)\n",
" # print(datos)\n",
" df = pd.DataFrame([i for i in datos[key]])\n",
" df.ts = pd.to_datetime(df.ts,unit='ms')\n",
" df.set_index('ts',inplace=True)\n",
" df.columns = [key]\n",
" for i,valor in enumerate(df[key]):\n",
" try:\n",
" df[key].iloc[i] = float(valor)\n",
" except:\n",
" df[key].iloc[i] = np.nan\n",
" df[key] = df[key].astype(\"float64\")\n",
"\n",
" #df[key] = pd.to_numeric(df[key])\n",
" # df = df.resample(\"60S\").pad()\n",
" df.dropna(inplace=True)\n",
" df.index += pd.Timedelta('-6H')\n",
" self.datos = df\n",
" return df\n",
" except:\n",
" print('no hay datos')\n",
"\n",
" "
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"ajuste = pd.Timedelta('-6H') \n",
"fecha1 = parse(\"2022-04-11\") \n",
"fecha2 = fecha1 + pd.Timedelta(\"6D\")\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[\"Hum.\",\"Hum.2\",\"Humedad\",\"Humedad2\",\"Litros 1\",\"Temp.\",\"Temp.2\",\"Temp.R\",\"Temp.R2\",\"Temperatura\",\"Temperatura2\",\"Temperaturaderocio\",\"Temperaturaderocio2\",\"Thermocouple_1\",\"Thermocouple_10\",\"Thermocouple_11\",\"Thermocouple_12\",\"Thermocouple_2\",\"Thermocouple_3\",\"Thermocouple_4\",\"Thermocouple_5\",\"Thermocouple_6\",\"Thermocouple_7\",\"Thermocouple_8\",\"Thermocouple_9\",\"corriente\",\"fp\",\"potencia\",\"voltaje\"]\n",
"no hay datos\n",
"no hay datos\n",
"no hay datos\n",
"no hay datos\n",
"no hay datos\n",
"no hay datos\n",
"no hay datos\n",
"no hay datos\n",
"no hay datos\n",
"no hay datos\n",
"no hay datos\n",
"no hay datos\n"
]
}
],
"source": [
"tmp= TB(config_file='config_privado.ini',device_name='Termopares cafe')\n",
"sensores = [\"Thermocouple_1\",\"Thermocouple_10\",\"Thermocouple_11\",\n",
" \"Thermocouple_12\",\"Thermocouple_2\",\"Thermocouple_3\",\n",
" \"Thermocouple_4\",\"Thermocouple_5\",\"Thermocouple_6\",\n",
" \"Thermocouple_7\",\"Thermocouple_8\",\"Thermocouple_9\"]\n",
"# lista = [tmp.get_df(key=sensor,start_datetime=fecha1,end_datetime=fecha2).resample('1min').mean() for sensor in sensores]\n",
"lista = [tmp.get_df(key=sensor) for sensor in sensores]\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading