multisplit
[iramuteq] / tabcatego.py
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
5 #License: GNU/GPL
6
7 #------------------------------------
8 # import des modules python
9 #------------------------------------
10 import os
11 import tempfile
12 import json
13 import datetime
14 from time import sleep
15 from uuid import uuid4
16
17 import langue
18 langue.run()
19
20 #------------------------------------
21 # import des modules wx
22 #------------------------------------
23 import wx
24
25 #------------------------------------
26 # import des fichiers du projet
27 #------------------------------------
28 from chemins import ConstructPathOut, simipath, ffr, PathOut
29 from functions import print_liste, exec_rcode, read_list_file, check_Rresult, indices_simi, treat_var_mod, normpath_win32
30 from dialog import SelectColDial, FreqDialog
31 from analysematrix import AnalyseMatrix
32 from listlex import *
33 from configparser import RawConfigParser
34
35
36 class Categorisation(AnalyseMatrix):
37
38     def doparametres(self, dlg = None) :
39         self.listactives = self.parametres.get('listactives', False)
40         self.actives = self.parametres.get('actives', False)
41         self.cmd = self.parametres.get('cmd', False)
42         self.dirout = self.parametres.get('pathout', False)
43         self.Source = None
44         if self.dirout :
45             self.pathout = PathOut(dirout = self.dirout)
46         if not self.parametres.get('isopen', False) :
47             if self.tableau is None :
48                 self.tableau = parent.tableau
49             self.tableau.parametres['mineff'] = 0
50             dialcol = FreqDialog(self.parent, self.tableau.get_colnames(), _("Select columns"), size=(600, 250), showNA = False)
51             dialcol.CenterOnParent()
52             res = dialcol.ShowModal()
53             if res == wx.ID_OK :
54                 if not self.actives :
55                     self.tableau.selected_col = dialcol.m_listBox1.GetSelections()
56                     actives = self.tableau.getactlistfromselection(self.tableau.selected_col)
57                 else :
58                     actives = self.actives
59                 if isinstance(actives, dict) :
60                     actives = [[val, actives[val][0]] for val in actives]
61                     self.tableau.actives = dict(actives)
62                 self.tableau.make_listactives()
63                 actives = dict([[i, val] for i, val in enumerate(actives)])
64                 if not self.pathout :
65                     self.parametres['pathout'] = ConstructPathOut(self.parametres['pathout'], 'Categorisation')
66                 else :
67                     self.parametres['pathout'] = self.dirout
68                 self.pathout.createdir(self.parametres['pathout'])
69                 self.pathout.dirout = self.parametres['pathout']
70                 #self.doanalyse2()
71             else :
72                 dialcol.Destroy()
73                 self.parametres = None
74                 return False
75
76     def doanalyse(self) :
77         count = 1
78         keepGoing = self.dlg.Update(count)
79         #----------------------------------------------------------------
80         self.DictForme = {}
81         self.Min = 10
82         self.Linecontent = []
83         self.tableau.dictpathout = self.pathout
84         #self.DictPathOut['mat01'] = fromprof
85         #self.PrintScript()
86         cate = {'TOCATE':{}, 'CATE':{}}
87         for val in self.tableau.actives :
88             cate['TOCATE'][val] = self.tableau.actives[val][0]
89         with open(self.pathout['cate.json'], 'w', encoding='utf8') as f :
90             f.write(json.dumps(cate))
91         self.tableau.save_tableau(self.pathout['analyse.db'])
92         self.dlg.Destroy()
93