Coder Social home page Coder Social logo

openenergyplatform / oem2orm Goto Github PK

View Code? Open in Web Editor NEW
2.0 8.0 1.0 121 KB

Repository for the oem2orm tool. oem2orm creates SQL tables from open energy metadata strings. It also allows to upload and download metadata to and from a table on the OEP.

License: GNU General Public License v3.0

Python 100.00%
oep sqlalchemy-engine oemetadata database-migrations

oem2orm's People

Contributors

chrwm avatar henhuy avatar jh-rli avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

henhuy

oem2orm's Issues

Update requirements.txt

When cloning the repo and creating and environment for development purposes from requirements.txt, I stumbled upon requirement problems for pandas and sqlalchemy while testing code.

@jh-RLI is it fair to fix both package versions to pandas==1.2.4, sqlalchemy==1.3.16 as noted here or does anything speaks against it? If only the latter is possible then a dev note would be nice.

Parsing error when opening metadata

When using the package, a parsing error occurred when opening the metadata file in oep_oedialect_oem2orm.py

Changing the argument in line 169 from "r" to "rb" fixed the issue.

with open(metadata_file, "rb") as metadata_json:
        metadata = json.loads(metadata_json.read())
    tables_raw = jmespath.search("resources", metadata)

Handle single table objects, not list of tables

Requested by @jnnr:

Can we use the same function, but for single tables? This would allow us to not leave the loop here.

What I mean: Do not do this:

for table in tables:

and this within the function
metadata_files = [
str(file) for file in oem_folder_path.iterdir() if file.suffix == ".json"
]
for metadata_file in metadata_files:

Error while updating metadata on OEP is not forwarded

When updating metadata on the OEP via oep_oedialect_oem2orm.api_updateMdOnTable status_code of response is checked whether it is 200. If an error occurs (aka status_code != "200") the error gets logged, but no error is thrown.
Thus, a user cannot know whether updated worked or not.
I would suggest throwing a `MetadataError``with information from response if upload fails.

How to clean release: Commits differ on master and develop post release

@henhuy, as you noticed, there is always (I assume since you merged master back to develop) a diff between master and develop after I do a release - I follow the Vincent Diressen workflow, but I think I missed something as sometimes the branches are in sync, but most of the time they differ by 2-3 commits, but actually contain the same content. Maybe this is because github creates additional merge commits? Or do i have to use another merge strategy.

Maybe you have an idea how to make it cleaner :)

git branching model

Improve Docs

The documentation is still not complete.

  • Include requirements on OEM fields
  • Rework Usage

Improve error and status messages when uploading tables

Uploading tables with oem2orm, e.g. using the script from the tutorial section, is not user-friendly due a lack of helpful error messages.

  • Inform the user which table is processed. Currently, when the table creation fails and throws a bad/unspecific error message, it is not clear which table is the reason (in case of uploading a bulk of tables)
  • Improve the error messages when violating the postgresql naming conventions for column headers and resources-name. Relates to #16 (comment)

Improve error messages

Some error messages are not shown to the user

  1. ce in

    except oedialect.engine.ConnectionException as ce:
    error_msg = f'Error when uploading table "{table.name}".'
    logging.error(error_msg)
    raise DatabaseError(error_msg) from ce

  2. null in type field results in internal server error,

Reproduce with:
Metadata meta_dat.json
Error msg:

    if item.split(" ")[-1] == "array":
       ^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'split'

try:
column_type = TYPES[field["type"]]
except KeyError:
raise MetadataError(
"Unknown column type", field, field["type"], metadata_file
)

Metadata to ORM feature

I requested a feature to convert the oemetadata JSON to ORM.
This makes the publication of data easy.

My collegue @henhuy developed this package md2orm and @jh-RLI pushed it to this repo.

Planned toolchain for Data Upload:

2020-03-09_MD2OEP-upload_0 2

  1. Create metadata from data
  2. Create ORM from metadata using MD2ORM
  3. Create ERM usind ERAlchemy
  4. Upload data to OEP using oedialect
  5. Upload metadata and add tags

Upload with oem2orm dtype `int` is interpreted as `bigint`

Using this tutorial and this metadata yields the table below on the OEP

grafik

Upload with example_df.to_sql(table_name, connection, schema=schema, if_exists='append', index=False) yields the error:

Out of range float values are not JSON compliant
Writing to umas_potentials failed!

and no data will be uploaded.

However, when I use https://modex.rl-institut.de/create_table/ to create and upload the table, this yields

grafik

and upload works fine.

The columns id and id_scal both contain integer values.

Final table: https://openenergy-platform.org/dataedit/view/model_draft/umas_potentials

OEDialect and SQLAlchemy versions not working

Two errors in setup.py:

  1. OEDialect is set to v1.1 but must be 0.1.1 instead
  2. SQLAlchemy v1.3.14 is not working with latest OEDialect (>=1.3.16 there), thus this must be upgraded to v1.3.16 (latest version is not working - don't know which one latest working version)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.