forked from GuilhermeMene/QAQCMin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqaqcmin_main.py
812 lines (605 loc) · 28.6 KB
/
qaqcmin_main.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
# -*- coding: utf-8 -*-
##########################################
#Name: Guilherme Mene Ale Primo
#Date: 18/01/2020
# QAQC geochemical data control and report
##########################################
#import libraries
import wx
import wx.xrc
import wx.lib.agw.ribbon as rb
import wx.grid
import numpy as np
import sys
import sqlite3 as sqlite
import matplotlib.pyplot as plt
import src.standard_dialog
import src.settings_dialog
import datetime as date
import os
import src.make_Report as mr
from wx.lib.pdfviewer import pdfViewer, pdfButtonPanel
# Set MainFrame
class MainFrame( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"Geochemical QAQC Program", pos = wx.DefaultPosition, size = wx.Size( 700,700 ), style = wx.DEFAULT_FRAME_STYLE )
self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )
box = wx.BoxSizer( wx.VERTICAL )
open_Proj = wx.Window.NewControlId()
save_Proj = wx.Window.NewControlId()
exp_Rep = wx.Window.NewControlId()
std_db = wx.Window.NewControlId()
open_Setting = wx.Window.NewControlId()
exit_bot = wx.Window.NewControlId()
self.rb = rb.RibbonBar( self , wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.lib.agw.ribbon.RIBBON_BAR_DEFAULT_STYLE )
self.Page1 = rb.RibbonPage( self.rb, wx.ID_ANY, u"MyRibbonPage" , wx.NullBitmap , 0 )
self.file_panel = rb.RibbonPanel( self.Page1, wx.ID_ANY, wx.EmptyString , wx.NullBitmap , wx.DefaultPosition, wx.DefaultSize, wx.lib.agw.ribbon.RIBBON_PANEL_DEFAULT_STYLE )
self.rbb1 = rb.RibbonButtonBar( self.file_panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0)
self.rbb1.AddSimpleButton( open_Proj, u"Open Project", wx.Bitmap( u"img/open_47.png", wx.BITMAP_TYPE_ANY ), wx.EmptyString)
self.rbb1.AddSimpleButton( save_Proj, u"Save Project", wx.Bitmap( u"img/save_47.png", wx.BITMAP_TYPE_ANY ), wx.EmptyString)
self.rbb1.AddSimpleButton( exp_Rep, u"Print Report", wx.Bitmap( u"img/report_47.png", wx.BITMAP_TYPE_ANY ), wx.EmptyString)
self.db_panel = rb.RibbonPanel( self.Page1, wx.ID_ANY, wx.EmptyString , wx.NullBitmap , wx.DefaultPosition, wx.DefaultSize, wx.lib.agw.ribbon.RIBBON_PANEL_DEFAULT_STYLE )
self.rbb2 = rb.RibbonButtonBar( self.db_panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0)
self.rbb2.AddSimpleButton( std_db, u"Standard Database", wx.Bitmap( u"img/database_47.png", wx.BITMAP_TYPE_ANY ), wx.EmptyString)
self.exit_panel = rb.RibbonPanel( self.Page1, wx.ID_ANY, wx.EmptyString , wx.NullBitmap , wx.DefaultPosition, wx.DefaultSize, wx.lib.agw.ribbon.RIBBON_PANEL_DEFAULT_STYLE )
self.rbb3 = rb.RibbonButtonBar( self.exit_panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0)
self.rbb3.AddSimpleButton( open_Setting, u" Settings", wx.Bitmap( u"img/set_47.png", wx.BITMAP_TYPE_ANY ), wx.EmptyString)
self.rbb3.AddSimpleButton( exit_bot, u" Exit", wx.Bitmap( u"img/exit_47.png", wx.BITMAP_TYPE_ANY ), wx.EmptyString)
self.rb.Realize()
#Set buttom event in the Ribbon buttons
self.rbb1.Bind(rb.EVT_RIBBONBUTTONBAR_CLICKED, self.openProject, id=open_Proj)
self.rbb1.Bind(rb.EVT_RIBBONBUTTONBAR_CLICKED, self.SaveProject, id=save_Proj)
self.rbb1.Bind(rb.EVT_RIBBONBUTTONBAR_CLICKED, self.ExportReport, id=exp_Rep)
self.rbb2.Bind(rb.EVT_RIBBONBUTTONBAR_CLICKED, self.StandardDB, id=std_db)
self.rbb3.Bind(rb.EVT_RIBBONBUTTONBAR_CLICKED, self.open_Setting,None, id=open_Setting)
self.rbb3.Bind(rb.EVT_RIBBONBUTTONBAR_CLICKED, self.Onclose,None, id=exit_bot)
box.Add( self.rb, 0, wx.ALL|wx.EXPAND, 5 )
self.note = wx.Notebook( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 )
self.data_panel = wx.Panel( self.note, wx.ID_ANY, wx.DefaultPosition, wx.Size( -1,-1 ), 0 )
box1 = wx.BoxSizer( wx.HORIZONTAL )
self.Datagrid = wx.grid.Grid( self.data_panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 )
# Grid
self.Datagrid.CreateGrid( 100, 4 )
self.Datagrid.EnableEditing( True )
self.Datagrid.EnableGridLines( True )
self.Datagrid.EnableDragGridSize( False )
self.Datagrid.SetMargins( 50, 0 )
# Columns
self.Datagrid.SetColSize( 0, 100 )
self.Datagrid.SetColSize( 1, 100 )
self.Datagrid.SetColSize( 2, 100 )
self.Datagrid.SetColSize( 3, 100 )
self.Datagrid.EnableDragColMove( False )
self.Datagrid.EnableDragColSize( True )
self.Datagrid.SetColLabelSize( 30 )
self.Datagrid.SetColLabelValue( 0, u"Sample ID" )
self.Datagrid.SetColLabelValue( 1, u"Sample Type" )
self.Datagrid.SetColLabelValue( 2, u"Duplicate" )
self.Datagrid.SetColLabelValue( 3, u"Assay 01" )
#self.Datagrid.SetColLabelValue( 4, u"Assay 02" )
#self.Datagrid.SetColLabelValue( 5, u"Assay 03" )
self.Datagrid.SetColLabelAlignment( wx.ALIGN_CENTER, wx.ALIGN_CENTER )
# Rows
self.Datagrid.EnableDragRowSize( True )
self.Datagrid.SetRowLabelSize( 50 )
self.Datagrid.SetRowLabelAlignment( wx.ALIGN_CENTER, wx.ALIGN_CENTER )
# Label Appearance
# Cell Defaults
self.Datagrid.SetDefaultCellAlignment( wx.ALIGN_CENTER, wx.ALIGN_TOP )
box1.Add( self.Datagrid, 0, wx.ALL, 5 )
box2 = wx.BoxSizer( wx.VERTICAL )
box2.Add( ( 0, 0), 1, wx.EXPAND, 5 )
self.m_staticText2 = wx.StaticText( self.data_panel, wx.ID_ANY, u"Open Data File ", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_staticText2.Wrap( -1 )
box2.Add( self.m_staticText2, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
self.open_file = wx.BitmapButton( self.data_panel, wx.ID_ANY, wx.NullBitmap, wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW|0 )
self.open_file.SetBitmap( wx.Bitmap( u"img/opendata_47.png", wx.BITMAP_TYPE_ANY ) )
box2.Add( self.open_file, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
#Set open file data function
self.open_file.Bind(wx.EVT_BUTTON, self.LoadData)
box2.Add( ( 0, 0), 1, 0, 5)
self.m_staticText2 = wx.StaticText( self.data_panel, wx.ID_ANY, u"Clear Data ", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_staticText2.Wrap( -1 )
box2.Add( self.m_staticText2, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
self.clear_datagrid = wx.BitmapButton( self.data_panel, wx.ID_ANY, wx.NullBitmap, wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW|0 )
self.clear_datagrid.SetBitmap( wx.Bitmap( u"img/trash_47.png", wx.BITMAP_TYPE_ANY ) )
box2.Add( self.clear_datagrid, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
#Set open file data function
self.clear_datagrid.Bind(wx.EVT_BUTTON, self.clear_DataGrid)
box2.Add( ( 0, 0), 1, 0, 5 )
self.m_sline = wx.StaticLine( self.data_panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL )
box2.Add(self.m_sline, 0, wx.EXPAND |wx.ALL, 5 )
#set the Technical Manager
self.m_st_technicalman = wx.StaticText(self.data_panel, wx.ID_ANY, u"Technical Manager:", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_st_technicalman.Wrap( -1 )
box2.Add(self.m_st_technicalman, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5)
self.m_Tech = wx.TextCtrl( self.data_panel, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
box2.Add(self.m_Tech, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5)
#set the Batch name
self.m_st_batch = wx.StaticText(self.data_panel, wx.ID_ANY, u"Batch Name:", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_st_batch.Wrap( -1 )
box2.Add(self.m_st_batch, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5)
self.m_Bath = wx.TextCtrl( self.data_panel, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
box2.Add(self.m_Bath, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5)
self.m_staticText3 = wx.StaticText( self.data_panel, wx.ID_ANY, u"Run", wx.DefaultPosition, wx.DefaultSize, 0 )
self.m_staticText3.Wrap( -1 )
box2.Add( self.m_staticText3, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
self.run_bot = wx.BitmapButton( self.data_panel, wx.ID_ANY, wx.NullBitmap, wx.DefaultPosition, wx.DefaultSize, wx.BU_AUTODRAW|0 )
self.run_bot.SetBitmap( wx.Bitmap( u"img/run_47.png", wx.BITMAP_TYPE_ANY ) )
box2.Add( self.run_bot, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 )
#Set open file data function
self.run_bot.Bind(wx.EVT_BUTTON, self.runProject)
box2.Add( ( 0, 0), 1, wx.EXPAND, 5 )
box1.Add( box2, 1, wx.EXPAND, 5 )
self.data_panel.SetSizer( box1 )
self.data_panel.Layout()
box1.Fit( self.data_panel )
self.note.AddPage( self.data_panel, u"DATA", True )
#Set the report panel
self.report_panel = wx.Panel( self.note, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
gs_report = wx.BoxSizer(wx.VERTICAL)
self.buttonpanel = pdfButtonPanel(self.report_panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0)
self.pdfViewer = pdfViewer(self.report_panel, wx.ID_ANY, wx.DefaultPosition,
wx.DefaultSize,
wx.HSCROLL|wx.VSCROLL|wx.SUNKEN_BORDER)
self.pdfViewer.UsePrintDirect = "False"
# introduce buttonpanel and viewer to each other
self.buttonpanel.viewer = self.pdfViewer
self.pdfViewer.buttonpanel = self.buttonpanel
#add the buutonpanel and pdfviewer to boxsizer
gs_report.Add( self.buttonpanel, 1, wx.ALL, 5 )
gs_report.Add( self.pdfViewer, 100, wx.EXPAND |wx.ALL, 5 )
self.report_panel.SetSizer( gs_report )
self.report_panel.Layout()
gs_report.Fit( self.report_panel )
self.note.AddPage( self.report_panel, u"Report", False )
box.Add( self.note, 1, wx.EXPAND |wx.ALL, 5 )
self.SetSizer( box )
self.Layout()
self.Centre( wx.BOTH )
#set the types
self.type = ["SMP", "BLANK", "DUP"]
#Load std for list
self.Load_STD()
#set the setting parameters
self.Get_setting()
#clear temporary files
self.Clear_tempFiles()
#set Datagrid cell Editor for fill with list
self.type_editor = wx.grid.GridCellChoiceEditor(self.type, True)
#set the editor cell
for i in range(0,100):
self.Datagrid.SetCellEditor(i, 1, self.type_editor)
def Clear_tempFiles(self):
"""This function clear temporary files
"""
#Remove the blank chart
if os.path.isfile(os.path.normpath(os.getcwd()) + "/.chart/blankchart.png"):
os.remove(os.path.normpath(os.getcwd()) + "/.chart/blankchart.png")
else:
pass
#Remove the duplicate chart
if os.path.isfile(os.path.normpath(os.getcwd()) + "/.chart/dupchart.png"):
os.remove(os.path.normpath(os.getcwd()) + "/.chart/dupchart.png")
else:
pass
#Remove the standard chart
if os.path.isfile(os.path.normpath(os.getcwd()) + "/.chart/stdchart.png"):
os.remove(os.path.normpath(os.getcwd()) + "/.chart/stdchart.png")
else:
pass
def Get_setting(self):
#read setting file
set_path = os.path.normpath(os.getcwd()) + "/setting"
with open(set_path, "r") as set_file:
project_settings = []
for line in set_file:
line = line.rstrip('\n')
project_settings.append(line)
self.l_path = str(project_settings[0])
self.s_unit = str(project_settings[1])
#check if logo is empty
if not self.l_path:
self.l_path = os.path.normpath(os.getcwd()) + "/img/nologo.png"
else:
pass
def open_Setting(self, event):
"""This function open the setting dialog
"""
#set the icon of app
icon_path = os.path.normpath(os.getcwd()) + "/img/qaqcmin_icon.png"
icon = wx.Icon(icon_path, wx.BITMAP_TYPE_PNG)
set_dialog = src.settings_dialog.SETDialog(self)
set_dialog.SetIcon(icon)
set_dialog.Show()
def clear_DataGrid(self, event):
""" This fuction clear datagrid
"""
self.resp = wx.MessageBox(' Are you sure about that ?\n This will remove all data in the table...', 'Warning',
wx.OK | wx.CANCEL | wx.ICON_WARNING)
if self.resp == wx.OK:
# Clear datagrid
self.Datagrid.ClearGrid()
else:
pass
def Load_STD(self):
""" This fuction fill the std combobox in the datagrid choice editor
"""
#Connect to database
self.conn = sqlite.connect('db/standard_db.db')
self.cursor = self.conn.cursor()
self.num_tables_db = self.cursor.execute("""SELECT count(*) FROM sqlite_master WHERE type = 'table'""").fetchone()
if self.num_tables_db[0] == 0:
self.cursor.execute("""create table if not exists Standards (Id INTEGER PRIMARY KEY,
std_name text, certified_value real, std_deviation real);""")
else:
#Execute query for get std_names
self.nstds = self.cursor.execute("""SELECT std_name FROM Standards""")
#append names to type variable
for line in self.nstds:
self.type.append(line[0])
self.conn.close()
def __del__( self ):
pass
def LoadData(self, event):
""" This fuction load the data from text file
"""
#Open File Dialog
with wx.FileDialog(self, "Open Data File", wildcard="CSV Files (*.csv)|*.csv| TXT Files (*.txt)|*.txt",
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as fileDialog:
if fileDialog.ShowModal() == wx.ID_CANCEL:
return #If the user cancel
pathname = fileDialog.GetPath()
#get data and fill datagrid
try:
c1, c2 = np.loadtxt(pathname, dtype=str, delimiter=',', skiprows=1, unpack=True)
for i in range(0, len(c1)):
self.Datagrid.SetCellValue(i, 0, str(c1[i]))
self.Datagrid.SetCellValue(i, 1, "SMP")
self.Datagrid.SetCellValue(i, 2, "")
self.Datagrid.SetCellValue(i, 3, str(c2[i]))
except IOError:
wx.MessageBox("Cannot open data file '%s'.", pathname, "Cannot open data file")
except ValueError:
wx.MessageBox("Cannot open data file \n Are yout sure about file format?", "Incorrect File format")
def openProject(self, event):
""" This fuction open project file
"""
wx.MessageBox("This function is not implemented yet", "Sorry")
def SaveProject(self, event):
""" This fuction save the project file
"""
wx.MessageBox("This function is not implemented yet", "Sorry")
def ExportReport(self, event):
""" This fuction open a dialog for print report
"""
wx.MessageBox("This function is not implemented yet", "Sorry")
def StandardDB(self, event):
""" This fuction open the Standard managment dilaog.
"""
#set the icon of app
icon_path = os.path.normpath(os.getcwd()) + "/img/qaqcmin_icon.png"
icon = wx.Icon(icon_path, wx.BITMAP_TYPE_PNG)
std_dialog = src.standard_dialog.STDDialog(self)
std_dialog.SetIcon(icon)
std_dialog.Show()
def runProject(self, event):
""" This fuction get the data from datagrid and make plots of BLANK, DUP and STD.
"""
#set the lists
self.s_Id = []
self.s_type = []
self.DupId = []
self.s_Assay1 = []
#Get values of datagrid
for row in range(0, 100):
self.s_Id.append(self.Datagrid.GetCellValue(row, 0))
self.s_type.append(self.Datagrid.GetCellValue(row, 1))
self.DupId.append(self.Datagrid.GetCellValue(row, 2))
self.s_Assay1.append(self.Datagrid.GetCellValue(row, 3))
#get the batch and technical manager values
#get the batch name
self.batch_name = self.m_Bath.GetValue()
#get the technical manager name
self.technical = self.m_Tech.GetValue()
if self.s_Id[0] == '':
wx.MessageBox("Cannot run the project. \n Datagrid is empty", "Datagrid is empty")
else:
#filter the None of data
self.s_Id = list(filter(None, self.s_Id))
self.s_type = list(filter(None, self.s_type))
self.s_Assay1 = list(filter(None, self.s_Assay1))
self.DupId = list(filter(None, self.DupId))
#convert the assay ppb to ppm
for i in range(0, len(self.s_Assay1)):
if self.s_Assay1[i] == 'N.A.':
self.s_Assay1[i] = float(0.003)
elif self.s_Assay1[i] == '<5':
self.s_Assay1[i] = float(0.003)
else:
self.s_Assay1[i] = float(int(self.s_Assay1[i])/1000)
##############################
#getting data of blank samples
#set the blank list
self.s_blankAssay = []
self.s_blank_num =[]
self.s_blankId = []
# Separate the types of QAQC items
for i in range(0, len(self.s_Id)):
if self.s_type[i] == "BLANK":
self.s_blankId.append(self.s_Id[i])
self.s_blankAssay.append(self.s_Assay1[i])
self.s_blank_num.append(i)
##############################
#get std data from database
#Connect to database
self.conn = sqlite.connect('db/standard_db.db')
self.cursor = self.conn.cursor()
#Execute query for get std_names
self.stdname = self.cursor.execute("""SELECT * FROM Standards""")
self.std_name = []
self.std_value = []
self.std_deviation = []
for line in self.stdname.fetchall():
self.std_name.append(line[1])
self.std_value.append(line[2])
self.std_deviation.append(line[3])
self.conn.close()
#separete the types of qaqc items STANDARD
self.standard_project = []
for std in range(0, len(self.std_name)):
self.standard_project.append([])
for item in range(0, len(self.s_type)):
if self.s_type[item] == self.std_name[std]:
std_status = self.get_Std_status(self.std_deviation[std], self.s_Assay1[item], self.std_value[std])
self.standard_project[std].append([self.s_type[item], self.s_Id[item], self.s_Assay1[item], self.std_value[std],
self.std_deviation[std], (abs(self.s_Assay1[item] - self.std_value[std]) / self.std_value[std]) *100,
std_status])
self.standard_project = list(filter(None, self.standard_project))
##############################
#separete the types of qaqc items DUPLICATE
self.s_DupAssay = [] #is the resutl of the sample that have a duplicate
self.s_DupId = [] #is the Id of the sample that have a duplicate
#self.DupId is the Id of duplicate sample
#self.DupAssay is the assay of duplicate sample
# Get duplicates of datagrid
for i in range(0, len(self.s_Id)):
if self.s_type[i] == "DUP":
self.s_DupId.append(self.s_Id[i])
self.s_DupAssay.append(self.s_Assay1[i])
##############################
#check what the data exist or not for plot into graphics
qaqc_items = ""
#check if blank exist and plot then
if len(self.s_blankAssay) > 0:
#Plot blank into graphics
self.plotBlank()
else:
qaqc_items += "Blank "
if len(self.s_DupAssay) > 0:
#plot DUP into graphics
self.plotDUP()
else:
qaqc_items += "Duplicate "
if len(self.standard_project) > 0:
#plot STD into graphics
self.plotSTD()
else:
qaqc_items += "Standard "
#warning if data not exist
if len(qaqc_items) > 0:
wx.MessageBox("Warning! . \n {} data is empty".format(qaqc_items), "0 {} found.".format(qaqc_items))
self.make_Report() #make the repost first
plt.show()
else:
self.make_Report() #make the report first
plt.show()
def make_Report(self):
self.blank_project = []
self.dup_project = []
#preparing the blank data
if len(self.s_blankId) > 0:
self.blank_status = []
for i in range(0, len(self.s_blankAssay)):
if self.s_blankAssay[i] > 0.01:
self.blank_status.append("Disapproved")
else:
self.blank_status.append("Approved")
#zipping the blank data into one list
self.blank_project.append([self.s_blankId, self.s_blankAssay, self.blank_status])
else:
pass
#preparing the duplicate data
if len(self.s_DupId) > 0:
self.DupDiff = []
#calculate the difference of duyplicate samples
for i in range(0, len(self.s_DupId)):
self.DupDiff.append((abs(self.s_DupAssay[i] - self.DupAssay[i]) / self.DupAssay[i]) * 100 )
#zipping the duplicate data into one list
self.dup_project.append([self.s_DupId, self.s_DupAssay, self.DupId, self.DupAssay, self.DupDiff])
else:
pass
#update the logo path
self.Get_setting()
#call funtino to make pdf Report
pdfFilePath= mr.makeReport.makePdf(self, self.blank_project, self.dup_project, self.standard_project, self.batch_name, self.technical, self.l_path)
self.pdfViewer.LoadFile(pdfFilePath)
def get_Std_status(self, stdDev, sampAssay, stdAssay):
if (stdDev + stdAssay) > sampAssay > (stdAssay - stdDev):
self.std_status = "Approved"
elif (2*stdDev + stdAssay) > sampAssay > (stdAssay - 2*stdDev):
self.std_status = "Revise"
elif (3*stdDev + stdAssay) > sampAssay > (stdAssay - 3*stdDev):
self.std_status = "Disapproved"
else:
self.std_status = "Disapproved"
return self.std_status
def plotBlank(self):
"""This function plot the blank data in the chart"""
#set the roundrobin of blank data
blank_rr = []
blank_x = []
for i in range(0, 100):
blank_x.append(i)
blank_rr.append(0.01)
#setting the plot setup
fig , ax_blank = plt.subplots(num="Blank Plot - Quality Control Chart", figsize=(8, 6))
ax_blank.plot(self.s_blank_num, self.s_blankAssay, label='Samples', color= 'b', marker='s', linestyle='--')
ax_blank.plot(blank_x, blank_rr, label='Blank Limit', color='red')
for sample in range(len(self.s_blankId)):
ax_blank.annotate(self.s_blankId[sample], (self.s_blank_num[sample], self.s_blankAssay[sample] + 0.0005), rotation=90, verticalalignment='bottom')
ax_blank.set_title("Blank Samples Plot - Quality Control Chart")
ax_blank.set_xlabel("Samples")
ax_blank.set_ylabel("Au (ppm) Fire Assay")
ax_blank.set_xticklabels([])
ax_blank.set_yticks((0.00250, 0.01250, 0.02250))
ax_blank.grid(axis='y')
plt.legend()
blank_path = os.getcwd()+ "/.chart/blankchart.png"
plt.savefig(blank_path, dpi = 150, quality = 95)
def plotSTD(self):
"""This function read the standards database and get the round robin of std"""
#setting number of stds
num_stds = len(self.standard_project)
if num_stds <= 1:
#set multiple plot of stds
fig, ax_std = plt.subplots(num="Standard Plot - Quality Control Chat", figsize=(8, 6))
fig.subplots_adjust(top= 0.90, bottom= 0.10, left= 0.10, right= 0.95, wspace = .15)
self.getRoundRobin()
#plot the 1st round robin (approval)
ax_std.plot(self.standard_x, self.standard_rr[0], label='Approved', color='green')
ax_std.plot(self.standard_x, self.standard_rr[3], color='green')
#plot the 2st round robin (revise)
ax_std.plot(self.standard_x, self.standard_rr[1], label='Revise', color='yellow')
ax_std.plot(self.standard_x, self.standard_rr[4], color='yellow')
#plot the 2st round robin (revise)
ax_std.plot(self.standard_x, self.standard_rr[2], label='Disapproved', color='red')
ax_std.plot(self.standard_x, self.standard_rr[5], color='red')
if len(self.standard_project[0]) > 1:
for sample in range(0, len(self.standard_project[0])):
#plot same standard in the figure
ax_std.plot(sample, self.standard_project[0][sample][2], label='Standard', color= 'b', marker='s', linestyle='--')
#ax_std.scatter(sample, self.standard_project[0][sample][2], label='Standard', color= 'b', marker='s')
ax_std.annotate(self.standard_project[0][sample][1], (sample, self.standard_project[0][sample][2] + (self.standard_project[0][sample][2]* 0.05)),
rotation=90, verticalalignment='bottom')
else:
#plot a standard in the figure
ax_std.plot(0, self.standard_project[0][0][2], label='Standard', color= 'b', marker='s', linestyle='--')
ax_std.annotate(self.standard_project[0][0][1], (0, self.standard_project[0][0][2] + (self.standard_project[0][0][2]* 0.05)),
rotation=90, verticalalignment='bottom')
#set the axis
ax_std.set_title("Standard {} Plot - Quality Control Chart".format(self.standard_project[0][0][0]))
ax_std.set_xticklabels([])
ax_std.set_xlabel("Samples")
ax_std.set_ylabel("Au (ppm) Fire Assay")
ax_std.grid(axis='y')
plt.legend(loc='upper right')
else:
if num_stds > 2:
#set a plot in the figure for more 2 plots
fig, ax_std = plt.subplots(1, num_stds, num="Standard Plot - Quality Control Chat", figsize=(18, 6))
else:
#set a plot in the figure for until 2 plots
fig, ax_std = plt.subplots(1, num_stds, num="Standard Plot - Quality Control Chat", figsize=(15, 6))
fig.subplots_adjust(top= 0.90, bottom= 0.10, left= 0.05, right= 0.95, wspace = .15)
ax_std = ax_std.ravel()
#set list of standards and plot
for i in range(0, len(self.standard_project)):
self.standard_rr, self.standard_x = self.getRoundRobin(i)
#plot the 1st round robin (approval)
ax_std[i].plot(self.standard_x, self.standard_rr[0], label='Approved', color='green')
ax_std[i].plot(self.standard_x, self.standard_rr[3], color='green')
#plot the 2st round robin (revise)
ax_std[i].plot(self.standard_x, self.standard_rr[1], label='Revise', color='yellow')
ax_std[i].plot(self.standard_x, self.standard_rr[4], color='yellow')
#plot the 2st round robin (revise)
ax_std[i].plot(self.standard_x, self.standard_rr[2], label='Disapproved', color='red')
ax_std[i].plot(self.standard_x, self.standard_rr[5], color='red')
for sample in range(0, len(self.standard_project[i])):
#plot the scatter with standards
ax_std[i].plot(sample, self.standard_project[i][sample][2], label='Standard', color= 'b', marker='s', linestyle='--')
ax_std[i].annotate(self.standard_project[i][sample][1], (sample, self.standard_project[i][sample][2] + (self.standard_project[i][sample][2]* 0.05)),
rotation=90, verticalalignment='bottom')
#set the axis
ax_std[i].set_title("Standard {} Plot - Quality Control Chart".format(self.standard_project[i][0][0]))
ax_std[i].set_xticklabels([])
ax_std[i].set_xlabel("Samples")
ax_std[i].set_ylabel("Au (ppm) Fire Assay")
ax_std[i].grid(axis='y')
plt.legend(loc='upper right')
std_path = os.getcwd()+ "/.chart/stdchart.png"
plt.savefig(std_path, dpi = 150, quality = 95)
def getRoundRobin(self, standard_index = 0):
"""This function get round robin for plot standards"""
#get round robin of standard database
self.standard_rr = []
self.standard_x = []
for j in range(0, len(self.std_name)):
if self.std_name[j] == self.standard_project[standard_index][0][0]:
self.n_std = self.std_name[j]
self.v_std = self.std_value[j]
self.d_std = self.std_deviation[j]
#set the range of plots
for n in range(0, 20):
self.standard_rr.append([])
#set the round robin
for num in range(0, 20):
#append the num_x
self.standard_x.append(num)
#append the std deviation
self.standard_rr[0].append(self.v_std + self.d_std) #set the approved (+)
self.standard_rr[1].append(self.v_std + (2*self.d_std))#set the revise (+)
self.standard_rr[2].append(self.v_std + (3*self.d_std))#set the disapproved (+)
self.standard_rr[3].append(self.v_std - self.d_std)#set the approved (-)
self.standard_rr[4].append(self.v_std - (2*self.d_std))#set the revise (-)
self.standard_rr[5].append(self.v_std - (3*self.d_std))#set the disapproved (-)
return self.standard_rr, self.standard_x
def plotDUP(self):
"""This function plot the duplicate samples on the graphics"""
#get the assay of the duplicate
dup_assay = self.get_Dupassay()
#get the round robin of duplicate samples
XUp10,YUp10,XDn10,YDn10,XUp5,YUp5,XDn5,YDn5,XBis,YBis = np.loadtxt('db/dup_rr.csv', delimiter=',', skiprows=1, unpack=True)
#setting the plot setup
fig , ax_dup = plt.subplots(num="Duplicates - Quality Control Chart", figsize= (8, 6))
#set the UP 10% range
ax_dup.plot(XUp10, YUp10, color='red')
#set the UP 5% range
ax_dup.plot(XUp5, YUp5, color='yellow')
#set the Bissetriz of duplicates chart
ax_dup.plot(XBis, YBis, color='blue')
#set the Bottom 10% range
ax_dup.plot(XDn10, YDn10, color='red')
#set the Bottom 5% range
ax_dup.plot(XDn5, YDn5, color='yellow')
#plot the values of duplicate samples (x is the original sample and y is the dupicate of sample)
ax_dup.plot(self.s_DupAssay, self.DupAssay, label='Duplicate samples', marker='s', color='b', linestyle='--')
ax_dup.set_title("Duplicates Samples Plot - Quality Control Chart")
ax_dup.set_xlabel("Au (ppm) Fire Assay")
ax_dup.set_ylabel("Au (ppm) Fire Assay")
ax_dup.set_xlim(-0.5, 7)
ax_dup.set_ylim(-0.5, 7)
ax_dup.grid(axis='y')
plt.legend(loc='lower right')
dup_path = os.getcwd()+ "/.chart/dupchart.png"
plt.savefig(dup_path, dpi = 150, quality = 95)
def get_Dupassay(self):
"""This function get id for the duplicate samples"""
self.DupAssay = []
for i in range(0, len(self.s_Id)):
for j in range(0, len(self.DupId)):
if self.DupId[j] == self.s_Id[i]:
self.DupAssay.append(self.s_Assay1[i])
return self.DupAssay
def Onclose(self, event):
sys.exit(0)
if __name__ == "__main__":
#Create the app
app = wx.App()
#set the icon of app
icon_path = os.path.normpath(os.getcwd()) + "/img/qaqcmin_icon.png"
icon = wx.Icon(icon_path, wx.BITMAP_TYPE_PNG)
frame = MainFrame(None)
frame.SetIcon(icon)
frame.Show()
app.MainLoop()