mirror of
https://github.com/Steffo99/sophon.git
synced 2024-12-22 14:54:22 +00:00
🔧 Add a last_update field in the DataFlow model
This commit is contained in:
parent
5cad29679f
commit
d274c35293
2 changed files with 58 additions and 0 deletions
18
sophon/core/migrations/0005_alter_dataflow_last_update.py
Normal file
18
sophon/core/migrations/0005_alter_dataflow_last_update.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.2 on 2021-04-07 17:34
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('core', '0004_dataflow'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='dataflow',
|
||||||
|
name='last_update',
|
||||||
|
field=models.DateTimeField(auto_now=True, help_text='The datetime at which the properties of this DataFlow were last updated.', verbose_name='Last updated'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -1,4 +1,7 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
import pandas
|
||||||
|
import pandasdmx
|
||||||
|
import pandasdmx.message
|
||||||
|
|
||||||
|
|
||||||
class DataSource(models.Model):
|
class DataSource(models.Model):
|
||||||
|
@ -31,6 +34,42 @@ class DataSource(models.Model):
|
||||||
null=True
|
null=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def to_pandasdmx_source(self) -> pandasdmx.source.Source:
|
||||||
|
"""
|
||||||
|
Convert the :class:`.DataSource` to a :class:`pandasdmx.source.Source`\\ .
|
||||||
|
|
||||||
|
:return: The :class:`pandasdmx.source.Source`\\ .
|
||||||
|
|
||||||
|
.. todo:: :func:`.to_pandasdmx` does not currently support non :attr:`.builtin` sources.
|
||||||
|
"""
|
||||||
|
return pandasdmx.source.sources[self.pandasdmx_id]
|
||||||
|
|
||||||
|
def to_pandasdmx_request(self) -> pandasdmx.Request:
|
||||||
|
"""
|
||||||
|
Convert the :class:`.DataSource` to a :class:`pandasdmx.Request` client.
|
||||||
|
|
||||||
|
:return: The :class:`pandasdmx.Request`\\ .
|
||||||
|
"""
|
||||||
|
return pandasdmx.Request(source=self.to_pandasdmx_source().id)
|
||||||
|
|
||||||
|
def request_flows(self) -> tuple[pandas.Series, pandas.Series]:
|
||||||
|
"""
|
||||||
|
Retrieve all available dataflows and datastructures as two :class:`pandas.Series`\\ .
|
||||||
|
|
||||||
|
:return: A :class:`tuple` containing all dataflows and all datastructures.
|
||||||
|
|
||||||
|
.. note:: This seems to be an expensive operation, as it may take a few minutes to execute.
|
||||||
|
|
||||||
|
.. todo:: This function assumes both ``dataflow`` and ``structure`` will always be available.
|
||||||
|
Can something happen to make at least one of them :data:`None` ?
|
||||||
|
"""
|
||||||
|
source = self.to_pandasdmx_request()
|
||||||
|
message: pandasdmx.message.Message = source.dataflow()
|
||||||
|
data: dict[str, pandas.Series] = message.to_pandas()
|
||||||
|
flows = data["dataflow"]
|
||||||
|
structs = data["structure"]
|
||||||
|
return flows, structs
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.pandasdmx_id
|
return self.pandasdmx_id
|
||||||
|
|
||||||
|
@ -55,6 +94,7 @@ class DataFlow(models.Model):
|
||||||
last_update = models.DateTimeField(
|
last_update = models.DateTimeField(
|
||||||
"Last updated",
|
"Last updated",
|
||||||
help_text="The datetime at which the properties of this DataFlow were last updated.",
|
help_text="The datetime at which the properties of this DataFlow were last updated.",
|
||||||
|
auto_now=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
description = models.CharField(
|
description = models.CharField(
|
||||||
|
|
Loading…
Reference in a new issue