Merge branch 'develop'

pull/64/head
13621160019@163.com 2021-08-15 14:10:41 +08:00
commit bd03f67c75
11 changed files with 41 additions and 54 deletions

View File

@ -80,62 +80,60 @@ class CostFileCollection:
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.USER_UUID_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN') description='API.USER_UUID_NOT_FOUND_IN_HEADERS_PLEASE_LOGIN')
cnx = mysql.connector.connect(**config.myems_user_db) cnx_user_db = mysql.connector.connect(**config.myems_user_db)
cursor = cnx.cursor() cursor_user_db = cnx_user_db.cursor()
query = (" SELECT utc_expires " query = (" SELECT utc_expires "
" FROM tbl_sessions " " FROM tbl_sessions "
" WHERE user_uuid = %s AND token = %s") " WHERE user_uuid = %s AND token = %s")
cursor.execute(query, (user_uuid, token,)) cursor_user_db.execute(query, (user_uuid, token,))
row = cursor.fetchone() row = cursor_user_db.fetchone()
if row is None: if row is None:
if cursor: if cursor_user_db:
cursor.close() cursor_user_db.close()
if cnx: if cnx_user_db:
cnx.disconnect() cnx_user_db.disconnect()
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_SESSION_PLEASE_RE_LOGIN') description='API.INVALID_SESSION_PLEASE_RE_LOGIN')
else: else:
utc_expires = row[0] utc_expires = row[0]
if datetime.utcnow() > utc_expires: if datetime.utcnow() > utc_expires:
if cursor: if cursor_user_db:
cursor.close() cursor_user_db.close()
if cnx: if cnx_user_db:
cnx.disconnect() cnx_user_db.disconnect()
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.USER_SESSION_TIMEOUT') description='API.USER_SESSION_TIMEOUT')
cursor.execute(" SELECT id " cursor_user_db.execute(" SELECT id "
" FROM tbl_users " " FROM tbl_users "
" WHERE uuid = %s ", " WHERE uuid = %s ",
(user_uuid,)) (user_uuid,))
row = cursor.fetchone() row = cursor_user_db.fetchone()
if row is None: if row is None:
if cursor: if cursor_user_db:
cursor.close() cursor_user_db.close()
if cnx: if cnx_user_db:
cnx.disconnect() cnx_user_db.disconnect()
raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST', raise falcon.HTTPError(falcon.HTTP_400, title='API.BAD_REQUEST',
description='API.INVALID_USER_PLEASE_RE_LOGIN') description='API.INVALID_USER_PLEASE_RE_LOGIN')
else:
user_id = row[0]
cnx = mysql.connector.connect(**config.myems_historical_db) cnx_historical_db = mysql.connector.connect(**config.myems_historical_db)
cursor = cnx.cursor() cursor_historical_db = cnx_historical_db.cursor()
add_values = (" INSERT INTO tbl_cost_files " add_values = (" INSERT INTO tbl_cost_files "
" (file_name, uuid, upload_datetime_utc, status, file_object ) " " (file_name, uuid, upload_datetime_utc, status, file_object ) "
" VALUES (%s, %s, %s, %s, %s) ") " VALUES (%s, %s, %s, %s, %s) ")
cursor.execute(add_values, (filename, cursor_historical_db.execute(add_values, (filename,
file_uuid, file_uuid,
datetime.utcnow(), datetime.utcnow(),
'new', 'new',
raw_blob)) raw_blob))
new_id = cursor.lastrowid new_id = cursor_historical_db.lastrowid
cnx.commit() cnx_historical_db.commit()
cursor.close() cursor_historical_db.close()
cnx.disconnect() cnx_historical_db.disconnect()
resp.status = falcon.HTTP_201 resp.status = falcon.HTTP_201
resp.location = '/costfiles/' + str(new_id) resp.location = '/costfiles/' + str(new_id)

View File

@ -2,7 +2,7 @@ import base64
import uuid import uuid
import os import os
from openpyxl.chart import PieChart, LineChart, Reference from openpyxl.chart import PieChart, LineChart, Reference
from decimal import * from decimal import Decimal
from openpyxl.styles import PatternFill, Border, Side, Alignment, Font from openpyxl.styles import PatternFill, Border, Side, Alignment, Font
from openpyxl.drawing.image import Image from openpyxl.drawing.image import Image
from openpyxl import Workbook from openpyxl import Workbook

View File

@ -2,7 +2,7 @@ import falcon
import simplejson as json import simplejson as json
import mysql.connector import mysql.connector
import config import config
from anytree import Node, AnyNode, LevelOrderIter from anytree import AnyNode, LevelOrderIter
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from decimal import Decimal from decimal import Decimal
import excelexporters.combinedequipmentbatch import excelexporters.combinedequipmentbatch

View File

@ -2,7 +2,7 @@ import falcon
import simplejson as json import simplejson as json
import mysql.connector import mysql.connector
import config import config
from anytree import Node, AnyNode, LevelOrderIter from anytree import AnyNode, LevelOrderIter
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from decimal import Decimal from decimal import Decimal
import excelexporters.equipmentbatch import excelexporters.equipmentbatch

View File

@ -2,7 +2,7 @@ import falcon
import simplejson as json import simplejson as json
import mysql.connector import mysql.connector
import config import config
from anytree import Node, AnyNode, LevelOrderIter from anytree import AnyNode, LevelOrderIter
import excelexporters.equipmenttracking import excelexporters.equipmenttracking

View File

@ -2,9 +2,8 @@ import falcon
import simplejson as json import simplejson as json
import mysql.connector import mysql.connector
import config import config
from anytree import Node, AnyNode, LevelOrderIter from anytree import AnyNode, LevelOrderIter
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from decimal import Decimal
import excelexporters.meterbatch import excelexporters.meterbatch

View File

@ -2,7 +2,7 @@ import falcon
import simplejson as json import simplejson as json
import mysql.connector import mysql.connector
import config import config
from anytree import Node, AnyNode, LevelOrderIter from anytree import AnyNode, LevelOrderIter
import excelexporters.metertracking import excelexporters.metertracking
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone

View File

@ -2,7 +2,7 @@ import falcon
import simplejson as json import simplejson as json
import mysql.connector import mysql.connector
import config import config
from anytree import Node, AnyNode, LevelOrderIter from anytree import AnyNode, LevelOrderIter
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from decimal import Decimal from decimal import Decimal
import excelexporters.shopfloorbatch import excelexporters.shopfloorbatch

View File

@ -2,7 +2,7 @@ import falcon
import simplejson as json import simplejson as json
import mysql.connector import mysql.connector
import config import config
from anytree import Node, AnyNode, LevelOrderIter from anytree import AnyNode, LevelOrderIter
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from decimal import Decimal from decimal import Decimal
import excelexporters.storebatch import excelexporters.storebatch

View File

@ -2,7 +2,7 @@ import falcon
import simplejson as json import simplejson as json
import mysql.connector import mysql.connector
import config import config
from anytree import Node, AnyNode, LevelOrderIter from anytree import AnyNode, LevelOrderIter
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from decimal import Decimal from decimal import Decimal
import excelexporters.tenantbatch import excelexporters.tenantbatch

View File

@ -283,7 +283,6 @@ def process(logger, data_source_id, host, port):
except Exception as e: except Exception as e:
logger.error("Error in step 4.3.1 of acquisition process " + str(e)) logger.error("Error in step 4.3.1 of acquisition process " + str(e))
# ignore this exception # ignore this exception
pass
# update tbl_analog_value_latest # update tbl_analog_value_latest
delete_values = " DELETE FROM tbl_analog_value_latest WHERE point_id IN ( " delete_values = " DELETE FROM tbl_analog_value_latest WHERE point_id IN ( "
@ -306,7 +305,6 @@ def process(logger, data_source_id, host, port):
except Exception as e: except Exception as e:
logger.error("Error in step 4.3.2 of acquisition process " + str(e)) logger.error("Error in step 4.3.2 of acquisition process " + str(e))
# ignore this exception # ignore this exception
pass
try: try:
# trim ", " at the end of string and then execute # trim ", " at the end of string and then execute
@ -315,7 +313,6 @@ def process(logger, data_source_id, host, port):
except Exception as e: except Exception as e:
logger.error("Error in step 4.3.3 of acquisition process " + str(e)) logger.error("Error in step 4.3.3 of acquisition process " + str(e))
# ignore this exception # ignore this exception
pass
if len(energy_value_list) > 0: if len(energy_value_list) > 0:
add_values = (" INSERT INTO tbl_energy_value (point_id, utc_date_time, actual_value) " add_values = (" INSERT INTO tbl_energy_value (point_id, utc_date_time, actual_value) "
@ -337,7 +334,6 @@ def process(logger, data_source_id, host, port):
except Exception as e: except Exception as e:
logger.error("Error in step 4.4.1 of acquisition process: " + str(e)) logger.error("Error in step 4.4.1 of acquisition process: " + str(e))
# ignore this exception # ignore this exception
pass
# update tbl_energy_value_latest # update tbl_energy_value_latest
delete_values = " DELETE FROM tbl_energy_value_latest WHERE point_id IN ( " delete_values = " DELETE FROM tbl_energy_value_latest WHERE point_id IN ( "
@ -361,7 +357,6 @@ def process(logger, data_source_id, host, port):
except Exception as e: except Exception as e:
logger.error("Error in step 4.4.2 of acquisition process " + str(e)) logger.error("Error in step 4.4.2 of acquisition process " + str(e))
# ignore this exception # ignore this exception
pass
try: try:
# trim ", " at the end of string and then execute # trim ", " at the end of string and then execute
@ -371,7 +366,6 @@ def process(logger, data_source_id, host, port):
except Exception as e: except Exception as e:
logger.error("Error in step 4.4.3 of acquisition process " + str(e)) logger.error("Error in step 4.4.3 of acquisition process " + str(e))
# ignore this exception # ignore this exception
pass
if len(digital_value_list) > 0: if len(digital_value_list) > 0:
add_values = (" INSERT INTO tbl_digital_value (point_id, utc_date_time, actual_value) " add_values = (" INSERT INTO tbl_digital_value (point_id, utc_date_time, actual_value) "
@ -393,7 +387,6 @@ def process(logger, data_source_id, host, port):
except Exception as e: except Exception as e:
logger.error("Error in step 4.5.1 of acquisition process: " + str(e)) logger.error("Error in step 4.5.1 of acquisition process: " + str(e))
# ignore this exception # ignore this exception
pass
# update tbl_digital_value_latest # update tbl_digital_value_latest
delete_values = " DELETE FROM tbl_digital_value_latest WHERE point_id IN ( " delete_values = " DELETE FROM tbl_digital_value_latest WHERE point_id IN ( "
@ -415,7 +408,6 @@ def process(logger, data_source_id, host, port):
except Exception as e: except Exception as e:
logger.error("Error in step 4.5.2 of acquisition process " + str(e)) logger.error("Error in step 4.5.2 of acquisition process " + str(e))
# ignore this exception # ignore this exception
pass
try: try:
# trim ", " at the end of string and then execute # trim ", " at the end of string and then execute
@ -424,7 +416,6 @@ def process(logger, data_source_id, host, port):
except Exception as e: except Exception as e:
logger.error("Error in step 4.5.3 of acquisition process " + str(e)) logger.error("Error in step 4.5.3 of acquisition process " + str(e))
# ignore this exception # ignore this exception
pass
# update data source last seen datetime # update data source last seen datetime
update_row = (" UPDATE tbl_data_sources " update_row = (" UPDATE tbl_data_sources "
@ -436,7 +427,6 @@ def process(logger, data_source_id, host, port):
except Exception as e: except Exception as e:
logger.error("Error in step 4.6 of acquisition process " + str(e)) logger.error("Error in step 4.6 of acquisition process " + str(e))
# ignore this exception # ignore this exception
pass
# sleep and continue the next iteration of the inner while loop # sleep and continue the next iteration of the inner while loop
time.sleep(config.interval_in_seconds) time.sleep(config.interval_in_seconds)