-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
67 lines (49 loc) · 1.74 KB
/
utils.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
import csv
import pandas as pd
from braid import *
class FamilyParser:
def __init__(self, csv_file):
self.raw_csv = open(csv_file, newline='', encoding='utf-8-sig')
self.family_data = csv.DictReader(self.raw_csv)
self.family_members = None
self.birthdays = None
def __del__(self):
self.raw_csv.close()
def __next__(self):
return next(self.family_data)
def get_family_members(self):
if self.family_members is None:
self.family_members = []
for member in self.family_data:
self.family_members.append(FamilyMember(member))
return self.family_members
def get_month_sorted_family(self):
if self.family_members is None:
self.get_family_members()
return sorted(self.family_members, key=lambda x: x.get_birth().month)
class FamilyMember:
def __init__(self, infoDict):
self.birth = pd.to_datetime(infoDict["Birth"], dayfirst=True)
self.death = pd.to_datetime(infoDict["Death"], dayfirst=True)
self.reference_num = int(infoDict["Reference Number"])
self.name = infoDict["Name"]
self.thread = None
def get_ref_num(self):
return self.reference_num
def get_name(self):
return self.name
def get_birth(self):
return self.birth
def get_death(self):
return self.death
def set_braid_thread(self, thread):
self.thread = thread
def get_thread(self):
return self.thread
def passed(self, year):
if pd.isnull(self.death) or self.death.year > year:
return False
elif self.death.year == year:
self.thread.chord = E2, DOM
self.thread.velocity = 1
return True