2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2012 Pierre Ratinaud
13 from chemins import ffr,FFF, ConstructPathOut
14 import wx.lib.sized_controls as sc
15 from time import sleep
16 from functions import exec_rcode, check_Rresult, progressbar
17 from PrintRScript import ProtoScript
18 from analysematrix import AnalyseMatrix
19 from dialog import ProtoDial
21 class Prototypical(AnalyseMatrix) :
22 # def __init__(self, parent, parametres):
23 # self.parent = parent
24 # self.tableau = self.parent.tableau
25 # self.parametres = parametres
26 # self.parametres['filename'] = parent.tableau.parametre['filename']
27 # self.parametres['pathout'] = ConstructPathOut(parent.tableau.parametre['filename'], 'proto')
28 # self.parametres['type'] = 'proto'
29 # dlg = progressbar(self.parent, 2)
30 # self.colnames = self.tableau.get_colnames()
31 # AnalyseMatrix.__init__(self, parent, parent.tableau, self.parametres, dlg = dlg)
33 def doparametres(self, dlg = None):
34 self.dial = ProtoDial(self.ira, self.tableau.colnames)
35 self.dial.CenterOnParent()
37 self.val = self.dial.ShowModal()
38 if self.val==wx.ID_OK :
39 self.ColSel1 = self.dial.variables.GetSelections()
40 self.ColSel2 = self.dial.rangs.GetSelections()
42 if len(self.ColSel1) != len(self.ColSel2) :
43 print 'pas meme taille'
46 if self.dial.choix_freq.GetSelection() == 0 :
47 self.parametres['limfreq'] = 'NULL'
49 self.parametres['limfreq'] = self.dial.freqlim.GetValue()
50 if self.dial.choix_rang.GetSelection() == 0 :
51 self.parametres['limrang'] = 'NULL'
53 self.parametres['limrang'] = self.dial.ranglim.GetValue()
54 self.parametres['freqmin'] = int(self.dial.m_textCtrl4.GetValue())
55 if self.dial.typegraph.GetSelection() == 0 :
56 self.parametres['typegraph'] = 'classical'
57 self.parametres['cloud'] = False
58 elif self.dial.typegraph.GetSelection() == 1 :
59 self.parametres['typegraph'] = 'classical'
60 self.parametres['cloud'] = True
62 self.parametres['typegraph'] = 'plan'
66 self.parametres = None
69 table_assoc, table_rank = self.dotable()
70 self.makedatas(table_assoc, table_rank)
74 table_assoc = self.tableau.select_col(self.ColSel1)
75 table_rank = self.tableau.select_col(self.ColSel2)
76 return table_assoc, table_rank
78 def makedatas(self, table_assoc, table_rank) :
80 for i in range(0, len(table_assoc)) :
81 for j, word in enumerate(table_assoc[i]) :
82 if word.strip() != "" :
85 if table_rank[i][j] != '' :
86 words[word][1].append(float(table_rank[i][j]))
88 if table_rank[i][j] != '' :
89 words[word] = [1, [float(table_rank[i][j])]]
92 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']]
93 with open(self.pathout['table.csv'], 'w') as f :
94 f.write('\n'.join(['\t'.join(['"' + val[0] +'"', `val[1]`, `val[2]`]) for val in res]))
95 #self.parent.tableau.parametres = self.parent.tableau.parametre
96 #self.parent.tableau.save_tableau(self.pathout['analyse.db'])
99 script = ProtoScript(self)
101 self.doR(script.scriptout)