Skip to content

Commit

Permalink
Merge pull request #47 from wseis/main
Browse files Browse the repository at this point in the history
source
  • Loading branch information
wseis authored Apr 29, 2024
2 parents 0f2f8ce + 6eaf489 commit 3d9ecbb
Show file tree
Hide file tree
Showing 13 changed files with 404 additions and 15 deletions.
Binary file modified tools/.DS_Store
Binary file not shown.
Binary file modified tools/qmratool/.DS_Store
Binary file not shown.
32 changes: 27 additions & 5 deletions tools/qmratool/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Field, ButtonHolder, Submit, Div
from formtools.wizard.views import SessionWizardView

from django.forms import modelformset_factory

class RAForm(forms.ModelForm):
def __init__(self, user, *args, **kwargs):
Expand Down Expand Up @@ -64,10 +64,26 @@ class Meta:


class InflowForm(forms.ModelForm):
#min = forms.DecimalField(label="Minimum Logremoval")
#max = forms.DecimalField(label="Maximum Logremoval")
class Meta:
model = Inflow
fields = ["pathogen", "min", "max", "reference"]

fields = ['pathogen', 'min', 'max']

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.fields['pathogen'].disabled = True
self.fields['min'].label = "Minimum concentration"
self.fields['max'].label = "Maximum concentration"

self.helper.layout = Layout(
'pathogen',
'min',
'max',
# Add more fields as needed
)
InflowFormSet = modelformset_factory(Inflow, form=InflowForm, extra=3)

class ExposureForm(forms.ModelForm):
class Meta:
Expand Down Expand Up @@ -109,12 +125,18 @@ class Meta:
class LogRemovalForm(forms.ModelForm):
class Meta:
model = LogRemoval
fields = ["min", "max", "pathogen_group", "reference"]
fields = ["pathogen_group", "reference","min", "max"]

def __init__(self, *args, **kwargs):
super(LogRemovalForm, self).__init__(*args, **kwargs)
self.fields["reference"].queryset = Reference.objects.filter(id=51)
self.fields["pathogen_group"].widget = forms.HiddenInput()
self.fields['reference'].disabled = True
self.fields['pathogen_group'].disabled = True
self.fields['min'].label = "Minimum Logremoval"
self.fields['max'].label = "Maximum Logremoval"
#self.fields["pathogen_group"].widget = forms.HiddenInput()

LogRemovalFormSet = modelformset_factory(LogRemoval, form=LogRemovalForm, extra=3)


class ComparisonForm(forms.ModelForm):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 4.1.2 on 2024-04-23 14:31

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
dependencies = [
("qmratool", "0002_riskassessment_created_at"),
]

operations = [
migrations.AddField(
model_name="sourcewater",
name="user",
field=models.ForeignKey(
default=1,
on_delete=django.db.models.deletion.CASCADE,
related_name="sourcewaters",
to=settings.AUTH_USER_MODEL,
),
),
migrations.AlterField(
model_name="inflow",
name="water_source",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="inflow",
to="qmratool.sourcewater",
),
),
]
38 changes: 33 additions & 5 deletions tools/qmratool/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ class User(AbstractUser):


class SourceWater(models.Model):
user = models.ForeignKey(
User, related_name="sourcewaters", default=1, on_delete=models.CASCADE
)
water_source_name = models.CharField(max_length=64)
water_source_description = models.CharField(max_length=2000)
water_source_description = models.TextField(max_length=2000)

def __str__(self):
return self.water_source_name
Expand Down Expand Up @@ -40,16 +43,38 @@ class Treatment(models.Model):
)
description = models.TextField(max_length=1000)

# category = models.CharField(max_length=64, default = "wastewater")
def __str__(self):
return self.name

def get_lrv(self, pathogen_group):
try:
return self.logremoval.get(pathogen_group__pathogen_group=pathogen_group)
except self.logremoval.model.DoesNotExist:
return None

def serialize(self):
def get_min_max(pathogen_group):
lrv = self.get_lrv(pathogen_group)
if lrv is not None:
return float(lrv.min), float(lrv.max)
else:
return 'n.a.', 'n. a.'

virus_min, virus_max = get_min_max("Viruses")
bacteria_min, bacteria_max = get_min_max("Bacteria")
protozoa_min, protozoa_max = get_min_max("Protozoa")

return {
"id": self.id,
"name": self.name,
"description": self.description,
"group": self.group,
"virus_min": virus_min,
"virus_max": virus_max,
"bacteria_min": bacteria_min,
"bacteria_max": bacteria_max,
"protozoa_min": protozoa_min,
"protozoa_max": protozoa_max,
}


Expand Down Expand Up @@ -103,9 +128,9 @@ class LogRemoval(models.Model):
class Inflow(models.Model):
pathogen = models.ForeignKey(Pathogen, on_delete=models.CASCADE)
reference = models.ForeignKey(Reference, on_delete=models.CASCADE)
water_source = models.ForeignKey(SourceWater, on_delete=models.CASCADE)
min = models.DecimalField(decimal_places=8, default=-100, max_digits=20)
max = models.DecimalField(decimal_places=8, default=-100, max_digits=20)
water_source = models.ForeignKey(SourceWater, on_delete=models.CASCADE, related_name="inflow")
min = models.DecimalField(decimal_places=8, default=100, max_digits=20)
max = models.DecimalField(decimal_places=8, default=100, max_digits=20)
mean = models.DecimalField(decimal_places=8, max_digits=20, default=-100, null=True)
alpha = models.DecimalField(
decimal_places=8, max_digits=20, default=-100, null=True
Expand All @@ -115,6 +140,9 @@ class Inflow(models.Model):
pathogen_in_ref = models.CharField(max_length=200, default="unknown")
notes = models.CharField(max_length=200, default="unknown")

#def get_absolute_url(self):
# return reverse("inflow-detail", kwargs={"pk": self.pk})


class Health(models.Model):
pathogen = models.ForeignKey(Pathogen, on_delete=models.CASCADE)
Expand Down
9 changes: 8 additions & 1 deletion tools/qmratool/static/qmratool/option.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@ document.addEventListener('DOMContentLoaded', function() {
// Customize content based on the field
if (fieldName === 'exposure') {
return `<strong>${titleCaseDataName}</strong><br>${data.description}<br>Events per year [N]: <strong>${data.events_per_year}</strong><br>Volume per event [L]: <strong>${data.volume_per_event}</strong>`;
} else {
} else if (fieldName === 'treatment') {
return `<strong>${titleCaseDataName}</strong><br>${data.description}<br>
Virus removal: <strong>${data.virus_min}-${data.virus_max}</strong><br>
Bacteria removal:: <strong>${data.bacteria_min}-${data.bacteria_max}</strong> <br>
Protozoa removal:: <strong>${data.protozoa_min}-${data.protozoa_max}</strong>`;

}
else {
return `<strong>${titleCaseDataName}</strong><br>${data.description}`;
}
}
Expand Down
24 changes: 24 additions & 0 deletions tools/qmratool/templates/qmratool/inflow_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

{% extends "qmratool/layout.html" %}!-- Extend your base template -->
{% load crispy_forms_tags %}
{% block body %}

<div class="container" style="padding: 5%">
<div class="row">
<div class="col-sm-8">
<h1 class = "headline">Create a new Inflow</h1>
<form method="post">
{% csrf_token %}
{{ source_form|crispy }}
{{ inflow_formset.management_form }}
{% for form in inflow_formset %}
<div class="inflow-form">
{{ form|crispy }}
</div>
{% endfor %}
<button class = "btn btn-primary" type="submit">Submit</button>
</form>
</div>
</div>
</div>
{% endblock %}
4 changes: 2 additions & 2 deletions tools/qmratool/templates/qmratool/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ <h1 class = "kwb_headline"> QMRA </h1>
<a class="nav-link text_link_kwb" href="{%url 'index'%}"> My Risk Assessments</a>
</li>
<li class="nav-item active">
<a class="nav-link text_link_kwb" href=""> My Source Waters</a>
<a class="nav-link text_link_kwb" href="{%url 'source-water-list'%}"> My Source Waters</a>
</li>
<li class="nav-item active">
<a class="nav-link text_link_kwb" href="{%url 'treatment_edit'%}"> My Treatments</a>
<a class="nav-link text_link_kwb" href="{%url 'treatment-list'%}"> My Treatments</a>
</li>
<li class="nav-item active">
<a class="nav-link text_link_kwb" href="{%url 'scenario_edit'%}"> My Exposure scenarios</a>
Expand Down
24 changes: 24 additions & 0 deletions tools/qmratool/templates/qmratool/logremoval_form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

{% extends "qmratool/layout.html" %}!-- Extend your base template -->
{% load crispy_forms_tags %}
{% block body %}

<div class="container" style="padding: 5%">
<div class="row">
<div class="col-sm-8">
<h1 class = "headline">Create a new Treatment</h1>
<form method="post">
{% csrf_token %}
{{ treatment_form|crispy }}
{{ logremoval_formset.management_form }}
{% for form in logremoval_formset %}
<div class="logremoval-form">
{{ form|crispy }}
</div>
{% endfor %}
<button class = "btn btn-primary" type="submit">Submit</button>
</form>
</div>
</div>
</div>
{% endblock %}
69 changes: 69 additions & 0 deletions tools/qmratool/templates/qmratool/sourcewater_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{% extends "qmratool/layout.html" %}
{% load crispy_forms_tags %}


{% block body %}
<div class="container" style="padding: 5%">
<div class="row action-panel">
<div class="col">
<h4 class= "mb-2 .kwb_headline"> Configure a custom source water</h4>
<a class = "btn btn-primary mt-3" href="{%url 'create_water_source_inflows'%}">
Configuration a new source water
</a>
</div>
</div>
<div class="row">
<div class="col-10">
{% if user.is_authenticated %}
<h4 class= "mb-5 mt-5 .kwb_headline"> My Source waters</h4>
{%for source_water in object_list%}

<div class="media p-3 mt-3 custom-media" data-url="" style="border: 2px solid; border-radius: 5px; border-color: #d3d3d3 ">
<div class="media-left mt-2 pr-3">
<svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="0.906006" y="0.361328" width="50" height="50" rx="4" fill="#0003e2"/>

<svg width="51" height="51" viewBox="-5 -2 40 40" fill="#0003e2" xmlns="http://www.w3.org/2000/svg">
<rect x="1.90601" y="1.64844" width="26" height="32" rx="3" stroke="white" stroke-width="2"/>
<path d="M7.15601 8.89844L21.906 8.89844" stroke="white" stroke-width="2" stroke-linecap="round"/>
<path d="M7.15601 14.7319L21.906 14.7319" stroke="white" stroke-width="2" stroke-linecap="round"/>
<path d="M7.15601 20.5649L21.906 20.5649" stroke="white" stroke-width="2" stroke-linecap="round"/>
<path d="M7.15601 26.3984L21.906 26.3984" stroke="white" stroke-width="2" stroke-linecap="round"/>
</svg>
</svg>
</a>


</div >
<div class="media-body" >
<h4 class="media-heading d-flex justify-content-between .kwb_headline">{{source_water.water_source_name|title}}
<span>
<svg width="93" height="21" viewBox="0 0 93 21" fill="none" xmlns:xlink="http://www.w3.org/1999/xlink">
<a xlink:href="" target="__blank">
<circle cx="10.0881" cy="10.4404" r="10" fill="#AFAFAF"/>
<path d="M4.76792 16.3104L5.98981 11.7283L13.7284 3.98966L17.0886 7.34985L9.35 15.0885L4.76792 16.3104Z" fill="white"/>
</a>
<a xlink:href="" target="__blank">
<circle cx="36.0439" cy="10.4404" r="10" fill="#AFAFAF"/>
<rect x="39.9143" y="4.34375" width="3.1485" height="14.0952" transform="rotate(45 39.9143 4.34375)" fill="white"/>
<rect x="42.1406" y="14.3105" width="3.1485" height="14.0952" transform="rotate(135 42.1406 14.3105)" fill="white"/>
</a>
</svg>
</h4>

</span>

<p> {{source_water.water_source_description|capfirst}} </p>
</div>
</div>

{%empty%}
There are currently no Source waters.
{%endfor%}
{%endif%}
</div>
</div>
</div>


{% endblock %}
69 changes: 69 additions & 0 deletions tools/qmratool/templates/qmratool/treatment_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{% extends "qmratool/layout.html" %}
{% load crispy_forms_tags %}


{% block body %}
<div class="container" style="padding: 5%">
<div class="row action-panel">
<div class="col">
<h4 class= "mb-2 .kwb_headline"> Configure a custom Treatment</h4>
<a class = "btn btn-primary mt-3" href="{%url 'create_treatment_logremoval'%}">
Configure a new treatment
</a>
</div>
</div>
<div class="row">
<div class="col-10">
{% if user.is_authenticated %}
<h4 class= "mb-5 mt-5 .kwb_headline"> My Treatment</h4>
{%for treatment in object_list%}

<div class="media p-3 mt-3 custom-media" data-url="" style="border: 2px solid; border-radius: 5px; border-color: #d3d3d3 ">
<div class="media-left mt-2 pr-3">
<svg width="50" height="50" viewBox="0 0 50 50" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="0.906006" y="0.361328" width="50" height="50" rx="4" fill="#0003e2"/>

<svg width="51" height="51" viewBox="-5 -2 40 40" fill="#0003e2" xmlns="http://www.w3.org/2000/svg">
<rect x="1.90601" y="1.64844" width="26" height="32" rx="3" stroke="white" stroke-width="2"/>
<path d="M7.15601 8.89844L21.906 8.89844" stroke="white" stroke-width="2" stroke-linecap="round"/>
<path d="M7.15601 14.7319L21.906 14.7319" stroke="white" stroke-width="2" stroke-linecap="round"/>
<path d="M7.15601 20.5649L21.906 20.5649" stroke="white" stroke-width="2" stroke-linecap="round"/>
<path d="M7.15601 26.3984L21.906 26.3984" stroke="white" stroke-width="2" stroke-linecap="round"/>
</svg>
</svg>
</a>


</div >
<div class="media-body" >
<h4 class="media-heading d-flex justify-content-between .kwb_headline">{{treatment.name|title}}
<span>
<svg width="93" height="21" viewBox="0 0 93 21" fill="none" xmlns:xlink="http://www.w3.org/1999/xlink">
<a xlink:href="" target="__blank">
<circle cx="10.0881" cy="10.4404" r="10" fill="#AFAFAF"/>
<path d="M4.76792 16.3104L5.98981 11.7283L13.7284 3.98966L17.0886 7.34985L9.35 15.0885L4.76792 16.3104Z" fill="white"/>
</a>
<a xlink:href="" target="__blank">
<circle cx="36.0439" cy="10.4404" r="10" fill="#AFAFAF"/>
<rect x="39.9143" y="4.34375" width="3.1485" height="14.0952" transform="rotate(45 39.9143 4.34375)" fill="white"/>
<rect x="42.1406" y="14.3105" width="3.1485" height="14.0952" transform="rotate(135 42.1406 14.3105)" fill="white"/>
</a>
</svg>
</h4>

</span>

<p> {{treatment.description|capfirst}} </p>
</div>
</div>

{%empty%}
There are currently no Treatments.
{%endfor%}
{%endif%}
</div>
</div>
</div>


{% endblock %}
4 changes: 4 additions & 0 deletions tools/qmratool/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,9 @@
# administration routes
path("dsgvo", views.dsgvo, name="dsgvo"),
path('raform/', RAFormWizard.as_view(), name='raform_wizard'),
path('create-inflow/', views.create_water_source_and_inflows, name='create_water_source_inflows'),
path('source-water', views.SourceWaterListView.as_view(), name="source-water-list"),
path('treatment', views.TreatmentListView.as_view(), name="treatment-list"),
path('create-treatment', views.create_treatment_and_logremoval, name="create_treatment_logremoval"),
]

Loading

0 comments on commit 3d9ecbb

Please sign in to comment.