Refactor calendar (month and year view), switching to vertical slice arch. Also in progress of refactoring of stats so they are retreived after inital page load for performance sake
This commit is contained in:
60
utils.py
60
utils.py
@@ -1,6 +1,5 @@
|
||||
import colorsys
|
||||
from datetime import datetime, date, timedelta
|
||||
import random
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
@@ -214,65 +213,6 @@ def flatten(lst):
|
||||
result.append(item)
|
||||
return result
|
||||
|
||||
|
||||
def get_date_info(input_date, selected_view):
|
||||
if selected_view not in ['month', 'year']:
|
||||
raise ValueError(
|
||||
'selected_view must be either "month" or "year"')
|
||||
|
||||
# First day of the month
|
||||
first_day_of_month = input_date.replace(day=1)
|
||||
|
||||
# Last day of the month
|
||||
if input_date.month == 12:
|
||||
last_day_of_month = input_date.replace(
|
||||
year=input_date.year+1, month=1, day=1) - timedelta(days=1)
|
||||
else:
|
||||
last_day_of_month = input_date.replace(
|
||||
month=input_date.month+1, day=1) - timedelta(days=1)
|
||||
|
||||
# First and last day of the year
|
||||
first_day_of_year = input_date.replace(month=1, day=1)
|
||||
last_day_of_year = input_date.replace(
|
||||
year=input_date.year+1, month=1, day=1) - timedelta(days=1)
|
||||
|
||||
# Next/previous month
|
||||
year, month = divmod(input_date.year * 12 + input_date.month, 12)
|
||||
next_month = date(year, month + 1, 1)
|
||||
prev_month_last_day = first_day_of_month - timedelta(days=1)
|
||||
prev_month = prev_month_last_day.replace(day=1)
|
||||
|
||||
# Next/previous year
|
||||
next_year = input_date.replace(year=input_date.year+1)
|
||||
prev_year = input_date.replace(year=input_date.year-1)
|
||||
|
||||
# Business logic, should move above to a separate function
|
||||
if selected_view == 'month':
|
||||
# Step 1: Find the first Sunday before or on the first day of the month
|
||||
days_to_subtract = (first_day_of_month.weekday() + 1) % 7
|
||||
start_date = first_day_of_month - timedelta(days=days_to_subtract)
|
||||
|
||||
# Step 2: Calculate the last day to display, based on the number of weeks
|
||||
end_date = start_date + timedelta(days=6 * 7 - 1)
|
||||
|
||||
return {
|
||||
'next_date': next_month,
|
||||
'previous_date': prev_month,
|
||||
'first_date_of_view': first_day_of_month,
|
||||
'last_date_of_view': last_day_of_month,
|
||||
'start_date': start_date,
|
||||
'end_date': end_date,
|
||||
}
|
||||
elif selected_view == 'year':
|
||||
return {
|
||||
'next_date': next_year,
|
||||
'previous_date': prev_year,
|
||||
'first_date_of_view': first_day_of_year,
|
||||
'last_date_of_view': last_day_of_year,
|
||||
'start_date': first_day_of_year,
|
||||
'end_date': last_day_of_year,
|
||||
}
|
||||
|
||||
def get_exercise_graph_model(title, estimated_1rm, repetitions, weight, start_dates, messages, epoch, person_id, exercise_id):
|
||||
min_date, max_date = min(start_dates), max(start_dates)
|
||||
min_e1rm, max_e1rm = min(estimated_1rm), max(estimated_1rm)
|
||||
|
||||
Reference in New Issue
Block a user