Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stacked allocations for commitment view #236

Merged
merged 2 commits into from
Oct 16, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9"]
python-version: ["3.11", "3.12"]
os: [ubuntu-22.04]
runs-on: ${{ matrix.os }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion RSEAdmin/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import include, url
from django.conf.urls import include
from django.urls import re_path
from django.contrib import admin

Expand Down
1,039 changes: 515 additions & 524 deletions poetry.lock

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ authors = ["Paul Richmond <[email protected]>"]
license = "MIT"

[tool.poetry.dependencies]
python = "^3.8"
Django = "^3.2"
django-adminlte2 = "~0.4.1"
python = "^3.11"
Django = "^4.2"
django-adminlte2 = "~0.4.3"
django-polymorphic = "^3.1"
gunicorn = {version = "^20.1", optional = true}
psycopg2 = "^2.9"
gunicorn = {version = "^22.0", optional = true}
psycopg2 = "^2.9.9"
mysqlclient = {version = "^2", optional = true}
python-dateutil = "~2.8.2"
python-dateutil = "~2.9.0"
cryptography = "^39.0"
setuptools = "69.5.1"

[tool.poetry.dev-dependencies]
pytest-cov = "^3.0"
Expand Down
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
62 changes: 61 additions & 1 deletion 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 All @@ -9,7 +11,7 @@
from django.db.utils import OperationalError, ProgrammingError
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from polymorphic.models import PolymorphicModel
from django.db.models import Max, Min, QuerySet
from typing import Iterator, Union, TypeVar, Generic
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' | list,
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
Loading