Browse Source

Initial commit

mingyue-unimat 19 hours ago
parent
commit
e5617d4704

+ 32 - 0
config/config.py

@@ -0,0 +1,32 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+import os
+
+configs = {
+    "rabbitmq_config": {"username": os.getenv("USERNAME_RM", "guest"),
+                        "password": os.getenv("PASSWORD_RM", "ntRbt_+dgd8"),
+                        "host": os.getenv("HOST_RM", "39.105.175.99"),
+                        "port": os.getenv("PORT_RM", 5672),
+                        "virtual_host": os.getenv("VIRTUAL_HOST_RM", "/"),
+                        "exchange_type": os.getenv("EXCHANGE_TYPE", "direct"),
+                        "exchange_get": os.getenv("EXCHANGE_GET", "sem.server.exchange"),
+                        "queue_name_get": os.getenv("QUEUE_NAME_GET", "sem.server.queue.chillertemp.input"),
+                        "routing_key_get": os.getenv("ROUTING_KEY_GET", "chillertemp.input"),
+                        "exchange_send": os.getenv("EXCHANGE_SEND", "sem.server.exchange"),
+                        "queue_name_send": os.getenv("QUEUE_NAME_SEND", "sem.server.queue.chillertemp.output"),
+                        "routing_key_send": os.getenv("ROUTING_KEY_SEND", "chillertemp.output")}}
+
+
+mysql_configs = {
+    "em_embasic": {"host": os.getenv("MYSQL_HOST", "hdc-emm-external.rwlb.rds.aliyuncs.com"),
+                   "port": os.getenv("MYSQL_PORT", "3306"),
+                   "user": os.getenv("MYSQL_USER", "readonly_chiller"),
+                   "password": os.getenv("MYSQL_PASSWORD", "xafnTU5j"),
+                   "db": os.getenv("MYSQL_DB_EMBASIC", "em_embasic"),
+                   "charset": os.getenv("MYSQL_CHARSET", "utf8")},
+    "em_bsem": {"host": os.getenv("MYSQL_HOST", "hdc-emm-external.rwlb.rds.aliyuncs.com"),
+                "port": os.getenv("MYSQL_PORT", "3306"),
+                "user": os.getenv("MYSQL_USER", "readonly_chiller"),
+                "password": os.getenv("MYSQL_PASSWORD", "xafnTU5j"),
+                "db": os.getenv("MYSQL_DB_EMBSEM", "em_bsem"),
+                "charset": os.getenv("MYSQL_CHARSET", "utf8")}}

+ 2 - 87
data_initialize_standard/constant.py

@@ -24,94 +24,9 @@ ExpectedStructure = {
         "chillerConfigInfo": ["waterTempControlMode", "isContinuousRun", "coolingShutdownOffset", "coolingRestartOffset",
                               "safetyPreDiffLowerLimit", "safetyLoadRatioLowerLimit", "chillerTempStep"],
         "chillerSafetyPara": ["circuitNumber", "circuitParameter"],
-        "stationInfo": ["userName", "stationName", "stationId", "runMode", "triggerTime", "chilledWaterMainTempOut",
-                        "chilledWaterMainTempIn", "allChillersInfo"],
+        "stationInfo": ["userName", "coolingStationName", "stationId", "runMode", "triggerTime",
+                        "chilledWaterMainTempOut", "chilledWaterMainTempIn", "allChillersInfo"],
         "chillerInfo": ["chillerId", "chillerName", "capacityRated", "refriType", "chillerWaterTempSet",
                         "chillerOffTimeLatest", "offSetTempLatestCooling", "chillerWaterTempOut", "chillerWaterTempIn",
                         "runStatus", "chillerPowerRatio", "loadRate", "upControlTimeLatest", "downControlTimeLatest"],
     }
-
-
-# def check_data_integrity(dic_input):
-#     # 定义预期的数据结构
-#     missing_fields = []
-#
-#     # 检查顶层字段缺失
-#     for top_key in ExpectedStructure:
-#         if top_key not in dic_input:
-#             missing_fields.append(top_key)
-#
-#     # 检查子字段缺失
-#     # for top_key in ExpectedStructure:
-#         if top_key in dic_input:
-#             current_data = dic_input[top_key]
-#             if isinstance(current_data, dict):
-#                 expected_subkeys = ExpectedStructure[top_key]
-#                 for sub_key in expected_subkeys:
-#                     if sub_key not in current_data:
-#                         missing_fields.append(f"{top_key}.{sub_key}")
-#
-#     # 检查空值的递归函数
-#     def find_empty_fields(data, parent_path='', empty_fields=None):
-#         if empty_fields is None:
-#             empty_fields = set()
-#
-#         if isinstance(data, dict):
-#             for key, value in data.items():
-#                 new_path = f"{parent_path}.{key}" if parent_path else key
-#                 # 检查当前值是否为空
-#                 if value is None:
-#                     empty_fields.add(new_path)
-#                 elif isinstance(value, str) and value.strip() == '':
-#                     empty_fields.add(new_path)
-#                 elif isinstance(value, (list, dict)) and not value:
-#                     empty_fields.add(new_path)
-#                 # 递归检查子元素
-#                 find_empty_fields(value, new_path, empty_fields)
-#         elif isinstance(data, list):
-#             if not data:  # 空列表
-#                 empty_fields.add(parent_path)
-#             else:
-#                 for index, item in enumerate(data):
-#                     new_path = f"{parent_path}[{index}]"
-#                     # 检查当前元素是否为空
-#                     if item is None:
-#                         empty_fields.add(new_path)
-#                     elif isinstance(item, str) and item.strip() == '':
-#                         empty_fields.add(new_path)
-#                     elif isinstance(item, (list, dict)) and not item:
-#                         empty_fields.add(new_path)
-#                     # 递归检查子元素
-#                     find_empty_fields(item, new_path, empty_fields)
-#         else:
-#             # 检查字符串是否为空
-#             if isinstance(data, str) and data.strip() == '':
-#                 empty_fields.add(parent_path)
-#         return empty_fields
-#
-#     # 查找所有空值路径
-#     empty_paths = find_empty_fields(dic_input)
-#
-#     return missing_fields, empty_paths
-#
-# dic_input = {}
-#
-# # 执行检查
-# missing_fields, empty_paths = check_data_integrity(dic_input)
-#
-# # 输出结果
-# print("输入参数中缺失关键字段,退出水温智控算法计算")
-# print("输入参数中关键数据存在空值,退出水温智控算法计算")
-# print("缺失字段检查结果:")
-# if missing_fields:
-#     print("缺失字段:")
-#     print("\n".join(missing_fields))
-# else:
-#     print("无缺失字段")
-#
-# print("\n空值字段检查结果:")
-# if empty_paths:
-#     print("存在空值的字段路径:")
-#     print("\n".join(sorted(empty_paths)))
-# else:
-#     print("无空值字段")

+ 45 - 0
data_initialize_standard/data_standardization.py

@@ -1,4 +1,5 @@
 import pandas as pd
+from data_initialize_standard.constant import *
 
 
 class DataStandardization(object):
@@ -12,6 +13,50 @@ class DataStandardization(object):
                 Num += 1
         return Num
 
+    def check_data(self):
+        # 定义预期的数据结构
+        missing_fields = []
+        # 检查顶层字段缺失
+        for top_key in ExpectedStructure:
+            if top_key not in self.data_dict:
+                missing_fields.append(top_key)
+            # 检查子字段缺失
+            if top_key in self.data_dict:
+                current_data = self.data_dict[top_key]
+                if isinstance(current_data, dict):
+                    expected_subkeys = ExpectedStructure[top_key]
+                    for sub_key in expected_subkeys:
+                        if sub_key not in current_data:
+                            missing_fields.append(f"{top_key}.{sub_key}")
+
+        # 检查空值的递归函数
+        def find_empty_fields(data, parent_path='', empty_fields=None):
+            if empty_fields is None:
+                empty_fields = set()
+            if isinstance(data, dict):
+                for key, value in data.items():
+                    new_path = f"{parent_path}.{key}" if parent_path else key
+                    # 检查当前值是否为空
+                    if value is None:
+                        empty_fields.add(new_path)
+                    elif isinstance(value, str) and value.strip() == '':
+                        empty_fields.add(new_path)
+                    elif isinstance(value, (list, dict)) and not value:
+                        empty_fields.add(new_path)
+                    # 递归检查子元素
+                    find_empty_fields(value, new_path, empty_fields)
+            elif isinstance(data, list):
+                if not data:  # 空列表
+                    empty_fields.add(parent_path)
+            else:
+                # 检查字符串是否为空
+                if isinstance(data, str) and data.strip() == '':
+                    empty_fields.add(parent_path)
+            return empty_fields
+        # 查找所有空值路径
+        empty_paths = find_empty_fields(self.data_dict)
+        return missing_fields, empty_paths
+
     def dict_standard(self):
 
         dict_chiller_cooling = self.data_dict['chillerConfigInfo']

+ 31 - 31
data_initialize_standard/results.py

@@ -2,37 +2,37 @@ import datetime
 import numpy as np
 
 
-def DictResultsNull(dict_chiller_outer, dict_chiller_inner, dict_code, results_depict):
-    if isinstance(dict_code['triggerTime'], str):
-        trigger_time = dict_code['triggerTime']
-    else:
-        trigger_time = dict_code['triggerTime'].strftime("%Y-%m-%d %H:%M:%S")
-    resultsOutput = {'userName': dict_chiller_outer['userName'],
-                     'coolingStationName': dict_chiller_outer['coolingStationName'],
-                     'chillerName': dict_chiller_outer['chillerName'],
-                     'chillerId': dict_chiller_outer['chillerId'],
-                     'isOrder': False,
-                     'waterTempSetNew': None,
-                     'controlMode': dict_code['controlMode'],
-                     'energyMode': dict_code['energyMode'],
-                     # 'triggerTime': dict_code['triggerTime'].strftime("%Y-%m-%d %H:%M:%S"),
-                     'triggerTime': trigger_time,
-                     'isHardwareControl': dict_code['isHardwareControl'],
-                     'runStatus': dict_chiller_inner['runStatus'][-1],
-                     'chillerWaterTempOut': dict_chiller_inner['chillerWaterTempOut'][-1],
-                     'chillerWaterTempSet': dict_chiller_inner['chillerWaterTempSet'],
-                     'chillerWaterTempSetUpper': dict_chiller_inner['chillerWaterTempSetUpper'],
-                     'ahuName': [],
-                     'tempReal': [],
-                     'humiReal': [],
-                     'dewTempReal': [],
-                     'tempLimit': [],
-                     'humiLimit': [],
-                     'dewTempLimit': [],
-                     'worstTerminalInfo': {},
-                     'resultsDepict': results_depict
-                     }
-    return resultsOutput
+# def DictResultsNull(dict_chiller_outer, dict_chiller_inner, dict_code, results_depict):
+#     if isinstance(dict_code['triggerTime'], str):
+#         trigger_time = dict_code['triggerTime']
+#     else:
+#         trigger_time = dict_code['triggerTime'].strftime("%Y-%m-%d %H:%M:%S")
+#     resultsOutput = {'userName': dict_chiller_outer['userName'],
+#                      'coolingStationName': dict_chiller_outer['coolingStationName'],
+#                      'chillerName': dict_chiller_outer['chillerName'],
+#                      'chillerId': dict_chiller_outer['chillerId'],
+#                      'isOrder': False,
+#                      'waterTempSetNew': None,
+#                      'controlMode': dict_code['controlMode'],
+#                      'energyMode': dict_code['energyMode'],
+#                      # 'triggerTime': dict_code['triggerTime'].strftime("%Y-%m-%d %H:%M:%S"),
+#                      'triggerTime': trigger_time,
+#                      'isHardwareControl': dict_code['isHardwareControl'],
+#                      'runStatus': dict_chiller_inner['runStatus'][-1],
+#                      'chillerWaterTempOut': dict_chiller_inner['chillerWaterTempOut'][-1],
+#                      'chillerWaterTempSet': dict_chiller_inner['chillerWaterTempSet'],
+#                      'chillerWaterTempSetUpper': dict_chiller_inner['chillerWaterTempSetUpper'],
+#                      'ahuName': [],
+#                      'tempReal': [],
+#                      'humiReal': [],
+#                      'dewTempReal': [],
+#                      'tempLimit': [],
+#                      'humiLimit': [],
+#                      'dewTempLimit': [],
+#                      'worstTerminalInfo': {},
+#                      'resultsDepict': results_depict
+#                      }
+#     return resultsOutput
 
 
 def DictResultsNormal(is_suction_with_liquid, is_control, results_depict, water_temp_set_new, dict_chiller_inner,

+ 21 - 14
service/public_method.py

@@ -34,24 +34,37 @@ class PublicMethodClass(ControlPeriodStepAdjust):
     #     Num = self.ds.null_judge()
     #     return dict_back_useless, Num
 
-    def output_abnormal_situation(self, Num, is_control=1):
+    def output_abnormal_situation(self, missing_fields, empty_paths, is_control=1):
         """
         异常情况的输出
-        :param Num:
+        :param missing_fields: 缺失字段列表
+        :param empty_paths: 空值对应字段列表
         :param is_control:
         :return:
         """
-        if Num > 0:
-            self.results_depict = '输入参数存在空值,无计算结果'
-        elif self.dict_code['controlMode'] == 0:
+        # if Num > 0:
+        #     self.results_depict = '输入参数存在空值,无计算结果'
+        # elif self.dict_code['controlMode'] == 0:
+        #     self.results_depict = '智控开关状态关闭,无计算结果'
+        # elif is_control == 0:
+        #     self.results_depict = '距上次下发指令周期太短,无计算结果'
+        # else:
+        #     self.results_depict = '输入参数错误,无计算结果'
+        # logger.critical("============%s============" % self.results_depict)
+        # self.dict_results = DictResultsNull(self.dict_chiller_outer, self.dict_chiller_inner, self.dict_code,
+        #                                     self.results_depict)
+        if self.dict_input['controlConfigInfo']['controlMode'] == 0:
             self.results_depict = '智控开关状态关闭,无计算结果'
+        elif missing_fields:
+            self.results_depict = '输入数据存在缺失字段,无计算结果,缺失的字段:%s' % missing_fields
+        elif empty_paths:
+            self.results_depict = '输入数据存在空值,无计算结果,空值的字段:' + str(empty_paths)
         elif is_control == 0:
             self.results_depict = '距上次下发指令周期太短,无计算结果'
         else:
-            self.results_depict = '输入参数错误,无计算结果'
+            self.results_depict = '智控开关输入参数错误,无计算结果'
         logger.critical("============%s============" % self.results_depict)
-        self.dict_results = DictResultsNull(self.dict_chiller_outer, self.dict_chiller_inner, self.dict_code,
-                                            self.results_depict)
+        self.dict_results = DictResultsAbnormal(self.dict_input, self.results_depict)
         return None
 
     def output_normal_situation(self, is_safety_issue):
@@ -225,11 +238,5 @@ class PublicMethodClass(ControlPeriodStepAdjust):
             self.water_temp_set_new = None
             self.results_depict = '算法智控状态输入错误'
             logger.critical('============算法智控状态输入错误============')
-        # if self.water_temp_set_new:
-        #     # 水温设定值校验
-        #     self.water_temp_set_new = round(self.water_temp_set_new, 1)
-        #     self.water_temp_set_verify(self.terminal_cal)
-        #     # 判断是否要调节水温
-        #     self.is_adjust_judge()
         return self.water_temp_set_new
 

+ 11 - 12
service/standard_service.py

@@ -8,23 +8,22 @@ from logs.logger import *
 class StandardService(PublicMethodClass):
     def __init__(self, dict_input):
         super(StandardService, self).__init__(dict_input)
+        self.dict_input = dict_input
 
     def main_multi_comp_service(self):
+        # 数据校核
+        logger.critical("============开始对输入数据进行完整性校验============")
         self.ds = DataStandardization(self.dict_input)
-        Num = self.ds.null_judge()
-        self.dict_chiller_inner, self.dict_chiller_outer, self.dict_code, self.dict_upper_correct, \
-            self.data_temp_humi = self.ds.data_multi_comp()
-
-        # 获取数据
-        # 数据处理
+        missing_fields, empty_paths = self.ds.check_data()
 
         # 判断输入数据是否满足计算条件,且智控开关开启
-
-        if Num > 0 or self.dict_code['controlMode'] != 1:
-            self.output_abnormal_situation(Num)
-
-        # 数据处理正常,开启计算
+        if missing_fields or empty_paths or self.dict_input['controlConfigInfo']['controlMode'] != 1:
+            self.output_abnormal_situation(missing_fields, empty_paths)
         else:
+            logger.critical("============输入数据完整性校验通过============")
+            # 数据校核正常,开启计算
+            self.dict_chiller_inner, self.dict_chiller_outer, self.dict_code, self.dict_upper_correct, \
+            self.data_temp_humi = self.ds.data_multi_comp()
             # 运行安全校验
             logger.critical("============开始设备安全运行校验============")
             mcsv = MultiCompSafetyVerify(self.dict_chiller_inner, self.dict_upper_correct)
@@ -54,5 +53,5 @@ class StandardService(PublicMethodClass):
                         self.is_adjust_judge()
                 self.output_normal_situation(is_safety_issue)
             else:
-                self.output_abnormal_situation(Num, is_control)
+                self.output_abnormal_situation(missing_fields, empty_paths, is_control)
         return self.dict_results