Skip to content

Commit

Permalink
Hack hack hack
Browse files Browse the repository at this point in the history
  • Loading branch information
cmutel committed Oct 8, 2024
1 parent be50656 commit b55e896
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 6 deletions.
11 changes: 7 additions & 4 deletions sentier_data_tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
__all__ = (
"__version__",
"Datapackage",
"DatapackageWriter" "ProductIRI",
"Record",
"UnitIRI",
"DatapackageWriter",
"example_data_dir",
"GeonamesIRI",
"ModelTermIRI",
"Record",
"ProductIRI",
"reset_local_database",
"UnitIRI",
)

__version__ = "0.1.3"

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,
Expand Down
41 changes: 41 additions & 0 deletions sentier_data_tools/common.py
Original file line number Diff line number Diff line change
@@ -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

Empty file.
10 changes: 9 additions & 1 deletion sentier_data_tools/iri.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion sentier_data_tools/local_data_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions tests/integration/test_product_iri.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from sentier_data_tools import ProductIRI

0 comments on commit b55e896

Please sign in to comment.