-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfTraitement.py
107 lines (86 loc) · 2.5 KB
/
fTraitement.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 10 19:43:14 2017
@author: temoana
"""
import re
#Renvoie un dictionnaire de cle Fonction(indice) et valeur une liste de valeur
def readGEO(filegeo):
d={}
lval = []
fic = open (filegeo,'r')
for ligne in fic:
r = re.search( '(.*)\(([0-9]*)\) = ({.*});' , ligne )
if r :
fonction = r.group(1)
indice = r.group (2)
val = r.group(3)
val = val.strip('{}')
lval = val.split(',')
d[fonction+'('+indice+')'] = lval
fic.close()
return d
#d = readGEO('trueone.geo')
#for cle,val in d.items():
# print (cle + ' = ' + str(val))
#print ()
# Renvoie un dictionnaire qui a X et Y en clé et les coordonnees a changé en valeur
#filetxt = 'substitution.txt'
def readSubstitution (filetxt):
dico={}
fic = open (filetxt,'r')
for ligne in fic:
r = re.search( '<#(.)>:(.*)' , ligne )
if r :
cle = r.group(1)
val = r.group(2)
l = val.split(';')
dico[cle]=l
fic.close()
return dico, len(l)
#dico, l = readSubstitution('substitution.txt')
#for cle,val in dico.items():
#print (str(cle) + " = " + str(val))
#Renvoie deux listes la premiere est la str(Fonction) et l'autre son int(indice) associé
#Peut etre construit dans read
def DecomposeCle(dic):
l = []
k = []
for cle in dic:
r = re.search('(.*)\(([0-9]*)\)', cle)
if r :
l.append(str(r.group(1)))
k.append(str(r.group(2)))
return l,k
#fonction,indice = DecomposeCle(d)
#for i in range(len(fonction)) :
# print (fonction[i] + " a pour indice " + indice[i])
#Renvoie les indices de la Fonction du dictionnaire
def IndiceFonction (dic,fonction) :
l,k = DecomposeCle (dic)
ListeIndice = []
for n in range(len(dic)) :
if l[n] == fonction :
ListeIndice.append(k[n])
return ListeIndice
#a = IndiceFonction(d,'Point')
#print (a)
def minmaxListe (l) :
minl = l[0]
maxl = l[0]
for i in range(1,len(l)) :
if minl > l[i] :
minl = l[i]
elif maxl < l[i] :
maxl = l[i]
return minl, maxl
#l = [ 145, 7, 52, 5, 221, 8]
#print(minListe(l))
#Renvoie True si un élément appartient a une liste ou False sinon
#def appartient (liste, element) :
# a = False
# for i in range(len(liste)) :
# if liste[i] == element:
# a = True
# return a