-
Notifications
You must be signed in to change notification settings - Fork 0
/
driving_plan.py
26 lines (21 loc) · 964 Bytes
/
driving_plan.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
from typing import List, Tuple
from pydantic import BaseModel
class DrivingPlan(BaseModel):
drivings: List[Tuple[int, int]]
def per_family(self) -> List[Tuple[int, List[int]]]:
plan = []
for f in sorted(list(set([f for f, w in self.drivings]))):
plan.append([f, [w for ff, w in self.drivings if ff == f]])
return plan
def per_weekend(self) -> List[Tuple[int, List[int]]]:
plan = []
for w in sorted(list(set([w for f, w in self.drivings]))):
plan.append([w, [f for f, ww in self.drivings if ww == w]])
return plan
def show(self):
print('-'*80)
for weekend, families in self.per_weekend():
print(f'Weekend #{weekend}: {", ".join([f"Famille {family}" for family in families])}')
print('-'*10)
for family, weekends in self.per_family():
print(f'Family #{family}: {", ".join([f"WE{weekend}" for weekend in weekends])}')