Merge branch 'master' of http://www.netdig.org/git/iramuteq
[iramuteq] / analysematrix.py
1 #!/bin/env python
2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2013 Pierre Ratinaud
5 #Lisense: GNU GPL
6
7
8
9 import logging
10 import os
11 from time import time
12 from uuid import uuid4
13
14
15 from chemins import PathOut
16 from functions import exec_rcode, check_Rresult, DoConf
17 from time import time, sleep
18 from openanalyse import OpenAnalyse
19
20 class AnalyseMatrix :
21     def __init__(self, ira, tableau, parametres = None, dlg = False) :
22         self.tableau = tableau
23         self.ira = ira
24         self.parent = ira
25         self.dlg = dlg
26         self.parametres = parametres
27         self.val = False
28         if not 'pathout' in self.parametres :
29             self.pathout = PathOut(tableau.parametres['filename'], analyse_type = parametres['type'], dirout = parametres['pathout'])
30         else :
31             self.pathout = PathOut(filename = tableau.parametres['filename'], dirout = self.parametres['pathout'], analyse_type = self.parametres['type'])
32
33         self.parametres['pathout'] = self.pathout.dirout
34         self.parametres['uuid'] = str(uuid4())
35         self.parametres['name'] = os.path.split(self.parametres['pathout'])[1]
36         self.parametres['encoding'] = self.ira.syscoding
37
38         self.t1 = time()
39         result_analyse = self.doanalyse()
40         if result_analyse is None :
41             self.time = time() - self.t1
42             minutes, seconds = divmod(self.time, 60)
43             hours, minutes = divmod(minutes, 60)            
44             self.parametres['time'] = '%.0fh %.0fm %.0fs' % (hours, minutes, seconds)
45             self.parametres['ira'] = self.pathout['Analyse.ira']
46             DoConf().makeoptions([self.parametres['type']], [self.parametres], self.pathout['Analyse.ira'])
47             self.ira.history.addMatrix(self.parametres)
48             if dlg :
49                 dlg.Destroy()
50                 OpenAnalyse(self.parent, self.parametres['ira'])
51                 #self.ira.tree.AddAnalyse(self.parametres)
52                 self.val = 5100
53         else :
54             self.val = False
55             if dlg :
56                 dlg.Destroy()
57  
58     def doanalyse(self) :
59         pass
60     
61     def doR(self, Rscript, wait = False, dlg = None, message = '') :
62         log.info('R code...')
63         pid = exec_rcode(self.ira.RPath, Rscript, wait = wait)
64         while pid.poll() is None :
65             if dlg :
66                 self.dlg.Pulse(message)
67                 sleep(0.2)
68             else :
69                 sleep(0.2)
70         return check_Rresult(self.ira, pid)
71