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 #------------------------------------
13 from time import sleep
14 from uuid import uuid4
19 #------------------------------------
20 # import des modules wx
21 #------------------------------------
24 #------------------------------------
25 # import des fichiers du projet
26 #------------------------------------
27 from chemins import ConstructPathOut, simipath, ffr, PathOut
28 from functions import print_liste, exec_rcode, read_list_file, check_Rresult, indices_simi, treat_var_mod, normpath_win32
29 from dialog import SelectColDial, FreqDialog
30 from guifunct import PrefSimi
31 from analysematrix import AnalyseMatrix
32 from PrintRScript import PrintSimiScript
34 from configparser import RawConfigParser
37 class DoSimi(AnalyseMatrix):
39 def doparametres(self, dlg = None) :
40 self.fromprof = self.parametres.get('fromprof', False)
41 self.wordgraph = self.parametres.get('wordgraph', False)
42 self.listactives = self.parametres.get('listactives', False)
43 self.actives = self.parametres.get('actives', False)
44 self.openfromprof = self.parametres.get('openfromprof', False)
45 self.cmd = self.parametres.get('cmd', False)
46 self.dirout = self.parametres.get('pathout', False)
48 self.paramsimi = self.parametres
50 self.paramsimi = {'coeff' : 0,
71 'cola' : (200,200,200),
83 self.indices = indices_simi
86 self.pathout = PathOut(dirout = self.dirout)
87 if not self.parametres.get('isopen', False) :
88 if self.tableau is None :
89 self.tableau = parent.tableau
90 self.tableau.parametres['mineff'] = 0
91 if not self.fromprof :
92 dialcol = FreqDialog(self.parent, self.tableau.get_colnames(), _("Select columns"), size=(600, 250), showNA = False)
93 dialcol.CenterOnParent()
94 res = dialcol.ShowModal()
99 self.tableau.selected_col = dialcol.m_listBox1.GetSelections()
100 actives = self.tableau.getactlistfromselection(self.tableau.selected_col)
102 actives = self.actives
103 if isinstance(actives, dict) :
104 actives = [[val, actives[val][0]] for val in actives]
105 self.tableau.actives = dict(actives)
106 self.tableau.make_listactives()
107 actives = dict([[i, val] for i, val in enumerate(actives)])
108 self.dial = PrefSimi(self.parent, -1, self.paramsimi, self.indices, wordlist = actives)
109 self.dial.CenterOnParent()
110 self.val = self.dial.ShowModal()
111 if self.val == wx.ID_OK :
112 last = self.dial.listcol.GetFirstSelected()
113 lastl = [self.dial.listcol.GetFirstSelected()]
114 indexes = [self.dial.listcol.getColumnText(self.dial.listcol.GetFirstSelected(),0)]
115 while self.dial.listcol.GetNextSelected(last) != -1:
116 last = self.dial.listcol.GetNextSelected(last)
118 indexes.append(self.dial.listcol.getColumnText(last,0))
119 self.column = [self.tableau.listactives.index(val) for val in indexes]
121 self.paramsimi = self.make_param()
122 self.parametres.update(self.paramsimi)
123 #self.parametres['type'] = 'simimatrix'
124 if not self.pathout :
125 self.parametres['pathout'] = ConstructPathOut(self.parametres['pathout'], 'SimiMatrix')
127 self.parametres['pathout'] = self.dirout
128 self.pathout.createdir(self.parametres['pathout'])
129 self.pathout.dirout = self.parametres['pathout']
134 self.parametres = None
138 self.parametres = None
141 def doanalyse(self) :
142 self.pathout.basefiles(simipath)
143 with open(normpath_win32(self.pathout['selected.csv']), 'w', encoding='utf8') as f :
144 f.write('\n'.join([repr(val) for val in self.column]))
146 keepGoing = self.dlg.Update(count)
147 #----------------------------------------------------------------
150 self.Linecontent = []
151 #--------------------------------------------------------
153 #if not self.fromprof :
154 #self.pathout = ConstructPathOut(self.tableau.parametres['filename'], 'Simi')
155 #self.DictPathOut = construct_simipath(self.pathout)
156 self.tableau.dictpathout = self.pathout
157 self.dlg.Update(count, "passage en O/1")
158 if not self.fromprof :
159 self.tableau.make_01_from_selection(self.tableau.selected_col)
160 #self.Linecontent = parent.table
163 #self.pathout = pathout
164 #self.DictPathOut = construct_simipath(self.pathout)
165 self.DictPathOut = self.pathout
166 #self.DictPathOut['mat01'] = fromprof
167 self.script = PrintSimiScript(self)
168 self.script.make_script()
171 self.dlg.Update(count, "R...")
172 #self.DoR(script.scriptout, dlg = self.dlg, message = 'R...')
173 self.tmpfile = self.script.scriptout
176 self.tableau.save_tableau(self.pathout['analyse.db'])
179 #self.dlg.Update(count, u"")
188 def make_param(self) :
189 if self.paramsimi['first'] :
192 keep_coord = self.dial.check_coord.GetValue()
193 #self.select = self.dial.check_colch.GetValue()
194 paramsimi = {'coeff' : self.dial.choice1.GetSelection(),
195 'layout' : self.dial.choice2.GetSelection(),
196 'type_graph' : self.dial.choice3.GetSelection(),
197 'arbremax' : self.dial.check1.GetValue(),
198 'coeff_tv' : self.dial.check_s_size.GetValue(),
199 'coeff_tv_nb' : self.dial.spin_tv.GetValue(),
200 'tvprop' : self.dial.check2.GetValue(),
201 'tvmin' : self.dial.spin_tvmin.GetValue(),
202 'tvmax' : self.dial.spin_tvmax.GetValue(),
203 'coeff_te' : self.dial.check3.GetValue(),
204 'coeff_temin' : self.dial.spin_temin.GetValue(),
205 'coeff_temax' : self.dial.spin_temax.GetValue(),
206 'label_e' : self.dial.check_elab.GetValue(),
207 'label_v' : self.dial.check_vlab.GetValue(),
208 'vcex' : self.dial.check_vcex.GetValue(),
209 'vcexmin' : self.dial.spin_vcexmin.GetValue(),
210 'vcexmax' : self.dial.spin_vcexmax.GetValue(),
211 'cex' : self.dial.spin_cex.GetValue(),
212 'seuil_ok' : self.dial.check_seuil.GetValue(),
213 'seuil' : self.dial.spin_seuil.GetValue(),
214 'cols' : self.dial.cols.GetColour(),
215 'cola' : self.dial.cola.GetColour(),
216 'width' : self.dial.spin_width.GetValue(),
217 'height' : self.dial.spin_height.GetValue(),
219 'keep_coord' : keep_coord,
220 'alpha' : self.dial.slider_sphere.GetValue(),
221 'film' : self.dial.film.GetValue(),
222 'svg' : self.dial.choix_format.GetSelection(),
223 'halo' : self.dial.halo.GetValue(),
224 'com' : self.dial.comcheck.GetValue(),
225 'communities' :self.dial.choix_com.GetSelection(),
227 if 'cexfromchi' in self.paramsimi :
228 paramsimi['cexfromchi'] = self.dial.checkit.GetValue()
229 if 'sfromchi' in self.paramsimi :
230 paramsimi['sfromchi'] = self.dial.checki.GetValue()
231 if 'vlabcolor' in self.paramsimi :
232 paramsimi['vlabcolor'] = self.paramsimi['vlabcolor']
233 if 'check_bystar' in dir(self.dial) :
234 paramsimi['bystar'] = self.dial.check_bystar.GetValue()
235 paramsimi['stars'] = self.paramsimi['stars']
236 if 'tmpchi' in self.paramsimi :
237 paramsimi['tmpchi'] = self.paramsimi['tmpchi']
241 if self.parametres['type_graph'] == 1:
242 if self.parametres['svg'] :
243 filename, ext = os.path.splitext(self.script.filename)
244 fileout = filename + '.svg'
246 fileout = self.script.filename
247 if os.path.exists(self.DictPathOut['liste_graph']):
248 graph_simi = read_list_file(self.DictPathOut['liste_graph'])
249 graph_simi.append([os.path.basename(fileout), self.script.txtgraph])
251 graph_simi = [[os.path.basename(fileout), self.script.txtgraph]]
252 print_liste(self.DictPathOut['liste_graph'], graph_simi)
255 if self.paramsimi['type_graph'] == 1 :
261 pid = exec_rcode(self.ira.RPath, self.tmpfile, wait = wait, graph = graph)
262 if self.paramsimi['type_graph'] == 1 :
263 while pid.poll() == None :
269 check_Rresult(self.parent, pid)