1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2020 Pierre Ratinaud
4 #modification pour python 3 : Laurent Mérat, 6x7 - mai 2020
7 #------------------------------------
8 # import des modules python
9 #------------------------------------
14 from time import sleep
16 #------------------------------------
17 # import des modules wx
18 #------------------------------------
20 import wx.lib.sized_controls as sc
22 #------------------------------------
23 # import des fichiers du projet
24 #------------------------------------
25 from chemins import ffr,FFF, ConstructPathOut
26 from functions import exec_rcode, check_Rresult, progressbar
27 from PrintRScript import ProtoScript
28 from analysematrix import AnalyseMatrix
29 from dialog import ProtoDial
32 class Prototypical(AnalyseMatrix) :
34 # def __init__(self, parent, parametres):
35 # self.parent = parent
36 # self.tableau = self.parent.tableau
37 # self.parametres = parametres
38 # self.parametres['filename'] = parent.tableau.parametre['filename']
39 # self.parametres['pathout'] = ConstructPathOut(parent.tableau.parametre['filename'], 'proto')
40 # self.parametres['type'] = 'proto'
41 # dlg = progressbar(self.parent, 2)
42 # self.colnames = self.tableau.get_colnames()
43 # AnalyseMatrix.__init__(self, parent, parent.tableau, self.parametres, dlg = dlg)
45 def doparametres(self, dlg = None):
46 self.dial = ProtoDial(self.ira, self.tableau.colnames)
47 self.dial.CenterOnParent()
48 self.val = self.dial.ShowModal()
49 if self.val==wx.ID_OK :
50 self.ColSel1 = self.dial.variables.GetSelections()
51 self.ColSel2 = self.dial.rangs.GetSelections()
52 if len(self.ColSel1) != len(self.ColSel2) :
53 print('pas meme taille')
56 if self.dial.choix_freq.GetSelection() == 0 :
57 self.parametres['limfreq'] = 'NULL'
59 self.parametres['limfreq'] = self.dial.freqlim.GetValue()
60 if self.dial.choix_rang.GetSelection() == 0 :
61 self.parametres['limrang'] = 'NULL'
63 self.parametres['limrang'] = self.dial.ranglim.GetValue()
64 self.parametres['freqmin'] = int(self.dial.m_textCtrl4.GetValue())
65 if self.dial.typegraph.GetSelection() == 0 :
66 self.parametres['typegraph'] = 'classical'
67 self.parametres['cloud'] = False
68 elif self.dial.typegraph.GetSelection() == 1 :
69 self.parametres['typegraph'] = 'classical'
70 self.parametres['cloud'] = True
72 self.parametres['typegraph'] = 'plan'
76 self.parametres = None
79 table_assoc, table_rank = self.dotable()
80 self.makedatas(table_assoc, table_rank)
84 table_assoc = self.tableau.select_col(self.ColSel1)
85 table_rank = self.tableau.select_col(self.ColSel2)
86 return table_assoc, table_rank
88 def makedatas(self, table_assoc, table_rank) :
90 for i in range(0, len(table_assoc)) :
91 for j, word in enumerate(table_assoc[i]) :
92 if word.strip() != "" :
95 if table_rank[i][j] != '' :
96 words[word][1].append(float(table_rank[i][j]))
98 if table_rank[i][j] != '' :
99 words[word] = [1, [float(table_rank[i][j])]]
101 words[word] = [1, []]
102 res = [[word, words[word][0], float(sum(words[word][1])) / len(words[word][1])] for word in words if len(words[word][1]) != 0 and words[word][0] >= self.parametres['freqmin']]
103 with open(self.pathout['table.csv'], 'w', encoding='utf8') as f :
104 f.write('\n'.join(['\t'.join(['"' + val[0] +'"', repr(val[1]), repr(val[2])]) for val in res]))
105 #self.parent.tableau.parametres = self.parent.tableau.parametre
106 #self.parent.tableau.save_tableau(self.pathout['analyse.db'])
109 script = ProtoScript(self)
111 self.doR(script.scriptout)