Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions states/djo/dictee.mod.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ class State(BaseState):
name = "dictee"
index = 7
delay = 30

dictee_font = "./static/fonts/Montserrat-Medium.ttf"
dictee_font_bold = "./static/fonts/Montserrat-BoldItalic.ttf"
show_time = 7 # time every result is displayed on-screen, including slide animation
results = []
elapsed = 0

# get dictee data
async def get_results(self):
try:
response = await self.client.get("https://dictee.djoleden.nl/lichtkrant-api/", timeout=5)
response = await self.client.get("https://dictee.djoleden.nl/api/v1/lichtkrant", timeout=5)
except httpx.RequestError:
return []
return response.json()
Expand All @@ -30,31 +33,31 @@ async def check(self, _state):
async def run(self):
scroll_x = 0
fonts = {
"font9": ImageFont.truetype(self.font_path, size=9),
"font11": ImageFont.truetype(self.font_path, size=11),
"font16": ImageFont.truetype(self.font_path, size=16)
"font9": ImageFont.truetype(self.dictee_font, size=9),
"font11": ImageFont.truetype(self.dictee_font, size=11),
"font16": ImageFont.truetype(self.dictee_font_bold, size=16)
}

while not self.killed:
image = Image.new("RGB", (96, 32), "black")
draw = ImageDraw.Draw(image)
draw.rectangle([(0, 0), (96, 9)], fill=(89, 49, 150))
draw.rectangle([(0, 0), (96, 9)], fill=(7, 40, 50))
draw.text((48, 1), "UITSLAG DICTEE", fill="white", anchor="mt", font=fonts["font11"])
for i, res in enumerate(self.results):
draw.text((2 + i * 96 - scroll_x, 12), res["name"], fill="white", anchor="lt", font=fonts["font11"])
draw.text((2 + i * 96 - scroll_x, 23), str(res["score"]) + "/" + str(res["total"]),
fill=(200, 200, 200), anchor="lt", font=fonts["font9"])
draw.text((2 + i * 96 - scroll_x, 11), res["name"], fill="white", anchor="lt", font=fonts["font11"])
draw.text((2 + i * 96 - scroll_x, 22), f"{res['score']} / {res['total']}",
fill=(200, 200, 200), anchor="lt", font=fonts["font9"])

grade = round(res["score"] * 9 / res["total"] + 1, 1)
grade_color = "lime" if grade >= 5.5 else "red"
draw.text((93 + i * 96 - scroll_x, 21), str(grade), fill=grade_color, anchor="rm", font=fonts["font16"])
grade_color = "lime" if res["passed"] else "red"
draw.text((93 + i * 96 - scroll_x, 20), str(res["grade"]),
fill=grade_color, anchor="rm", font=fonts["font16"])

await self.output_image(image)
self.elapsed += 0.2
self.elapsed += 0.1
if self.elapsed % self.show_time >= (self.show_time - 1) and len(self.results) > 1:
# round() to prevent addition glitches
scroll_x = round(scroll_x + (96 / 5), 1)
scroll_x = round(scroll_x + (96 / 10), 1)
if scroll_x >= len(self.results) * 96:
scroll_x = 0

await asyncio.sleep(0.2)
await asyncio.sleep(0.1)
Binary file added static/fonts/Montserrat-BoldItalic.ttf
Binary file not shown.
Binary file added static/fonts/Montserrat-Medium.ttf
Binary file not shown.
Binary file removed static/fonts/nm-games-font.ttf
Binary file not shown.