Skip to content
Snippets Groups Projects
Commit 955580d9 authored by Tor-Einar Skog's avatar Tor-Einar Skog
Browse files

Data classes ready

parent e7823a58
Branches
Tags
No related merge requests found
......@@ -16,7 +16,7 @@ classifiers =
package_dir =
= src
packages = find:
python_requires = >=3.6
python_requires = >=3.7
[options.packages.find]
where = src
\ No newline at end of file
#!/usr/bin/python3
"""
Copyright (c) 2023 NIBIO <http://www.nibio.no/>.
This file is part of VIPSCore-Python-Common.
VIPSCore-Python-Common is free software: you can redistribute it and/or modify
it under the terms of the NIBIO Open Source License as published by
NIBIO, either version 1 of the License, or (at your option) any
later version.
VIPSCore-Python-Common is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
NIBIO Open Source License for more details.
You should have received a copy of the NIBIO Open Source License
along with VIPSCore-Python-Common. If not, see <http://www.nibio.no/licenses/>.
"""
#
# @author Tor-Einar Skog <tor-einar.skog@nibio.no>
# https://www.pedaldrivenprogramming.com/2020/12/fastapi-fundamentals-pydantic/
from datetime import datetime
from shapely import geometry
from pydantic import BaseModel, validator, constr
class Result(BaseModel):
"""Represents a set of DSS model result values for a given point in space (Point, Polygon, MultiPolygon) and time (Period or immediate) """
valid_time_start: datetime # TODO make sure it's always timezone aware
valid_time_end: datetime # TODO make sure it's always timezone aware
valid_geometry: geometry
warning_status: int
all_values: dict
def get_keys(self):
return set(self.all_values.keys) if self.all_values is not None else set()
@validator(["valid_time_start","valid_time_end"])
def ensure_timezone(cls, v):
if v.tzinfo is None or v.tzinfo.utcoffset(v) is None:
raise ValueError("%s must be timezone aware" % v)
return v
class ModelConfiguration(BaseModel):
"""All the input data for the model."""
config_parameters: dict
model_id: constr(min_length=10, max_length=10)
class WeatherObservation(BaseModel):
"""Data class for a single weather observatin"""
element_measurement_type_id: str
log_interval_id: int
time_measured: datetime
value: float
# Log interval categories
LOG_INTERVAL_ID_1M = 8;
LOG_INTERVAL_ID_5M = 9;
LOG_INTERVAL_ID_10M = 6;
LOG_INTERVAL_ID_15M = 5;
LOG_INTERVAL_ID_30M = 4;
LOG_INTERVAL_ID_1H = 1;
LOG_INTERVAL_ID_3H = 3;
LOG_INTERVAL_ID_6H = 7;
LOG_INTERVAL_ID_1D = 2;
@validator("time_measured")
def ensure_timezone(cls, v):
if v.tzinfo is None or v.tzinfo.utcoffset(v) is None:
raise ValueError("%s must be timezone aware" % v)
return v
......@@ -22,9 +22,9 @@ along with VIPSCore-Python-Common. If not, see <http://www.nibio.no/licenses/>.
# @author Tor-Einar Skog <tor-einar.skog@nibio.no>
from abc import ABC, abstractmethod
from typing import List, Dict
from vipscore_common.entities import Result
class Model(ABC):
class VIPSModel(ABC):
# Default language is English
default_language = "en"
......@@ -40,7 +40,7 @@ class Model(ABC):
pass
@abstractmethod
def get_result(self) -> List[Result]:
def get_result(self) -> list[Result]:
"""Get the results as a list of Result objects (TODO ref)"""
pass
......@@ -100,6 +100,6 @@ class Model(ABC):
pass
@abstractmethod
def get_sample_config(self) -> Dict:
def get_sample_config(self) -> dict:
"""A sample configuration in JSON format (TODO check relation with Dict)"""
pass
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment