-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from SocialFinanceDigitalLabs/16-split-datacon…
…tainer-processes 16 split datacontainer processes, add bootstrap datepicker and implement historic view
- Loading branch information
Showing
18 changed files
with
399 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import plotly.express as px | ||
from demand_model.multinomial.predictor import Prediction | ||
|
||
|
||
def prediction_chart(prediction: Prediction): | ||
df_pp = prediction.population.unstack().reset_index() | ||
df_pp.columns = ["from", "date", "value"] | ||
|
||
# visualise prediction using unstacked dataframe | ||
fig = px.line(df_pp, y="value", x="date", color="from") | ||
fig.update_layout(title="Prediction") | ||
fig_html = fig.to_html(full_html=False) | ||
return fig_html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,92 @@ | ||
import pandas as pd | ||
from bootstrap_datepicker_plus.widgets import DatePickerInput | ||
from crispy_forms.helper import FormHelper | ||
from crispy_forms.layout import Column, Layout, Row, Submit | ||
from django import forms | ||
|
||
|
||
class PredictFilter(forms.Form): | ||
start_date = forms.DateField( | ||
widget=forms.widgets.DateInput(attrs={'type': 'date'}), | ||
label='Start Date', | ||
widget=DatePickerInput(), | ||
label="Start Date", | ||
required=True, | ||
) | ||
end_date = forms.DateField( | ||
widget=DatePickerInput(range_from="start_date"), | ||
label="End Date", | ||
required=True, | ||
) | ||
|
||
|
||
class HistoricDataFilter(forms.Form): | ||
start_date = forms.DateField( | ||
widget=DatePickerInput(), | ||
label="Start Date", | ||
required=True, | ||
) | ||
end_date = forms.DateField( | ||
widget=forms.widgets.DateInput(attrs={'type': 'date'}), | ||
label='End Date', | ||
widget=DatePickerInput(range_from="start_date"), | ||
label="End Date", | ||
required=True, | ||
) | ||
la = forms.ChoiceField(label="Local Authority", required=False, choices=[]) | ||
placement_types = forms.MultipleChoiceField( | ||
widget=forms.CheckboxSelectMultiple, | ||
label="Placement Type", | ||
required=False, | ||
choices=[], | ||
) | ||
|
||
def __init__(self, *args, **kwargs): | ||
la_choices = kwargs.pop("la_choices") | ||
placement_type_choices = kwargs.pop("placement_type_choices") | ||
|
||
super().__init__(*args, **kwargs) | ||
self.fields["la"].choices = [("all", "All")] + [(la, la) for la in la_choices] | ||
self.fields["la"].initial = "all" | ||
self.fields["placement_types"].choices = [ | ||
(placement_type, placement_type) | ||
for placement_type in placement_type_choices | ||
] | ||
self.helper = FormHelper() | ||
self.helper.layout = Layout( | ||
Row( | ||
Column("start_date", css_class="form-group col-md-6 mb-0"), | ||
Column("end_date", css_class="form-group col-md-6 mb-0"), | ||
css_class="form-row", | ||
), | ||
Row( | ||
Column("la", css_class="form-group col-md-6 mb-0"), | ||
Column("placement_types", css_class="form-group col-md-4 mb-0"), | ||
css_class="form-row", | ||
), | ||
Submit("submit", "Filter"), | ||
) | ||
|
||
def filter_by_start_date(self, data: pd.DataFrame): | ||
data = data.loc[data.DECOM.dt.date >= self.cleaned_data["start_date"]] | ||
return data | ||
|
||
def filter_by_end_date(self, data: pd.DataFrame): | ||
data = data.loc[data.DEC.dt.date <= self.cleaned_data["end_date"]] | ||
return data | ||
|
||
def filter_by_la(self, data: pd.DataFrame): | ||
if self.cleaned_data["la"] != "all": | ||
data = data.loc[data.LA == self.cleaned_data["la"]] | ||
return data | ||
|
||
def filter_by_placement_type(self, data: pd.DataFrame): | ||
if self.cleaned_data["placement_types"] != []: | ||
loc = data.placement_type.astype(str).isin( | ||
self.cleaned_data["placement_types"] | ||
) | ||
data = data.loc[loc] | ||
return data | ||
|
||
def apply_filters(self, data: pd.DataFrame): | ||
data = self.filter_by_start_date(data) | ||
data = self.filter_by_end_date(data) | ||
data = self.filter_by_la(data) | ||
data = self.filter_by_placement_type(data) | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
dm_regional_app/templates/dm_regional_app/views/historic.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{% extends "dm_regional_app/base.html" %} | ||
{% load crispy_forms_tags %} | ||
{% block content %} | ||
{{ form.media }} | ||
<form method="POST"> | ||
{% csrf_token %} | ||
{% crispy form %} | ||
</form> | ||
<div class="row"> | ||
<div class="col"> | ||
<h1>Total # of entry into care</h1> | ||
<p>{{ entry_into_care_count }}</p> | ||
</div> | ||
<div class="col"> | ||
<h1>Total # of exiting care</h1> | ||
<p>{{ exiting_care_count }}</p> | ||
</div> | ||
</div> | ||
<div class="alert alert-primary" role="alert"> | ||
TODO - add the relevant charts here! | ||
|
||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.