Преглед изворни кода

六号机组坯实绩(测试版)

oldwine пре 5 месеци
родитељ
комит
4ef7896381
3 измењених фајлова са 53 додато и 21 уклоњено
  1. 5 4
      models/billet_counter.py
  2. 14 12
      models/billet_trace_pusher.py
  3. 34 5
      models/data_sender.py

+ 5 - 4
models/billet_counter.py

@@ -177,7 +177,7 @@ class Counter:
 
     def begin_cutting_action(self, i):
         # 写入日志
-        self.logger.info(f'[Counter]{i+1}流:开始切割')
+        # self.logger.info(f'[Counter]{i+1}流:开始切割')
 
         # 计入模块
         sizing = self.length_cutting[i].data
@@ -192,7 +192,7 @@ class Counter:
 
     def end_cutting_action(self, i):
         # 写入日志
-        self.logger.info(f'[Counter]{i+1}流:完成切割')
+        # self.logger.info(f'[Counter]{i+1}流:完成切割')
 
         # 复位流状态
         cutting_state_heat = self.cutting_state_heat[i]
@@ -248,7 +248,7 @@ class Counter:
             # 生成坯号,使用sender向外发送信号
             ccmNo = heatData['ccmNo']
             billetNo = heatData['heatNo'] + ccmNo + str(sno) + '{:0>2}'.format(strandIndex)
-            self.logger.info(f"[Counter]{sno}流:{heatData['heatNo']}炉第{heatIndex}根计入系统,坯号:{billetNo}")
+            # self.logger.info(f"[Counter]{sno}流:{heatData['heatNo']}炉第{heatIndex}根计入系统,坯号:{billetNo}")
 
             # [坯号, 炉次信息, 定尺, 拉速, 开浇时间, 停浇时间]
             self.send_list[sno-1] = [billetNo, heatData, sizing, speed, time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())]
@@ -259,7 +259,8 @@ class Counter:
                 pass
                 # self.sender.heat_first(heatData)
         else:
-            self.logger.info(f"[Counter]{sno}流:未知炉第{heatIndex}根,本炉无法计入系统,下一炉开始正常")
+            pass
+            # self.logger.info(f"[Counter]{sno}流:未知炉第{heatIndex}根,本炉无法计入系统,下一炉开始正常")
 
 
     def start_limit(self):

+ 14 - 12
models/billet_trace_pusher.py

@@ -261,6 +261,16 @@ class Trace_pusher:
 
 
     def billet_union(self, billets):
+        if self.sizing_count_heatNo != self.current_heatNo:
+            self.sizing_count_heatNo = self.current_heatNo
+            self.sizing_count = {}
+
+        if billets[0][2] not in self.sizing_count:
+            self.sizing_count[billets[0][2]] = 0
+
+        self.sizing_count[billets[0][2]] += 1
+        billet_unionNo = self.current_heatNo + '{:0>5}'.format(int(billets[0][2])) + '{:0>2}'.format(self.sizing_count[billets[0][2]])
+
         billetsNo = []
         ccmNo = self.current_heatData['ccmNo'] if self.current_heatData else '0'
         for i in billets:
@@ -270,18 +280,10 @@ class Trace_pusher:
             billetNo = self.current_heatNo + ccmNo + strandNo + '{:0>2}'.format(self.strand[int(strandNo)-1])
             billetsNo.append(billetNo)
             if self.current_heatData:
-                self.sender.billet_upload(self.current_heatData, billetNo, self.total, i[2], i[3], i[4], i[5])
+                self.sender.billet_upload(self.current_heatData, billetNo, self.total, i[2], i[3], i[4], i[5], billet_unionNo)
         
-        if self.sizing_count_heatNo != self.current_heatNo:
-            self.sizing_count_heatNo = self.current_heatNo
-            self.sizing_count = {}
-
-        if billets[0][2] not in self.sizing_count:
-            self.sizing_count[billets[0][2]] = 0
-
-        self.sizing_count[billets[0][2]] += 1
-
-        billet_unionNo = self.current_heatNo + '{:0>5}'.format(int(billets[0][2])) + '{:0>2}'.format(self.sizing_count[billets[0][2]])
+        if self.current_heatData:
+            self.sender.billet_union(self.current_heatData, billet_unionNo, billetsNo, int(billets[0][2]))
 
         self.logger.info(f"{self.current_heatNo}炉组号{billet_unionNo}钢坯{len(billets)}根:\n    {'、'.join(billetsNo)}")
 
@@ -314,7 +316,7 @@ class Trace_pusher:
         self.total += 1
         self.strand[int(strandNo)-1] += 1
         billetNo = self.current_heatNo + ccmNo + strandNo + '{:0>2}'.format(self.strand[int(strandNo)-1])
-        self.sender.billet_upload(self.current_heatData, billetNo, self.total, i[2], i[3], i[4], i[5])
+        self.sender.billet_upload(self.current_heatData, billetNo, self.total, i[2], i[3], i[4], i[5], '')
 
         self.logger.info(f"{self.current_heatNo}炉钢坯热送:{billetNo}")
 

+ 34 - 5
models/data_sender.py

@@ -8,7 +8,8 @@ class Sender:
 
         self.topic = {
             'billet_add': 'trace/performance/billet/add',
-            'heat_add': 'trace/performance/converter/add'
+            'heat_add': 'trace/performance/converter/add',
+            'billet_union': 'trace/billet/billetAssemblyNumber/add'
         }
 
         self.url = {
@@ -52,7 +53,19 @@ class Sender:
             'thickness'         : 170,
             'weight'            : 0.0,
             'cutStartTime'      : '',
-            'cutStopTime'       : ''
+            'cutStopTime'       : '',
+            'assemblyNumber'    : ''
+        }
+
+        self.billet_union_temp = {
+            "ccmNo": 0,             # 铸机号 int数值类型
+            "heatNo": "",           # 炉号	 字符串类型
+            "billetsNo": "",        # 坯号集合 字符串类型 逗号隔开
+            "assemblyNumber": "",   # 组坯号  字符串类型
+            "assemblyTime": "",     # 组坯时间  Date日期类型
+            "length": 0,            # 定尺	 int数值类型
+            "billetsNum": 0,        # 钢坯数量 int数值类型
+            "billetWeight": 0       # 钢坯坯重  double高精度数值类型
         }
 
         self.mqtt_cli = None
@@ -72,7 +85,7 @@ class Sender:
         self.logger.info(f"[SENDER]使用 {'MQTT'if self.mqtt_cli else ''} {'HTTP'if self.http_flag else ''} 发送数据")
         self.logger.debug(f"[SENDER]{purpose}:{payload}")
         
-        if self.mqtt_cli:
+        if self.mqtt_cli and purpose in self.topic:
             if not self.mqtt_cli.is_connected:
                 self.logger.error('[SENDER]MQTT:发送失败,MQTT未连接')
 
@@ -81,7 +94,7 @@ class Sender:
             else:
                 self.logger.info('[SENDER]MQTT:数据包发送成功')
 
-        if self.http_flag:
+        if self.http_flag and purpose in self.url:
             try:
                 self.logger.debug('[SENDER]HTTP:'+requests.post(self.url[purpose], json=payload, timeout=2).text)
             except:
@@ -181,7 +194,7 @@ class Sender:
         self._billet[heat_data.get('heatNo', '')+str(heatnoIndex)] = tmp
         self.send('billet_add', tmp)
 
-    def billet_upload(self, heat_data, billetNo, heatnoIndex, sizing, speed, starttime, stoptime):
+    def billet_upload(self, heat_data, billetNo, heatnoIndex, sizing, speed, starttime, stoptime, unionNo):
         tmp = self.billet_tangible_temp.copy()
         tmp['optype'] = 1
         tmp['heatNo'] = heat_data.get('heatNo', '')
@@ -198,10 +211,26 @@ class Sender:
         tmp['weight'] = sizing / 1000 * 0.2265
         tmp['cutStartTime'] = starttime
         tmp['cutStopTime'] = stoptime
+        tmp['assemblyNumber'] = unionNo
 
         #此处应存储进数据库
         self.send('billet_add', tmp)
 
+    def billet_union(self, heat_data, unionNo, billetNos, sizing):
+        tmp = self.billet_union_temp.copy()
+        
+        tmp['ccmNo'] = heat_data.get('ccmNo', '')
+        tmp['heatNo'] = heat_data.get('heatNo', '')
+        tmp['billetsNo'] = ','.join(billetNos)
+        tmp['assemblyNumber'] = unionNo
+        tmp['assemblyTime'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
+        tmp['length'] = sizing
+        tmp['billetsNum'] = len(billetNos)
+        tmp['billetWeight'] = sizing / 1000 * 0.2265 * tmp['billetsNum']
+
+        #此处应存储进数据库
+        self.send('billet_union', tmp)
+
 if __name__ == '__main__':
     mqttcli = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2, 'python-mqtt-992-sender_test')
     mqttcli.username_pw_set('admin', '123456')