2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2013 Pierre Ratinaud
11 from uuid import uuid4
12 from chemins import PathOut
13 from functions import exec_rcode, check_Rresult, DoConf, progressbar
14 from time import time, sleep
15 from openanalyse import OpenAnalyse
19 def __init__(self, ira, tableau, parametres = None, dlg = None) :
20 self.tableau = tableau
21 if self.tableau.csvtable is None :
26 self.parametres = parametres
28 if not 'pathout' in self.parametres :
29 self.parametres['pathout'] = PathOut(tableau.parametres['originalpath'], analyse_type = self.parametres['type'], dirout = tableau.parametres['pathout']).mkdirout()
30 self.pathout = PathOut(analyse_type = self.parametres['type'], dirout = self.parametres['pathout'])
32 self.pathout = PathOut(filename = tableau.parametres['originalpath'], dirout = self.parametres['pathout'], analyse_type = self.parametres['type'])
34 #self.parametres['pathout'] = self.pathout.dirout
35 self.parametres['uuid'] = str(uuid4())
36 self.parametres['name'] = os.path.split(self.parametres['pathout'])[1]
37 self.parametres['encoding'] = self.ira.syscoding
38 self.parametres['matrix'] = self.tableau.parametres['uuid']
39 self.tableau.pathout.dirout = self.parametres['pathout']
40 self.doparametres(dlg = dlg)
41 if self.dlg is not None :
42 self.dlg = progressbar(self.ira, self.dlg)
43 if self.parametres is not None :
45 if not os.path.exists(self.parametres['pathout']) :
46 self.pathout.createdir(self.parametres['pathout'])
47 result_analyse = self.doanalyse()
49 result_analyse = False
50 if result_analyse is None :
51 if self.parametres.get('tohistory', True) :
52 self.time = time() - self.t1
53 minutes, seconds = divmod(self.time, 60)
54 hours, minutes = divmod(minutes, 60)
55 self.parametres['time'] = '%.0fh %.0fm %.0fs' % (hours, minutes, seconds)
56 self.parametres['ira'] = self.pathout['Analyse.ira']
57 DoConf().makeoptions([self.parametres['type']], [self.parametres], self.pathout['Analyse.ira'])
58 self.ira.history.addMatrixAnalyse(self.parametres)
59 if self.dlg is not None :
61 if self.parametres.get('tohistory', True) :
62 OpenAnalyse(self.parent, self.parametres['ira'])
63 self.ira.tree.AddMatAnalyse(self.parametres)
67 if self.dlg is not None :
76 def doparametres(self, dlg = None):
79 def doR(self, Rscript, wait = False, dlg = None, message = '') :
80 #log.info('R code...')
81 pid = exec_rcode(self.ira.RPath, Rscript, wait = wait)
82 while pid.poll() is None :
84 self.dlg.Pulse(message)
88 return check_Rresult(self.ira, pid)