Skip to content

Commit

Permalink
Merge pull request #112 from kippnorcal/staging
Browse files Browse the repository at this point in the history
Bringing back Chronic Absences; Filtering out Stockton HS
  • Loading branch information
iMark3000 authored Sep 30, 2024
2 parents f54f05b + 9591fbf commit e4414d0
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 40 deletions.
14 changes: 11 additions & 3 deletions high_health/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import logging
import math
from typing import List
from datetime import datetime
from dateutil.relativedelta import relativedelta
from itertools import chain, groupby
from django.contrib.auth.models import Group
from django.contrib.auth.decorators import login_required, user_passes_test
from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import PermissionDenied
from django.db.models import Avg
from django.http import JsonResponse
Expand Down Expand Up @@ -54,8 +56,7 @@ def metrics(school_level):
data = []
for metric in metrics:
# Note: Summer 2024 - filtering out all HH reports except ADA, CA, and Suspensions
# Temporarily commenting out metric 3 - chronic absence
if metric.id in (2, 5):
if metric.id in (2, 3, 5):
measures = metric.measure_set.filter(school__school_level=school_level, is_current=True).order_by(order_by)
if measures:
metric_data = {
Expand All @@ -67,6 +68,12 @@ def metrics(school_level):
return sorted(data, key=lambda d: d["last_updated"], reverse=True)


def fill_missing_measures(measures, schools: List[Site]):
missing_indexes = set([index for index, measure in enumerate(measures) if measure.school not in schools])
filled_list = [measure if index not in missing_indexes else None for index, measure in enumerate(measures)]
return filled_list


def last_value(values):
if values:
return values[-1]
Expand Down Expand Up @@ -320,7 +327,8 @@ def high_health(request, school_level=None):
if school_level.name == "RS":
schools = Site.objects.filter(school_level=school_level).order_by("id")
else:
schools = Site.objects.filter(school_level=school_level)
# Filtering out Stockton HS
schools = Site.objects.filter(school_level=school_level).exclude(id=36)
context = {
"school_level": school_level,
"schools": schools,
Expand Down
10 changes: 5 additions & 5 deletions templates/high_health.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ <h1><strong>High Health:</strong> {{ school_level.display_name }}</h1>
</span>
</td>
{% for measure in metric.measures %}
{% if measure.value is None %}
<td class="text-center">
<span class="text-muted">
N/A
</span>
{% if measure is None or measure.value is None %}
<td class="text-center">
<span class="text-muted" id="metric-hover" data-toggle="tooltip" data-placement="right" title="No data for this school and metric">
N/A
</span>
</td>
{% else %}
<td
Expand Down
82 changes: 50 additions & 32 deletions templatetags/high_health_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
from typing import Union

from django import template
from high_health.models import Measure
Expand All @@ -10,59 +11,73 @@


@register.filter
def goal_format(measure):
def goal_format(measure: Measure) -> str:
# This method creates a tag that determines the color of the text
# Color codings found in css file
if measure.metric.frequency == "MoM":
current_month = measure.month
last_year = measure.year - 1
try:
previous_outcome = Measure.objects.filter(
metric=measure.metric.id,
date__month=current_month,
date__year=last_year,
school=measure.school)[0].value
except IndexError:
previous_outcome = measure.goal.previous_outcome
if previous_outcome is None:
previous_outcome = measure.goal.previous_outcome
previous_outcome = get_mom_previous_outcome(measure)
return mom_color_eval(measure, previous_outcome)
else:
previous_outcome = measure.goal.previous_outcome
return yoy_color_eval(measure, previous_outcome)


def yoy_color_eval(measure, previous):
def yoy_color_eval(measure: Measure, previous: Union[int, None]) -> str:
if measure.goal.goal_type.upper() == "ABOVE":
if measure.value >= measure.goal.target:
return "success"
elif previous is None:
return "secondary"
elif measure.goal.target > measure.value >= previous:
return "secondary"
else:
return "danger"
else:
elif measure.goal.goal_type.upper() != "ABOVE":
if measure.value <= measure.goal.target:
return "success"
elif previous is None:
return "secondary"
elif measure.goal.target < measure.value <= previous:
return "secondary"
else:
return "danger"


def mom_color_eval(measure, previous):
# Filtering the % Staffed metric out of evaluation
if measure.metric.id == 36:
return "secondary"
def get_mom_previous_outcome(measure: Measure) -> Union[int, None]:
current_month = measure.month
last_year = measure.year - 1
try:
previous_outcome = Measure.objects.filter(
metric=measure.metric.id,
date__month=current_month,
date__year=last_year,
school=measure.school)[0].value
except IndexError:
previous_outcome = None
return previous_outcome


def mom_color_eval(measure, previous: Union[int, None]) -> str:
# Filtering the % Staffed metric out of evaluation
if measure.goal.goal_type.upper() == "ABOVE":
if measure.value < previous:
if previous is None:
if measure.value >= measure.goal.target:
return "success"
else:
return "secondary"
elif measure.value < previous:
return "danger"
elif measure.value >= measure.goal.target and measure.value >= previous:
return "success"
else:
return "secondary"
else:
if measure.value > previous:
if previous is None:
if measure.value >= measure.goal.target:
return "success"
else:
return "secondary"
elif measure.value > previous:
return "danger"
elif measure.value <= measure.goal.target and measure.value <= previous:
return "success"
Expand All @@ -71,24 +86,27 @@ def mom_color_eval(measure, previous):


@register.filter
def addstr(arg1, arg2):
def addstr(arg1: str, arg2: str) -> str:
"""concatenate arg1 & arg2"""
return str(arg1) + str(arg2)


@register.filter
def goal_distance(measure):
if measure.goal.goal_type == "ABOVE":
if measure.value < measure.goal.target:
return f"-{measure.goal.target - measure.value}% below goal"
else:
return f"+{measure.value - measure.goal.target}% above goal"
def goal_distance(measure: Measure) -> str:
if measure.goal is not None:
if measure.goal.goal_type == "ABOVE":
if measure.value < measure.goal.target:
return f"-{measure.goal.target - measure.value}% below goal"
else:
return f"+{measure.value - measure.goal.target}% above goal"

else:
if measure.value > measure.goal.target:
return f"+{measure.value - measure.goal.target}% above goal"
else:
return f"-{measure.goal.target - measure.value}% below goal"
if measure.value > measure.goal.target:
return f"+{measure.value - measure.goal.target}% above goal"
else:
return f"-{measure.goal.target - measure.value}% below goal"
else:
return "No goal set for this metric."


register.filter("goal_format", goal_format)
Expand Down

0 comments on commit e4414d0

Please sign in to comment.