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

Data objects in place, unittests running

parent 955580d9
Branches
Tags
No related merge requests found
# VIPSCore-Python-Common # VIPSCore-Python-Common
Lorem Ipsum Lorem Ipsum
## Unit tests
The tests are located in the `src/vipscore_common/tests` folder, and we're using Python's standard [`unittest` library](https://docs.python.org/3/library/unittest.html)
To run the unit tests, move to the root folder of the project, and execute:
``` bash
python3 -m unittest discover -s tests -t src/vipscore_common
```
\ No newline at end of file
from .model import * from .vips_model import *
\ No newline at end of file from .entities import *
\ No newline at end of file
...@@ -23,36 +23,42 @@ along with VIPSCore-Python-Common. If not, see <http://www.nibio.no/licenses/>. ...@@ -23,36 +23,42 @@ along with VIPSCore-Python-Common. If not, see <http://www.nibio.no/licenses/>.
# https://www.pedaldrivenprogramming.com/2020/12/fastapi-fundamentals-pydantic/ # https://www.pedaldrivenprogramming.com/2020/12/fastapi-fundamentals-pydantic/
from datetime import datetime from datetime import datetime
from shapely import geometry from shapely.geometry import Point, Polygon
from pydantic import BaseModel, validator, constr from pydantic import BaseModel, validator, constr
from typing import Any, Union
class Result(BaseModel): 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) """ """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_start: datetime # TODO make sure it's always timezone aware
valid_time_end: datetime # TODO make sure it's always timezone aware valid_time_end: datetime # TODO make sure it's always timezone aware
valid_geometry: geometry valid_geometry: Any
warning_status: int warning_status: int
all_values: dict all_values: dict
def get_keys(self): def get_keys(self):
return set(self.all_values.keys) if self.all_values is not None else set() return set(self.all_values.keys) if self.all_values is not None else set()
@validator(["valid_time_start","valid_time_end"]) @validator("valid_time_start","valid_time_end")
def ensure_timezone(cls, v): def ensure_timezone(cls, v):
if v.tzinfo is None or v.tzinfo.utcoffset(v) is None: if v.tzinfo is None or v.tzinfo.utcoffset(v) is None:
raise ValueError("%s must be timezone aware" % v) raise ValueError("%s must be timezone aware" % v)
return v return v
@validator("valid_geometry")
def ensure_geometry(cls,v):
if v is not None and not isinstance(v, Point) and not isinstance(v, Polygon):
raise ValueError("%s is not a " % v)
class ModelConfiguration(BaseModel): class ModelConfiguration(BaseModel):
"""All the input data for the model.""" """All the input data for the model."""
config_parameters: dict
model_id: constr(min_length=10, max_length=10) model_id: constr(min_length=10, max_length=10)
config_parameters: dict
class WeatherObservation(BaseModel): class WeatherObservation(BaseModel):
"""Data class for a single weather observatin""" """Data class for a single weather observation"""
element_measurement_type_id: str elementMeasurementTypeId: str
log_interval_id: int logIntervalId: int
time_measured: datetime timeMeasured: datetime
value: float value: float
# Log interval categories # Log interval categories
...@@ -66,7 +72,7 @@ class WeatherObservation(BaseModel): ...@@ -66,7 +72,7 @@ class WeatherObservation(BaseModel):
LOG_INTERVAL_ID_6H = 7; LOG_INTERVAL_ID_6H = 7;
LOG_INTERVAL_ID_1D = 2; LOG_INTERVAL_ID_1D = 2;
@validator("time_measured") @validator("timeMeasured")
def ensure_timezone(cls, v): def ensure_timezone(cls, v):
if v.tzinfo is None or v.tzinfo.utcoffset(v) is None: if v.tzinfo is None or v.tzinfo.utcoffset(v) is None:
raise ValueError("%s must be timezone aware" % v) raise ValueError("%s must be timezone aware" % v)
......
#!/usr/bin/python3
LICENSE = """
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/>.
"""
from vips_model import VIPSModel
from entities import Result, ModelConfiguration, WeatherObservation
class ReferenceModel(VIPSModel):
MODEL_ID = "REFERENCEM"
COPYRIGHT = "(c) 2023 NIBIO"
def set_configuration(self, model_configuration: ModelConfiguration):
if not isinstance(model_configuration, ModelConfiguration):
raise ValueError("%s is not a ModelConfiguration object" % model_configuration)
if model_configuration.model_id != ReferenceModel.MODEL_ID:
raise ValueError("%s is not the correct model ID!" % model_configuration.model_id)
self.sowing_date = model_configuration.config_parameters["sowingDate"]
self.observations = []
for node in model_configuration.config_parameters["observations"]:
self.observations.append(WeatherObservation(**node))
def get_result(self) -> list[Result]:
"""Get the results as a list of Result objects (TODO ref)"""
pass
@property
def model_id(self) -> str:
"""10-character ID of the model. Must be unique (at least in the current system)"""
return ReferenceModel.MODEL_ID
@property
def license(self) -> str:
"""Returns the license for this piece of software"""
return LICENSE
@property
def copyright(self) -> str:
"""Name of person/organization that holds the copyright, and contact information"""
return ReferenceModel.COPYRIGHT
@property
def sample_config(self) -> dict:
"""A sample configuration in JSON format (TODO check relation with Dict)"""
return """
{
model_id:'REFERENCEM',
config_parameters: {
'sowingDate': '2022-03-01',
'observations': [
{'timeMeasured': '2015-03-01T00:00:00+01:00', 'elementMeasurementTypeId': 'TM', 'logIntervalId': '2', 'value': '1.41025'},
{'timeMeasured': '2015-03-02T00:00:00+01:00', 'elementMeasurementTypeId': 'TM', 'logIntervalId': '2', 'value': '2.87608333333333'},
{'timeMeasured': '2015-03-03T00:00:00+01:00', 'elementMeasurementTypeId': 'TM', 'logIntervalId': '2', 'value': '1.00854166666667'},
{'timeMeasured': '2015-03-04T00:00:00+01:00', 'elementMeasurementTypeId': 'TM', 'logIntervalId': '2', 'value': '-1.44675'}
]
}
}
"""
def get_model_name(self, language = VIPSModel.default_language) -> str:
"""Returns the model name in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
return "Reference Model"
def get_model_description(self, language = VIPSModel.default_language) -> str:
"""Returns the model description in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
return """
The model is a reference model for developers, showcasing best practices and functionalities of a model.
It's a simple day degree model for an imagined pest, and when thresholds are passed, the warning status progresses.
"""
def get_warning_status_interpretation(self, language = VIPSModel.default_language) -> str:
"""How to interpret the warning status (red-yellow-green, what does it mean?) in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
return """
Gray status (warning status == 0): Warning not applicable
Blue status (warning status == 1): Missing data
Green status (warning status == 2): No risk. Sleep well
Yellow status (warning status == 3): Medium risk. Be on the alert, inspect your field
Red status (warning status == 4): High risk. When the going gets tough, the tough get going
"""
def get_model_usage(self, language = VIPSModel.default_language) -> str:
"""Technical manual for this model, in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
return "TODO"
\ No newline at end of file
import unittest
import json
from reference_model import *
from entities import *
def get_model_configuration():
with open ("src/vipscore_common/tests/weather_data_2015_NO_aas_TMD.json") as f:
weather_observations = json.load(f)
return ModelConfiguration(
model_id=ReferenceModel.MODEL_ID,
config_parameters={
"sowingDate": "2022-03-01",
"observations": weather_observations
}
)
class TestReferenceModel(unittest.TestCase):
def test_set_configuration(self):
"""
Passing a configuration object does not fail
"""
#print(get_model_configuration())
instance = ReferenceModel()
instance.set_configuration(get_model_configuration())
def test_get_model_id(self):
"""
The model returns the correct ID
"""
instance = ReferenceModel()
self.assertEqual(instance.model_id, ReferenceModel.MODEL_ID)
def test_get_license(self):
"""
The model returns its license
"""
instance = ReferenceModel()
self.assertIsNotNone(instance.license)
def test_get_copyright(self):
"""
The model returns its copyright notice
"""
instance = ReferenceModel()
self.assertEqual(instance.copyright, ReferenceModel.COPYRIGHT)
def test_get_sample_config(self):
"""
The model returns its sample configuration
"""
instance = ReferenceModel()
self.assertIsNotNone(instance.sample_config)
def test_get_model_name(self):
"""
The model returns its name in the default language
"""
instance = ReferenceModel()
self.assertEqual(instance.get_model_name(), "Reference Model")
def test_get_model_description(self):
"""
The model returns a description
"""
instance = ReferenceModel()
self.assertIsNotNone(instance.get_model_description())
def test_get_warning_status_interpretation(self):
"""
The model returns a warning status interpretation
"""
instance = ReferenceModel()
self.assertIsNotNone(instance.get_warning_status_interpretation())
def test_get_model_usage(self):
"""
The model returns a description of usage
"""
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
[{"timeMeasured": "2015-03-01T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"1.41025"},
{"timeMeasured": "2015-03-02T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"2.87608333333333"},
{"timeMeasured": "2015-03-03T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"1.00854166666667"},
{"timeMeasured": "2015-03-04T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"-1.44675"},
{"timeMeasured": "2015-03-05T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"0.506208333333333"},
{"timeMeasured": "2015-03-06T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"5.055"},
{"timeMeasured": "2015-03-07T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"5.29470833333333"},
{"timeMeasured": "2015-03-08T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"5.78691666666667"},
{"timeMeasured": "2015-03-09T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"3.44725"},
{"timeMeasured": "2015-03-10T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"6.848625"},
{"timeMeasured": "2015-03-11T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"5.59816666666667"},
{"timeMeasured": "2015-03-12T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"2.78283333333333"},
{"timeMeasured": "2015-03-13T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"0.640458333333333"},
{"timeMeasured": "2015-03-14T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"1.04645833333333"},
{"timeMeasured": "2015-03-15T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"2.46125"},
{"timeMeasured": "2015-03-16T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"3.87916666666667"},
{"timeMeasured": "2015-03-17T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"3.67829166666667"},
{"timeMeasured": "2015-03-18T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"3.16966666666667"},
{"timeMeasured": "2015-03-19T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"2.41620833333333"},
{"timeMeasured": "2015-03-20T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"3.30125"},
{"timeMeasured": "2015-03-21T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"-0.05"},
{"timeMeasured": "2015-03-22T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"0.198625"},
{"timeMeasured": "2015-03-23T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"4.522"},
{"timeMeasured": "2015-03-24T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"5.11220833333333"},
{"timeMeasured": "2015-03-25T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"1.92391666666667"},
{"timeMeasured": "2015-03-26T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"-0.728625"},
{"timeMeasured": "2015-03-27T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"1.34791666666667"},
{"timeMeasured": "2015-03-28T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"1.19704166666667"},
{"timeMeasured": "2015-03-29T00:00:00+01:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"3.0285"},
{"timeMeasured": "2015-03-30T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"2.43166666666667"},
{"timeMeasured": "2015-03-31T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"1.33133333333333"},
{"timeMeasured": "2015-04-01T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"2.65516666666667"},
{"timeMeasured": "2015-04-02T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"4.430875"},
{"timeMeasured": "2015-04-03T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"3.55983333333333"},
{"timeMeasured": "2015-04-04T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"2.77170833333333"},
{"timeMeasured": "2015-04-05T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"1.38383333333333"},
{"timeMeasured": "2015-04-06T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"3.98670833333333"},
{"timeMeasured": "2015-04-07T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"9.01775"},
{"timeMeasured": "2015-04-08T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"8.91166666666667"},
{"timeMeasured": "2015-04-09T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"7.22270833333333"},
{"timeMeasured": "2015-04-10T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"6.97625"},
{"timeMeasured": "2015-04-11T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"5.57629166666667"},
{"timeMeasured": "2015-04-12T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"7.04654166666667"},
{"timeMeasured": "2015-04-13T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"4.99058333333333"},
{"timeMeasured": "2015-04-14T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"2.80320833333333"},
{"timeMeasured": "2015-04-15T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"4.93241666666667"},
{"timeMeasured": "2015-04-16T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"5.9735"},
{"timeMeasured": "2015-04-17T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"7.18533333333333"},
{"timeMeasured": "2015-04-18T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"6.27766666666667"},
{"timeMeasured": "2015-04-19T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"9.67808333333333"},
{"timeMeasured": "2015-04-20T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"12.619375"},
{"timeMeasured": "2015-04-21T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"9.36679166666667"},
{"timeMeasured": "2015-04-22T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"10.2030416666667"},
{"timeMeasured": "2015-04-23T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"10.283375"},
{"timeMeasured": "2015-04-24T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"6.46583333333333"},
{"timeMeasured": "2015-04-25T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"6.93266666666667"},
{"timeMeasured": "2015-04-26T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"5.83495833333333"},
{"timeMeasured": "2015-04-27T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"3.63970833333333"},
{"timeMeasured": "2015-04-28T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"4.384875"},
{"timeMeasured": "2015-04-29T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"5.09408333333333"},
{"timeMeasured": "2015-04-30T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"5.92683333333333"},
{"timeMeasured": "2015-05-01T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"6.25795833333333"},
{"timeMeasured": "2015-05-02T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"7.288375"},
{"timeMeasured": "2015-05-03T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"7.64233333333333"},
{"timeMeasured": "2015-05-04T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"6.635125"},
{"timeMeasured": "2015-05-05T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"8.50175"},
{"timeMeasured": "2015-05-06T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"10.0941666666667"},
{"timeMeasured": "2015-05-07T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"8.244125"},
{"timeMeasured": "2015-05-08T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"7.713875"},
{"timeMeasured": "2015-05-09T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"5.05933333333333"},
{"timeMeasured": "2015-05-10T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"7.57520833333333"},
{"timeMeasured": "2015-05-11T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"8.462375"},
{"timeMeasured": "2015-05-12T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"8.358875"},
{"timeMeasured": "2015-05-13T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"8.77766666666667"},
{"timeMeasured": "2015-05-14T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"8.607625"},
{"timeMeasured": "2015-05-15T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"8.09604166666667"},
{"timeMeasured": "2015-05-16T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"7.50833333333333"},
{"timeMeasured": "2015-05-17T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"6.54245833333333"},
{"timeMeasured": "2015-05-18T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"7.69970833333333"},
{"timeMeasured": "2015-05-19T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"8.07091666666667"},
{"timeMeasured": "2015-05-20T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"8.867875"},
{"timeMeasured": "2015-05-21T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"9.208125"},
{"timeMeasured": "2015-05-22T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"9.121875"},
{"timeMeasured": "2015-05-23T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"10.79"},
{"timeMeasured": "2015-05-24T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"7.42295833333333"},
{"timeMeasured": "2015-05-25T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"10.12575"},
{"timeMeasured": "2015-05-26T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"8.83808333333333"},
{"timeMeasured": "2015-05-27T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"10.7490833333333"},
{"timeMeasured": "2015-05-28T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"7.59116666666667"},
{"timeMeasured": "2015-05-29T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"9.37595833333333"},
{"timeMeasured": "2015-05-30T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"7.42141666666667"},
{"timeMeasured": "2015-05-31T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"9.32220833333333"},
{"timeMeasured": "2015-06-01T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"10.172875"},
{"timeMeasured": "2015-06-02T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"8.14145833333333"},
{"timeMeasured": "2015-06-03T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"12.1733333333333"},
{"timeMeasured": "2015-06-04T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"11.7168333333333"},
{"timeMeasured": "2015-06-05T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"11.3925833333333"},
{"timeMeasured": "2015-06-06T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"12.4829166666667"},
{"timeMeasured": "2015-06-07T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"12.4883333333333"},
{"timeMeasured": "2015-06-08T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"11.553375"},
{"timeMeasured": "2015-06-09T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"12.049"},
{"timeMeasured": "2015-06-10T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"12.6334583333333"},
{"timeMeasured": "2015-06-11T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"15.27825"},
{"timeMeasured": "2015-06-12T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"15.5879166666667"},
{"timeMeasured": "2015-06-13T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"13.7035416666667"},
{"timeMeasured": "2015-06-14T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"12.6875"},
{"timeMeasured": "2015-06-15T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"11.745"},
{"timeMeasured": "2015-06-16T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"12.6172083333333"},
{"timeMeasured": "2015-06-17T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"9.92666666666667"},
{"timeMeasured": "2015-06-18T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"11.4045833333333"},
{"timeMeasured": "2015-06-19T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"13.51625"},
{"timeMeasured": "2015-06-20T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"16.45875"},
{"timeMeasured": "2015-06-21T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"15.18375"},
{"timeMeasured": "2015-06-22T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"13.7395833333333"},
{"timeMeasured": "2015-06-23T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"15.4683333333333"},
{"timeMeasured": "2015-06-24T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"14.41"},
{"timeMeasured": "2015-06-25T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"11.9941666666667"},
{"timeMeasured": "2015-06-26T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"13.3546666666667"},
{"timeMeasured": "2015-06-27T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"14.6145833333333"},
{"timeMeasured": "2015-06-28T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"13.945"},
{"timeMeasured": "2015-06-29T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"15.6325"},
{"timeMeasured": "2015-06-30T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"17.3604166666667"},
{"timeMeasured": "2015-07-01T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"18.7570833333333"},
{"timeMeasured": "2015-07-02T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"18.8091666666667"},
{"timeMeasured": "2015-07-03T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"18.5004166666667"},
{"timeMeasured": "2015-07-04T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"17.57125"},
{"timeMeasured": "2015-07-05T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"18.7654166666667"},
{"timeMeasured": "2015-07-06T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"16.05125"},
{"timeMeasured": "2015-07-07T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"16.28625"},
{"timeMeasured": "2015-07-08T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"13.0458333333333"},
{"timeMeasured": "2015-07-09T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"13.05375"},
{"timeMeasured": "2015-07-10T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"14.67875"},
{"timeMeasured": "2015-07-11T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"14.4104166666667"},
{"timeMeasured": "2015-07-12T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"15.665"},
{"timeMeasured": "2015-07-13T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"15.2191666666667"},
{"timeMeasured": "2015-07-14T00:00:00+02:00","elementMeasurementTypeId":"TM", "logIntervalId":"2", "value":"15.345"}]
\ No newline at end of file
...@@ -21,8 +21,8 @@ along with VIPSCore-Python-Common. If not, see <http://www.nibio.no/licenses/>. ...@@ -21,8 +21,8 @@ along with VIPSCore-Python-Common. If not, see <http://www.nibio.no/licenses/>.
# All models in VIPSCore-Python must extend this abstract class # All models in VIPSCore-Python must extend this abstract class
# @author Tor-Einar Skog <tor-einar.skog@nibio.no> # @author Tor-Einar Skog <tor-einar.skog@nibio.no>
from abc import ABC, abstractmethod from abc import ABC, abstractmethod, abstractproperty
from vipscore_common.entities import Result from entities import Result, ModelConfiguration
class VIPSModel(ABC): class VIPSModel(ABC):
...@@ -32,7 +32,7 @@ class VIPSModel(ABC): ...@@ -32,7 +32,7 @@ class VIPSModel(ABC):
# Set the configuration object (with all its possible parameters) # Set the configuration object (with all its possible parameters)
# Must be done before you call get_result # Must be done before you call get_result
@abstractmethod @abstractmethod
def set_configuration(self, model_configuration): def set_configuration(self, model_configuration: ModelConfiguration):
""" """
Set the configuration object (with all its possible parameters) Set the configuration object (with all its possible parameters)
Must be done before you call get_result Must be done before you call get_result
...@@ -44,62 +44,50 @@ class VIPSModel(ABC): ...@@ -44,62 +44,50 @@ class VIPSModel(ABC):
"""Get the results as a list of Result objects (TODO ref)""" """Get the results as a list of Result objects (TODO ref)"""
pass pass
@property
@abstractmethod @abstractmethod
def get_model_id(self) -> str: def model_id(self) -> str:
"""10-character ID of the model. Must be unique (at least in the current system)""" """10-character ID of the model. Must be unique (at least in the current system)"""
pass pass
@property
@abstractmethod @abstractmethod
def get_model_name(self) -> str: def sample_config(self) -> dict:
"""Returns the model name in the default language""" """A sample configuration in JSON format (TODO check relation with Dict)"""
pass
@abstractmethod
def get_model_name(self, language: str) -> str:
"""Returns the model name in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
pass pass
@property
@abstractmethod @abstractmethod
def get_license(self) -> str: def license(self) -> str:
"""Returns the license for this piece of software""" """Returns the license for this piece of software"""
pass pass
@property
@abstractmethod @abstractmethod
def get_copyright(self) -> str: def copyright(self) -> str:
"""Name of person/organization that holds the copyright, and contact information""" """Name of person/organization that holds the copyright, and contact information"""
pass pass
@abstractmethod @abstractmethod
def get_model_description(self) -> str: def get_model_name(self, language: str) -> str:
"""Description of model (In default_language). Should include interpretation of the red-yellow-green warning system""" """Returns the model name in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
pass pass
@abstractmethod @abstractmethod
def get_model_description(self, language: str) -> str: def get_model_description(self, language: str) -> str:
"""Returns the model description in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)""" """Returns the model description in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
pass pass
@abstractmethod
def get_warning_status_interpretation(self) -> str:
"""How to interpret the warning status (red-yellow-green, what does it mean?) in the default language"""
pass
@abstractmethod @abstractmethod
def get_warning_status_interpretation(self, language: str) -> str: def get_warning_status_interpretation(self, language: str) -> str:
"""How to interpret the warning status (red-yellow-green, what does it mean?) in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)""" """How to interpret the warning status (red-yellow-green, what does it mean?) in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
pass pass
@abstractmethod
def get_model_usage(self) -> str:
"""Technical manual for this model, in the default language"""
pass
@abstractmethod @abstractmethod
def get_model_usage(self, language: str) -> str: def get_model_usage(self, language: str) -> str:
"""Technical manual for this model, in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)""" """Technical manual for this model, in the specified language (<a href="http://www.loc.gov/standards/iso639-2/php/English_list.php">ISO-639-2</a>)"""
pass pass
@abstractmethod
def get_sample_config(self) -> dict: \ No newline at end of file
"""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