Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add/hdruk/2.1.3 #21

Merged
merged 11 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions available.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"HDRUK": [
"2.1.2",
"2.1.3",
"2.1.0",
"2.0.2"
],
Expand Down
2,015 changes: 2,015 additions & 0 deletions hdr_schemata/models/HDRUK/2.1.3/schema.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions hdr_schemata/models/HDRUK/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .v2_1_2 import Hdruk212
from .v2_1_3 import Hdruk213
8 changes: 8 additions & 0 deletions hdr_schemata/models/HDRUK/create_json_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from pydantic import ValidationError
import v2_1_2
import v2_1_3
import json

v2_1_2.Hdruk212.save_schema()
v2_1_3.Hdruk213.save_schema()
v2_1_3.Hdruk213.save_schema("latest/dev/schema.json")
23 changes: 12 additions & 11 deletions hdr_schemata/models/HDRUK/latest/dev/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1607,14 +1607,6 @@
"Temporal": {
"additionalProperties": false,
"properties": {
"accrualPeriodicity": {
"allOf": [
{
"$ref": "#/$defs/Periodicity"
}
],
"description": "Please indicate the frequency of distribution release. If a dataset is distributed regularly please choose a distribution release periodicity from the constrained list and indicate the next release date. When the release date becomes historical, a new release date will be calculated based on the publishing periodicity. If a dataset has been published and will remain static please indicate that it is static and indicated when it was released. If a dataset is released on an irregular basis or \u201con-demand\u201d please indicate that it is Irregular and leave release date as null. If a dataset can be published in real-time or near-real-time please indicate that it is continuous and leave release date as null. Notes: see https://www.dublincore.org/specifications/dublin-core/collection-description/frequency/"
},
"distributionReleaseDate": {
"anyOf": [
{
Expand Down Expand Up @@ -1679,12 +1671,21 @@
],
"description": "Please indicate the typical time-lag between an event and the data for that event appearing in the dataset",
"title": "Time Lag"
},
"publishingFrequency": {
"allOf": [
{
"$ref": "#/$defs/Periodicity"
}
],
"description": "Please indicate the frequency of distribution release. If a dataset is distributed regularly please choose a distribution release periodicity from the constrained list and indicate the next release date. When the release date becomes historical, a new release date will be calculated based on the publishing periodicity. If a dataset has been published and will remain static please indicate that it is static and indicated when it was released. If a dataset is released on an irregular basis or \u201con-demand\u201d please indicate that it is Irregular and leave release date as null. If a dataset can be published in real-time or near-real-time please indicate that it is continuous and leave release date as null. Notes: see https://www.dublincore.org/specifications/dublin-core/collection-description/frequency/",
"title": "Publishing Frequency"
}
},
"required": [
"accrualPeriodicity",
"startDate",
"timeLag"
"timeLag",
"publishingFrequency"
],
"title": "Temporal",
"type": "object"
Expand Down Expand Up @@ -2009,6 +2010,6 @@
"accessibility",
"observations"
],
"title": "Hdruk212",
"title": "Hdruk213",
"type": "object"
}
5 changes: 0 additions & 5 deletions hdr_schemata/models/HDRUK/test.py

This file was deleted.

6 changes: 6 additions & 0 deletions hdr_schemata/models/HDRUK/v2_1_3/Provenance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from hdr_schemata.models.HDRUK.base import Provenance as BaseProvenance
from .Temporal import Temporal


class Provenance(BaseProvenance):
temporal: Temporal
16 changes: 16 additions & 0 deletions hdr_schemata/models/HDRUK/v2_1_3/Temporal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from pydantic import Field
from hdr_schemata.definitions.HDRUK import Periodicity
from hdr_schemata.models.HDRUK.base.Temporal import Temporal as BaseTemporal
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if it would make sense to import Temporal from the latest schema version rather than from HDRUK.base?

Hypothetically, say for version 2.1.4 we wanted to change the name timeLag to timeDelay or something. For 2.1.4 the developer would import base.Temporal and have to make two modifications to it (timeLag -> timeDelay and accrualPeriodicity -> publishFrequency). I imagine it would be easy to miss a previous iteration that was made to base.Temporal. IIUC, importing from the latest version by default should mean the developer doesn't have to go back and check previous iterations.

Copy link
Collaborator Author

@calmacx calmacx Jan 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great that you checked but this is simply because 2.1.2 is the base and the latest version.

While we have older versions of the schema, these are json-schema only and not pydantic. Therefore the 'base' of the HDRUK schema is 2.1.2. When we make a 2.1.4 then yeh definitely you're right to import from the latest schema which would be from hdr_schemata.models.HDRUK.v2_1_3.Temporal

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could rename Base to be 2.1.2 if that's less confusing?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right of course, I hadn't realised this was a special case because 2.1.2 is the Base. It's probably worth writing some documentation about how to make these updates to the schema re importing from the latest version.

from pydantic import BaseModel, Field
from hdr_schemata.models import remove_fields_from_cls


class Temporal(BaseTemporal):
publishingFrequency: Periodicity = Field(
...,
title="Publishing Frequency",
description="Please indicate the frequency of distribution release. If a dataset is distributed regularly please choose a distribution release periodicity from the constrained list and indicate the next release date. When the release date becomes historical, a new release date will be calculated based on the publishing periodicity. If a dataset has been published and will remain static please indicate that it is static and indicated when it was released. If a dataset is released on an irregular basis or “on-demand” please indicate that it is Irregular and leave release date as null. If a dataset can be published in real-time or near-real-time please indicate that it is continuous and leave release date as null. Notes: see https://www.dublincore.org/specifications/dublin-core/collection-description/frequency/",
)


remove_fields_from_cls(Temporal, ["accrualPeriodicity"])
18 changes: 18 additions & 0 deletions hdr_schemata/models/HDRUK/v2_1_3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from hdr_schemata.models.HDRUK.v2_1_2 import Hdruk212
import json
from typing import Optional
from pydantic import Field
from .Provenance import Provenance


class Hdruk213(Hdruk212):
provenance: Optional[Provenance] = Field(
None,
description="Provenance information allows researchers to understand data within the context of its origins and can be an indicator of quality, authenticity and timeliness.",
title="Provenance",
)

@classmethod
def save_schema(cls, location="./2.1.3/schema.json"):
with open(location, "w") as f:
json.dump(cls.model_json_schema(), f, indent=6)
Loading