-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSistemaEncuestas.py
More file actions
375 lines (317 loc) · 12.6 KB
/
SistemaEncuestas.py
File metadata and controls
375 lines (317 loc) · 12.6 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
from ast import If
import csv
from re import L
from configparser import ConfigParser
from datetime import date
import os
class Geografias:
# CONSTRUCTOR
def __init__(self, pComuna, pSeccion, pDivision):
self.__Comuna = pComuna
self.__Seccion = pSeccion
self.__Division = pDivision
# GETTERS
@property
def Comuna(self):
return self.__Comuna
@property
def Seccion(self):
return self.__Seccion
@property
def Division(self):
return self.__Division
# SETTERS
@Comuna.setter
def Comuna(self, pComuna):
self.__Comuna = pComuna
@Seccion.setter
def Seccion(self, pSeccion):
self.__Seccion = pSeccion
@Division.setter
def Division(self, pDivision):
self.__Division = pDivision
def GeoCompleta(self):
return 'C'+self.__Comuna+'S'+self.__Seccion+'D'+self.__Division
# la info formularios es un archivo
class Personas(Geografias):
# CONSTRUCTOR
def __init__(self, pNombre, pApellido, pCargo, pLegajo, geografia):
self.__Nombre = pNombre
self.__Apellido = pApellido
self.__Cargo = pCargo
self.__Legajo = pLegajo
self.geografia = geografia
# super().__init__(pComuna, pSeccion, pDivision)
# GETTERS
@property
def Nombre(self):
return self.__Nombre
# GETTERS
@property
def Apellido(self):
return self.__Apellido
# GETTERS
@property
def Cargo(self):
return self.__Cargo
# GETTERS
@property
def Legajo(self):
return self.__Legajo
# SETTERS
@Nombre.setter
def Nombre(self, pNombre):
self.__Nombre = pNombre
# SETTERS
@Apellido.setter
def Apellido(self, pApellido):
self.__Apellido = pApellido
# SETTERS
@Cargo.setter
def Cargo(self, pCargo):
self.__Cargo = pCargo
# SETTERS
@Legajo.setter
def Legajo(self, pLegajo):
self.__Legajo = pLegajo
class Informes(Geografias):
def cantEncuestados():
encuestas=[]
count=0
encuestas=Encuestas.consultarEncuestas()
for linea in encuestas:
count+=1
return count
def porcentajesAumentaran():
encuestas={}
aumentaran=0
lista=[0]*15
encuestas=Encuestas.consultarEncuestas()
for i in encuestas:
if i["preg1"].lower()=='si':
lista[int(i["comuna"])-1]=lista[int(i["comuna"])-1]+1
for j in range(len(lista)):
aumentaran=(lista[j]/len(encuestas))*100
print(f"De la comuna {j+1} cree que aumentaran los preccios el {aumentaran}%")
print(f"De la comuna {j+1} No cree que aumentaran los preccios el {100-aumentaran}%")
def productoEnAumento():
encuestas = {}
aumentaran = 0
lista = [0] * 15
encuestas = Encuestas.consultarEncuestas()
for i in encuestas:
if i["preg1"].lower() == 'si':
lista[int(i["comuna"]) - 1] = lista[int(i["comuna"]) - 1] + 1
class Encuestas(Geografias):
def __init__(self, preg1, preg2, preg3, preg4, geografia):
self.pre1 = preg1
self.pre2 = preg2
self.pre3 = preg3
self.pre4 = preg4
self.geografia = geografia
#GETTERS
@property
def Preg1(self):
return self.pre1
@property
def Preg2(self):
return self.pre2
@property
def Preg3(self):
return self.pre3
@property
def Preg4(self):
return self.pre4
@property
def Geografia(self):
return self.geografia
#SETTERS
@Preg1.setter
def Preg1(self, pre1):
self.pre1 = pre1
@Preg2.setter
def Preg2(self, pre2):
self.pre2 = pre2
@Preg3.setter
def Preg3(self, pre3):
self.pre3 = pre3
@Preg4.setter
def Preg4(self, pre4):
self.pre4 = pre4
@Geografia.setter
def Geografia(self, geografia):
self.geografia = geografia
def cargaEncuestas():
encabezados = ("Inflacion aumentara: ", "Producto mayor aumento: ", "Aumento sus ingresos: ","Compras extraordinarias: ","su Comuna: ","su Seccion :", "su Division :")
fileName = "D:\Python-POO\Python-POO\Encuestas\procesadoEl" + date.today().strftime("%d-%m-%Y") + ".txt"
guardar = "si"
try:
while guardar == "si":
encuestasCargada = {}
renglonCargado = []
for cadaEncabezado in encabezados:
encuestasCargada[cadaEncabezado] = input(f"ingrese {cadaEncabezado} ")
geo=Geografias(encuestasCargada["su Comuna: "],encuestasCargada["su Seccion :"], encuestasCargada["su Division :"])
encu=Encuestas(encuestasCargada["Inflacion aumentara: "],encuestasCargada["Producto mayor aumento: "],encuestasCargada["Aumento sus ingresos: "],encuestasCargada["Compras extraordinarias: "],geo)
with open(fileName, "a", newline="") as file:
archivoCSV = csv.writer(file, delimiter=",")
renglonCargado.append(encu.Preg1)
renglonCargado.append(encu.Preg2)
renglonCargado.append(encu.Preg3)
renglonCargado.append(encu.Preg4)
renglonCargado.append(geo.GeoCompleta())
renglonCargado.append(geo.Comuna)
archivoCSV.writerow(renglonCargado)
guardar = input("\tDesea seguir agregando empleados? Si/No: ").lower()
except Exception as e:
print(f"error: {e}")
finally:
Gestiones.Menu()
def consultarEncuestas () :
os.chdir('D:\Python-POO\Python-POO\Encuestas')
filelist = os.listdir(os.getcwd())
data = []
for archivo in filelist:
encabezados = ("preg1", "preg2", "preg3", "preg4","geo","comuna")
with open(archivo,"r", newline='') as lecCSV:
reader = csv.DictReader(lecCSV,fieldnames=encabezados)
for row in reader:
data.append(row)
print(f"Datos cargados: {data}") # Imprimir datos cargados
return data
# encabezados = ("preg1", "preg2", "preg3", "preg4","geo")
# # with open(archivo, "r") as lecCSV:
# # lectura = csv.DictReader(lecCSV,fieldnames=encabezados)
# # for linea in lectura:
# # if linea["geo"] == Encuestas.Geografia:
# # print(" es igual el dato")
# with open(archivo,"r", newline='') as lecCSV:
# reader = csv.DictReader(lecCSV,fieldnames=encabezados)
# # next(reader, None) # skip the headers
# data = []
# for row in reader:
# data.append(row)
# return data
class Gestiones():
# ESTA CLASE ADMINISTRA LOS METODOS DE GESTION DEL PROGRAMA
def Login(pUsuario, pClave):
try:
with open("logins.csv", "r") as read_obj:
try:
csv_reader = csv.reader(read_obj)
row = []
for row in csv_reader:
if pUsuario == row[0] and pClave == row[1]:
return True
except Exception as e:
print(e)
finally:
read_obj.close()
# except:
# print("El Archivo de logeuo esta corrupto o no existe")
except Exception as e:
print(e)
def CargaLiderYCoord():
try:
lider = 0
coordinador = 0
clave = input("Ingrese la clave habilitadora: ")
# LEO EL ARCHIVO config.cfg PARA SABER SI PUEDE CREAR LIDERES Y COORDINADORES
config_object = ConfigParser()
config_object.read("config.cfg")
userinfo = config_object["USERINFO"]
if clave == userinfo["key1"]:
# MIENTRAS NO LOS CARGUE TODOS SIGUE CARGANDO
while lider < 90 or coordinador < 15:
# CARGO PRIMERO LOS COORDINADORES
if coordinador < 15:
try:
print('Cargando el Coordinador numero %2d, Maximo 15' % (coordinador + 1))
nombre = input('Nombre Coordinador: ')
apellido = input('Apellido Coordinador: ')
dni = input('DNI Coordinador: ')
legajo = 'C-' + dni
cargo = 'Coordinador'
# INTENTO GUARDARLO AL ARCHIVO
# ABRO EL ARCHIVO PARA AGREGAR AL FINAL
with open("Coordinadores.txt", "a") as file_object:
# GUARDO MI COORDINADOR Y SALTO DE LINEA
file_object.write(nombre + apellido + ',' + legajo + '\n')
coordinador += 1
except Exception as e:
print(e)
finally:
# CIERRO EL ARCHIVO
file_object.close()
# SIGO CON LOS LIDERES
elif lider < 90:
try:
print('Cargando el Lider numero %2d, Maximo 15' % (coordinador + 1))
nombre = input('Nombre lider: ')
apellido = input('Apellido lider: ')
dni = input('DNI lider: ')
legajo = 'L-' + dni
cargo = 'Lider'
# INTENTO GUARDARLO AL ARCHIVO
# ABRO EL ARCHIVO PARA AGREGAR AL FINAL
with open("Lideres.txt", "a") as file_object:
# GUARDO MI COORDINADOR Y SALTO DE LINEA
file_object.write(nombre + apellido + ',' + legajo + '\n')
coordinador += 1
except Exception as e:
print(e)
finally:
# CIERRO EL ARCHIVO
file_object.close()
print('Finalizo la carga de Lideres y coordinadores')
Gestiones.Menu()
except Exception as e:
print(e)
def Menu():
try:
print('Menu:')
print('Opcion 1: Cargar Lideres y Coordinadores')
print('Opcion 2: Login')
print('Opcion 3: Salir')
#print('Opcion 4: Cargar Encuesta')
print('Opcion 4: Consultar Encuestas') #ES NECESARIO CONSULTARLAS, EL NOMMBRE DEL ARCHIVO VA A SER RANDOM
print('Opcion 5: Cantidad de Encuestados Totales?')
print('Opcion 6: Porcentaje de personas creen precios aumentaran?')
print('Opcion 10: Porcentaje de personas creen precios aumentaran?')
opcion = input('Elija su opcion: ')
match opcion:
case '1':
Gestiones.CargaLiderYCoord()
Gestiones.Menu()
case '2':
usuario = input('ingrese usuario: ')
clave = input('ingrese clave: ')
if Gestiones.Login(usuario, clave):
Encuestas.cargaEncuestas()
else:
print ('Usuario o Clave incorrectas.')
Gestiones.Menu()
case '3':
# EL RETURN 0 ME SACA DE LA SELECCION
return 0
case '4':
#ES NECESARIO CONSULTARLAS, EL NOMMBRE DEL ARCHIVO VA A SER RANDOM
Encuestas.consultarEncuestas()
Gestiones.Menu()
print(f"Encuestas: {Encuestas}")
case '5':
cantidad=Informes.cantEncuestados()
print(f"La cantidad de encuestados totales es {cantidad}")
Gestiones.Menu()
case '6':
aumentaran=Informes.porcentajesAumentaran()
# print(f"Porcentaje de personas que creen que aumentaran es {aumentaran}%")
# print(f"Porcentaje de personas que creen no aumentara es {100-aumentaran}%")
Gestiones.Menu()
case '10':
print("opcion 10!!!")
Gestiones.Menu()
except Exception as e:
print(e)
# METODO MAIN
Gestiones.Menu()