-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathScheduleImage.py
More file actions
151 lines (116 loc) · 5.69 KB
/
ScheduleImage.py
File metadata and controls
151 lines (116 loc) · 5.69 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
import ast
from wand.image import Image
from wand.display import display
from wand.drawing import Drawing
from wand.color import Color
import sqlite3
from Classes.Group import Group
from Classes.Student import Student
from Classes.Teacher import Teacher
from Classes.Appointment import Appointment
appDbConn = sqlite3.connect('./appointments.db')
appDbCursor = appDbConn.cursor()
dbConn = sqlite3.connect('./database.db')
dbCursor = dbConn.cursor()
# Input variables
titleText = "Rooster voor week 69"
groupIds = ast.literal_eval(dbCursor.execute('SELECT groupInDepartments FROM STUDENTS WHERE student = \'[temp redacted]\' ').fetchone()[0])
groups = [Group.from_tuple(dbCursor.execute(f'SELECT * FROM GROUPS WHERE id = {groupId}').fetchone()) for groupId in groupIds]
appointments = []
for group in groups:
appointments += appDbCursor.execute(f'SELECT * FROM \'45\' WHERE groupsInDepartments LIKE ?', (f"%{group.id}%",)).fetchall()
weekStartTimestamp = 1730674800
appointments = [Appointment.from_tuple(appointment) for appointment in appointments]
minTimeSlot = min([appointment.startTimeSlot for appointment in appointments])
maxTimeSlot = max([appointment.endTimeSlot for appointment in appointments])
print(minTimeSlot)
print(maxTimeSlot)
# Color Variables
titleColor = Color("white")
titleStrokeColor = Color("gray95")
titleTextColor = Color("black")
weekColor = Color("white")
weekStrokeColor = Color("gray95")
weekTextColor = Color("black")
dayColor = Color("gray90")
dayStrokeColor = Color("gray85")
dayTextColor = Color("black")
appointmentColor = Color("purple")
appointmentStrokeColor = Color("indigo")
appointmentTextColor = Color("black")
# Width and Height of the image
width = 1600
height = 1000
# Margins
appointmentMargin = 5
dayMargin = 5
weekMargin = 10
titleMarginTopBottom = 20
titleMarginLeftRight = 100
# Title Factor, how much of the image the title should take (including margin)
titleFactor = 0.15
titleFontSize = 50
# Calculate the height of the title
titleHeight = height * titleFactor
# Title
titleDrawing = Drawing()
titleDrawing.fill_color = titleColor
titleDrawing.stroke_color = titleStrokeColor
titleDrawing.rectangle(left=titleMarginLeftRight, top=titleMarginTopBottom, right=width - titleMarginLeftRight, bottom=titleHeight - titleMarginTopBottom, radius=10)
titleTextDrawing = Drawing()
titleTextDrawing.font_size = titleFontSize
titleTextDrawing.fill_color = titleTextColor
titleTextDrawing.text_alignment = "center"
titleTextDrawing.text(int(width / 2), int(titleHeight / 2 + titleFontSize / 3), titleText)
# Week
weekDrawing = Drawing()
weekDrawing.fill_color = weekColor
weekDrawing.stroke_color = weekStrokeColor
weekDrawing.rectangle(left=weekMargin, top=weekMargin + titleHeight, right=width-weekMargin, bottom=height-weekMargin, radius=10)
# Days
dayTitleSpace = 50
dayWidth = (width - 2 * weekMargin) / 5
dayHeight = height - titleHeight - 2 * weekMargin
appointmentHeight = (dayHeight - dayTitleSpace - 2 * dayMargin) / (maxTimeSlot - minTimeSlot + 1)
dayDrawing = Drawing()
dayDrawing.fill_color = dayColor
dayDrawing.stroke_color = dayStrokeColor
dayDrawingText = Drawing()
dayDrawingText.font_size = 20
dayDrawingText.fill_color = dayTextColor
dayDrawingText.text_alignment = "center"
appointmentDrawing = Drawing()
appointmentDrawing.fill_color = appointmentColor
appointmentDrawing.stroke_color = appointmentStrokeColor
appointmentTextDrawing = Drawing()
appointmentTextDrawing.font_size = 20
appointmentTextDrawing.fill_color = appointmentTextColor
appointmentTextDrawing.text_alignment = "center"
for i in range(5):
dayStartTimestamp = weekStartTimestamp + i * 86400
dayEndTimestamp = weekStartTimestamp + (i + 1) * 86400
appointmentsOfDay = [appointment for appointment in appointments if dayStartTimestamp <= appointment.start < dayEndTimestamp]
dayDrawing.rectangle(left=weekMargin + i * dayWidth + dayMargin, top=weekMargin + titleHeight + dayMargin, right=weekMargin + (i + 1) * dayWidth - dayMargin, bottom=height - weekMargin - dayMargin, radius=10)
dayDrawingText.text(int(weekMargin + i * dayWidth + dayWidth / 2), int(weekMargin + titleHeight + dayMargin + dayTitleSpace / 2), "Day " + str(i + 1))
for appointment in appointmentsOfDay:
appointmentLocation = appointment.locationsOfBranch[0]
appointmentLocationName = dbCursor.execute(f"SELECT name FROM LOCATIONS WHERE id = {appointmentLocation}").fetchone()[0]
appointmentText = f"{str(appointment.startTimeSlot) + ((" - " + str(appointment.endTimeSlot)) if appointment.endTimeSlot != appointment.startTimeSlot else "")} - {appointment.subjects[0]} - {appointment.teachers[0]} - {appointmentLocationName} "
appointmentStart = appointment.startTimeSlot
appointmentEnd = appointment.endTimeSlot
appointmentTop = titleHeight + weekMargin + dayMargin + dayTitleSpace + appointmentMargin + (appointmentStart - minTimeSlot) * appointmentHeight
appointmentBottom = titleHeight + weekMargin + dayMargin + dayTitleSpace + (appointmentEnd - minTimeSlot + 1) * appointmentHeight - appointmentMargin
appointmentDrawing.rectangle(left=weekMargin + i * dayWidth + dayMargin + appointmentMargin, top=appointmentTop, right=weekMargin + (i + 1) * dayWidth - dayMargin - appointmentMargin, bottom=appointmentBottom, radius=10)
appointmentTextDrawing.text(int(weekMargin + i * dayWidth + dayWidth / 2), int(appointmentTop + (appointmentBottom - appointmentTop) / 2), appointmentText)
# Finalize
img = Image(width=width, height=height, format="png")
titleDrawing.draw(img)
titleTextDrawing.draw(img)
weekDrawing.draw(img)
dayDrawing.draw(img)
dayDrawingText.draw(img)
appointmentDrawing.draw(img)
appointmentTextDrawing.draw(img)
img.format = "PNG"
img.save(filename="schedule.png")
# display(img)