Skip to content

Commit

Permalink
Merge pull request #18 from DunklesArchipel/cli-fields
Browse files Browse the repository at this point in the history
Fix fields CLI csv command
  • Loading branch information
DunklesArchipel authored Sep 18, 2023
2 parents 5561aee + 168dcec commit 49ff790
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
23 changes: 23 additions & 0 deletions doc/news/cli-fields.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* Added <news item>.

**Changed:**

* Changed <news item>.

**Removed:**

* Removed <news item>.

**Fixed:**

* Fixed <news item>.

**Deprecated:**

* Deprecated <news item>.

**Performance:**

* Improved <news item>.
15 changes: 12 additions & 3 deletions echemdbconverters/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,26 @@ def convert(csv, device, outdir, metadata):

from echemdbconverters.csvloader import CSVloader

fields = None

if metadata:
metadata = yaml.load(metadata, Loader=yaml.SafeLoader)
try:
fields = metadata["figure description"]["schema"]["fields"]
except (KeyError, AttributeError):
logger.warning("No units to the fields provided in the metadata")

if device:
with open(csv, "r") as file: # pylint: disable=unspecified-encoding
loader = CSVloader.create(device)(file)
else:
with open(csv, "r") as file: # pylint: disable=unspecified-encoding
loader = CSVloader(file)

if metadata:
metadata = yaml.load(metadata, Loader=yaml.SafeLoader)
# if metadata:
# metadata = yaml.load(metadata, Loader=yaml.SafeLoader)

fields = loader.derive_fields()
fields = loader.derive_fields(fields=fields)

_create_outfiles(csv, loader, fields, metadata, outdir)

Expand Down
10 changes: 7 additions & 3 deletions test/generated/unit.json.expected
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
"fields": [
{
"name": "t",
"type": "integer"
"type": "integer",
"unit": "s"
},
{
"name": "E",
"type": "integer"
"type": "integer",
"unit": "U",
"reference": "RHE"
},
{
"name": "j",
"type": "integer"
"type": "integer",
"unit": "uA / cm2"
}
]
},
Expand Down

0 comments on commit 49ff790

Please sign in to comment.