Skip to content

Commit

Permalink
Heatmap same-date fix (#411)
Browse files Browse the repository at this point in the history
* +- tomorrow fix

* formatting

fix accidental formatting from when debugging

* Reformat using black

---------

Co-authored-by: Kresten Laust <[email protected]>
  • Loading branch information
Naitsabot and krestenlaust authored Mar 3, 2024
1 parent 397730a commit 39b7b1b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions stregsystem/purchase_heatmap.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from datetime import datetime, timedelta, date
from typing import List, NamedTuple, Tuple

from stregsystem.models import Product, Member, Category
from datetime import datetime, timedelta, date

from stregsystem.templatetags.stregsystem_extras import money


Expand Down Expand Up @@ -184,6 +183,9 @@ def __get_heatmap_data_by_date(
end_date: datetime.date,
weeks_to_display: int,
) -> List[Tuple[date, List[Product]]]:
# add a day
end_date += timedelta(days=1)

days_to_go_back = (7 * weeks_to_display) - (6 - end_date.weekday() - 1)
cutoff_date = end_date - timedelta(days=days_to_go_back)

Expand All @@ -205,6 +207,10 @@ def __get_heatmap_data_by_date(
products_by_day[-1].append(last_sale_list[sale_index].product)
sale_index += 1

# remove added day
products_by_day.pop(0)
dates_by_day.pop(0)

return list(zip(dates_by_day, products_by_day))


Expand Down

0 comments on commit 39b7b1b

Please sign in to comment.