Skip to content

Commit c4c8d8e

Browse files
committed
merged all classes in the same files and added checks
1 parent 9721fea commit c4c8d8e

File tree

2 files changed

+160
-20
lines changed

2 files changed

+160
-20
lines changed

main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
3+
4+
5+
6+
7+
if __name__ == "__main__":

persona.py

Lines changed: 153 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,70 @@
11
from abc import ABCMeta, abstractmethod
22
import logging
3+
from datetime import datetime
4+
35

46
logging.basicConfig(filename = 'log_es_persona.log' ,format=' %(levelname)s %(asctime) s %(message)s',level=logging.DEBUG)
57
logger = logging.getLogger(__name__)
68

9+
stipendi = {
10+
"addetto_pulizia": {
11+
1: 2000,
12+
2: 1800,
13+
3: 1700,
14+
4: 1500,
15+
5: 1400,
16+
6: 1300,
17+
7: 1200
18+
},
19+
"inserviente": {
20+
1: 2050,
21+
2: 1850,
22+
3: 1750,
23+
4: 1550,
24+
5: 1450,
25+
6: 1350,
26+
7: 1250
27+
},
28+
"operaio": {
29+
1: 2500,
30+
2: 2300,
31+
3: 2000,
32+
4: 1900,
33+
5: 1800,
34+
6: 1500,
35+
7: 1400
36+
},
37+
"fattorino": {
38+
1: 2500,
39+
2: 2300,
40+
3: 2000,
41+
4: 1900,
42+
5: 1800,
43+
6: 1500,
44+
7: 1400
45+
},
46+
"Manager": {
47+
1: 4000,
48+
2: 3700,
49+
3: 3500,
50+
4: 3300,
51+
5: 3000,
52+
6: 2800,
53+
7: 2500
54+
},
55+
"Driettore": {
56+
1: 7000,
57+
2: 6500,
58+
3: 6200,
59+
4: 6000,
60+
5: 5800,
61+
6: 5500,
62+
7: 5000
63+
}
64+
65+
}
66+
67+
768
class Persona(metaclass=ABCMeta):
869
def __init__(self,nome, cognome, data_nascita, sesso, peso):
970
self._nome=nome
@@ -98,13 +159,6 @@ def check_id(idbadge):
98159
@abstractmethod
99160
def stipendio(self):
100161
pass
101-
102-
103-
from persona import Persona
104-
from datetime import datetime
105-
import logging
106-
107-
logger = logging.getLogger(__name__)
108162

109163

110164
class Studente(Persona):
@@ -184,6 +238,8 @@ def __init__(self, nome: str, cognome: str, sesso: bool, peso: int, data_di_nasc
184238
self._corso_di_studio = corso_di_studio
185239
self._alchool = alchool
186240
self._esami = esami
241+
logger.info(f"Studente {self._nome} {self._cognome}, matricola {self._matricola}, iscritto al corso di studio "
242+
f"{self._corso_di_studio}")
187243

188244
def __eq__(self, other):
189245
"""
@@ -194,8 +250,8 @@ def __eq__(self, other):
194250
return True if self._matricola == other.matricola else False
195251

196252
def __str__(self):
197-
return str(f"Studente {self._nome} {self._cognome}, matricola {self._matricola}, iscritto al corso di studio"
198-
f"{self._corso_di_studio}")
253+
return f"Studente {self._nome} {self._cognome}, matricola {self._matricola}, iscritto al corso di studio " \
254+
f"{self._corso_di_studio}"
199255

200256
def calcolo_media_esami(self):
201257
"""
@@ -216,19 +272,13 @@ def calcola_tasso_alcolemico(self):
216272
return sum_beverage * 0.008 * 1.055 / (coefficente_difusione * self._peso)
217273

218274

219-
from persona import Lavoratore
220-
221-
222275
class LavoratorePiva(Lavoratore):
223276
def __init__(self,nome, cognome, data_nascita, sesso, peso, idbadge, mansione,tariffa_gg, ore_lavorate):
224-
super().__init__(nome, cognome, data_nascita, sesso, peso, idbadge, mansione, tariffa_gg, ore_lavorate)
277+
super().__init__(nome, cognome, data_nascita, sesso, peso, idbadge, mansione)
225278
self._tariffa_gg=tariffa_gg
226279
self._ore_lavorate=ore_lavorate
227280
logger.info("E' stato inserito un lavoratore con P.iva.")
228281

229-
230-
231-
232282
def __str__(self):
233283
return super().__str__() + ' ' + self._tariffa_gg + ' ' + self._ore_lavorate
234284

@@ -258,9 +308,92 @@ def set_ore_lavorate(self,x):
258308
else:
259309
self._ore_lavorate=x
260310

261-
262-
263311
def calcola_stipendio(self):
264312
stipendio= sum(map(lambda x: x[0] + x[1], self._tariffa_gg.values(),self._ore_lavorate.values()))
265-
return stipendio
266-
313+
return stipendio
314+
315+
316+
class Dipendente(Lavoratore):
317+
318+
@staticmethod
319+
def check_liv(liv):
320+
if not isinstance(liv, int) or not 0 < liv <= 7:
321+
raise ValueError('Inserire un livello corretto')
322+
323+
def __init__(self, nome, cognome, data_nascita, sesso, peso, idbadge, mansione, livello):
324+
super().__init__(nome, cognome, data_nascita, sesso, peso, idbadge, mansione)
325+
Dipendente.check_liv(livello)
326+
self._livello = livello
327+
logger.info("E' stato inserito un dipendente.")
328+
329+
def __str__(self):
330+
return super().__str__() + ' ' + self._livello
331+
332+
def __eq__(self, other):
333+
if isinstance(other, Dipendente):
334+
if super().__eq__(other) and other._livello == self._livello:
335+
return True
336+
return False
337+
338+
def __hash__(self):
339+
return hash((super().__hash__(), self._livello))
340+
341+
def get_livello(self):
342+
return self._livello
343+
344+
def set_livello(self, x):
345+
Dipendente.check_liv(x)
346+
self._livello = x
347+
348+
349+
350+
def calcolo_stipendio(self, mansione, livl):
351+
return stipendi.get(mansione).get(livl)
352+
353+
354+
class FactoryDipendenti:
355+
356+
@staticmethod
357+
def createDipendente(tipo, *args, **kwargs):
358+
if tipo == "Dipendente":
359+
return Dipendente(*args, **kwargs)
360+
elif tipo == "LavoratorePiva":
361+
return LavoratorePiva(*args, **kwargs)
362+
363+
364+
class Check:
365+
366+
@staticmethod
367+
def max_tasso_alcolemico(studenti):
368+
tasso_alcolemico = [s.calcola_tasso_alcolemico() for s in studenti]
369+
max_tasso = max(tasso_alcolemico)
370+
return next(filter(lambda x: x.calcola_tasso_alcolemico() == max_tasso, studenti))
371+
372+
# senza lambda
373+
374+
# max_tasso = studenti[0].calcolo_tasso_alcolemico()
375+
# studente_max = studenti[0]
376+
# for s in studenti[1:]:
377+
# if s.calcola_tasso_alcolemico() > max_tasso:
378+
# studente_max = s
379+
# return studente_max
380+
381+
@staticmethod
382+
def max_media_studenti(studenti):
383+
media_studenti = [s.calcolo_media_esami() for s in studenti]
384+
max_media = max(media_studenti)
385+
return next(filter(lambda x: x.calcolo_media_esami() == max_media, studenti))
386+
387+
@staticmethod
388+
def is_ubriaco(studenti):
389+
return False if Check.max_media_studenti(studenti) == Check.max_tasso_alcolemico(studenti) else True
390+
391+
@staticmethod
392+
def aumento_a_livello(mansione, livello, aumento):
393+
if mansione not in stipendi.keys():
394+
raise ValueError("Mansione non presente.")
395+
if livello not in stipendi[mansione]:
396+
raise ValueError("Livello non in mansione")
397+
if isinstance(aumento, int):
398+
raise ValueError("Aumento deve essere di tipo intero")
399+
stipendi[mansione][livello] = + aumento

0 commit comments

Comments
 (0)