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):
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)
34 res = self.check_val()
38 self.dial = ProtoDial(self.ira, self.colnames)
39 self.dial.CenterOnParent()
41 self.val = self.dial.ShowModal()
42 if self.val==wx.ID_OK :
43 self.ColSel1 = self.dial.variables.GetSelections()
44 self.ColSel2 = self.dial.rangs.GetSelections()
46 if len(self.ColSel1) != len(self.ColSel2) :
47 print 'pas meme taille'
50 if self.dial.choix_freq.GetSelection() == 0 :
51 self.parametres['limfreq'] = 'NULL'
53 self.parametres['limfreq'] = self.dial.freqlim.GetValue()
54 if self.dial.choix_rang.GetSelection() == 0 :
55 self.parametres['limrang'] = 'NULL'
57 self.parametres['limrang'] = self.dial.ranglim.GetValue()
58 self.parametres['freqmin'] = int(self.dial.m_textCtrl4.GetValue())
59 table_assoc, table_rank = self.dotable()
60 self.makedatas(table_assoc, table_rank)
66 table_assoc = self.tableau.select_col(self.ColSel1)
67 table_rank = self.tableau.select_col(self.ColSel2)
68 return table_assoc, table_rank
70 def makedatas(self, table_assoc, table_rank) :
72 for i in range(0, len(table_assoc)) :
73 for j, word in enumerate(table_assoc[i]) :
76 if table_rank[i][j] != '' :
77 words[word][1].append(int(table_rank[i][j]))
79 if table_rank[i][j] != '' :
80 words[word] = [1, [int(table_rank[i][j])]]
83 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']]
84 with open(self.pathout['table.csv'], 'w') as f :
85 f.write('\n'.join(['\t'.join(['"' + val[0] +'"', `val[1]`, `val[2]`]) for val in res]))
86 self.parent.tableau.parametres = self.parent.tableau.parametre
87 self.parent.tableau.save_tableau(self.pathout['analyse.db'])
90 script = ProtoScript(self)
92 self.doR(script.scriptout)