statnett / cimsparql Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
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 attributesIt 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 initializedIf 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 existSuggestion: 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 propertyIt 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.
This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.
These updates have all been created already. Click a checkbox below to force a retry/rebase of any.
.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
pyproject.toml
python ^3.10
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.