-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathseed.py
More file actions
109 lines (94 loc) · 5.13 KB
/
Copy pathseed.py
File metadata and controls
109 lines (94 loc) · 5.13 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
from datetime import datetime, time, date, timedelta
from models.enums.animal_species import Species
from models.enums.schedule_state import ScheduleState
from models.user import Admin, Vet, Caretaker, Volunteer
from models.animal import Animal
from models.walk_schedule import WalkSchedule
from models.examination import Examination, Vaccination, PreventiveCheckUp
from models.request import Request
from models.enums.vaccination_type import VaccinationType
from models.metadata import Metadata
import pytz
def seed_data(db):
# Checking metadata table to see, if data were olready seeded
# Prevention of seeding new data with every refresh
if Metadata.query.filter_by(name='seed_data').first():
return
gmt_tz = pytz.timezone("Europe/Prague")
# User seeds
admin1 = Admin(login='admin1', first_name='John', last_name='Doe', password='1234', role='admin', email='admin1@example.com')
vet1 = Vet(login='vet1', first_name='James', last_name='Smith', password='1234', role='vet', email='vet1@example.com')
vet2 = Vet(login='vet2', first_name='Gordon', last_name='Ramsay', password='1234', role='vet', email='vet2@example.com')
caretaker1 = Caretaker(login='caretaker1', first_name='Robert', last_name='Adams', password ='1234', role='caretaker', email='caretaker1@example.com')
volunteer1 = Volunteer(login='volunteer1', first_name='Teresa', last_name='Gilbert', password ='1234', role='volunteer', email='volunteer1@example.com', verified=True)
volunteer2 = Volunteer(login='volunteer2', first_name='Simon', last_name='Doe', password ='1234', role='volunteer', email='volunteer2@example.com', verified=True)
db.session.add_all([admin1, vet1, vet2, caretaker1, volunteer1, volunteer2])
db.session.commit()
# Animal seeds
animal1 = Animal(name='Bob', species=Species.DOG.value, weight=30, birth_date=datetime(2020, 10, 1, 12, 0), photo='https://images.pexels.com/photos/5265677/pexels-photo-5265677.jpeg', description="A good Boy")
animal2 = Animal(name='Greg', species=Species.CAT.value, weight=30, birth_date=datetime(2021, 10, 1, 12, 0), photo='https://images.pexels.com/photos/20787/pexels-photo.jpg', description="A cute cat")
db.session.add_all([animal1, animal2])
db.session.commit()
# Examination seeds
vaccination1 = Vaccination(date=datetime(2024, 10, 6, 12, 0), description='Rabies vaccination', type='vaccination', animal_id=animal1.id, vet_id=vet1.id, vaccination_type=VaccinationType.RABIES.value)
vaccination2 = Vaccination(date=datetime(2024, 10, 6, 12, 0), description='Distemper vaccination', type='vaccination', animal_id=animal1.id, vet_id=vet1.id, vaccination_type=VaccinationType.DISTEMPER.value)
vaccination3 = Vaccination(date=datetime(2024, 10, 6, 12, 0), description='Parvovirus vaccination', type='vaccination', animal_id=animal2.id, vet_id=vet1.id, vaccination_type=VaccinationType.PARVOVIRUS.value)
checkup1 = PreventiveCheckUp(date=datetime(2024, 10, 6, 15, 0), description='General health checkup', type='preventive_checkup', animal_id=animal2.id, vet_id=vet1.id)
db.session.add_all([vaccination1, vaccination2, vaccination3, checkup1])
db.session.commit()
request1 = Request(
title='Preventive CheckUp',
description="Animal needs a preventive checkup",
caretaker_id=caretaker1.id,
animal_id=animal1.id,
vet_id=vet1.id)
request2 = Request(
title='Examination',
description="Animal needs to get checked for ticks",
caretaker_id=caretaker1.id,
animal_id=animal2.id,
vet_id=vet1.id)
db.session.add_all([request1, request2])
db.session.commit()
# Walk schedule seeds
schedule1 = WalkSchedule(
date= date(2024, 12, 12),
start_time=time( 12, 0),
end_time=time(13, 0),
description='Morning walk',
state=ScheduleState.FREE.value,
animal_id=animal1.id,
caretaker_id=caretaker1.id)
schedule2 = WalkSchedule(
date=date(2024, 12, 12),
start_time=time(12, 0),
end_time=time(13, 0),
description='Evening walk',
state=ScheduleState.FREE.value,
animal_id=animal2.id,
caretaker_id=caretaker1.id)
schedule3 = WalkSchedule(
date=date(2024, 10, 10),
start_time=time(12, 0),
end_time=time(13, 0),
description='Evening walk',
state=ScheduleState.COMPLETED.value,
animal_id=animal2.id,
caretaker_id=caretaker1.id,
volunteer_id=volunteer1.id)
schedule4 = WalkSchedule(
date=datetime.now(gmt_tz).date(),
start_time=(datetime.now(gmt_tz) - timedelta(minutes=30)).time(),
end_time=(datetime.now(gmt_tz) + timedelta(minutes=30)).time(),
description='Walk',
state=ScheduleState.IN_PROGRESS.value,
animal_id=animal2.id,
caretaker_id=caretaker1.id,
volunteer_id=volunteer1.id)
db.session.add_all([schedule1, schedule2, schedule3, schedule4])
db.session.commit()
# Adding seed flag into metadata table
seed_flag = Metadata(name='seed_data', value='true')
db.session.add(seed_flag)
db.session.commit()
# print("Seed.py: Finished seeding data")