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

restore dose-unit endpoint values to endpoint list #729

Merged
merged 27 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fedfc0b
begin prefilters
shapiromatron Sep 25, 2022
74ce132
Replaced endpoint list views with django-filter implementations
rabstejnek Oct 19, 2022
d6f827a
Merge branch 'main' into prefilters
rabstejnek Oct 19, 2022
b157e94
Remove old javascript tables for endpoints
rabstejnek Oct 19, 2022
b640513
Merge branch 'prefilters' of https://github.com/shapiromatron/hawc in…
rabstejnek Oct 19, 2022
078438f
Add row in endpoint table to convey no endpoints
rabstejnek Oct 19, 2022
f7ec736
Merge branch 'main' into prefilters
shapiromatron Nov 7, 2022
715a0c5
change autocomplete to not require auth
shapiromatron Nov 7, 2022
2ea0f4a
fix paginator instead of making new one
shapiromatron Nov 7, 2022
c9bca09
do not return form
shapiromatron Nov 7, 2022
b9c2f52
use standard queryset filter instead of prefilter method
shapiromatron Nov 7, 2022
0efbedc
rewrite form creation hook
shapiromatron Nov 8, 2022
a83d43b
check views individually
shapiromatron Nov 8, 2022
542c09e
Merge branch 'main' into prefilters
shapiromatron Nov 8, 2022
62ef78d
add columns
munnsmunns Nov 8, 2022
9d73a52
few more updates
shapiromatron Nov 8, 2022
2a89721
Merge commit '542c09ea4984a1f271dc6cb0d8a72b7dcb8bbf4b' into prefilters
shapiromatron Nov 8, 2022
1bba479
WIP create a dict w/ frontend values
munnsmunns Nov 8, 2022
d049cb5
update templates for header/footer
shapiromatron Nov 9, 2022
d3b5d3d
reimplement loel, noel, and bmdl fields
shapiromatron Nov 9, 2022
e4479ce
use correct noel/loel names
shapiromatron Nov 9, 2022
4b23b92
Merge commit '1bba47957bcb5a2b5d08849f24c6172f167cb117' into loel-lists
shapiromatron Nov 9, 2022
0af5672
removed unused JS
shapiromatron Nov 9, 2022
33dd121
remove JS
shapiromatron Nov 9, 2022
bbd3e61
Merge remote-tracking branch 'origin/main' into loel-lists
shapiromatron Nov 9, 2022
54e25ab
Merge branch 'main' into loel-lists
shapiromatron Nov 9, 2022
44b518a
Merge branch 'main' into loel-lists
shapiromatron Nov 9, 2022
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
50 changes: 46 additions & 4 deletions hawc/apps/animal/managers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from typing import Any, Dict, List
from typing import Any, Dict, List, Optional

import numpy as np
import pandas as pd
from django.apps import apps
from django.db import transaction
from django.db.models import Max, Min
from django.db import models, transaction
from django.db.models import Max, Min, OuterRef, QuerySet, Subquery, Value
from rest_framework.serializers import ValidationError

from ..assessment.models import Assessment
from ..assessment.models import Assessment, DoseUnits
from ..common.models import BaseManager, get_distinct_charfield, get_distinct_charfield_opts
from ..vocab.constants import VocabularyTermType
from ..vocab.models import Term
Expand Down Expand Up @@ -104,9 +104,51 @@ def by_dose_regime(self, dose_regime):
return self.filter(dose_regime=dose_regime)


class EndpointQuerySet(QuerySet):
def annotate_dose_values(self, dose_units: Optional[DoseUnits] = None) -> QuerySet:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reaaaallly cool!

"""Annotate dose unit-specific responses from queryset, if a dose-unit is available.

Args:
dose_units (Optional[DoseUnits]): selected dose units, if exists
"""
if dose_units is None:
return self.annotate(
units_name=Value("", output_field=models.CharField()),
noel_value=Value(None, output_field=models.FloatField(null=True)),
loel_value=Value(None, output_field=models.FloatField(null=True)),
bmd=Value(None, output_field=models.FloatField(null=True)),
bmdl=Value(None, output_field=models.FloatField(null=True)),
)
DoseGroup = apps.get_model("animal", "DoseGroup")
noel_value_qs = DoseGroup.objects.filter(
dose_regime__animalgroup__endpoints=OuterRef("pk"),
dose_group_id=OuterRef("NOEL"),
dose_units=dose_units,
)
loel_value_qs = DoseGroup.objects.filter(
dose_regime__animalgroup__endpoints=OuterRef("pk"),
dose_group_id=OuterRef("LOEL"),
dose_units=dose_units,
)
Model = apps.get_model("bmd", "Model")
bmd_qs = Model.objects.filter(
selectedmodel__endpoint=OuterRef("pk"), selectedmodel__dose_units=dose_units
)
return self.annotate(
units_name=Value(dose_units.name, output_field=models.CharField()),
noel_value=Subquery(noel_value_qs.values("dose")),
loel_value=Subquery(loel_value_qs.values("dose")),
bmd=Subquery(bmd_qs.values("output__BMD")),
bmdl=Subquery(bmd_qs.values("output__BMDL")),
)


class EndpointManager(BaseManager):
assessment_relation = "assessment"

def get_queryset(self):
return EndpointQuerySet(self.model, using=self._db)

def published(self, assessment_id=None):
return self.get_qs(assessment_id).filter(animal_group__experiment__study__published=True)

Expand Down
11 changes: 8 additions & 3 deletions hawc/apps/animal/templates/animal/endpoint_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<h2>Assessment endpoints ({{page_obj.paginator.count}} found)</h2>
{% include 'common/filter_list.html' with plural_object_name='endpoints' %}
<table id="mainTbl" class="table table-sm table-striped">
{% bs4_colgroup '15,20,15,50' %}
{% bs4_thead 'Study,Experiment,Animal group,Endpoint' %}
{% bs4_colgroup '12,14,15,24,7,7,7,7,7' %}
{% bs4_thead header_names %}
<tbody>
{% for object in object_list %}
<tr>
Expand All @@ -28,10 +28,15 @@ <h2>Assessment endpoints ({{page_obj.paginator.count}} found)</h2>
<i data-id={{object.pk}} class="fa fa-eye previewModalIcon ml-2" title="preview in a modal"></i>
</span>
</td>
<td>{{object.units_name|default:"-"}}</td>
<td>{{object.noel_value|default:"-"}}</td>
<td>{{object.loel_value|default:"-"}}</td>
<td>{{object.bmd|default:"-"}}</td>
<td>{{object.bmdl|default:"-"}}</td>
</tr>
{% empty %}
<tr>
<td colspan="4">
<td colspan="9">
No endpoints available
</td>
</tr>
Expand Down
11 changes: 10 additions & 1 deletion hawc/apps/animal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,16 @@ class EndpointFilterList(BaseFilterList):
filterset_class = filterset.EndpointFilterSet

def get_queryset(self):
return super().get_queryset().select_related("animal_group__experiment__study")
qs = super().get_queryset()
form = self.filterset.form
dose_units = form.cleaned_data["dose_units"] or form.fields["dose_units"].queryset.first()
return qs.select_related("animal_group__experiment__study").annotate_dose_values(dose_units)

def get_context_data(self, **kwargs):
oel_names = self.assessment.get_noel_names()
header_names = f"Study,Experiment,Animal group,Endpoint,Units,{oel_names.noel},{oel_names.loel},BMD,BMDL"
kwargs.update(header_names=header_names)
return super().get_context_data(**kwargs)


@method_decorator(beta_tester_required, name="dispatch")
Expand Down
2 changes: 1 addition & 1 deletion hawc/apps/assessment/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def get_vocabulary_display(self) -> str:
else:
return ""

def get_noel_names(self):
def get_noel_names(self) -> NoelNames:
if self.noel_name == constants.NoelName.NEL:
return NoelNames(
"NEL",
Expand Down