events
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
from PIL import Image, ImageDraw, ImageFont
|
from PIL import Image, ImageDraw, ImageFont
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from datetime import datetime
|
from datetime import datetime, time
|
||||||
import logging
|
import logging
|
||||||
import signal
|
import signal
|
||||||
import sys
|
import sys
|
||||||
@@ -88,6 +88,67 @@ def draw_clock():
|
|||||||
#draw_label('Time:', x - MARGIN_PIXELS, y + CLOCK_HEIGHT_PIXELS)
|
#draw_label('Time:', x - MARGIN_PIXELS, y + CLOCK_HEIGHT_PIXELS)
|
||||||
|
|
||||||
|
|
||||||
|
def draw_countdown(x, y, target_dt, size=STATUS_SIZE_MULTIPLIER):
|
||||||
|
"""
|
||||||
|
Draws a countdown/countup to target_dt: green if more than 15 minutes away,
|
||||||
|
yellow if less than 15 minutes away, red if target_dt is in the past.
|
||||||
|
"""
|
||||||
|
now = datetime.now()
|
||||||
|
delta_seconds = (target_dt - now).total_seconds()
|
||||||
|
if delta_seconds >= 0:
|
||||||
|
color = (255, 255, 0) if delta_seconds < 15 * 60 else (0, 255, 0)
|
||||||
|
else:
|
||||||
|
color = (255, 0, 0)
|
||||||
|
|
||||||
|
total = abs(int(delta_seconds))
|
||||||
|
hours, remainder = divmod(total, 3600)
|
||||||
|
minutes = remainder // 60
|
||||||
|
|
||||||
|
draw_clock_digits(x, y, size, f'{hours:02}', f'{minutes:02}', 1, color)
|
||||||
|
|
||||||
|
|
||||||
|
WORKDAY_EVENTS = [
|
||||||
|
(7, 0, 'Wake up'),
|
||||||
|
(8, 0, 'Start working'),
|
||||||
|
(11, 0, 'Scrum meeting'),
|
||||||
|
(14, 0, 'Physiotherapy'),
|
||||||
|
(15, 0, 'Lunch'),
|
||||||
|
(18, 0, 'Close work day'),
|
||||||
|
(18, 30, 'Evening walk'),
|
||||||
|
(22, 0, 'Close the day'),
|
||||||
|
(23, 0, 'Go to sleep'),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def next_workday_event(now=None):
|
||||||
|
"""
|
||||||
|
Returns (target_dt, label) for the next event in WORKDAY_EVENTS, or None on weekends.
|
||||||
|
Once past the last event of the day, keeps returning it (now overdue) until midnight.
|
||||||
|
"""
|
||||||
|
now = now or datetime.now()
|
||||||
|
if now.weekday() >= 5:
|
||||||
|
return None
|
||||||
|
|
||||||
|
today = now.date()
|
||||||
|
for hour, minute, label in WORKDAY_EVENTS:
|
||||||
|
dt = datetime.combine(today, time(hour, minute))
|
||||||
|
if dt > now:
|
||||||
|
return dt, label
|
||||||
|
|
||||||
|
last_hour, last_minute, last_label = WORKDAY_EVENTS[-1]
|
||||||
|
return datetime.combine(today, time(last_hour, last_minute)), last_label
|
||||||
|
|
||||||
|
|
||||||
|
def draw_next_event(order):
|
||||||
|
result = next_workday_event()
|
||||||
|
if result is None:
|
||||||
|
return
|
||||||
|
target, label = result
|
||||||
|
x, y = status_clock_position(order)
|
||||||
|
draw_countdown(x, y, target, STATUS_SIZE_MULTIPLIER)
|
||||||
|
draw_label(f'{label}:', x - MARGIN_PIXELS, y + CLOCK_HEIGHT_PIXELS * STATUS_SIZE_MULTIPLIER)
|
||||||
|
|
||||||
|
|
||||||
def milestone_countdown(order, target_date, label):
|
def milestone_countdown(order, target_date, label):
|
||||||
x, y = status_clock_position(order)
|
x, y = status_clock_position(order)
|
||||||
right_x = x + CLOCK_WIDTH_PIXELS * STATUS_SIZE_MULTIPLIER
|
right_x = x + CLOCK_WIDTH_PIXELS * STATUS_SIZE_MULTIPLIER
|
||||||
@@ -124,25 +185,12 @@ def draw_fasting(status, order):
|
|||||||
|
|
||||||
if 'fasting' in status and status['fasting']:
|
if 'fasting' in status and status['fasting']:
|
||||||
label = 'Breakfast'
|
label = 'Breakfast'
|
||||||
date = datetime.strptime(status['fast']['projected_end'], "%Y-%m-%d %H:%M:%S")
|
target = datetime.strptime(status['fast']['projected_end'], "%Y-%m-%d %H:%M:%S")
|
||||||
delta = date - datetime.now()
|
|
||||||
hours = delta.seconds // 3600
|
|
||||||
minutes = (delta.seconds // 60) % 60
|
|
||||||
color = (0, 255, 0)
|
|
||||||
else:
|
else:
|
||||||
label = 'Fasting'
|
label = 'Fasting'
|
||||||
date = datetime.now().replace(hour=16, minute=0, second=0, microsecond=0)
|
target = datetime.now().replace(hour=16, minute=0, second=0, microsecond=0)
|
||||||
if date > datetime.now():
|
|
||||||
delta = date - datetime.now()
|
|
||||||
color = (0, 255, 0)
|
|
||||||
else:
|
|
||||||
delta = datetime.now() - date
|
|
||||||
color = (255, 0, 0)
|
|
||||||
|
|
||||||
hours = delta.seconds // 3600
|
draw_countdown(x, y, target, STATUS_SIZE_MULTIPLIER)
|
||||||
minutes = (delta.seconds // 60) % 60
|
|
||||||
|
|
||||||
draw_clock_digits(x, y, STATUS_SIZE_MULTIPLIER, f'{hours:02}', f'{minutes:02}', 1, color)
|
|
||||||
draw_label(f'{label}:', x - MARGIN_PIXELS, y + CLOCK_HEIGHT_PIXELS * STATUS_SIZE_MULTIPLIER)
|
draw_label(f'{label}:', x - MARGIN_PIXELS, y + CLOCK_HEIGHT_PIXELS * STATUS_SIZE_MULTIPLIER)
|
||||||
|
|
||||||
def clear_status_area():
|
def clear_status_area():
|
||||||
@@ -153,6 +201,7 @@ def clear_status_area():
|
|||||||
|
|
||||||
while True:
|
while True:
|
||||||
draw_clock()
|
draw_clock()
|
||||||
|
draw_next_event(order=2.5)
|
||||||
try:
|
try:
|
||||||
status = get_status_data()
|
status = get_status_data()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user