Giter Site home page Giter Site logo

cimsparql's People

Contributors

danhje avatar davidkleiven avatar leifwar avatar martinhaberg avatar nalu-svk avatar renovate-bot avatar renovate[bot] avatar simenjohnsrud avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

cimsparql's Issues

Clean up Prefix/CimModel/GraphDB hirarchy

There are some "problems" with the Prefix/CimModel/GraphDB classes that makes the code difficult to read

CimModel calls setup_client that does not exist

_setup_client is implemented lower in the hirarchy. Thus it is not possible to make an instance of CimModel even though it is not abstract.
Solution: Either make the class abstract and require that children implement _setup_client. It appears like CimModel does not need any of the things in _setup_client, thus the call can probably just be removed, and then the child GraphDBClient can call it.

_prefixes in GraphDBClient initialized with URL???

_prefixes is a dict, and by following the setter method it is a dict. But when a property-setter is called with a URL and the result is a dict, it is a bit confustion.

Suggestion: Create a function fetch_prefixes that returns the dict and write

self.prefixes = fetch_prefixes(url)

_setup_client adds attributes

It would be quite easy to avoid this. In __init__ move

       self.user = os.getenv("GRAPHDB_USER")
        self.passwd = os.getenv("GRAPHDB_USER_PASSWD")
        self.service = service
        self.sparql = SPARQLWrapper(self.service)

into __init__. And add a method _init_sparql that performs the additional initialization of the sparql attribute

Prefix access self._prefixes before initialized

If and instance of Prefix is made, it will crash if the prefixes property is called.

Solution: Add an __init__ method to Prefix and initialize self._prefixes with None or empty dict. If None, it must be handled in the property (e.g. return empty dict if None)

Prefix: cim_version assumes that the "cim" key exist

Suggestion: Check if "cim" exists first. If not, return None

CimModel: TypeMapper only needs the prefixes.

Solution: is it possible to only pass prefixes instead of the entire CimModel instance

CimModel: Initialize self._data_version instead of handling AttributeError in the property

Use template based predefined queries

It is currently impossible to read predefined queries just by looking at the code, you have to use dry_run to understand the query. We should generate templates for all the queries, making them easier to read, maintain and optimize.

The templates could be defined as variables

BUS_DATA="SELECT ?mrid ?name ?busname ?un Where {?t_mrid ....   FILTER regex(?area, '${area}'}"

or it could be read from files

SELECT  ?mrid ?name ?busname ?un
WHERE {
  ?t_mrid  rdf:type cim:TopologicalNode;
           cim:IdentifiedObject.name ?busname;
           cim:IdentifiedObject.mRID ?mrid;
           cim:TopologicalNode.BaseVoltage/cim:BaseVoltage.nominalVoltage ?un;
           cim:TopologicalNode.ConnectivityNodeContainer ?cont .
  ?cont cim:IdentifiedObject.aliasName|cim:IdentifiedObject.name ?name;
        cim:VoltageLevel.Substation/cim:Substation.Region/cim:SubGeographicalRegion.Region/cim:IdentifiedObject.name ?area .
  FILTER regex(?area, '${area}')
}

where final query is generated using string Template.

from string import Template

with open('bus_data.sparql', 'r') as fid:
    BUS_DATA = fid.read()
    
bus_data_query = Template(BUS_DATA).substitute({'area': 'NO'})

Using queries defined in files makes it possible to use an editor with sparql-mode capabilities for both reading/writing, formatting and testing.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/codeql-analysis.yml
  • actions/checkout v4
  • github/codeql-action v3
  • github/codeql-action v3
  • github/codeql-action v3
.github/workflows/deploy.yml
  • actions/checkout v4
  • actions/setup-python v5
  • abatilo/actions-poetry v2.3.0
  • actions/checkout v4
  • actions/setup-python v5
  • abatilo/actions-poetry v2.3.0
  • actions/configure-pages v4
  • actions/upload-pages-artifact v3
  • actions/deploy-pages v4
.github/workflows/poetry.yml
  • actions/checkout v4
  • actions/setup-python v5
  • abatilo/actions-poetry v2.3.0
  • fredrikaverpil/poetry-update v1.2
  • peter-evans/create-pull-request v5
.github/workflows/tests.yml
  • actions/checkout v4
  • actions/setup-python v5
  • abatilo/actions-poetry v2.3.0
  • actions/checkout v4
  • actions/setup-python v5
  • abatilo/actions-poetry v2.3.0
  • codecov/codecov-action v3
  • eclipse/rdf4j-workbench 4.3.8
poetry
pyproject.toml
  • python ^3.10

  • Check this box to trigger a request for Renovate to run again on this repository

Fix type-hints

Type-hints are missing some places for example

 @classmethod
    def col_map(cls, data_row, columns) -> Tuple[Dict[str, str]]:
        columns = columns or {}
        col_map = cls._col_map(data_row)
        col_map.update(columns)
        return col_map

and the return type also seems off.

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.