Skip to content

Commit ca0918a

Browse files
committed
chore: Apply suggestions to labels & outputs
1 parent 7a3a835 commit ca0918a

7 files changed

Lines changed: 40 additions & 2 deletions

File tree

uvdat/core/rest/analytics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def list_types(self, request, project_id: int, **kwargs):
4545
"name": instance.name,
4646
"db_value": instance.db_value,
4747
"description": instance.description,
48+
"details": instance.details,
4849
"attribution": instance.attribution,
4950
"input_options": filtered_input_options,
5051
"input_types": instance.input_types,

uvdat/core/rest/serializers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ class AnalysisTypeSerializer(serializers.Serializer):
264264
name = serializers.CharField(max_length=255)
265265
db_value = serializers.CharField(max_length=25)
266266
description = serializers.CharField(max_length=255)
267+
details = serializers.CharField(max_length=2048, allow_null=True)
267268
attribution = serializers.CharField(max_length=255)
268269
input_options = serializers.JSONField()
269270
input_types = serializers.JSONField()

uvdat/core/tasks/analytics/analysis_type.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class AnalysisType(ABC):
1111
def __init__(self, *args):
1212
self.name = ""
1313
self.description = ""
14+
self.details = None
1415
self.db_value = "" # cannot be longer than 25 characters
1516
self.input_types = {}
1617
self.output_types = {}
@@ -34,6 +35,10 @@ def validate_inputs(self, inputs):
3435
if input_name not in inputs:
3536
raise AnalysisInputError(f"{input_name} not provided.")
3637

38+
def finalize(self, result):
39+
# Override this to perform custom finalization
40+
pass
41+
3742

3843
class AnalysisInputError(Exception):
3944
pass
@@ -55,5 +60,15 @@ def on_failure(self, exc, task_id, args, kwargs, einfo):
5560
task_result.write_error(err_msg)
5661

5762
def after_return(self, status, retval, task_id, args, kwargs, einfo): # noqa: PLR0913
63+
# Avoid circular import
64+
from . import analysis_types
65+
5866
task_result = self.get_task_result(args)
5967
task_result.complete()
68+
69+
analysis_type = next(iter(
70+
t for t in analysis_types
71+
if t().db_value == task_result.task_type
72+
), None)
73+
if analysis_type is not None:
74+
analysis_type().finalize(task_result)

uvdat/core/tasks/analytics/flood_simulation.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,15 @@
1616
class FloodSimulation(AnalysisType):
1717
def __init__(self):
1818
super().__init__()
19-
self.name = "Flood Simulation"
19+
self.name = "AI Flood Simulation"
2020
self.description = "Select parameters to simulate a 24-hour flood of the Charles River"
21+
self.details = (
22+
"The AI extreme precipitation downscaler achieves a Mean Absolute Error (MAE) "
23+
"of 3.82 mm and a MAE of Annual Precipitation Maxima of 20.46 mm when tested "
24+
"on an unseen validation period of n=7305 days. The AI-optimized SIMHYD "
25+
"hydrological model achieves a Nash-Sutcliffe Efficiency (NSE) of 0.70 when "
26+
"tested on an unseen validation period of n=6209 days."
27+
)
2128
self.db_value = "flood_simulation"
2229
self.input_types = {
2330
"initial_conditions_id": "string",
@@ -61,6 +68,11 @@ def run_task(self, *, project, **inputs):
6168
flood_simulation.delay(result.id)
6269
return result
6370

71+
def finalize(self, result):
72+
seconds = (result.completed - result.created).total_seconds()
73+
result.status = f"AI Simulation completed in {seconds:.2f} seconds (compare to baseline 5-hour numerical simulation)."
74+
result.save()
75+
6476

6577
@shared_task(base=AnalysisTask)
6678
def flood_simulation(result_id):

web/src/components/sidebars/AnalyticsPanel.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,14 @@ watch(
233233
</template>
234234
</v-tooltip>
235235
</v-card-title>
236+
<v-expansion-panels v-if="analysisStore.currentAnalysisType.details">
237+
<v-expansion-panel bg-color="transparent">
238+
<v-expansion-panel-title class="py-3" style="min-height: 0">Details</v-expansion-panel-title>
239+
<v-expansion-panel-text class="px-3">
240+
{{ analysisStore.currentAnalysisType.details }}
241+
</v-expansion-panel-text>
242+
</v-expansion-panel>
243+
</v-expansion-panels>
236244

237245
<v-tabs v-model="analysisStore.currentAnalysisTab" align-tabs="center" fixed-tabs>
238246
<v-tab value="new">Run New</v-tab>

web/src/store/panel.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function defaultPanelArrangement(): FloatingPanelConfig[] {
6464
},
6565
{
6666
id: "analytics",
67-
label: "Analytics",
67+
label: "AI & Analytics",
6868
visible: false,
6969
closeable: true,
7070
collapsed: true,

web/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,7 @@ export interface AnalysisType {
403403
name: string;
404404
db_value: string;
405405
description: string;
406+
details: string;
406407
attribution: string;
407408
input_options: Record<string, any>;
408409
input_types: Record<string, any>;

0 commit comments

Comments
 (0)