main.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import numpy as np
  2. import pandas as pd
  3. from MIDDLE.SaftyCenter.Common import FeiShuData
  4. from MIDDLE.SaftyCenter.Common import DBDownload
  5. import time, datetime
  6. from pandas.core.frame import DataFrame
  7. from apscheduler.schedulers.blocking import BlockingScheduler
  8. from DataStatistics import DataSta
  9. #............................主程序...................................
  10. def Week_Task():
  11. all_period_fault_info=DataFrame(columns=['factory','week','level1_count','level2_count','level3_count','level4_count','level5_count','solve_rate'])
  12. #............................获取数据................................
  13. toweek='Week'+time.strftime('%W')
  14. CS_Data=FeiShuData.getFeiShuDATA()
  15. host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
  16. port=3306
  17. db='safety_platform'
  18. user='qx_read'
  19. password='Qx@123456'
  20. mode=2
  21. tablename1='all_fault_info'
  22. DBRead=DBDownload.DBDownload(host, port, db, user, password,mode)
  23. with DBRead as DBRead:
  24. df_fltinfo=DBRead.getdata('product_id','level','code','start_time',tablename=tablename1,factory='骑享',sn='',timename='',st='',sp='')#dbdownload经过了改编
  25. #............................获取时间................................
  26. end_time=datetime.datetime.now()
  27. # end_time=datetime.datetime.strptime(end_time,'%Y-%m-%d')
  28. start_time=end_time-datetime.timedelta(days=7)
  29. start_time=start_time.strftime('%Y-%m-%d')
  30. end_time=end_time.strftime('%Y-%m-%d')
  31. FltAlarmInfo,Celltype=DataSta.SaftyWarningSta(CS_Data,df_fltinfo,start_time,end_time)
  32. FaultLvlCount=DataSta.WeekInfoSta(df_fltinfo,start_time,end_time)
  33. lvl1=FaultLvlCount[FaultLvlCount['level']==1]['product_id'].values
  34. lvl2=FaultLvlCount[FaultLvlCount['level']==2]['product_id'].values
  35. lvl3=FaultLvlCount[FaultLvlCount['level']==3]['product_id'].values
  36. lvl4=FaultLvlCount[FaultLvlCount['level']==4]['product_id'].values
  37. lvl5=FaultLvlCount[FaultLvlCount['level']==5]['product_id'].values
  38. all_period_fault_info.loc[0,'factory']='骑享'
  39. all_period_fault_info.loc[0,'week']=toweek
  40. all_period_fault_info.loc[0,'level1_count']=lvl1
  41. all_period_fault_info.loc[0,'level2_count']=lvl2
  42. all_period_fault_info.loc[0,'level3_count']=lvl3
  43. all_period_fault_info.loc[0,'level4_count']=lvl4
  44. all_period_fault_info.loc[0,'level5_count']=lvl5
  45. all_period_fault_info.loc[0,'solve_rate']=FltAlarmInfo.loc[0,'OprationManageRate']
  46. def Minutes_Task():
  47. #............................获取数据................................
  48. host='172.16.121.236'
  49. port=3306
  50. db='fastfun'
  51. user='readonly'
  52. password='Fast1234'
  53. mode=3
  54. tablename1='ff_battery_accum'
  55. DBRead=DBDownload.DBDownload(host, port, db, user, password,mode)
  56. with DBRead as DBRead:
  57. df_last_accum=DBRead.getdata('devcode','dsg_phaccum','dsg_ahaccum',tablename=tablename1,factory='',sn='',timename='',st='',sp='')#dbdownload经过了改编
  58. host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
  59. port=3306
  60. db='qx_cas'
  61. user='qx_read'
  62. password='Qx@123456'
  63. mode=3
  64. tablename2='bat_first_data_time'
  65. DBRead=DBDownload.DBDownload(host, port, db, user, password,mode)
  66. with DBRead as DBRead:
  67. df_FirstDataTime=DBRead.getdata('sn','first_data_time',tablename=tablename2,factory='',sn='',timename='',st='',sp='')#dbdownload经过了改编
  68. CS_Data=FeiShuData.getFeiShuDATA()
  69. host='rm-bp10j10qy42bzy0q77o.mysql.rds.aliyuncs.com'
  70. port=3306
  71. db='safety_platform'
  72. user='qx_read'
  73. password='Qx@123456'
  74. mode=2
  75. tablename1='all_fault_info'
  76. DBRead=DBDownload.DBDownload(host, port, db, user, password,mode)
  77. with DBRead as DBRead:
  78. df_fltinfo=DBRead.getdata('product_id','level','code','start_time',tablename=tablename1,factory='骑享',sn='',timename='',st='',sp='')#dbdownload经过了改编
  79. #............................获取时间................................
  80. end_time=datetime.datetime.now()
  81. # end_time=datetime.datetime.strptime(end_time,'%Y-%m-%d')
  82. start_time=end_time-datetime.timedelta(days=1)
  83. start_time=start_time.strftime('%Y-%m-%d')
  84. end_time=end_time.strftime('%Y-%m-%d')
  85. #............................执行程序................................
  86. FltAlarmInfo,Celltype=DataSta.SaftyWarningSta(CS_Data,df_fltinfo,start_time,end_time)
  87. SatftyCount=DataSta.SftyWrngClsfy(df_fltinfo)
  88. MaxAccumAh,TotalAccumAh,MaxCycle,MaxRunningHour,TotalRunHour=DataSta.AccumInfo(df_last_accum,df_FirstDataTime,end_time)
  89. all_statistic_info=DataFrame(columns=['factory','total_alarm','alarm_total_today','alarm_not_close_today','alarm_close_today','alarm_uregent_total_today','alarm_uregent_close_today','alarm_uregent_not_close_today','alarm_close_total','run_time_total','dischrg_total','odo_total','max_dischrg_one','max_runtime_one','max_cycle_one','max_odo_one','alarm_close_total','alarm_total','cell_type','cell_type_count','cell_safety_risk_count','data_safety_risk_count','status_safety_risk_count','hv_safety_risk_count','system_safety_risk_count','sample_safety_risk_count','controller_safety_risk_count','design_safety_risk_count'])
  90. all_statistic_info.loc[0,'factory']='骑享'
  91. all_statistic_info.loc[0,'total_alarm']=FltAlarmInfo.loc[0,'SftyPlt_Data_Total']
  92. all_statistic_info.loc[0,'alarm_total_today']=FltAlarmInfo.loc[0,'SftyPlt_Data_day']
  93. all_statistic_info.loc[0,'alarm_close_today']=FltAlarmInfo.loc[0,'CS_Warning_day_Finish_Count']
  94. all_statistic_info.loc[0,'alarm_not_close_today']=FltAlarmInfo.loc[0,'SftyPlt_Data_day']-FltAlarmInfo.loc[0,'CS_Warning_day_Finish_Count']
  95. all_statistic_info.loc[0,'alarm_uregent_total_today']=FltAlarmInfo.loc[0,'SftyPlt_EmgcyData_day']
  96. all_statistic_info.loc[0,'alarm_uregent_close_today']=FltAlarmInfo.loc[0,'SftyPlt_EmgcyData_day_Finish_Count']
  97. all_statistic_info.loc[0,'alarm_uregent_not_close_today']=FltAlarmInfo.loc[0,'SftyPlt_EmgcyData_day']-FltAlarmInfo.loc[0,'SftyPlt_EmgcyData_day_Finish_Count']
  98. all_statistic_info.loc[0,'run_time_total']=TotalRunHour
  99. all_statistic_info.loc[0,'dischrg_total']=TotalAccumAh
  100. all_statistic_info.loc[0,'odo_total']=0
  101. all_statistic_info.loc[0,'max_dischrg_one']=MaxAccumAh
  102. all_statistic_info.loc[0,'max_runtime_one']=MaxRunningHour
  103. all_statistic_info.loc[0,'max_cycle_one']=MaxCycle
  104. all_statistic_info.loc[0,'max_odo_one']=0
  105. all_statistic_info.loc[0,'alarm_close_total']=FltAlarmInfo.loc[0,'CS_Warning_Total_Finish_Count']
  106. all_statistic_info.loc[0,'alarm_total']=FltAlarmInfo.loc[0,'SftyPlt_Data_Total']
  107. CellType=Celltype.columns.tolist()
  108. CellType=','.join(CellType)
  109. all_statistic_info.loc[0,'cell_type']=str(CellType)
  110. CellTypeCount=str(Celltype.loc[0].values)
  111. CellTypeCount=''.join(CellTypeCount)
  112. all_statistic_info.loc[0,'cell_type_count']=str(CellTypeCount)
  113. all_statistic_info.loc[0,'cell_safety_risk_count']=SatftyCount.loc[0,'CellSaftyCount']
  114. all_statistic_info.loc[0,'data_safety_risk_count']=SatftyCount.loc[0,'DataSaftyCodeCount']
  115. all_statistic_info.loc[0,'status_safety_risk_count']=SatftyCount.loc[0,'StateSaftyCodeCount']
  116. all_statistic_info.loc[0,'hv_safety_risk_count']=SatftyCount.loc[0,'HvSaftyCodeCount']
  117. all_statistic_info.loc[0,'system_safety_risk_count']=SatftyCount.loc[0,'SysSaftyCodeCount']
  118. all_statistic_info.loc[0,'sample_safety_risk_count']=SatftyCount.loc[0,'SamplingSatyCount']
  119. all_statistic_info.loc[0,'controller_safety_risk_count']=SatftyCount.loc[0,'CtrlSaftyCodeCount']
  120. all_statistic_info.loc[0,'design_safety_risk_count']=SatftyCount.loc[0,'DsnSaftyCodeCount']
  121. #定时任务.......................................................................................................................................................................
  122. #Week_Task()
  123. Minutes_Task()
  124. scheduler = BlockingScheduler()
  125. scheduler.add_job(Week_Task, 'interval', days=7, id='Week_Task')
  126. scheduler.add_job(Minutes_Task, 'interval', seconds=300, id='Hour_Task')
  127. try:
  128. scheduler.start()
  129. except Exception as e:
  130. scheduler.shutdown()
  131. print(repr(e))