Added report generator for thingsboard
This commit is contained in:
109
migration/plcfreshwater.ipynb
Normal file
109
migration/plcfreshwater.ipynb
Normal file
@@ -0,0 +1,109 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"{'monthHolding': 12345,\n",
|
||||
" 'dayHolding': 12367,\n",
|
||||
" 'lifetime': 123469,\n",
|
||||
" 'day': 14,\n",
|
||||
" 'month': 3,\n",
|
||||
" 'Totalizers': False,\n",
|
||||
" 'year': 2024}"
|
||||
]
|
||||
},
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import json, time\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"# Original JSON object\n",
|
||||
"original_json = {\n",
|
||||
" 'Todays': 43,\n",
|
||||
" 'Yesterdays': 42,\n",
|
||||
" 'Current Months': 5555,\n",
|
||||
" 'Previous Months': 5552,\n",
|
||||
" 'Monthly Holding': 12345,\n",
|
||||
" 'Daily Holding': 12367,\n",
|
||||
" 'Lifetime': 123469,\n",
|
||||
" 'Day': 14,\n",
|
||||
" 'Month': 3,\n",
|
||||
" 'Last Report': 12343432324324,\n",
|
||||
" 'Totalizers': False\n",
|
||||
"}\n",
|
||||
"\"\"\"\n",
|
||||
"{\n",
|
||||
" \"day\": 0,\n",
|
||||
" \"dayHolding\": 0,\n",
|
||||
" \"lifetime\": 0,\n",
|
||||
" \"month\": 0,\n",
|
||||
" \"monthHolding\": 0,\n",
|
||||
" \"week\": 0,\n",
|
||||
" \"weekHolding\": 0,\n",
|
||||
" \"year\": 0,\n",
|
||||
" \"yearHolding\": 0\n",
|
||||
"}\n",
|
||||
"\"\"\"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def convertPersist(original_json):\n",
|
||||
" # Mapping of keys\n",
|
||||
" key_mapping = {\n",
|
||||
" 'Todays': None, \n",
|
||||
" 'Yesterdays': None, \n",
|
||||
" 'Current Months': None, \n",
|
||||
" 'Previous Months': None, \n",
|
||||
" 'Monthly Holding': 'monthHolding',\n",
|
||||
" 'Daily Holding': 'dayHolding',\n",
|
||||
" 'Lifetime': 'lifetime',\n",
|
||||
" 'Day': 'day',\n",
|
||||
" 'Month': 'month',\n",
|
||||
" 'Last Report': None,\n",
|
||||
" 'Totalizers': 'Totalizers'\n",
|
||||
" }\n",
|
||||
" now = round(time.time()/600)*600*1000\n",
|
||||
" # Convert keys and build new JSON object\n",
|
||||
" new_json = {}\n",
|
||||
" for original_key, new_key in key_mapping.items():\n",
|
||||
" if new_key:\n",
|
||||
" new_json[new_key] = original_json[original_key]\n",
|
||||
" new_json[\"year\"] = time.gmtime(now/1000.0).tm_year\n",
|
||||
" # Convert to JSON format\n",
|
||||
" #new_json_str = json.dumps(new_json, indent=4, sort_keys=True)\n",
|
||||
" return(new_json)\n",
|
||||
"convertPersist(original_json=original_json)\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "env-01",
|
||||
"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.10.5"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
Reference in New Issue
Block a user