-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathSTDF_Reader_GUI.py
1984 lines (1738 loc) · 96.8 KB
/
STDF_Reader_GUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding:utf-8 -*-
###################################################
# STDF Reader Tool #
# Version: Beta 0.8 #
# #
# Sep. 18, 2019 #
# A light STDF reader and analysis tool #
# A project forked from Thomas Kaunzinger #
# #
# References: #
# PySTDF Library #
# PyQt5 #
# numpy #
# matplotlib #
# countrymarmot (cp + cpk) #
# PyPDF #
# ZetCode + sentdex (PyQt tutorials) #
# My crying soul because there's no documentation #
###################################################
###################################################
#######################
# IMPORTING LIBRARIES #
#######################
# import fix_qt_import_error
# from PyQt5.QtWidgets import QWidget, QDesktopWidget, QApplication, QToolTip, QPushButton
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from pystdf.Writers import *
from abc import ABC
import numpy as np
import pandas as pd
import time, datetime, logging, re, csv
import xlsxwriter
import qtawesome as qta
import os
import matplotlib
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# from numba import jit
from src.Backend import Backend
from src.FileRead import FileReaders
from src.Threads import PdfWriterThread, CsvParseThread, XlsxParseThread, DiagParseThread, SingleRecParseThread
from llm.chat import ChatBot
Version = 'Beta 0.8.24'
###################################################
########################
# QT GUI FUNCTIONALITY #
########################
# These are the functions for the QMainWindow/widget application objects that run the whole interface
class Application(QMainWindow): # QWidget):
# Construct me
def __init__(self):
super().__init__()
# Have to read the imported .txt file but I'm not totally sure how
self.data = None
self.number_of_sites = None
self.list_of_test_numbers = []
self.list_of_test_numbers_string = []
self.tnumber_list = []
self.tname_list = []
self.test_info_list = []
self.df_csvs = []
self.df_csv = pd.DataFrame()
self.sdr_parse = []
self.list_of_duplicate_test_numbers = []
self.s2s_correlation_report_df = pd.DataFrame()
# exitAct = QAction(QIcon('exit.png'), '&Exit', self)
# exitAct.setShortcut('Ctrl+Q')
# exitAct.triggered.connect(qApp.quit)
# aboutAct = QAction(QIcon('about.png'), '&About', self)
# aboutAct.triggered.connect(self.aboutecho)
#
# menubar = self.menuBar()
# fileMenu = menubar.addMenu('&File')
# helpMenu = menubar.addMenu('&Help')
# fileMenu.addAction(exitAct)
# helpMenu.addAction(aboutAct)
# Set icon for window, the img path should be full absolute path for compiling
self.pix = QPixmap(pathname + r'\img\icon.ico')
icon = QIcon()
icon.addPixmap(self.pix, QIcon.Normal, QIcon.Off)
self.setWindowIcon(icon)
# Set the window title
self.window_title = QLabel()
self.window_title.setText('STDF Reader For AP ' + Version)
self.window_title.setFont(QFont("Times", 14, weight=QFont.Bold))
self.window_title_img = QLabel()
self.window_title_img.setPixmap(self.pix)
# self.window_title_img.setGeometry(0, 100, 3, 3)
self.window_title_img.setScaledContents(True)
self.window_title_img.setMaximumHeight(20)
self.window_title_img.setMaximumWidth(20)
# lb1 = QLabel(self)
# lb1.setGeometry(0, 250, 300, 200)
# lb1.setPixmap(pix)
# lb1.setStyleSheet("border: 2px solid red")
# lb1.setScaledContents(True)
self.button_close = QPushButton(qta.icon('mdi.window-close'), '')
self.button_about = QPushButton(qta.icon('mdi.window-maximize'), '')
self.button_mini = QPushButton(qta.icon('mdi.window-minimize'), '')
self.button_close.clicked.connect(self.close)
self.button_about.clicked.connect(self.aboutecho)
self.button_mini.clicked.connect(self.showMinimized)
self.status_text = QLabel()
self.status_text.setText('Welcome!')
self.status_text.setFont(QFont("Times", 12, weight=QFont.Bold))
self.step_1 = QGroupBox('Step 1: Convert to CSV')
self.step_2 = QGroupBox('Step 2: Upload CSV for Analysis')
# self.step_2.setTitle('Step 2: Upload CSV for Analysis')
# Button to parse to .csv
self.stdf_upload_button = QPushButton(qta.icon('fa5s.file-csv', color='green', color_active='black'),
'Parse STD/STDF to .csv log')
self.stdf_upload_button.setToolTip(
'Browse for stdf to create .csv file. This is helpful when doing data analysis')
self.stdf_upload_button.clicked.connect(self.open_parsing_dialog_csv)
# Button to upload the .txt file to work with
self.txt_upload_button = QPushButton(qta.icon('fa5s.file-upload', color='blue', color_active='black'),
'Upload parsed .csv file')
self.txt_upload_button.setToolTip(
'Browse for the .csv file containing the parsed STDF data')
self.txt_upload_button.clicked.connect(self.open_text)
# Generates a summary of the loaded text
self.generate_summary_button = QPushButton(qta.icon('mdi.google-analytics', color='blue', color_active='black'),
'Generate data analysis report')
self.generate_summary_button.setToolTip(
'Generate a .xlsx data analysis report for the uploaded parsed .csv')
self.generate_summary_button.clicked.connect(self.generate_analysis_report)
# Selects a test result for the desired
self.select_test_menu = ComboCheckBox() # ComboCheckBox() # QComboBox()
self.select_test_menu.setToolTip(
'Select the tests to produce the PDF results for')
# Button to generate the test results for the desired tests from the selected menu
self.generate_pdf_button = QPushButton(qta.icon('fa5s.file-pdf', color='red', color_active='black'),
'Generate .pdf from selected tests')
self.generate_pdf_button.setToolTip(
'Generate a .pdf file with the selected tests from the parsed .txt')
self.generate_pdf_button.clicked.connect(self.plot_list_of_tests)
self.limit_toggle = QCheckBox('Plot against failure limits', self)
self.limit_toggle.setChecked(True)
self.limit_toggle.stateChanged.connect(self.toggler)
self.limits_toggled = True
self.group_toggle = QCheckBox('Plot tendency by file', self)
self.group_toggle.setChecked(False)
self.group_toggle.stateChanged.connect(self.group_by_file)
self.group_toggled = False
self.plot_tests_button = QPushButton(qta.icon('mdi.trending-up', color='red', color_active='orange'),
'Plot Selected Tests')
self.plot_tests_button.setToolTip('Plot Selected Tests\' Trendency')
self.plot_tests_button.clicked.connect(self.plot_list_of_tests_on_one_figure)
# Generates a correlation report for all sites of the loaded data
self.generate_correlation_button = QPushButton(
qta.icon('mdi.file-compare', color='black', color_active='black'),
'Generate correlation report of multiple stdf files')
self.generate_correlation_button.setToolTip(
'Generate a .xlsx correlation report of 2 stdf files for the uploaded parsed .csv')
self.generate_correlation_button.clicked.connect(self.generate_correlation_report)
# toggle for enable cherry pick of site data
self.cherry_pick_toggle = QCheckBox('Enable Cherry-Pick', self)
self.cherry_pick_toggle.setChecked(False)
self.cherry_pick_toggle.stateChanged.connect(self.enable_cherry_pick_flag)
self.cherry_pick_toggled = False
# Input the selected site list, split by comma
self.selected_site_line_edit = QLineEdit()
self.selected_site_line_edit.setText("Input selected site list here")
self.selected_site_line_edit.setToolTip("Input the selected site list for each file, split by comma, one site per file")
# toggle for enable analyse log with setting "Ignore Test Number"
self.ignore_TNUM_toggle = QCheckBox('Ignore Test Number', self)
self.ignore_TNUM_toggle.setChecked(False)
self.ignore_TNUM_toggle.stateChanged.connect(self.enable_ignore_tnum_flag)
self.ignore_TNUM_toggled = False
# toggle for enable analyse log with setting "Ignore Test Number"
self.ignore_chnum_toggle = QCheckBox('Ignore Channel Number', self)
self.ignore_chnum_toggle.setChecked(False)
self.ignore_chnum_toggle.stateChanged.connect(self.enable_ignore_chnum_flag)
self.ignore_chnum_toggled = False
# toggle for enable analyse log with setting "output converted csv as one file"
self.output_one_file_toggle = QCheckBox('Output as one file', self)
self.output_one_file_toggle.setChecked(True)
self.output_one_file_toggle.stateChanged.connect(self.enable_output_one_file_flag)
self.output_one_file_toggled = True
# Generates a correlation report for site2site compare
self.generate_correlation_button_s2s = QPushButton(
qta.icon('mdi.sitemap', color='yellow', color_active='black'),
'Generate correlation of Site2Site')
self.generate_correlation_button_s2s.setToolTip(
'Generate an Site2Site correlation report')
self.generate_correlation_button_s2s.clicked.connect(self.generate_s2s_correlation_report)
# Selects a test result for s2s correlation
self.select_s2s_test_menu = ComboCheckBox() # ComboCheckBox() # QComboBox()
self.select_s2s_test_menu.setToolTip(
'Select the tests to produce the heatmap results for site-to-site correlation')
# Button to generate the s2s test results for the desired tests from the selected s2s menu
self.generate_heatmap_button = QPushButton(
qta.icon('mdi.chart-scatter-plot', color='orange', color_active='black'),
'Generate heatmap from selected Site2Site tests')
self.generate_heatmap_button.setToolTip(
'Generate a heatmap with the selected s2s tests from the parsed .csv')
self.generate_heatmap_button.clicked.connect(
lambda: self.make_s2s_correlation_heatmap(self.s2s_correlation_report_df))
# Button to parse to atdf .xlsx
self.stdf_upload_button_xlsx = QPushButton(qta.icon('fa5s.file-excel', color='green', color_active='black'),
'Parse STD/STDF to .xlsx table')
self.stdf_upload_button_xlsx.setToolTip(
'Browse for a file ending in .std to create a parsed .xlsx file')
self.stdf_upload_button_xlsx.clicked.connect(self.open_parsing_dialog_xlsx)
# Selects STDF record to extract
self.select_stdf_rec_menu = QComboBox()
self.select_stdf_rec_menu.setToolTip('Select the single record to extract')
self.select_stdf_rec_menu.addItems(['DTR', 'GDR', 'TSR'])
self.rec_name = 'DTR'
self.select_stdf_rec_menu.currentIndexChanged[str].connect(self.get_rec_name) # 条目发生改变,发射信号,传递条目内容
#self.select_stdf_rec_menu.highlighted[str].connect(self.get_rec_name) # 在下拉列表中,鼠标移动到某个条目时发出信号,传递条目内容
# Button to parse a single record type to atdf .csv
self.stdf_upload_button_single_rec = QPushButton(qta.icon('mdi.selection-search', color='green', color_active='black'),
'Parse STD/STDF to .csv table')
self.stdf_upload_button_single_rec.setToolTip(
'Browse for a file ending in .std to create a parsed .csv file')
self.stdf_upload_button_single_rec.clicked.connect(self.open_parsing_single_rec)
# Selects tests for extracting sub-CSV
self.select_test_for_subcsv_menu = ComboCheckBox()
self.select_test_for_subcsv_menu.setToolTip('Select the tests to produce the sub-CSV for analysis')
# Extract a sub-CSV log
self.extract_subcsv = QPushButton(qta.icon('fa5s.file-csv', color='green', color_active='black'),
'Extract a sub-CSV log for chosen tests')
self.extract_subcsv.setToolTip('Extract a sub-CSV log for chosen tests')
self.extract_subcsv.clicked.connect(self.make_subcsv_for_chosen_tests)
# Convert STR/PSR to ASCII log
self.convert_SDTFV42007_to_ASCII = QPushButton(qta.icon('fa5s.file-csv', color='green', color_active='black'),
'Convert Diagnosis STDFV4-2007.1 to ASCII log')
self.convert_SDTFV42007_to_ASCII.setToolTip('Convert STR/PSR to Mentor like ASCII log')
self.convert_SDTFV42007_to_ASCII.clicked.connect(self.open_parsing_diagnosis_ascii)
# input text edit for LLM Chat
self.llm_prompt_edit = QPlainTextEdit()
self.llm_prompt_edit.setPlaceholderText("Input Your Instruction Here To Let AI Coding For You To Analyse Data.") #.setPlainText("Input Your Instruction Here")
self.llm_btn = QPushButton(qta.icon('mdi6.brain', color='green', color_active='black'), 'Go~')
self.llm_btn.setToolTip('Give order to AI')
self.llm_btn.clicked.connect(self.llm_chat)
# self.llm_prompt_edit.setMaximumHeight(self.llm_btn.height() * 1)
self.llm_prompt_edit.setFixedHeight(50) #.resize(100,100)
# Transpose CSV log
self.transpose_csv_btn = QPushButton(qta.icon('mdi6.table-column-width', color='green', color_active='black'),
'Convert table rows to columns')
self.transpose_csv_btn.setToolTip('Convert table rows to columns')
self.transpose_csv_btn.clicked.connect(self.make_csv_transpose)
self.progress_bar = QProgressBar()
self.WINDOW_SIZE = (750, 350)
self.file_path = None
self.text_file_location = self.file_path
self.setFixedSize(self.WINDOW_SIZE[0], self.WINDOW_SIZE[1]) #.setBaseSize(self.WINDOW_SIZE[0], self.WINDOW_SIZE[1])
self.center()
self.setWindowTitle('STDF Reader For AP ' + Version)
self.selected_tests = []
self.file_selected = False
self.threaded_task = PdfWriterThread(file_path=self.file_path, all_data=self.df_csv,
ptr_data=self.test_info_list, number_of_sites=self.number_of_sites,
selected_tests=self.selected_tests, limits_toggled=self.limits_toggled,
list_of_test_numbers=self.list_of_test_numbers, site_list=self.sdr_parse,
group_by_file=self.group_toggled)
self.threaded_task.notify_progress_bar.connect(self.on_progress)
self.threaded_task.notify_status_text.connect(self.on_update_text)
self.threaded_csv_parser = CsvParseThread(file_path=self.file_path)
self.threaded_csv_parser.notify_status_text.connect(
self.on_update_text)
self.threaded_xlsx_parser = XlsxParseThread(file_path=self.file_path)
self.threaded_xlsx_parser.notify_status_text.connect(self.on_update_text)
self.threaded_single_rec_parser = SingleRecParseThread(self.file_path, self.rec_name)
self.threaded_single_rec_parser.notify_status_text.connect(self.on_update_text)
self.threaded_diagnosis_parser = DiagParseThread(file_path=self.file_path)
self.threaded_diagnosis_parser.notify_status_text.connect(self.on_update_text)
self.generate_pdf_button.setEnabled(False)
self.select_test_menu.setEnabled(False)
self.generate_summary_button.setEnabled(False)
self.limit_toggle.setEnabled(False)
self.group_toggle.setEnabled(False)
self.plot_tests_button.setEnabled(False)
self.generate_correlation_button.setEnabled(False)
self.generate_correlation_button_s2s.setEnabled(False)
self.select_s2s_test_menu.setEnabled(False)
self.generate_heatmap_button.setEnabled(False)
self.select_test_for_subcsv_menu.setEnabled(False)
self.extract_subcsv.setEnabled(False)
self.selected_site_line_edit.setEnabled(False)
self.llm_prompt_edit.setEnabled(False)
self.llm_btn.setEnabled(False)
self.main_window()
# Tab for data analysis
def tab_data_analysis(self):
layout = QGridLayout()
layout.addWidget(self.generate_summary_button, 0, 0, 1, 4)
layout.addWidget(self.select_test_menu, 1, 0, 1, 4)
layout.addWidget(self.generate_pdf_button, 2, 0)
layout.addWidget(self.limit_toggle, 2, 1)
layout.addWidget(self.group_toggle, 2, 2)
layout.addWidget(self.plot_tests_button, 2, 3)
self.data_analysis_tab.setLayout(layout)
# Tab for data correlation
def tab_data_correlation(self):
layout = QGridLayout()
layout.addWidget(self.generate_correlation_button, 0, 0)
layout.addWidget(self.generate_correlation_button_s2s, 0, 1)
layout.addWidget(self.select_s2s_test_menu, 1, 0, 1, 2)
layout.addWidget(self.generate_heatmap_button, 2, 0)
self.correlation_tab.setLayout(layout)
# Tab for ATDF
def tab_atdf(self):
layout = QGridLayout()
layout.addWidget(self.stdf_upload_button_xlsx, 0, 0)
layout.addWidget(self.convert_SDTFV42007_to_ASCII, 0, 1)
# layout.addWidget(self.select_test_for_subcsv_menu, 1, 0, 1, 2)
# layout.addWidget(self.extract_subcsv, 2, 0)
layout.addWidget(self.select_stdf_rec_menu, 1, 0, 1, 1)
layout.addWidget(self.stdf_upload_button_single_rec, 1, 1, 1, 1)
self.to_atdf_tab.setLayout(layout)
# Tab for tools
def tab_tools(self):
layout = QGridLayout()
layout.addWidget(self.llm_prompt_edit, 0, 0)
layout.addWidget(self.llm_btn, 0, 1)
layout.addWidget(self.select_test_for_subcsv_menu, 1, 0)
layout.addWidget(self.extract_subcsv, 2, 0)
layout.addWidget(self.transpose_csv_btn, 2, 1)
self.tools_tab.setLayout(layout)
# Main interface method
def main_window(self):
# self.setGeometry(300, 300, 300, 200)
# self.resize(900, 700)
self.setFixedSize(self.WINDOW_SIZE[0], self.WINDOW_SIZE[1])
self.setWindowTitle('STDF Reader For AP ' + Version)
# Layout
layout = QGridLayout()
self.setLayout(layout)
# Adds the widgets together in the grid
# self.window_title.setAlignment(Qt.AlignCenter)
# self.window_title_img.setAlignment(Qt.AlignCenter)
layout.addWidget(self.window_title_img, 0, 11, 1, 1)
layout.addWidget(self.window_title, 0, 12, 1, 10)
layout.addWidget(self.button_mini, 0, 29, 1, 1)
layout.addWidget(self.button_about, 0, 30, 1, 1)
layout.addWidget(self.button_close, 0, 31, 1, 1)
layout.addWidget(self.status_text, 1, 0, 1, 32)
# layout.addWidget(self.stdf_upload_button_xlsx, 2, 0, 1, 16)
# layout.addWidget(self.test_frame, 2, 0, 2, 16)
# vbox = QVBoxLayout()
# vbox.addWidget(self.stdf_upload_button)
# vbox.addWidget(self.cherry_pick_toggle)
# vbox.addWidget(self.selected_site_line_edit)
# self.step_1.setLayout(vbox)
# layout.addWidget(self.step_1, 2, 0, 4, 16)
vbox = QGridLayout()
vbox.addWidget(self.ignore_TNUM_toggle, 2, 0, 1, 3)
vbox.addWidget(self.ignore_chnum_toggle, 2, 4, 1, 4)
vbox.addWidget(self.output_one_file_toggle, 2, 8, 1, 8)
vbox.addWidget(self.stdf_upload_button,3,0,1,16)
# vbox.addWidget(self.cherry_pick_toggle,3,0,1,8)
# vbox.addWidget(self.selected_site_line_edit,3,8,1,8)
self.step_1.setLayout(vbox)
layout.addWidget(self.step_1, 2, 0, 3, 16)
# layout.addWidget(self.stdf_upload_button, 3, 3, 1, 12)
vbox2 = QGridLayout()
vbox2.addWidget(self.cherry_pick_toggle, 2, 0, 1, 7)
vbox2.addWidget(self.selected_site_line_edit, 2, 8, 1, 8)
vbox2.addWidget(self.txt_upload_button,3,0,1,16)
self.step_2.setLayout(vbox2)
layout.addWidget(self.step_2, 2, 16, 3, 16)
# layout.addWidget(self.txt_upload_button, 3, 18, 1, 12)
tabs = QTabWidget(self)
self.data_analysis_tab = QWidget()
self.correlation_tab = QWidget()
self.to_atdf_tab = QWidget()
self.tools_tab = QWidget()
self.tab_data_analysis()
self.tab_data_correlation()
self.tab_atdf()
self.tab_tools()
tabs.addTab(self.data_analysis_tab, 'Data Analysis')
tabs.addTab(self.correlation_tab, 'Data Correlation')
tabs.addTab(self.to_atdf_tab, 'To ATDF')
tabs.addTab(self.tools_tab, 'Some Tools')
layout.addWidget(tabs, 6, 0, 4, 32)
layout.addWidget(self.progress_bar, 11, 0, 1, 32)
# Create an QWidget, and use layout_grid
widget = QWidget()
widget.setLayout(layout)
# Set 'widget' as central widget
self.setCentralWidget(widget)
self.button_close.setStyleSheet(
'''QPushButton{background:#F76677;border-radius:5px;}QPushButton:hover{background:red;}''')
self.button_about.setStyleSheet(
'''QPushButton{background:#F7D674;border-radius:5px;}QPushButton:hover{background:yellow;}''')
self.button_mini.setStyleSheet(
'''QPushButton{background:#6DDF6D;border-radius:5px;}QPushButton:hover{background:green;}''')
self.setWindowOpacity(0.95) # 设置窗口透明度
self.setWindowFlag(Qt.FramelessWindowHint) # 隐藏边框
pe = QPalette()
self.setAutoFillBackground(True)
# pe.setColor(QPalette.Window, Qt.lightGray) # 设置背景色
pe.setColor(QPalette.Background, Qt.lightGray)
self.setPalette(pe)
# Window settings
self.show()
def aboutecho(self):
QMessageBox.information(
self, 'About', 'Author:Chao Zhou \n verion ' + Version + ' \n 感谢您的使用! \n zhouchao486@gmail.com ',
QMessageBox.Ok)
# Centers the window
def center(self):
window = self.frameGeometry()
center_point = QDesktopWidget().availableGeometry().center()
window.moveCenter(center_point)
self.move(window.topLeft())
# 重写三个方法使我们的Example窗口支持拖动,上面参数window就是拖动对象
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.m_drag = True
self.m_DragPosition = event.globalPos() - self.pos()
event.accept()
self.setCursor(QCursor(Qt.OpenHandCursor))
def mouseMoveEvent(self, QMouseEvent):
if Qt.LeftButton and self.m_drag:
self.move(QMouseEvent.globalPos() - self.m_DragPosition)
QMouseEvent.accept()
def mouseReleaseEvent(self, QMouseEvent):
self.m_drag = False
self.setCursor(QCursor(Qt.ArrowCursor))
# Opens and reads a file to parse the data
def open_parsing_dialog(self):
self.status_text.setText('Parsing to .txt, please wait...')
filterboi = 'STDF (*.stdf *.std)'
filepath = QFileDialog.getOpenFileName(
caption='Open STDF File', filter=filterboi)
if filepath[0] == '':
self.status_text.setText('Please select a file')
pass
else:
self.status_text.update()
FileReaders.process_file(filepath[0])
self.status_text.setText(
str(filepath[0].split('/')[-1] + '_parsed.txt created!'))
# Opens and reads a file to parse the data to an csv
def open_parsing_dialog_csv(self):
# I can not figure out the process when parsing STDF, so...
self.progress_bar.setMinimum(0)
# Move QFileDialog out of QThread, in case of error under win 7
self.status_text.setText('Parsing to .csv file, please wait...')
filterboi = 'STDF (*.stdf *.std);;GZ (*.stdf.gz *.std.gz)'
# the native file-dialog automatically sorts the selected files (which may not be the case on all platforms).
# However, Qt's built-in file-dialog doesn't have this behaviour
filepath = QFileDialog.getOpenFileNames(
caption='Open STDF or GZ File', filter=filterboi, options=QFileDialog.DontUseNativeDialog)
self.status_text.update()
self.stdf_upload_button.setEnabled(False)
# self.progress_bar.setMaximum(0)
# # process specified site list
# site_list = []
# text = self.selected_site_line_edit.text()
# if self.cherry_pick_toggled and text != "Input selected site list here":
# site_list = text.replace('-',' ').replace(';',' ').replace(',',' ').split()
self.threaded_csv_parser = CsvParseThread(filepath, self.ignore_TNUM_toggled, self.output_one_file_toggled, self.ignore_chnum_toggled)
self.threaded_csv_parser.notify_progress_bar.connect(self.on_progress)
self.threaded_csv_parser.notify_status_text.connect(self.on_update_text)
self.threaded_csv_parser.finished.connect(self.set_progress_bar_max)
self.threaded_csv_parser.start()
self.stdf_upload_button.setEnabled(True)
# self.main_window()
# Opens and reads a file to parse the data to an xlsx
def open_parsing_dialog_xlsx(self):
self.progress_bar.setMinimum(0)
self.status_text.setText('Parsing to .xlsx file, please wait...')
filterboi = 'STDF (*.stdf *.std)'
filepath = QFileDialog.getOpenFileName(
caption='Open STDF File', filter=filterboi)
self.status_text.update()
self.stdf_upload_button_xlsx.setEnabled(False)
self.progress_bar.setMaximum(0)
self.threaded_xlsx_parser = XlsxParseThread(filepath[0])
self.threaded_xlsx_parser.notify_status_text.connect(self.on_update_text)
self.threaded_xlsx_parser.finished.connect(self.set_progress_bar_max)
self.threaded_xlsx_parser.start()
self.stdf_upload_button_xlsx.setEnabled(True)
def open_parsing_single_rec(self):
self.progress_bar.setMinimum(0)
self.status_text.setText('Parsing to .csv file, please wait...')
filterboi = 'STDF (*.stdf *.std)'
filepath = QFileDialog.getOpenFileName(
caption='Open STDF File', filter=filterboi)
rec_name = self.rec_name
self.status_text.update()
self.stdf_upload_button_single_rec.setEnabled(False)
self.progress_bar.setMaximum(0)
self.threaded_single_rec_parser = SingleRecParseThread(filepath[0], rec_name)
self.threaded_single_rec_parser.notify_status_text.connect(self.on_update_text)
self.threaded_single_rec_parser.finished.connect(self.set_progress_bar_max)
self.threaded_single_rec_parser.start()
self.stdf_upload_button_single_rec.setEnabled(True)
# self.main_window()
# Convert STDF V4 2007.1 to Mentor like log
def open_parsing_diagnosis_ascii(self):
self.progress_bar.setMinimum(0)
self.status_text.setText('Parsing Diagnosis file to .csv, please wait...')
filterboi = 'STDF (*.stdf *.std);;GZ (*.stdf.gz *.std.gz)'
filepath = QFileDialog.getOpenFileName(
caption='Open STDF or GZ File', filter=filterboi)
self.status_text.update()
self.convert_SDTFV42007_to_ASCII.setEnabled(False)
self.progress_bar.setMaximum(0)
self.threaded_diagnosis_parser = DiagParseThread(filepath[0])
self.threaded_diagnosis_parser.notify_status_text.connect(self.on_update_text)
self.threaded_diagnosis_parser.finished.connect(self.set_progress_bar_max)
self.threaded_diagnosis_parser.start()
self.convert_SDTFV42007_to_ASCII.setEnabled(True)
# self.main_window()
def set_progress_bar_max(self):
self.progress_bar.setMaximum(100)
QMessageBox.information(self, 'Go ahead, bro', 'Parse Complete !', QMessageBox.Ok)
# Checks if the toggle by limits mark is checked or not
def toggler(self, state):
if state == Qt.Checked:
self.limits_toggled = True
else:
self.limits_toggled = False
# Checks if the plot rhe tendency group by file or not
def group_by_file(self, state):
if state == Qt.Checked:
self.group_toggled = True
else:
self.group_toggled = False
def enable_cherry_pick_flag(self, state):
if state == Qt.Checked:
self.cherry_pick_toggled = True
self.selected_site_line_edit.setEnabled(True)
else:
self.cherry_pick_toggled = False
self.selected_site_line_edit.setEnabled(False)
def enable_ignore_tnum_flag(self, state):
if state == Qt.Checked:
self.ignore_TNUM_toggled = True
else:
self.ignore_TNUM_toggled = False
def enable_ignore_chnum_flag(self, state):
if state == Qt.Checked:
self.ignore_chnum_toggled = True
else:
self.ignore_chnum_toggled = False
def enable_output_one_file_flag(self, state):
if state == Qt.Checked:
self.output_one_file_toggled = True
else:
self.output_one_file_toggled = False
def process_csv_file(self):
self.df_csv = pd.DataFrame()
csv_data = pd.DataFrame()
self.list_of_test_numbers_string = []
self.tnumber_list = []
self.tname_list = []
self.test_info_list = []
test_info_list = []
i = 0
for filename in self.file_paths:
csv_data = pd.read_csv(filename, header=[0, 1, 2, 3, 4])
# Extracts the test name for the selecting
tmp_pd = csv_data.columns
single_columns = tmp_pd.get_level_values(4).values.tolist()[:16] # Get the part info
tnumber_list = tmp_pd.get_level_values(4).values.tolist()[16:]
tname_list = tmp_pd.get_level_values(0).values.tolist()[16:]
test_info_list = list(set(tmp_pd.values.tolist()[16:]).union(test_info_list))
list_of_test_numbers_string = [j + ' - ' + i for i, j in zip(tname_list, tnumber_list)]
# Change the multi-level columns to single level columns
single_columns = single_columns + list_of_test_numbers_string
csv_data.columns = single_columns
if self.cherry_pick_toggled:
site_list = []
text = self.selected_site_line_edit.text()
if self.cherry_pick_toggled and text != "Input selected site list here":
site_list = text.replace('-', ' ').replace(';', ' ').replace(',', ' ').split()
if len(self.file_paths) != len(site_list):
QMessageBox.information(
self, 'Error', "File count mismatch with input site list!",
QMessageBox.Ok)
break
site_index = int(site_list[i])
csv_data = csv_data[csv_data['SITE_NUM'].isin([site_index])].copy()
i += 1
if self.df_csv.empty:
self.df_csv = csv_data.copy()
else:
self.df_csv = pd.concat([self.df_csv, csv_data], sort=False,
join='outer', ignore_index=True)
# self.df_csv = pd.read_csv(self.file_path, header=[0, 1, 2, 3, 4]) # , dtype=str)
# self.df_csv.replace(r'\(F\)','',regex=True, inplace=True)
# self.df_csv.iloc[:,12:] = self.df_csv.iloc[:,12:].astype('float')
# Extracts the test name for the selecting
tmp_pd = self.df_csv.columns
self.single_columns = tmp_pd.values.tolist()[:16] # Get the part info
# self.tnumber_list = tmp_pd.values.tolist()[16:]
# self.tname_list = tmp_pd.values.tolist()[16:]
self.test_info_list = test_info_list # tmp_pd.values.tolist()[16:]
self.list_of_test_numbers_string = tmp_pd.values.tolist()[
16:] # [j + ' - ' + i for i, j in zip(self.tname_list, self.tnumber_list)]
# Change the multi-level columns to single level columns
# self.single_columns = self.single_columns + self.list_of_test_numbers_string
# self.df_csv.columns = self.single_columns
if self.df_csv.shape[0] > 0:
# Data cleaning, get rid of '(F)' and '(A)'
self.df_csv.replace(r'\((F|A)\)', '', regex=True, inplace=True)
self.df_csv.iloc[:, 16:] = self.df_csv.iloc[:, 16:].astype('float')
# self.df_csv[self.df_csv.columns[16:]] = self.df_csv[self.df_csv.columns[16:]].astype('float')
self.df_csv['X_COORD'] = self.df_csv['X_COORD'].astype(int)
self.df_csv['Y_COORD'] = self.df_csv['Y_COORD'].astype(int)
self.df_csv['SOFT_BIN'] = self.df_csv['SOFT_BIN'].astype(int)
self.df_csv['HARD_BIN'] = self.df_csv['HARD_BIN'].astype(int)
self.df_csv['LOT_ID'].fillna(value=9999, inplace=True)
self.df_csv['WAFER_ID'].fillna(value=9999, inplace=True)
self.df_csv['PART_ID'].fillna(value=9999, inplace=True)
self.df_csv['BIN_DESC'].fillna(value='NA', inplace=True)
# Extract the test name and test number list
self.list_of_test_numbers = [x.split(" - ") for x in
self.list_of_test_numbers_string] # [list(z) for z in (zip(self.tnumber_list, self.tname_list))]
self.tnumber_list = [x[0] for x in self.list_of_test_numbers]
self.tname_list = [x[1] for x in self.list_of_test_numbers]
# Get site array
self.sdr_parse = self.df_csv['SITE_NUM'].unique()
self.number_of_sites = len(self.sdr_parse)
else:
QMessageBox.information(
self, 'Warning', "Empty line in loaded file!",
QMessageBox.Ok)
# Opens and reads a file to parse the data. Much of this is what was done in main() from the text version
def open_text(self):
# Only accepts text files
filterboi = 'CSV Table (*.csv)'
# filepath = QFileDialog.getOpenFileName(
# caption='Open .csv File', filter=filterboi)
filepath = QFileDialog.getOpenFileNames(
caption='Open .csv File', filter=filterboi, options=QFileDialog.DontUseNativeDialog)
self.file_paths = filepath[0]
# Because you can open it and select nothing smh
if len(self.file_paths) > 0:
self.file_path = self.file_paths[0]
self.txt_upload_button.setEnabled(False)
self.progress_bar.setValue(0)
# initial key data variables
self.df_csv = pd.DataFrame()
self.list_of_test_numbers = []
self.list_of_duplicate_test_numbers = []
startt = time.time()
if self.file_path.endswith(".txt"):
pass
elif self.file_path.endswith(".std"):
pass
elif self.file_path.endswith(".csv"):
self.process_csv_file()
endt = time.time()
print('读取时间:', endt - startt)
logging.info('Debug message: ' + '读取时间:' + str(endt - startt))
# sdr_parse = self.sdr_data[0].split("|")
self.progress_bar.setValue(35)
self.file_selected = True
self.select_test_menu.loadItems(self.list_of_test_numbers_string)
self.select_s2s_test_menu.loadItems(self.list_of_test_numbers_string)
self.select_test_for_subcsv_menu.loadItems(self.list_of_test_numbers_string)
self.selected_tests = []
# log parsed document, if duplicate test number exist, show warning !
if len(self.list_of_duplicate_test_numbers) > 0:
self.status_text.setText(
'Parsed .csv uploaded! But Duplicate Test Number Found! Please Check \'duplicate_test_number.csv\'')
else:
self.status_text.setText('Parsed .csv uploaded!')
self.progress_bar.setValue(100)
self.txt_upload_button.setEnabled(True)
self.generate_pdf_button.setEnabled(True)
self.select_test_menu.setEnabled(True)
self.generate_summary_button.setEnabled(True)
self.limit_toggle.setEnabled(True)
self.group_toggle.setEnabled(True)
self.plot_tests_button.setEnabled(True)
self.generate_correlation_button.setEnabled(True)
self.generate_correlation_button_s2s.setEnabled(True)
self.select_s2s_test_menu.setEnabled(False)
self.generate_heatmap_button.setEnabled(False)
self.select_test_for_subcsv_menu.setEnabled(True)
self.extract_subcsv.setEnabled(True)
self.llm_prompt_edit.setEnabled(True)
self.llm_btn.setEnabled(True)
self.main_window()
else:
self.status_text.setText('Please select a file')
# find out the duplicate test number with differnet test name
def list_duplicates_of(self, seq, item, start_index): # start_index is to reduce the complex
start_at = -1
locs = []
while True:
try:
loc = seq.index(item, start_at + 1)
except ValueError:
break
else:
locs.append(start_index + loc)
start_at = loc
# Just find the first duplicate to reduce complex
if len(locs) == 2:
break
return locs
# Create a xlsx report including Data Statistics, Duplicate Test Number and Wafer Map
def generate_analysis_report(self):
nowTime = datetime.datetime.now().strftime('%Y%m%d-%H%M%S')
analysis_report_name = str(self.file_path[:-11] + "_analysis_report_" + nowTime + ".xlsx")
self.status_text.setText(
str(analysis_report_name + " is generating..."))
startt = time.time()
data_summary = self.make_data_summary_report()
endt = time.time()
print('data summary Time: ', endt - startt)
logging.info('Debug message: ' + 'data summary Time: ' + str(endt - startt))
startt = time.time()
duplicate_number_report = self.make_duplicate_num_report()
self.progress_bar.setValue(82)
endt = time.time()
print('duplicate number Time: ', endt - startt)
logging.info('Debug message: ' + 'duplicate number Time: ' + str(endt - startt))
startt = time.time()
bin_summary_list = self.make_bin_summary()
self.progress_bar.setValue(85)
endt = time.time()
print('bin summary Time: ', endt - startt)
logging.info('Debug message: ' + 'bin summary Time: ' + str(endt - startt))
startt = time.time()
wafer_map_list = self.make_wafer_map()
self.progress_bar.setValue(88)
endt = time.time()
print('wafer map Time: ', endt - startt)
logging.info('Debug message: ' + 'wafer map Time: ' + str(endt - startt))
startt = time.time()
# In case someone has the file open
try:
with pd.ExcelWriter(analysis_report_name, engine='xlsxwriter') as writer:
workbook = writer.book
# Light red fill for Bin 2XXX
format_2XXX = workbook.add_format({'bg_color': '#FF0000'})
# Orange fill for Bin 3XXX
format_3XXX = workbook.add_format({'bg_color': '#FF6600'})
# Dark red fill for Bin 4XXX
format_4XXX = workbook.add_format({'bg_color': '#FFC7CE'})
# Light yellow for Bin 6XXX
format_6XXX = workbook.add_format({'bg_color': '#FFEB9C'})
# Dark yellow for Bin 9XXX
format_9XXX = workbook.add_format({'bg_color': '#9C6500'})
# Green for Bin 1/1XXX
format_1XXX = workbook.add_format({'bg_color': '#008000'})
# Dark green for Bin 7XXX
format_7XXX = workbook.add_format({'bg_color': '#C6EFCE'})
# Add width and format for first column
format1 = workbook.add_format({'align': 'left'})
data_summary.to_excel(writer, sheet_name='Data Statistics')
row_table, column_table = data_summary.shape
worksheet = writer.sheets['Data Statistics']
# Freeze pane on the top row
worksheet.freeze_panes(1, 0)
# Set the width and align
worksheet.set_column('A:A', 25, format1)
worksheet.conditional_format(1, 13, row_table, 13,
{'type': 'cell', 'criteria': '<',
'value': 3.3, 'format': format_4XXX})
worksheet.conditional_format(1, 14, row_table, 14,
{'type': 'cell', 'criteria': '<',
'value': 1.33, 'format': format_4XXX})
worksheet.conditional_format(1, 15, row_table, 15,
{'type': 'cell', 'criteria': '<',
'value': 1.33, 'format': format_4XXX})
worksheet.conditional_format(1, 16, row_table, 16,
{'type': 'cell', 'criteria': '<',
'value': 1.33, 'format': format_4XXX})
worksheet.autofilter(0, 0, row_table, column_table)
self.progress_bar.setValue(89)
duplicate_number_report.to_excel(writer, sheet_name='Duplicate Test Number')
self.progress_bar.setValue(90)
# Output Bin Summary Sheet
start_row = 0
for i in range(len(bin_summary_list)):
bin_summary = bin_summary_list[i]
row_table, column_table = bin_summary.shape
bin_summary.to_excel(writer, sheet_name='Bin Summary', startrow=start_row)
worksheet = writer.sheets['Bin Summary']
worksheet.conditional_format(start_row + 1, 0,
start_row + row_table, 0,
{'type': 'cell',
'criteria': 'between',
'minimum': 1,
'maximum': 1999,
'format': format_1XXX})
worksheet.conditional_format(start_row + 1, 0,
start_row + row_table, 0,
{'type': 'cell',
'criteria': 'between',
'minimum': 2000,
'maximum': 2999,
'format': format_2XXX})
worksheet.conditional_format(start_row + 1, 0,
start_row + row_table, 0,
{'type': 'cell',
'criteria': 'between',
'minimum': 3000,
'maximum': 3999,
'format': format_3XXX})
worksheet.conditional_format(start_row + 1, 0,
start_row + row_table, 0,
{'type': 'cell',
'criteria': 'between',
'minimum': 4000,
'maximum': 4999,
'format': format_4XXX})
worksheet.conditional_format(start_row + 1, 0,
start_row + row_table, 0,
{'type': 'cell',
'criteria': 'between',
'minimum': 6000,
'maximum': 6999,
'format': format_6XXX})
worksheet.conditional_format(start_row + 1, 0,
start_row + row_table, 0,
{'type': 'cell',
'criteria': 'between',
'minimum': 7000,
'maximum': 7999,
'format': format_7XXX})
worksheet.conditional_format(start_row + 1, 0,
start_row + row_table, 0,
{'type': 'cell',
'criteria': 'between',
'minimum': 9000,
'maximum': 9999,
'format': format_9XXX})
self.progress_bar.setValue(90 + int(i / len(bin_summary_list) * 5))
start_row = start_row + row_table + 3
# Output Wafer Map Sheet: total wafer map and maps for each site
start_row = 0
for i in range(len(wafer_map_list)):
start_column = 0
for j in range(len(wafer_map_list[i])):
wafer_map = wafer_map_list[i][j]
row_table, column_table = wafer_map.shape
wafer_map.to_excel(writer, sheet_name='Wafer Map', startrow=start_row, startcol=start_column)
worksheet = writer.sheets['Wafer Map']
worksheet.conditional_format(start_row + 1, start_column + 1,
start_row + row_table, start_column + column_table,
{'type': 'cell',
'criteria': 'between',
'minimum': 1,
'maximum': 1999,
'format': format_1XXX})
worksheet.conditional_format(start_row + 1, start_column + 1,