Skip to content

Commit

Permalink
Add stacked allocations for commitment view
Browse files Browse the repository at this point in the history
  • Loading branch information
twinkarma committed Jul 26, 2024
1 parent c760819 commit 5496ba3
Show file tree
Hide file tree
Showing 13 changed files with 5,953 additions and 38 deletions.
1 change: 1 addition & 0 deletions rse/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class FilterProjectForm(FilterDateRangeForm):

rse_in_employment = forms.ChoiceField(
choices=(('All', 'All'), ('Yes', 'Yes'), ('No', 'No')),
initial="All",
widget=forms.Select(attrs={'class': 'form-control pull-right'})
)
# Type cant be filtered at database level as it is a property
Expand Down
60 changes: 60 additions & 0 deletions rse/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from __future__ import annotations

import math
from datetime import date, timedelta
from django.utils import timezone
from math import floor
Expand Down Expand Up @@ -894,6 +896,10 @@ def colour_rbg(self) -> Dict[str, int]:
b = hash(self.end) % 255
return {"r": r, "g": g, "b": b}

@property
def border_colour_rbg(self) -> Dict[str, int]:
return {colour_name: math.ceil(colour * 1.1) for colour_name, colour in self.colour_rbg.items()}


class DirectlyIncurredProject(Project):
"""
Expand Down Expand Up @@ -1242,3 +1248,57 @@ def commitment_summary(allocations: 'RSEAllocation', from_date: date = None, unt

# Return list of unique (date, effort, [RSEAllocation])
return list(zip(unique_dates, unique_effort, unique_cumulative_allocations))

@staticmethod
def stacked_commitment_summary(allocations: 'RSEAllocation',
from_date: date = None,
until_date: date = None,
percent_scaling = 1.0):
default_delta = timedelta(days=30*6)
if from_date is None:
from_date = date.today() - default_delta

if until_date is None:
until_date = date.today() + default_delta

if not isinstance(allocations, QuerySet):
# If it's a list item instead of a query object
# means multiple allocations have been passed
all_allocations = []
for allocation in allocations:
for item in allocation:
all_allocations.append(item)
allocations = all_allocations


# Get all dates
all_dates = {from_date, until_date, date.today()}
for item in allocations:
all_dates.add(item.start)
all_dates.add(item.end)

# Convert to list and sort earliest first
all_dates = list(all_dates)
all_dates.sort()

out_allocs = {}
for item in allocations:
item_alloc = []
if item.start >= from_date:
# Don't add if before from_date
item_alloc.append({"x": item.start, "y": item.percentage * percent_scaling})
for alloc_date in all_dates:
if item.start < alloc_date < item.end and from_date <= alloc_date <= until_date:
# Add allocation percentage for all dates between start and end
item_alloc.append({"x": alloc_date, "y": item.percentage * percent_scaling})
if item.end <= until_date:
# Don't add if after until_date
item_alloc.append({"x": item.end, "y": 0})
out_allocs[item] = item_alloc

return out_allocs





1 change: 1 addition & 0 deletions rse/static/chartjs/chart4.min.js

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions rse/static/chartjs/chart4.umd.js

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions rse/static/chartjs/chartjs-adapter-moment.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5496ba3

Please sign in to comment.