基于事件序列的数据获取

发布于:2024-09-18 ⋅ 阅读:(63) ⋅ 点赞:(0)

Data Get 
31670 /S

Update 2 AI_PC
3Mins /次

Import "Hggw"
 

PI Data

AA@BB@0@20240908_115221_31781

AA@BB@0@20240908_115521_31781

AA@BB@0@20240908_115821_31781

1、From PIdata Copy 2  AI PC 

2、AI PC UI Chart & Logic OK NG
 


Pump::

 

import pygame  
import os  
import numpy as np  
import random 
import pyautogui
import datetime  
import random  
import time 
from HslCommunication import MelsecMcNet
import pandas as pd

import json
import copy
import requests
import threading

# 初始化pygame  
pygame.init()  
  
# 设置窗口大小和标题  
WINDOW_WIDTH = 1920  
WINDOW_HEIGHT = 1080  
WINDOW_TITLE = "Pump"  
screen = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))  
pygame.display.set_caption(WINDOW_TITLE)  
  
# 设置字体(这里暂时未使用到,但保留以备后用)  
font = pygame.font.Font(r'C:\Windows\fonts\simHei.TTF', 30)
font2 = pygame.font.Font(r'C:\Windows\fonts\simHei.TTF', 23)
font3 = pygame.font.Font(r'C:\Windows\fonts\simHei.TTF', 600)
font6 = pygame.font.Font(r'C:\Windows\fonts\simHei.TTF', 50)
font66 = pygame.font.Font(r'C:\Windows\fonts\simHei.TTF', 90)

# Setting Demo Error
Pump_Error_Bf = pyautogui.prompt('请选择模式,Sample:1,NG Mode',default='0')
Pump_Error=int(Pump_Error_Bf)


# Setting Torndo
Tim_Time_Buffer=pyautogui.prompt('请输入龙卷风报警间隔时间,Sample:600 = 10 Mins ,最大 10 年',default='3')
Tim_Time=int(Tim_Time_Buffer)
print('LJF GAP Second =>',Tim_Time)

#LJF设定
class Tornado():
    def __init__(self, url, jobCat, scene, tag, userId, proxies_http,
                 proxies_https):
        super().__init__()
        self.url = url
        self.proxies_http = proxies_http
        self.proxies_https = proxies_https
        self._body = {
            'userId': userId,
            'desc': '',
            'scene': scene,
            'tag': tag,
            'jobCat': jobCat,
            'jobStatus': 'N'
        }
        self.api_lock = threading.Lock()

    def send_msg(self, desc):
        msg = {'desc': desc}
        _body = copy.deepcopy(self._body)
        _body.update(msg)
        header = {
            "Content-Type": 'application/x-www-form-urlencoded; charset=UTF-8'''
        }
        # For Fab Domain
        proxies = {'http': self.proxies_http, 'https': self.proxies_https}
        self.api_lock.acquire()
        try:
            r_post_ft = requests.post(url=self.url,
                                      data=_body,
                                      headers=header,
                                      proxies=proxies)
            return r_post_ft
        except Exception as ex:
            return ex
        finally:
            self.api_lock.release()

def send_msg(msg, tag=''):
    td_cfg = {
        "url": "http://10.8.15.222/security/SendMsgByTornado",
        "jobCat": "S17_FAB_Alarm",
        "scene": "PAC_LIMIT_ALARM",
        "tag": "OCA",
        "userId": "LAM",
        "proxies_http": "10.9.9.5:8080",
        "proxies_https": "10.9.9.5:8080"
    }

    td = Tornado(**td_cfg)
    return td.send_msg(msg)
    # res = td.send_msg(msg)
    # print(res)


text = "结果"  
text2 = "曲线说明:绿色表示OOC(Out of Control),红色表示OOS(Out of Spec)"  

text3 = "Up Sensor "  
text4 = "Down Sensor" 

text5 = "叶片异常:"  
text6 = "轴承内圈故障:" 
text7 = "轴承外圈故障:"  
text8 = "不对中:" 
text51 = "齿轮磨损:"  
text61 = "齿轮断齿:" 
text71 = "齿轮偏心:"  
text81 = "滚珠损伤:" 
text52 = "轴弯曲:"  
text62 = "不对中:" 

text9 = "OK" 
text999 ="NG"

text10 = "健康度(0.8 以上OK,小于0.8 NG)" 

text14='The Best View 1920 * 1080 '

text100 = "Pump PHM" 
  
# 主循环  
running = True  
clock = pygame.time.Clock()  
  
while running:  
    for event in pygame.event.get():  
        if event.type == pygame.QUIT:  
            running = False  
  
    # 填充背景  
    screen.fill((255, 255, 255))  


##PLC

    nowTime = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3]

##PLC


 
# 定义文件路径  
    file_path = r'D:\PumpData.txt'  
    with open(file_path, 'a', encoding='utf-8') as file:  
        current_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')  
        random_value2 = round(random.uniform(0.216, 0.456), 4)  
        random_value3 = round(random.uniform(0.326, 0.76), 4)  
        random_value4 = round(random.uniform(0.216, 0.456), 4)  
        random_value5 = round(random.uniform(0.326, 0.76), 4)  

        # 构造要写入文件的行  
        line = f'{current_time}\t{random_value2}\t{random_value3}\t{random_value4}\t{random_value5}\n'  
        print(line)  
        # 写入文件  
        file.write(line)  
        file.flush()  # 确保数据被写入磁盘  
          
        # 每0.01秒生成一行数据  
        time.sleep(0.0001)  

        # 读取文件 

    file_path = r"d:\PumpData.txt"  
    if not os.path.exists(file_path):  
        raise FileNotFoundError(f"File {file_path} not found.")  
      
    with open(file_path, 'r', encoding='utf-8') as file:  
        lines = file.readlines()  
      
    # 解析数据,只将第二列和第三列转换为浮点数  
    data = [[line.strip().split('\t')[0], float(line.strip().split('\t')[1]), float(line.strip().split('\t')[2])] for line in lines]  
      
    # 提取日期字符串、第二列和第三列数据(注意:这里我们假设每行至少有三列)  
    x_data = [row[0] for row in data]  # 日期字符串列表  
    y_data1 = [row[1] for row in data]  # 第二列数据(曲线1的y轴数据)  
    y_data2 = [row[2] for row in data]  # 第三列数据(曲线2的y轴数据)  
      
    # 只保留最新的50笔数据  
    x_data = x_data[-300:]  
    y_data1 = y_data1[-300:]  
    y_data2 = y_data2[-300:]  
      
    # 将数据转换为pygame可以使用的格式  
    # 注意:这里我们假设x轴是时间顺序,因此直接使用索引作为x值  
    x_points1 = [(i * WINDOW_WIDTH // len(x_data) + 190, int(WINDOW_HEIGHT - y_data1[i] * 200)) for i in range(len(x_data))]  

    x_points22 = [(i * WINDOW_WIDTH // len(x_data) + 190, int(WINDOW_HEIGHT - 118)) for i in range(len(x_data))]  
    x_points2 = [(i * WINDOW_WIDTH // len(x_data) + 190, int(WINDOW_HEIGHT - 108)) for i in range(len(x_data))]  

    x_points3 = [(i * WINDOW_WIDTH // len(x_data) + 190, int(WINDOW_HEIGHT - 30)) for i in range(len(x_data))]  
    x_points33 = [(i * WINDOW_WIDTH // len(x_data) + 190, int(WINDOW_HEIGHT - 20)) for i in range(len(x_data))]  

 
    x_points4 = [(i * WINDOW_WIDTH // len(x_data) + WINDOW_WIDTH //100 +150, int(WINDOW_HEIGHT - y_data2[i] * 480)) for i in range(len(x_data))]  

    x_points5 = [(i * WINDOW_WIDTH // len(x_data) + WINDOW_WIDTH //100 +150, int(WINDOW_HEIGHT - 388)) for i in range(len(x_data))]  
    x_points55 = [(i * WINDOW_WIDTH // len(x_data) + WINDOW_WIDTH //100 +150, int(WINDOW_HEIGHT -  378)) for i in range(len(x_data))]  

    x_points6 = [(i * WINDOW_WIDTH // len(x_data) + WINDOW_WIDTH //100 +150, int(WINDOW_HEIGHT -  140)) for i in range(len(x_data))]  
    x_points66 = [(i * WINDOW_WIDTH // len(x_data) + WINDOW_WIDTH //100 +150, int(WINDOW_HEIGHT -  130)) for i in range(len(x_data))]    

    # 绘制曲线的颜色  
    COLOR1 = (0, 255, 255)  # 红色  
    COLOR2 = (40, 255, 30)  # 绿色  
    BLACK = (0, 0, 0) 
    Green =(0,255,0)
    COLOR3 =(204,204,255)  #青色
    Yellow =(150, 0, 0)  # 黄色 
    REDD = (190, 0, 0)  # 红色 

  
    # 绘制曲线1  
    pygame.draw.lines(screen, COLOR3, False, x_points1, 2)  

    pygame.draw.lines(screen, Green, False, x_points2, 2)  
    pygame.draw.lines(screen, Yellow, False, x_points22, 2)  

    pygame.draw.lines(screen, Green, False, x_points3, 2)  
    pygame.draw.lines(screen, Yellow, False, x_points33, 2)  


    # 绘制曲线2  
    pygame.draw.lines(screen, COLOR1, False, x_points4, 2)  

    pygame.draw.lines(screen, Yellow, False, x_points5, 2)  
    pygame.draw.lines(screen, Green, False, x_points55, 2)

    pygame.draw.lines(screen, Green, False, x_points6, 2)  
    pygame.draw.lines(screen, Yellow, False, x_points66, 2)  


    # 绘制分割线,这里假设分割线在窗口高度的中间位置  
    pygame.draw.line(screen, BLACK, (0, WINDOW_HEIGHT // 2+100), (WINDOW_WIDTH, WINDOW_HEIGHT // 2+100), 2)

    #文本设定
    t5 = round(random.uniform(0.8, 1), 3) 
    t6 = round(random.uniform(0.8, 1), 3)  
    t7 = round(random.uniform(0.581, 0.787), 3)
    t777 = round(random.uniform(0.8, 1), 3)    
    t8 = round(random.uniform(0.8, 1), 3) 

    t51 = round(random.uniform(0.8, 1), 3) 
    t61 = round(random.uniform(0.8, 1), 3)  
    t71 = round(random.uniform(0.8, 1), 3)
    t81 = round(random.uniform(0.8, 1), 3) 
    t52 = round(random.uniform(0.8, 1), 3) 

    # 计算文本位置和大小  
    text_surface = font.render(text, True, BLACK)  
    text_rect = text_surface.get_rect(center=(WINDOW_WIDTH // 2-890, WINDOW_HEIGHT // 2-5