This commit is contained in:
1
migration/.gitignore
vendored
Normal file
1
migration/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.venv
|
29
migration/migrate-level.py
Normal file
29
migration/migrate-level.py
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import psycopg2
|
||||||
|
from loguru import logger
|
||||||
|
|
||||||
|
try:
|
||||||
|
srcConn = psycopg2.connect(database="level_monitoring_berresheim")
|
||||||
|
srcConn.autocommit = False
|
||||||
|
|
||||||
|
with srcConn.cursor() as srcCur:
|
||||||
|
srcCur.execute("select time, application_name, raw_level, level, status, battery from measurement_t")
|
||||||
|
for srcObj in srcCur:
|
||||||
|
timestamp = srcObj[0]
|
||||||
|
deviceName = srcObj[1]
|
||||||
|
rawLevel = srcObj[2]
|
||||||
|
level = srcObj[3]
|
||||||
|
status = srcObj[4]
|
||||||
|
battery = srcObj[5]
|
||||||
|
|
||||||
|
logger.info(f"{timestamp=}, {deviceName=}, {rawLevel=}, {level=}, {status=}, {battery=}")
|
||||||
|
|
||||||
|
destTime = timestamp
|
||||||
|
destApplication = "de-hottis-level-monitoring"
|
||||||
|
destDevice = "eui-a84041a2c18341d6"
|
||||||
|
destAttributes = '{"ApplicationId":"de-hottis-level-monitoring", "DeviceType":"dragino-ldds75", "Hint": "Migrated"}'
|
||||||
|
destValues = '{"Battery":{"unit":"V","label":"Battery","value":' + str(battery) + ',"variable":"Voltage"}, "Distance":{"unit":mm","label":"Distance","variable":"Level","value":' + str(rawLevel) + '}, "CorrectedDistance":{"unit":"mm", "label":"CorrectedDistance", "variable":"Level","value":' + str(level) + '}}'
|
||||||
|
logger.info(f"{destTime=}, {destApplication=}, {destDevice=}, {destAttributes=}, {destValues=}")
|
||||||
|
finally:
|
||||||
|
if srcConn:
|
||||||
|
srcConn.close()
|
||||||
|
|
2
migration/requirements.txt
Normal file
2
migration/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
loguru==0.7.2
|
||||||
|
psycopg2==2.9.9
|
Reference in New Issue
Block a user