diff --git a/sentier_data_tools/__init__.py b/sentier_data_tools/__init__.py index c1e2247..f43eb7a 100644 --- a/sentier_data_tools/__init__.py +++ b/sentier_data_tools/__init__.py @@ -3,11 +3,14 @@ __all__ = ( "__version__", "Datapackage", - "DatapackageWriter" "ProductIRI", - "Record", - "UnitIRI", + "DatapackageWriter", "example_data_dir", + "GeonamesIRI", + "ModelTermIRI", + "Record", + "ProductIRI", "reset_local_database", + "UnitIRI", ) __version__ = "0.1.3" @@ -15,7 +18,7 @@ from pathlib import Path from sentier_data_tools.datapackage import DatapackageWriter -from sentier_data_tools.iri import ProductIRI, UnitIRI +from sentier_data_tools.iri import ProductIRI, UnitIRI, ModelTermIRI, GeonamesIRI from sentier_data_tools.local_data_store import ( Datapackage, Record, diff --git a/sentier_data_tools/common.py b/sentier_data_tools/common.py new file mode 100644 index 0000000..aae6158 --- /dev/null +++ b/sentier_data_tools/common.py @@ -0,0 +1,41 @@ +from typing import Optional +from pydantic import BaseModel +import pandas as pd +from datetime import date + +from sentier_data_tools.iri import ProductIRI, GeonamesIRI + + +class Demand(BaseModel): + product_iri: ProductIRI + properties: Optional[list] + amount: float + spatial_context: GeonamesIRI = GeonamesIRI("https://sws.geonames.org/6295630/") + begin_date: Optional[date] = None + end_date: Optional[date] = None + + +class RunConfig(BaseModel): + num_samples: int = 1000 + + +class SentierModel: + def __init__(self, demand: Demand, run_config: RunConfig): + self.demand = demand + self.run_config = run_config + if self.run_config.begin_date is None: + self.run_config.begin_date = date(date.today().year - 5, 1, 1) + if self.run_config.end_date is None: + self.run_config.end_date = date(date.today().year + 5, 1, 1) + + def get_model_data(self) -> list[pd.DataFrame]: + pass + + def prepare(self) -> None: + self.get_model_data() + self.data_validity_checks() + self.resample() + + def run(self) -> list[Demand]: + pass + diff --git a/sentier_data_tools/example_model.py b/sentier_data_tools/example_model.py new file mode 100644 index 0000000..e69de29 diff --git a/sentier_data_tools/iri.py b/sentier_data_tools/iri.py index 14c478b..14c1f5b 100644 --- a/sentier_data_tools/iri.py +++ b/sentier_data_tools/iri.py @@ -79,4 +79,12 @@ class ProductIRI(VocabIRI): class UnitIRI(VocabIRI): - graph_url = "https://vocab.sentier.dev/qudt/" + graph_url = "https://vocab.sentier.dev/units/" + + +class ModelTermIRI(VocabIRI): + graph_url = "https://vocab.sentier.dev/model-terms/" + + +class GeonamesIRI(URIRef): + pass diff --git a/sentier_data_tools/local_data_store.py b/sentier_data_tools/local_data_store.py index 21a52e7..05e390d 100644 --- a/sentier_data_tools/local_data_store.py +++ b/sentier_data_tools/local_data_store.py @@ -69,11 +69,15 @@ class Record(Model): class Meta: database = db + @property + def dataframe(self): + return self.data.to_pandas() + # Function to query records by a column name def query_records_by_column(column_value): """Returns a list of records where the specified column is present.""" query = Record.select().where( - fn.JSON_CONTAINS(Record.columns, f'["{column_value}"]') + fn.JSON_CONTAINS(Record.columns, column_value) ) return list(query) diff --git a/tests/integration/test_product_iri.py b/tests/integration/test_product_iri.py index e69de29..4960444 100644 --- a/tests/integration/test_product_iri.py +++ b/tests/integration/test_product_iri.py @@ -0,0 +1,2 @@ +from sentier_data_tools import ProductIRI +