初稿
This commit is contained in:
commit
5051c5d71f
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
8
.idea/HM.iml
Normal file
8
.idea/HM.iml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
37
.idea/inspectionProfiles/Project_Default.xml
Normal file
37
.idea/inspectionProfiles/Project_Default.xml
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="HttpUrlsUsage" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoredUrls">
|
||||||
|
<list>
|
||||||
|
<option value="http://localhost" />
|
||||||
|
<option value="http://127.0.0.1" />
|
||||||
|
<option value="http://0.0.0.0" />
|
||||||
|
<option value="http://www.w3.org/" />
|
||||||
|
<option value="http://json-schema.org/draft" />
|
||||||
|
<option value="http://java.sun.com/" />
|
||||||
|
<option value="http://xmlns.jcp.org/" />
|
||||||
|
<option value="http://javafx.com/javafx/" />
|
||||||
|
<option value="http://javafx.com/fxml" />
|
||||||
|
<option value="http://maven.apache.org/xsd/" />
|
||||||
|
<option value="http://maven.apache.org/POM/" />
|
||||||
|
<option value="http://www.springframework.org/schema/" />
|
||||||
|
<option value="http://www.springframework.org/tags" />
|
||||||
|
<option value="http://www.springframework.org/security/tags" />
|
||||||
|
<option value="http://www.thymeleaf.org" />
|
||||||
|
<option value="http://www.jboss.org/j2ee/schema/" />
|
||||||
|
<option value="http://www.jboss.com/xml/ns/" />
|
||||||
|
<option value="http://www.ibm.com/webservices/xsd" />
|
||||||
|
<option value="http://activemq.apache.org/schema/" />
|
||||||
|
<option value="http://schema.cloudfoundry.org/spring/" />
|
||||||
|
<option value="http://schemas.xmlsoap.org/" />
|
||||||
|
<option value="http://cxf.apache.org/schemas/" />
|
||||||
|
<option value="http://primefaces.org/ui" />
|
||||||
|
<option value="http://tiles.apache.org/" />
|
||||||
|
<option value="http://httpbin.org" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="PyPep8Inspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
4
.idea/misc.xml
Normal file
4
.idea/misc.xml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/HM.iml" filepath="$PROJECT_DIR$/.idea/HM.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
14
db_connection.py
Normal file
14
db_connection.py
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# Author: Lee Wu Love Lele
|
||||||
|
# Datetime: 2024/9/7 21:20
|
||||||
|
import mysql.connector
|
||||||
|
|
||||||
|
# 连接 MySQL 数据库
|
||||||
|
connection = mysql.connector.connect(
|
||||||
|
host="rm-bp1442up0e0nlz95szo.mysql.rds.aliyuncs.com",
|
||||||
|
user="rhm_read_only",
|
||||||
|
password="aA123456+",
|
||||||
|
database="rhm_insure_dev"
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_connection():
|
||||||
|
return connection
|
||||||
26
db_dao.py
Normal file
26
db_dao.py
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
# Author: Lee Wu Love Lele
|
||||||
|
# Datetime: 2024/9/7 21:28
|
||||||
|
import db_connection
|
||||||
|
|
||||||
|
# 创建游标对象
|
||||||
|
connection = db_connection.get_connection()
|
||||||
|
cursor = connection.cursor()
|
||||||
|
weight_group_name = "subjectCallback"
|
||||||
|
rfid_group_name = "rfidCallback"
|
||||||
|
# 根据起止日期获取牛只体重信息
|
||||||
|
def get_cattle_weight_by_datetime(start_datetime, end_datetime, reader):
|
||||||
|
query = f"SELECT biz_time, biz_data FROM rhm_insure_dev.notify_log WHERE notify_group = '{weight_group_name}' AND reader_name = '{reader}' AND biz_time BETWEEN '{start_datetime}' AND '{end_datetime}' ORDER BY biz_time ASC"
|
||||||
|
cursor.execute(query)
|
||||||
|
result = cursor.fetchall()
|
||||||
|
return result
|
||||||
|
|
||||||
|
def get_rfid_by_datetime(start_datetime,end_datetime,reader):
|
||||||
|
query = f"SELECT biz_time, biz_data FROM rhm_insure_dev.notify_log WHERE notify_group = '{rfid_group_name}' AND reader_name = '{reader}' AND biz_time BETWEEN '{start_datetime}' AND '{end_datetime}' ORDER BY biz_time ASC"
|
||||||
|
cursor.execute(query)
|
||||||
|
result = cursor.fetchall()
|
||||||
|
print(query)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def close():
|
||||||
|
cursor.close()
|
||||||
|
connection.close()
|
||||||
102
main.py
Normal file
102
main.py
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
# This is a sample Python script.
|
||||||
|
|
||||||
|
# Press ⌃R to execute it or replace it with your code.
|
||||||
|
# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings.
|
||||||
|
import db_dao as dd
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
import matplotlib.dates as mdates
|
||||||
|
import pandas as pd
|
||||||
|
from datetime import datetime,timedelta
|
||||||
|
|
||||||
|
m_weight = []
|
||||||
|
m_datetime = []
|
||||||
|
m_start_time = '2024-09-09 06:50:00'
|
||||||
|
m_end_time = '2024-09-09 07:10:00'
|
||||||
|
# m_reader = '2405085412' # 客户看不到视频
|
||||||
|
m_weighbridge_reader = '2405085474' # 客户可以看到设备
|
||||||
|
# m_reader = '2404049517'
|
||||||
|
# m_reader = '2405085489'
|
||||||
|
|
||||||
|
m_rfid_reader = '0A26AE180665' # 对应地磅的 2405085474
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
date_format = "%Y-%m-%d %H:%M:%S"
|
||||||
|
# Press the green button in the gutter to run the script.
|
||||||
|
|
||||||
|
|
||||||
|
# 创建查询时间范围的序列
|
||||||
|
def create_timestamp_seq():
|
||||||
|
# 将起止时间转换为 datetime 对象
|
||||||
|
m_datetime_start_obj = datetime.strptime(m_start_time, date_format)
|
||||||
|
m_datetime_end_obj = datetime.strptime(m_end_time, date_format)
|
||||||
|
|
||||||
|
# 计算时间差并转为秒数
|
||||||
|
time_diff = m_datetime_end_obj - m_datetime_start_obj
|
||||||
|
seconds = time_diff.total_seconds()+1
|
||||||
|
|
||||||
|
# 创建时间序列,单位为秒
|
||||||
|
start_time = pd.Timestamp(m_start_time)
|
||||||
|
time_seconds_seq = pd.date_range(start=start_time, periods=int(seconds), freq='s') # 生成日期差秒数个时间点,每个时间点间隔1秒
|
||||||
|
return time_seconds_seq
|
||||||
|
|
||||||
|
# 补充缺失的时间秒数
|
||||||
|
def time_data_suppl(timestamp,data):
|
||||||
|
i = 1
|
||||||
|
sorted_data = []
|
||||||
|
for ts in timestamp:
|
||||||
|
format_ts = ts.strftime(date_format)
|
||||||
|
if format_ts not in data:
|
||||||
|
sorted_data.append(0)
|
||||||
|
else:
|
||||||
|
sorted_data.append(float(data[format_ts]))
|
||||||
|
# print(str(i)+' 存在数据:'+format_ts+' ------> '+data[format_ts])
|
||||||
|
i += 1
|
||||||
|
return sorted_data
|
||||||
|
|
||||||
|
# 对相同时间的数据去重复,取体重最大值
|
||||||
|
def time_data_dedup(data):
|
||||||
|
result_dict = {}
|
||||||
|
for row in data:
|
||||||
|
key = row[0].strftime(date_format)
|
||||||
|
if key not in result_dict or float(row[1]) > float(result_dict[key]):
|
||||||
|
result_dict[key] = float(row[1])
|
||||||
|
|
||||||
|
return result_dict
|
||||||
|
|
||||||
|
# rfid数据去重
|
||||||
|
def rfid_data_dedup(data):
|
||||||
|
# 保留顺序的去重方法
|
||||||
|
seen = set()
|
||||||
|
unique_tuple_list = []
|
||||||
|
for item in data:
|
||||||
|
if item not in seen:
|
||||||
|
unique_tuple_list.append(item)
|
||||||
|
seen.add(item)
|
||||||
|
return unique_tuple_list
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
timestamp_seq = create_timestamp_seq()
|
||||||
|
mysql_weight_result = dd.get_cattle_weight_by_datetime(m_start_time, m_end_time, m_weighbridge_reader)
|
||||||
|
mysql_rfid_result = dd.get_rfid_by_datetime(m_start_time, m_end_time, m_rfid_reader)
|
||||||
|
dd.close()
|
||||||
|
clean_weight_result = time_data_dedup(mysql_weight_result)
|
||||||
|
clean_rfid_result = rfid_data_dedup(mysql_rfid_result)
|
||||||
|
|
||||||
|
final_weight_result = time_data_suppl(timestamp_seq, clean_weight_result)
|
||||||
|
plt.figure(figsize=(24, 4))
|
||||||
|
plt.plot(timestamp_seq, final_weight_result, color='blue', linestyle='-', linewidth=1)
|
||||||
|
|
||||||
|
for rst in clean_rfid_result:
|
||||||
|
# 添加纵向分割线
|
||||||
|
plt.axvline(x=rst[0], color='r', linestyle='--', label=rst[1], linewidth = 0.5)
|
||||||
|
|
||||||
|
# 添加图例
|
||||||
|
plt.legend()
|
||||||
|
|
||||||
|
|
||||||
|
plt.xlabel('datetime')
|
||||||
|
plt.ylabel('weight(kg)')
|
||||||
|
plt.title('reader: ' + m_weighbridge_reader + '\n' + m_start_time + ' ---> ' + m_end_time)
|
||||||
|
plt.show()
|
||||||
Loading…
Reference in New Issue
Block a user