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

Assessment Detail/Value adjustments #1028

Merged
merged 13 commits into from
Jun 5, 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
13 changes: 0 additions & 13 deletions hawc/apps/assessment/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from pathlib import Path
from textwrap import dedent

import numpy as np
from django import forms
from django.conf import settings
from django.contrib import admin
Expand Down Expand Up @@ -238,18 +237,6 @@ def clean(self):
if not cleaned_data.get("uncertainty"):
msg = "Required for Noncancer evaluation types."
self.add_error("uncertainty", msg)
if (
cleaned_data.get("value")
and cleaned_data.get("pod_value")
and cleaned_data.get("uncertainty")
):
if not np.isclose(
cleaned_data["value"],
cleaned_data["pod_value"] / cleaned_data["uncertainty"],
rtol=0.01,
):
msg = "POD / uncertainty is not equal to value."
self.add_error("value", msg)

@property
def helper(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 5.0.6 on 2024-06-05 17:46

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("assessment", "0037_delete_blog"),
]

operations = [
migrations.AlterField(
model_name="assessmentdetail",
name="qa_id",
field=models.CharField(
blank=True,
help_text="Quality Assurance (QA) tracking identifier, if one exists.",
max_length=32,
verbose_name="Quality Assurance (QA) tracking identifier",
),
),
]
15 changes: 14 additions & 1 deletion hawc/apps/assessment/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import json
import logging
import uuid
from collections import namedtuple
from typing import Any, NamedTuple

import numpy as np
import pandas as pd
from django.apps import apps
from django.conf import settings
Expand All @@ -16,6 +18,7 @@
from django.template.defaultfilters import truncatewords
from django.urls import reverse
from django.utils import timezone
from django.utils.functional import cached_property
from pydantic import BaseModel as PydanticModel
from reversion import revisions as reversion

Expand Down Expand Up @@ -533,7 +536,7 @@ class AssessmentDetail(models.Model):
default=constants.PeerReviewType.NONE,
)
qa_id = models.CharField(
max_length=16,
max_length=32,
Copy link
Owner

Choose a reason for hiding this comment

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

if you change the model, you have to write a django migration, specifically for changes which alter the SQL schema, as this one would; I went ahead and created one.

blank=True,
verbose_name="Quality Assurance (QA) tracking identifier",
help_text="Quality Assurance (QA) tracking identifier, if one exists.",
Expand Down Expand Up @@ -720,6 +723,16 @@ def get_assessment(self):
def get_absolute_url(self):
return reverse("assessment:values-detail", args=[self.pk])

@cached_property
def check_calculated_value(self, rtol: float = 0.01) -> NamedTuple:
# check if calculated value is different than reported value
check = namedtuple("check", ["show_warning", "calculated_value", "tolerance"])
if self.value and self.pod_value and self.uncertainty and self.uncertainty > 0:
calculated = self.pod_value / self.uncertainty
if not np.isclose(self.value, calculated, rtol=rtol):
return check(True, calculated, rtol)
return check(False, 0, rtol)


class Attachment(models.Model):
objects = managers.AttachmentManager()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ <h3>Assessment Value for {{object.assessment}}</h3>
{% endfor %}
</tbody>
</table>
{% if obj_perms.edit and object.check_calculated_value.show_warning %}
{% alert warning %}
<p><b>Note: this message only appears to team members and higher.</b></p>
<p>
The calculated {{object.get_value_type_display}} ({{object.check_calculated_value.calculated_value|stringformat:'.3g'}} {{object.value_unit|default:""}}), is > {{object.check_calculated_value.tolerance|percentage}} different than the reported value ({{object.value}} {{object.value_unit|default:""}}). The calculated value was generated using the formula POD / UF, or {{object.pod_value}} / {{object.uncertainty}} = {{object.check_calculated_value.calculated_value|stringformat:'.3g'}}. This difference may be due to the level of precision the {{object.get_value_type_display}} is reported, but please review in case of an error.
</p>
{% endalert %}
{% endif %}
{% endblock %}

{% block extrajs %}
Expand Down
2 changes: 1 addition & 1 deletion make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ goto :eof
:sync-dev
python -m pip install -U pip uv
uv pip install -e ".[dev,docs]"
uv pip install -e client
uv pip install -e "client/"
yarn --cwd frontend
python manage.py migrate
python manage.py recreate_views
Expand Down
7 changes: 0 additions & 7 deletions tests/hawc/apps/assessment/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,6 @@ def test_errors(self, db_keys):
assert form.is_valid() is False
assert form.errors["uncertainty"] == ["Required for Noncancer evaluation types."]

# pod/uncertainty != value
data = valid_data.copy()
data.update(uncertainty=100)
form = AssessmentValueForm(data=data, parent=assessment)
assert form.is_valid() is False
assert form.errors["value"] == ["POD / uncertainty is not equal to value."]

def test_extra(self, db_keys):
assessment = Assessment.objects.get(id=db_keys.assessment_working)
valid_data = self.valid_data.copy()
Expand Down
Loading