Skip to content

Commit

Permalink
update pydantic and excel sheets after merging
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon Blackadder committed Sep 5, 2024
1 parent 16785ec commit ab6a78d
Show file tree
Hide file tree
Showing 21 changed files with 32 additions and 1,947 deletions.
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ There are metadata objects for each of the following metadata types:
| timeseries_db | `timeseries_db_schema.TimeseriesDatabaseSchema` |
| video | `video_schema.Model` |

### Python - Excel interface
### Python - Metadata Manager

The Excel interface exists to
The Manager exists to be an interface with Excel and to lightly assist creating schemas.

For Excel we can:

1. Create blank Excel files formatted for a given metadata type
2. Write metadata objects to Excel
Expand All @@ -48,29 +50,34 @@ The Excel interface exists to
To use it run:

```python
from metadataschemas import ExcelInterface
from metadataschemas import MetadataManager

ei = ExcelInterface()
mm = MetadataManager()

filename = ei.write_outline_metadata_to_excel(metadata_type='timeseries')
filename = mm.write_metadata_outline_to_excel('timeseries')

filename = ei.save_metadata_to_excel(metadata_type='timeseries',
filename = mm.save_metadata_to_excel('timeseries',
object=timeseries_metadata)

# Then after you have updated the metadata in the Excel file

updated_timeseries_metadata = ei.read_metadata_excel(filename = timeseries_metadata_filename)
updated_timeseries_metadata = mm.read_metadata_from_excel(timeseries_metadata_filename)
```

Note that the Excel interface currently does not support Geospatial metadata.
Note that the Excel write and save functions do not currently support Geospatial metadata.

The Excel interface also offers a convenient way to get started creating metadata in pydantic by creating an empty pydantic object for a given metadata type which can then be updated as needed.
The manager also offers a convenient way to get started creating metadata in pydantic by creating an empty pydantic object for a given metadata type which can then be updated as needed.

```python
survey_metadata = ei.type_to_outline(metadata_type="survey")
# list the supported metadata types
mm.metadata_type_names

survey_metadata.repositoryid = "repository id"
# get the pydantic class for a given metadata type
survey_type = mm.metadata_class_from_name("survey")

# create an instantiated pydantic object and then fill in your data
survey_metadata = mm.type_to_outline(metadata_type="survey")
survey_metadata.repositoryid = "repository id"
survey_metadata.study_desc.title_statement.idno = "project_idno"
```

Expand Down
Binary file modified excel_sheets/Document_metadata.xlsx
Binary file not shown.
Binary file modified excel_sheets/Resource_metadata.xlsx
Binary file not shown.
Binary file modified excel_sheets/Script_metadata.xlsx
Binary file not shown.
Binary file modified excel_sheets/Survey_metadata.xlsx
Binary file not shown.
Binary file modified excel_sheets/Table_metadata.xlsx
Binary file not shown.
Binary file modified excel_sheets/Timeseries_db_metadata.xlsx
Binary file not shown.
Binary file modified excel_sheets/Timeseries_metadata.xlsx
Binary file not shown.
Binary file modified excel_sheets/Video_metadata.xlsx
Binary file not shown.
2 changes: 1 addition & 1 deletion pydantic_schemas/document_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: document-schema.json
# timestamp: 2024-08-29T18:53:37+00:00
# timestamp: 2024-09-05T20:33:52+00:00

from __future__ import annotations

Expand Down
2 changes: 1 addition & 1 deletion pydantic_schemas/geospatial_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: geospatial-schema.json
# timestamp: 2024-08-29T18:53:39+00:00
# timestamp: 2024-09-05T20:33:54+00:00

from __future__ import annotations

Expand Down
2 changes: 1 addition & 1 deletion pydantic_schemas/image_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: image-schema.json
# timestamp: 2024-08-29T18:53:41+00:00
# timestamp: 2024-09-05T20:33:56+00:00

from __future__ import annotations

Expand Down
2 changes: 1 addition & 1 deletion pydantic_schemas/microdata_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: microdata-schema.json
# timestamp: 2024-08-29T18:53:43+00:00
# timestamp: 2024-09-05T20:33:58+00:00

from __future__ import annotations

Expand Down
2 changes: 1 addition & 1 deletion pydantic_schemas/resource_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: resource-schema.json
# timestamp: 2024-08-29T18:53:45+00:00
# timestamp: 2024-09-05T20:34:00+00:00

from __future__ import annotations

Expand Down
2 changes: 1 addition & 1 deletion pydantic_schemas/script_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: script-schema.json
# timestamp: 2024-08-29T18:53:47+00:00
# timestamp: 2024-09-05T20:34:02+00:00

from __future__ import annotations

Expand Down
2 changes: 1 addition & 1 deletion pydantic_schemas/table_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: table-schema.json
# timestamp: 2024-08-29T18:53:48+00:00
# timestamp: 2024-09-05T20:34:03+00:00

from __future__ import annotations

Expand Down
1,923 changes: 0 additions & 1,923 deletions pydantic_schemas/tests/test_template_to_pydantic.py

This file was deleted.

2 changes: 1 addition & 1 deletion pydantic_schemas/timeseries_db_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: timeseries-db-schema.json
# timestamp: 2024-08-29T18:53:50+00:00
# timestamp: 2024-09-05T20:34:05+00:00

from __future__ import annotations

Expand Down
7 changes: 4 additions & 3 deletions pydantic_schemas/timeseries_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: timeseries-schema.json
# timestamp: 2024-08-29T18:53:52+00:00
# timestamp: 2024-09-05T20:34:07+00:00

from __future__ import annotations

Expand Down Expand Up @@ -93,7 +93,7 @@ class Dimension(SchemaBaseModel):

class DefinitionReference(SchemaBaseModel):
source: Optional[str] = Field(None, title="Source")
uri: str = Field(..., description="URI", title="URI")
uri: Optional[str] = Field(None, description="URI", title="URI")
note: Optional[str] = Field(None, description="Note", title="Note")


Expand Down Expand Up @@ -313,6 +313,7 @@ class Note(SchemaBaseModel):


class RelatedIndicator(SchemaBaseModel):
id: Optional[str] = Field(None, description="Indicator unique identifier", title="Identifier")
code: Optional[str] = Field(None, title="Indicator code")
label: Optional[str] = Field(None, title="Indicator name")
uri: Optional[str] = Field(None, title="URI")
Expand Down Expand Up @@ -570,7 +571,7 @@ class TimePeriodFormat(Enum):

class CodeListItem(SchemaBaseModel):
code: Optional[str] = Field(None, title="Code")
name: Optional[str] = Field(None, title="Name")
label: Optional[str] = Field(None, title="Label")
description: Optional[str] = Field(None, title="Description")


Expand Down
2 changes: 1 addition & 1 deletion pydantic_schemas/utils/pydantic_to_excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def write_across_many_sheets(
):
wb = open_or_create_workbook(doc_filepath)
ws = create_sheet(wb, "metadata", sheet_number=0)
version = f"{metadata_type} type metadata version 20240812.1"
version = f"{metadata_type} type metadata version 20240905.1"
current_row = write_title_and_version_info(ws, title, version, protect_title=False)

children = seperate_simple_from_pydantic(ob)
Expand Down
2 changes: 1 addition & 1 deletion pydantic_schemas/video_schema.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# generated by datamodel-codegen:
# filename: video-schema.json
# timestamp: 2024-08-29T18:53:54+00:00
# timestamp: 2024-09-05T20:34:08+00:00

from __future__ import annotations

Expand Down

0 comments on commit ab6a78d

Please sign in to comment.