Skip to content

Commit

Permalink
Merge pull request #110 from kippnorcal/revert-109-staging
Browse files Browse the repository at this point in the history
Revert "Redo of #107"
  • Loading branch information
iMark3000 authored Sep 21, 2024
2 parents c3cc317 + 49bc813 commit 6d8f380
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 40 deletions.
52 changes: 17 additions & 35 deletions high_health/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
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
from django.shortcuts import render
from django_filters.rest_framework import DjangoFilterBackend
from accounts.models import Site, SchoolLevel
from high_health.models import EssentialQuestion, Metric, Measure, Goal
from .models import EssentialQuestion, Metric, Measure, Goal

from rest_framework import viewsets, filters
from .serializers import (
Expand Down Expand Up @@ -42,15 +41,7 @@ def last_updated(metric_id):
return None


def get_schools(school_level):
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)
return schools


def get_metrics(school_level):
def metrics(school_level):
if school_level.name == "RS":
order_by = "school__id"
else:
Expand All @@ -60,27 +51,18 @@ def get_metrics(school_level):
.distinct()
.order_by("id")
)
return metrics


def get_measures(hh_metrics, schools):
data = []
for metric in hh_metrics:
for metric in metrics:
# Note: Summer 2024 - filtering out all HH reports except ADA, CA, and Suspensions
measure_models = []
if metric.id in (2, 3, 5):
for school in schools:
try:
school_measure = Measure.objects.get(metric=metric, school=school, is_current=True)
except ObjectDoesNotExist:
school_measure = None
measure_models.append(school_measure)
metric_data = {
"metric": metric,
"last_updated": last_updated(metric.id),
"measures": measure_models,
}
data.append(metric_data)
measures = metric.measure_set.filter(school__school_level=school_level, is_current=True).order_by(order_by)
if measures:
metric_data = {
"metric": metric,
"last_updated": last_updated(metric.id),
"measures": measures,
}
data.append(metric_data)
return sorted(data, key=lambda d: d["last_updated"], reverse=True)


Expand Down Expand Up @@ -332,16 +314,16 @@ def chart_data(request, metric_id, school_id):
check_permissions, login_url="/unauthorized", redirect_field_name=None
)
def high_health(request, school_level=None):
# TODO: Convert to query school level by name instead of id
school_level = SchoolLevel.objects.get(pk=school_level)

schools = get_schools(school_level)
school_metrics = get_metrics(school_level)
metrics_and_measures = get_measures(school_metrics, schools)

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)
context = {
"school_level": school_level,
"schools": schools,
"metrics": metrics_and_measures,
"metrics": metrics(school_level),
"school_levels": SchoolLevel.objects.all(),
}
return render(request, "high_health.html", context)
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>High Health ({{ school_level.display_name }})</h1>
</span>
</td>
{% for measure in metric.measures %}
{% 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>
{% if measure.value is None %}
<td class="text-center">
<span class="text-muted">
N/A
</span>
</td>
{% else %}
<td
Expand Down

0 comments on commit 6d8f380

Please sign in to comment.