Skip to content

Commit

Permalink
Merge pull request #134 from ImperialCollegeLondon/validation
Browse files Browse the repository at this point in the history
Set up project with django-plotly-dash
  • Loading branch information
tsmbland authored Jan 31, 2024
2 parents 47ce385 + 366117b commit e1d8e9b
Show file tree
Hide file tree
Showing 8 changed files with 868 additions and 128 deletions.
4 changes: 4 additions & 0 deletions djangomain/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"management",
"crispy_forms",
"crispy_bootstrap4",
"django_plotly_dash.apps.DjangoPlotlyDashConfig",
]

MIDDLEWARE = [
Expand All @@ -91,6 +92,7 @@
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django_plotly_dash.middleware.BaseMiddleware",
]

ROOT_URLCONF = "djangomain.urls"
Expand Down Expand Up @@ -246,3 +248,5 @@

CRISPY_ALLOWED_TEMPLATE_PACKS = "bootstrap4"
CRISPY_TEMPLATE_PACK = "bootstrap4"

X_FRAME_OPTIONS = "SAMEORIGIN"
1 change: 1 addition & 0 deletions djangomain/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
name="schema-swagger-ui",
),
re_path(r"^redoc/$", schema_view.with_ui("redoc"), name="schema-redoc"),
path("django_plotly_dash/", include("django_plotly_dash.urls")),
]

urlpatterns += [
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pytz==2023.3.post1
PyYAML==6.0.1
uritemplate==4.1.1
crispy-bootstrap4==2023.1
django-plotly-dash==2.2.2

## Legacy dependency versions
# asgiref==3.3.4
Expand Down
39 changes: 39 additions & 0 deletions validated/dash_apps/finished_apps/daily_validation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from datetime import datetime
from decimal import Decimal

import plotly.express as px
from dash import dcc, html
from django_plotly_dash import DjangoDash

from station.models import Station
from validated.functions import daily_validation
from variable.models import Variable

# Create a Dash app
app = DjangoDash("DailyValidation")

# Filters (in final app this will get data from forms)
station: Station = Station.objects.order_by("station_code")[7]
variable: Variable = Variable.objects.order_by("variable_code")[0]
start_time: datetime = datetime.strptime("2023-03-01", "%Y-%m-%d")
end_time: datetime = datetime.strptime("2023-03-31", "%Y-%m-%d")
minimum: Decimal = Decimal(-5)
maximum: Decimal = Decimal(28)

# Load data
data: dict = daily_validation(
station=station,
variable=variable,
start_time=start_time,
end_time=end_time,
minimum=minimum,
maximum=maximum,
)

# Create plot
x = data["series"]["measurement"]["time"]
y = data["series"]["measurement"]["average"]
plot = px.line(x=x, y=y)

# Create layout
app.layout = html.Div([dcc.Graph(figure=plot)])
Loading

0 comments on commit e1d8e9b

Please sign in to comment.