testing.py 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. import datetime
  2. import time
  3. import warnings
  4. from matplotlib import pyplot as plt
  5. import pandas as pd
  6. from docx import Document
  7. from docx.enum.text import WD_BREAK
  8. from drawing_graphs import GraphsDrawing
  9. from processing_for_report import ProccessingPrismaCl
  10. from word_addition import *
  11. t1 = time.time()
  12. warnings.filterwarnings(action='ignore')
  13. # Следующее должно быть передающимися переменными
  14. start_date = datetime.date(2021, 1, 1)
  15. end_date = datetime.date(2021, 1, 31)
  16. days_amount = len(pd.date_range(start_date, end_date))
  17. process_1 = ProccessingPrismaCl(1, start_date=start_date, end_date=end_date,
  18. path_to_files='D:\\PRISMA20\\P1')
  19. process_2 = ProccessingPrismaCl(2, start_date=start_date, end_date=end_date,
  20. path_to_files='D:\\PRISMA20\\P2')
  21. graphs = GraphsDrawing(start_date=start_date, end_date=end_date,
  22. path_to_pic='C:\\Users\\pad_z\\OneDrive\\Рабочий стол\\PrismaPassport')
  23. worktime_1, breaks_1, n_vs_zero_tr_1, event_counter_fr_4_1, amp_5_fr_2_frame_1, amp_10_fr_1_frame_1, count_rate_amp_5_fr_2_1, count_rate_amp_10_fr_1_1 = process_1.day_proccessing()
  24. worktime_frame_1 = pd.DataFrame(worktime_1)
  25. n_vs_zero_tr_frame_1 = pd.DataFrame(n_vs_zero_tr_1)
  26. breaks_frame_1 = pd.DataFrame(breaks_1)
  27. event_counter_fr_4_1 = pd.DataFrame(event_counter_fr_4_1)
  28. count_rate_amp_5_fr_2_1 = pd.DataFrame(count_rate_amp_5_fr_2_1)
  29. count_rate_amp_10_fr_1_1 = pd.DataFrame(count_rate_amp_10_fr_1_1)
  30. worktime_2, breaks_2, n_vs_zero_tr_2, event_counter_fr_4_2, amp_5_fr_2_frame_2, amp_10_fr_1_frame_2, count_rate_amp_5_fr_2_2, count_rate_amp_10_fr_1_2 = process_2.day_proccessing()
  31. worktime_frame_2 = pd.DataFrame(worktime_2)
  32. n_vs_zero_tr_frame_2 = pd.DataFrame(n_vs_zero_tr_2)
  33. breaks_frame_2 = pd.DataFrame(breaks_2)
  34. event_counter_fr_4_2 = pd.DataFrame(event_counter_fr_4_2)
  35. count_rate_amp_5_fr_2_2 = pd.DataFrame(count_rate_amp_5_fr_2_2)
  36. count_rate_amp_10_fr_1_2 = pd.DataFrame(count_rate_amp_10_fr_1_2)
  37. brake_both_cl_time = 0
  38. for i in range(len(breaks_frame_1.index)):
  39. for j in range(len(breaks_frame_2.index)):
  40. if breaks_frame_1['Date'][i] == breaks_frame_2['Date'][j]:
  41. if breaks_frame_1['StartMinutes'][i] <= breaks_frame_2['StartMinutes'][j] < breaks_frame_1['EndMinutes'][i]:
  42. brake_both_cl_time += min(breaks_frame_2['EndMinutes'][j], breaks_frame_1['EndMinutes'][i]) - max(
  43. breaks_frame_2['StartMinutes'][j], breaks_frame_1['StartMinutes'][i])
  44. elif breaks_frame_2['StartMinutes'][j] <= breaks_frame_1['StartMinutes'][i] < breaks_frame_2['EndMinutes'][
  45. j]:
  46. brake_both_cl_time += min(breaks_frame_2['EndMinutes'][j], breaks_frame_1['EndMinutes'][i]) - max(
  47. breaks_frame_2['StartMinutes'][j], breaks_frame_1['StartMinutes'][i])
  48. real_worktime = worktime_frame_2['Worktime'].sum() - 24 * days_amount + worktime_frame_1[
  49. 'Worktime'].sum() + brake_both_cl_time / 60
  50. print(brake_both_cl_time)
  51. graphs.change_design()
  52. worktime_pic_path_1 = graphs.worktime_graph(cluster=1, worktime_frame=worktime_frame_1)
  53. worktime_pic_path_2 = graphs.worktime_graph(cluster=2, worktime_frame=worktime_frame_2)
  54. n_vs_zero_tr_pic_path_1 = graphs.neutron_to_0_tr_graph(cluster=1, neutron_num_0_tr_frame=n_vs_zero_tr_frame_1)
  55. n_vs_zero_tr_pic_path_2 = graphs.neutron_to_0_tr_graph(cluster=2, neutron_num_0_tr_frame=n_vs_zero_tr_frame_2)
  56. event_counter_fr_4_pic_path = graphs.amp_5_fr_4_graph(amp_5_fr_4_frame=event_counter_fr_4_1,
  57. amp_5_fr_4_frame_2=event_counter_fr_4_2,
  58. worktime_frame=worktime_frame_1,
  59. worktime_frame_2=worktime_frame_2)
  60. amp_distribution_pic_path_1 = graphs.amp_distribution_graph(cluster=1, amp_distribution_frame=amp_5_fr_2_frame_1,
  61. a_crit=6, freq=2)
  62. amp_distribution_pic_path_2 = graphs.amp_distribution_graph(cluster=2, amp_distribution_frame=amp_5_fr_2_frame_2,
  63. a_crit=6, freq=2)
  64. count_rate_amp_5_fr_2_pic_path_1 = graphs.count_rate_graph(cluster=1, count_rate_frame=count_rate_amp_5_fr_2_1,
  65. working_frame=worktime_frame_1,
  66. a_crit=5, freq=2)
  67. count_rate_amp_5_fr_2_pic_path_2 = graphs.count_rate_graph(cluster=2, count_rate_frame=count_rate_amp_5_fr_2_2,
  68. working_frame=worktime_frame_2,
  69. a_crit=5, freq=2)
  70. count_rate_amp_10_fr_1_pic_path_1 = graphs.count_rate_graph(cluster=1, count_rate_frame=count_rate_amp_10_fr_1_1,
  71. working_frame=worktime_frame_1,
  72. a_crit=10, freq=1)
  73. count_rate_amp_10_fr_1_pic_path_2 = graphs.count_rate_graph(cluster=2, count_rate_frame=count_rate_amp_10_fr_1_2,
  74. working_frame=worktime_frame_2,
  75. a_crit=10, freq=1)
  76. doc = Document()
  77. section_choice(doc)
  78. add_new_styles(doc)
  79. head = doc.add_paragraph(
  80. f'Справка о работе установки ПРИЗМА-32 в период с {start_date} по {end_date} ', style='Head-style')
  81. head.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
  82. table_title = doc.add_paragraph('Таблица 1: Время работы установки ПРИЗМА-32.', style='PItalic')
  83. table_title.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
  84. worktime_table = doc.add_table(4, 4, doc.styles['Table Grid'])
  85. worktime_table.cell(0, 0).text = '№ кластера'
  86. worktime_table.cell(0, 1).text = 'Экспозиции, ч.'
  87. worktime_table.cell(0, 2).text = 'Календарное время, ч.'
  88. worktime_table.cell(0, 3).text = 'Экспозиция, %'
  89. worktime_table.cell(1, 0).text = '1'
  90. worktime_table.cell(1, 1).text = str(round(worktime_frame_1['Worktime'].sum(), 2))
  91. worktime_table.cell(1, 2).text = str(24 * days_amount)
  92. worktime_table.cell(1, 3).text = str(
  93. round(worktime_frame_1['Worktime'].sum() / (24 * days_amount) * 100, 3)) + '%'
  94. worktime_table.cell(2, 0).text = '2'
  95. worktime_table.cell(2, 1).text = str(round(worktime_frame_2['Worktime'].sum(), 2))
  96. worktime_table.cell(2, 2).text = str(24 * days_amount)
  97. worktime_table.cell(2, 3).text = str(
  98. round(worktime_frame_2['Worktime'].sum() / (24 * days_amount) * 100, 3)) + '%'
  99. worktime_table.cell(3, 0).text = '1&2'
  100. worktime_table.cell(3, 1).text = str(round(real_worktime, 2))
  101. worktime_table.cell(3, 2).text = str(24 * days_amount)
  102. worktime_table.cell(3, 3).text = str(round(real_worktime / (24 * days_amount) * 100, 3)) + '%'
  103. make_table_bold(worktime_table, cols=4, rows=4)
  104. doc.add_paragraph()
  105. # В РАЗРАБОТКЕ
  106. fail_str_begin_1, fail_str_end_1, lost_minutes_1, break_1 = time_breaks_counter(brake_frame=breaks_frame_1)
  107. fail_str_begin_2, fail_str_end_2, lost_minutes_2, break_2 = time_breaks_counter(brake_frame=breaks_frame_2)
  108. brake_table_title = doc.add_paragraph('Таблица 2: Сводная таблица остановок и работ установки ПРИЗМА-32.', style='PItalic')
  109. brake_table_title.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
  110. brake_table = doc.add_table(len(fail_str_begin_1) + len(fail_str_begin_2) + 2, 5, doc.styles['Table Grid'])
  111. brake_table.alignment = WD_TABLE_ALIGNMENT.CENTER
  112. brake_table.cell(0, 0).text = '№ кластера'
  113. brake_table.cell(0, 0).merge(brake_table.cell(1, 0))
  114. brake_table.cell(0, 1).text = 'Время простоя'
  115. brake_table.cell(1, 1).text = 'c'
  116. brake_table.cell(1, 2).text = 'по'
  117. brake_table.cell(0, 1).merge(brake_table.cell(0, 2))
  118. brake_table.cell(0, 3).text = 'Кол-во потерянных минут (период)'
  119. brake_table.cell(0, 3).merge(brake_table.cell(1, 3))
  120. brake_table.cell(0, 4).text = 'Примечание'
  121. brake_table.cell(0, 4).merge(brake_table.cell(1, 4))
  122. for i in range(2, len(fail_str_begin_1) + 2):
  123. brake_table.cell(i, 0).text = '1'
  124. brake_table.cell(i, 1).text = str(fail_str_begin_1[i - 2])
  125. brake_table.cell(i, 2).text = str(fail_str_end_1[i - 2])
  126. brake_table.cell(i, 3).text = str(lost_minutes_1[i - 2])
  127. brake_table.cell(i, 4).text = ' '
  128. for i in range(2 + len(fail_str_begin_1), len(fail_str_begin_2) + 2 + len(fail_str_begin_1)):
  129. brake_table.cell(i, 0).text = '2'
  130. brake_table.cell(i, 1).text = str(fail_str_begin_2[i - 2 - len(fail_str_begin_1)])
  131. brake_table.cell(i, 2).text = str(fail_str_end_2[i - 2 - len(fail_str_begin_1)])
  132. brake_table.cell(i, 3).text = str(lost_minutes_2[i - 2 - len(fail_str_begin_1)])
  133. brake_table.cell(i, 4).text = ' '
  134. make_table_bold(brake_table, cols=5, rows=len(fail_str_begin_1) + len(fail_str_begin_2)+2)
  135. doc.add_paragraph()
  136. table_title = doc.add_paragraph(
  137. 'Таблица 3: Сводная таблица темпов счета событий и сигналов, отобранных как нейтрон кластеров установки ПРИЗМА-32.',
  138. style='PItalic')
  139. table_title.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
  140. neut_stat_info_1, neut_stat_info_2 = statistical_table(n_vs_zero_tr_frame_1, n_vs_zero_tr_frame_2, dimension='100/соб')
  141. neutron_table = doc.add_table(3, 3, doc.styles['Table Grid'])
  142. neutron_table.cell(0, 0).text = 'Счет/кластер'
  143. neutron_table.cell(0, 1).text = 'Кл1'
  144. neutron_table.cell(0, 2).text = 'Кл2'
  145. neutron_table.cell(1, 0).text = 'События (Fr ≥ 4, A ≥ 5), N соб./ч.'
  146. neutron_table.cell(1, 1).text = str(round((event_counter_fr_4_1['Events'] / worktime_frame_1['Worktime']).mean(), 2))
  147. neutron_table.cell(1, 2).text = str(round((event_counter_fr_4_2['Events'] / worktime_frame_2['Worktime']).mean(), 2))
  148. neutron_table.cell(2, 0).text = 'Нейтроны, (Nn)/соб.'
  149. neutron_table.cell(2, 1).text = str(round(neut_stat_info_1.iloc[0].sum(), 2))
  150. neutron_table.cell(2, 2).text = str(round(neut_stat_info_2.iloc[0].sum(), 2))
  151. make_table_bold(neutron_table, cols=3, rows=3)
  152. change_cell_size(neutron_table, column_num=3, size_arr=[2.5, 0.5, 0.5])
  153. doc.add_paragraph()
  154. notes = doc.add_paragraph('')
  155. notes.add_run('Примечание:').bold = True
  156. notes_description = doc.add_paragraph(
  157. ' В таблице 4 представлена сводная информация о неисправностях в работе детекторов кластера.')
  158. table_title = doc.add_paragraph('Таблица 4: Неисправности.', style='PItalic')
  159. table_title.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
  160. notes_table = doc.add_table(3, 5, doc.styles['Table Grid'])
  161. notes_table.cell(0, 0).text = '№'
  162. notes_table.cell(0, 1).text = 'Кластер'
  163. notes_table.cell(0, 2).text = '№ Детектора'
  164. notes_table.cell(0, 3).text = 'Период'
  165. notes_table.cell(0, 4).text = 'Примечание'
  166. notes_table.cell(1, 0).text = '1'
  167. notes_table.cell(2, 0).text = '2'
  168. change_cell_size(notes_table, column_num=5, size_arr=[0.3, 0.8, 1.2, 1, 4.2])
  169. run = doc.add_paragraph().add_run()
  170. run.add_break(WD_BREAK.PAGE)
  171. graphic_header = doc.add_paragraph('Продолжительность работы кластеров установки ПРИЗМА-32.', style='Head-graphic')
  172. graphic_header.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
  173. adding_graphic(doc, title='Рис. 1 - Продолжительность работы 1-го кластера в сутки', width=6,
  174. picture_path=worktime_pic_path_1)
  175. adding_graphic(doc, title='Рис. 2 - Продолжительность работы 2-го кластера в сутки', width=6,
  176. picture_path=worktime_pic_path_2)
  177. run = doc.add_paragraph().add_run()
  178. run.add_break(WD_BREAK.PAGE)
  179. graphic_header = doc.add_paragraph('Скорость счета событий установки ПРИЗМА-32.', style='Head-graphic')
  180. graphic_header.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
  181. adding_graphic(doc, title='Рис. 3 - Скорость счета событий Fr ≥ 4, A ≥ 5', width=7,
  182. picture_path=event_counter_fr_4_pic_path)
  183. run = doc.add_paragraph().add_run()
  184. run.add_break(WD_BREAK.PAGE)
  185. adding_graphic(doc, title='Рис. 4 - Число импульсов в событии, отобранных как нейтрон, при самозапуске кластер 1',
  186. width=6, picture_path=n_vs_zero_tr_pic_path_1)
  187. adding_graphic(doc, title='Рис. 5 - Число импульсов в событии, отобранных как нейтрон, при самозапуске кластер 2',
  188. width=6, picture_path=n_vs_zero_tr_pic_path_2)
  189. table_title = doc.add_paragraph(
  190. 'Таблица 5: Среднее число нейтронов (Nn) для детекторов установки ПРИЗМА-32 за месяц работы, нормированное на количество событий (Ns).(при самозапуске), ',
  191. style='PItalic')
  192. table_title.add_run('(100/соб)').bold = True
  193. table_title.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
  194. neutron_stat_table = doc.add_table(neut_stat_info_1.shape[0] + neut_stat_info_2.shape[0] + 2,
  195. neut_stat_info_1.shape[1] + 2,
  196. doc.styles['Table Grid'])
  197. draw_stat_table(neutron_stat_table, neut_stat_info_1, neut_stat_info_2)
  198. make_stat_table_bold(neutron_stat_table, cols=18, rows=6)
  199. run = doc.add_paragraph().add_run()
  200. run.add_break(WD_BREAK.PAGE)
  201. # Переделать, чтобы амплитуда и кратность были переменными.
  202. adding_graphic(doc, title='Рис. 6 - Скорость счета детекторов в 1-м кластере Fr ≥ 2, A > 5',
  203. width=6, picture_path=count_rate_amp_5_fr_2_pic_path_1)
  204. adding_graphic(doc, title='Рис. 7 - Скорость счета детекторов в 2-м кластере Fr ≥ 2, A > 5',
  205. width=6, picture_path=count_rate_amp_5_fr_2_pic_path_2)
  206. table_title = doc.add_paragraph(
  207. 'Таблица 6: Среднемесячные число срабатываний детекторов установки ПРИЗМА-32, cоб./час.',
  208. style='PItalic')
  209. table_title.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
  210. # print(f'{count_rate_amp_5_fr_2_1=}')
  211. # print(f'{count_rate_amp_5_fr_2_2=}')
  212. count_rate_stat_info_1, count_rate_stat_info_2 = statistical_table(count_rate_amp_5_fr_2_1, count_rate_amp_5_fr_2_2,
  213. dimension='cоб./ч.')
  214. count_stat_table = doc.add_table(count_rate_stat_info_1.shape[0] + count_rate_stat_info_2.shape[0] + 2,
  215. count_rate_stat_info_1.shape[1] + 2, doc.styles['Table Grid'])
  216. draw_stat_table(count_stat_table, count_rate_stat_info_1, count_rate_stat_info_2)
  217. make_stat_table_bold(count_stat_table, cols=18, rows=6)
  218. run = doc.add_paragraph().add_run()
  219. run.add_break(WD_BREAK.PAGE)
  220. adding_graphic(doc, title='Рис. 8 - Скорость счета детекторов в 1-м кластере Fr ≥ 1, A > 10',
  221. width=6, picture_path=count_rate_amp_10_fr_1_pic_path_1)
  222. adding_graphic(doc, title='Рис. 9 - Скорость счета детекторов в 2-м кластере Fr ≥ 1, A > 10',
  223. width=6, picture_path=count_rate_amp_10_fr_1_pic_path_2)
  224. table_title = doc.add_paragraph(
  225. 'Таблица 7: Среднемесячные число срабатываний детекторов установки ПРИЗМА-32, cоб./час.',
  226. style='PItalic')
  227. table_title.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
  228. count_rate_stat_info_1, count_rate_stat_info_2 = statistical_table(count_rate_amp_10_fr_1_1, count_rate_amp_10_fr_1_2,
  229. dimension='cоб./ч.')
  230. count_stat_table_2 = doc.add_table(count_rate_stat_info_1.shape[0] + count_rate_stat_info_2.shape[0] + 2,
  231. count_rate_stat_info_1.shape[1] + 2, doc.styles['Table Grid'])
  232. draw_stat_table(count_stat_table_2, count_rate_stat_info_1, count_rate_stat_info_2)
  233. make_stat_table_bold(count_stat_table_2, cols=18, rows=6)
  234. run = doc.add_paragraph().add_run()
  235. run.add_break(WD_BREAK.PAGE)
  236. graphic_header = doc.add_paragraph('На рисунке 8, 9 представлено число сигналов с А>5 кодов АЦП в час для 16 детекторов.',
  237. style='Head-graphic')
  238. graphic_header.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
  239. adding_graphic(doc, title='Рис. 10 - Амплитудное распределение сигналов от детекторов, кластер 1 (Fr ≥ 2 и А > 5)',
  240. width=6, picture_path=amp_distribution_pic_path_1)
  241. adding_graphic(doc, title='Рис. 11 - Амплитудное распределение сигналов от детекторов, кластер 2 (Fr ≥ 2 и А > 5)',
  242. width=6, picture_path=amp_distribution_pic_path_2)
  243. add_page_number(doc.sections[0].footer.paragraphs[0])
  244. doc.save(f'C:\\Users\\pad_z\\OneDrive\\Рабочий стол\\PrismaPassport\\2021\\{start_date}-{end_date}.docx')
  245. plt.close('all')
  246. print(time.time() - t1)