Skip to content

Commit

Permalink
Merge pull request #988 from sparcs-kaist/feature/timetable-image-7days
Browse files Browse the repository at this point in the history
feat: 7days timetable image
  • Loading branch information
sboh1214 authored Nov 6, 2023
2 parents 7950124 + 7244ca4 commit 8086f13
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions apps/timetable/services.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from enum import Enum
from typing import List, Optional, Tuple
import datetime
import pytz
Expand All @@ -8,7 +9,7 @@
from django.db.models import F, Case, When

from apps.session.models import UserProfile
from apps.subject.models import Lecture, Semester
from apps.subject.models import ClassTime, Lecture, Semester
from .models import Timetable


Expand All @@ -32,6 +33,10 @@
"#f4badb",
]

class TimetableType(Enum):
FIVE_DAYS = "5days"
SEVEN_DAYS = "7days"


def reorder_timetable(timetable: Timetable, target_arrange_order: int):
related_timetables = Timetable.get_related_timetables(timetable.user,
Expand Down Expand Up @@ -67,6 +72,17 @@ def get_timetable_entries(profile: UserProfile, table_id: int, year: int, semest

return list(table.lectures.filter(deleted=False))

def _get_timetable_type(lectures: List[Lecture]) -> TimetableType:
def _has_weekend():
for lecture in lectures:
classtimes: List[ClassTime] = lecture.classtimes.all()
for classtime in classtimes:
if classtime.day >= 5:
return True

return False

return TimetableType.SEVEN_DAYS if _has_weekend() else TimetableType.FIVE_DAYS

def _draw_rounded_rectangle(draw, points: Tuple[int, int, int, int], radius: int, color):
draw.pieslice([points[0], points[1], points[0] + radius * 2, points[1] + radius * 2],
Expand Down Expand Up @@ -150,7 +166,8 @@ def create_timetable_image(semester: Semester, lectures: List[Lecture], language
else:
file_path = "/var/www/otlplus/static/"

image = Image.open(file_path + "img/Image_template.png")
timetable_type = _get_timetable_type(lectures)
image = Image.open(file_path + f"img/Image_template_{timetable_type.value}.png")
draw = ImageDraw.Draw(image)
text_image = Image.new("RGBA", image.size)
text_draw = ImageDraw.Draw(text_image)
Expand All @@ -160,7 +177,8 @@ def create_timetable_image(semester: Semester, lectures: List[Lecture], language
is_english = language and ("en" in language)

semester_name = semester.get_name(language=language).title()
text_draw.text((952, 78),
semester_name_begin = 952 if timetable_type == TimetableType.FIVE_DAYS else 952 + 350
text_draw.text((semester_name_begin, 78),
semester_name,
fill=(204, 204, 204),
font=semester_font,
Expand Down
Binary file removed static/img/Image_template.png
Binary file not shown.
Binary file added static/img/Image_template_5days.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/Image_template_7days.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8086f13

Please sign in to comment.