python-eigen-ingenuity 0.4.34b1__tar.gz → 0.4.35b1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. python_eigen_ingenuity-0.4.35b1/PKG-INFO +751 -0
  2. python_eigen_ingenuity-0.4.35b1/README.md +730 -0
  3. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/eigeningenuity/core/__init__.py +1 -1
  4. python_eigen_ingenuity-0.4.35b1/modelbuilder/__init__.py +7 -0
  5. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/__init__.py +0 -0
  6. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/assetmodelbuilder.py +163 -0
  7. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/assetmodelcsvwriter.py +30 -0
  8. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/assetmodelutilities.py +121 -0
  9. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/configmanager.py +500 -0
  10. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/connectors/__init__.py +0 -0
  11. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/connectors/boltconnector.py +108 -0
  12. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/connectors/dbconnectors.py +40 -0
  13. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/connectors/genericconnector.py +30 -0
  14. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/connectors/httpsconnector.py +134 -0
  15. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/csvcontentsmanager.py +93 -0
  16. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/csvwriter.py +341 -0
  17. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/filemanager.py +380 -0
  18. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/fileprocessors.py +691 -0
  19. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/messages.py +61 -0
  20. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/queries/__init__.py +0 -0
  21. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/queries/cypherbuilder.py +332 -0
  22. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/queries/query.py +82 -0
  23. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/queries/typedefs.py +128 -0
  24. python_eigen_ingenuity-0.4.35b1/modelbuilder/src/versionmanager.py +354 -0
  25. python_eigen_ingenuity-0.4.35b1/python_eigen_ingenuity.egg-info/PKG-INFO +751 -0
  26. python_eigen_ingenuity-0.4.35b1/python_eigen_ingenuity.egg-info/SOURCES.txt +44 -0
  27. python_eigen_ingenuity-0.4.35b1/python_eigen_ingenuity.egg-info/entry_points.txt +2 -0
  28. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/python_eigen_ingenuity.egg-info/requires.txt +2 -1
  29. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/python_eigen_ingenuity.egg-info/top_level.txt +1 -0
  30. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/requirements.txt +3 -2
  31. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/setup.py +3 -0
  32. python-eigen-ingenuity-0.4.34b1/PKG-INFO +0 -425
  33. python-eigen-ingenuity-0.4.34b1/README.md +0 -415
  34. python-eigen-ingenuity-0.4.34b1/python_eigen_ingenuity.egg-info/PKG-INFO +0 -425
  35. python-eigen-ingenuity-0.4.34b1/python_eigen_ingenuity.egg-info/SOURCES.txt +0 -22
  36. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/MANIFEST.in +0 -0
  37. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/eigeningenuity/__init__.py +0 -0
  38. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/eigeningenuity/assetmodel.py +0 -0
  39. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/eigeningenuity/auth.py +0 -0
  40. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/eigeningenuity/elastic.py +0 -0
  41. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/eigeningenuity/events.py +0 -0
  42. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/eigeningenuity/historian.py +0 -0
  43. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/eigeningenuity/historianmulti.py +0 -0
  44. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/eigeningenuity/settings.py +0 -0
  45. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/eigeningenuity/smartdash.py +0 -0
  46. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/eigeningenuity/sql.py +0 -0
  47. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/eigeningenuity/util.py +0 -0
  48. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/pyproject.toml +0 -0
  49. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/python_eigen_ingenuity.egg-info/dependency_links.txt +0 -0
  50. {python-eigen-ingenuity-0.4.34b1 → python_eigen_ingenuity-0.4.35b1}/setup.cfg +0 -0
@@ -0,0 +1,751 @@
1
+ Metadata-Version: 2.1
2
+ Name: python-eigen-ingenuity
3
+ Version: 0.4.35b1
4
+ Summary: A python library used to query data from the Eigen Ingenuity system
5
+ Home-page: https://www.eigen.co/
6
+ Author: Murray Callander
7
+ Author-email: info@eigen.co
8
+ License: Apache License 2.0
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: numpy
11
+ Requires-Dist: pandas
12
+ Requires-Dist: pyserial
13
+ Requires-Dist: setuptools
14
+ Requires-Dist: urllib3
15
+ Requires-Dist: msal
16
+ Requires-Dist: cryptography
17
+ Requires-Dist: keyring
18
+ Requires-Dist: pyarrow
19
+ Requires-Dist: neo4j>=5.17.0
20
+ Requires-Dist: requests>=2.31.0
21
+
22
+ CONTENTS <!-- omit in toc -->
23
+ ============
24
+ - [About](#about)
25
+ - [Eigen Ingenuity](#eigen-ingenuity)
26
+ - [Installation](#installation)
27
+ - [Getting Started](#getting-started)
28
+ - [Historian](#historian)
29
+ - [Data Format](#data-format)
30
+ - [Query Multiple tags](#query-multiple-tags)
31
+ - [Functions](#functions)
32
+ - [General Functions:](#general-functions)
33
+ - [List Historians](#list-historians)
34
+ - [Get Default Historian](#get-default-historian)
35
+ - [Read Functions](#read-functions)
36
+ - [Get Current Data Points](#get-current-data-points)
37
+ - [Get Number of Points](#get-number-of-points)
38
+ - [Get Interpolated Points in a Time Range](#get-interpolated-points-in-a-time-range)
39
+ - [Get Values at Given Times](#get-values-at-given-times)
40
+ - [Get Raw Points in a Time Range](#get-raw-points-in-a-time-range)
41
+ - [Get Aggregates for a Time Range](#get-aggregates-for-a-time-range)
42
+ - [Get Aggregates on Intervals over a Time Range](#get-aggregates-on-intervals-over-a-time-range)
43
+ - [List Data Tags Matching Wildcard](#list-data-tags-matching-wildcard)
44
+ - [Get Tag Metadata](#get-tag-metadata)
45
+ - [Write Functions](#write-functions)
46
+ - [Create Or Update Data Tag](#create-or-update-data-tag)
47
+ - [Write Data Points to Tag](#write-data-points-to-tag)
48
+ - [Asset Model](#asset-model)
49
+ - [Execute a Raw Cypher Query](#execute-a-raw-cypher-query)
50
+ - [Asset Model Builder](#asset-model-builder)
51
+ - [Running the tool](#running-the-tool)
52
+ - [Command Line options](#command-line-options)
53
+ - [The Config File](#the-config-file)
54
+ - [Project structure](#project-structure)
55
+ - [Coming soon](#coming-soon)
56
+ - [Planned](#planned)
57
+ - [License](#license)
58
+
59
+ # About<a id="about"></a>
60
+
61
+ This library supports python 3.10 onwards. It may work for earlier versions of python3, but these are not supported. We do not support python 2 in any form.
62
+
63
+ The python-eigen-ingenuity library contains 2 modules:
64
+
65
+ ### 1. Eigen Ingenuity <!-- omit in toc -->
66
+ This module is used to query data from many of the databases in the Ingenuity Platform, including:
67
+ - timeseries historians (influx, PI, IP21, cognite)
68
+ - A Neo4j Graph database
69
+ - Sql sources (Oracle, msql, psql)
70
+ - Elasticsearch
71
+
72
+ The data can be returned in several formats, and supports multiple query types
73
+
74
+ ### 2. Model Builder <!-- omit in toc -->
75
+ We provide a portable CLI tool that can be used to build a model onto a neo4j instance from a list of csv files that define a set of nodes/properties and their relationships.
76
+
77
+ It can be used either to create a model from scratch (Though it does require an existing blank neo4j container/machine), or it can be directed to an existing neo4j to perform a merge/update.
78
+
79
+ It includes options for version nodes to track history and changes to nodes when a model is updated.
80
+
81
+ ---
82
+
83
+ # Eigen Ingenuity<a id="eigen-ingenuity"></a>
84
+
85
+ ## Installation<a id="installation"></a>
86
+
87
+
88
+ Install python (3.10+), then in the terminal run:
89
+
90
+ ```
91
+ pip install python-eigen-ingenuity
92
+ ```
93
+
94
+ All required Third party libraries will be automatically installed.
95
+
96
+ ## Getting Started<a id="getting-started"></a>
97
+
98
+ Begin by Importing the module at the top of a script with
99
+
100
+ ```
101
+ import eigeningenuity as eigen
102
+ ```
103
+
104
+ To use this module, you must first set an Ingenuity server to query, and a datasource within the server.
105
+
106
+ For example, for a historian with Ingenuity instance "https://demo.eigen.co/" and datasource "Demo-influxdb",
107
+
108
+
109
+ ```
110
+ server = eigen.EigenServer("https://demo.eigen.co/")
111
+ demo = eigen.get_historian("Demo-influxdb",server)
112
+ ```
113
+ Alternatively, it is possible to set the Ingenuity instance as the environmental variable "EIGENSERVER",
114
+ ```
115
+ os.environ["EIGENSERVER"] = "https://demo.eigen.co/"
116
+ demo = get_historian("Demo-influxdb")
117
+ ```
118
+
119
+ If the datasource of interest is the default datasource for the ingenuity instance, it can also be omitted:
120
+
121
+ ```
122
+ os.environ["EIGENSERVER"] = "https://demo.eigen.co/"
123
+ demo = get_historian()
124
+ ```
125
+
126
+ With the datasource set, the historian data can be queried with functions such as,
127
+ ```
128
+ demo.getInterpolatedRange(tag,start,end,points)
129
+ demo.getCurrentDataPoints(tag)
130
+ demo.listDataTags()
131
+ ```
132
+ Where:
133
+ - tag is the name of the tag to query
134
+ - start is the epoch timestamp (ms) of the beginning of the query window
135
+ - end is the epoch timestamp (ms) of the end of the query window
136
+ - points is the number of points to be returned
137
+
138
+ Each function will return an list, each element consisting of list of a value, timestamp and status, corresponding to a single point of data
139
+
140
+ To convert a Datetime (UTC or Local) to epoch, or vice-versa, you can use this tool: https://www.epochconverter.com/
141
+
142
+ ## Historian<a id="historian"></a>
143
+
144
+
145
+ #### Data Format<a id="data-format"></a>
146
+
147
+
148
+ Once the server and datasource have been configured, the historian data can be queried through functions we define in
149
+ the EXAMPLE FUNCTIONS section.
150
+
151
+ These functions can be used to query a single tag, or multiple tags at once. A tag in ingenuity with the form "datasource/tagname",
152
+ we query with, for example:
153
+
154
+ ```
155
+ datasource = eigen.get_historian("datasource")
156
+ tagdata = datasource.getCurrentDataPoints("tagname")
157
+ ```
158
+
159
+ Functions have multiple options on how to return the data, that can be specified using the "output" parameter:
160
+
161
+ - The Raw Response. (output="raw")
162
+ - A preformatted python dict (default: output="json")
163
+ - a pandas dataframe (default: output="df")
164
+
165
+ ##### Example <!-- omit in toc -->
166
+
167
+
168
+ ```
169
+ x = influx.getInterpolatedRange("DEMO_02TI301.PV","1 hour ago","now",3)
170
+ ```
171
+ - ##### Raw:
172
+
173
+ ```
174
+ {'items': {'DEMO_02TI301.PV': [{'value': 38.0, 'timestamp': 1701166741139, 'status': 'OK'}, {'value': 37.5, 'timestamp': 1701168541139, 'status': 'OK'}, {'value': 38.0, 'timestamp': 1701170341139, 'status': 'OK'}]}, 'unknown': []}
175
+ ```
176
+ - ##### Json
177
+
178
+ ```
179
+ [{'value': 35.88444444444445, 'timestamp': 1701166983980, 'status': 'OK'}, {'value': 33.5, 'timestamp': 1701168783980, 'status': 'OK'}, {'value': 34.0, 'timestamp': 1701170583980, 'status': 'OK'}]
180
+ ```
181
+ - ##### Dataframe
182
+ ```
183
+ ---
184
+ DEMO_02TI301.PV
185
+ 2023-11-28 11:23:39.201 38.0
186
+ 2023-11-28 10:53:39.201 36.0
187
+ 2023-11-28 10:23:39.201 33.0
188
+ ```
189
+ - ##### CSV
190
+ ```
191
+ DEMO_02TI301.PV,37.1718,1701167341282,OK
192
+ DEMO_02TI301.PV,35.5,1701169141282,OK
193
+ DEMO_02TI301.PV,37.0,1701170941283,OK
194
+ ```
195
+
196
+ The CSV output type allows for 2 additional optional parameters:
197
+
198
+ - multi-csv: Creates a separate csv for each tag queried, rather than placing them all in one. Also puts tag in filename rather than in row
199
+ - filepath: Specify a directory to write the csv files to
200
+
201
+ #### Query Multiple tags<a id="query-multiple-tags"></a>
202
+
203
+
204
+ if multiple tags are queried in a single request, the data will be returned as a dictionary, with the tag IDs as its keys,
205
+ the individual dictionary entries will retain the same format returned when querying a single tag
206
+ ____
207
+
208
+ ## Functions<a id="functions"></a>
209
+
210
+ ### General Functions:<a id="general-functions"></a>
211
+
212
+ Simple Functions to check server defaults
213
+
214
+ #### List Historians<a id="list-historians"></a>
215
+ ###### Method: list_historians <!-- omit in toc -->
216
+
217
+ Find all historians on the instance
218
+ ```
219
+ from eigeningenuity import list_historians
220
+ list_historians(eigenserver)
221
+ ```
222
+ Where:
223
+ - (Optional) eigenserver is the ingenuity instance of interest (If omitted will look for environmental variable EIGENSERVER)
224
+
225
+ Returns a list of strings
226
+
227
+ #### Get Default Historian<a id="get-default-historian"></a>
228
+ ###### Method: get_default_historian_name <!-- omit in toc -->
229
+ Find the name of the default historian of the instance, if one exists
230
+ ```
231
+ from eigeningenuity import get_default_historian_name
232
+ get_default_historian_name(eigenserver)
233
+ ```
234
+ Where:
235
+ - (Optional) eigenserver is the ingenuity instance of interest (If omitted will look for environmental variable EIGENSERVER)
236
+
237
+ Returns a string, or None
238
+
239
+ ### Read Functions<a id="read-functions"></a>
240
+
241
+ ##### The following functions are designed to help the user pull and process data from historians into a python environment <!-- omit in toc -->
242
+
243
+ #### Get Current Data Points<a id="get-current-data-points"></a>
244
+ ###### Method: getCurrentDataPoints <!-- omit in toc -->
245
+
246
+ Find the most recent raw datapoint for each tag
247
+ ```
248
+ demo.getCurrentDataPoints(tags,output)
249
+ ```
250
+ Where:
251
+ - tags is a list of IDs of tags to query
252
+ - output (optional) [See DATA FORMAT section](#data-format)
253
+ - multi-csv (optional) [See DATA FORMAT section](#data-format)
254
+ - filepath (optional) [See DATA FORMAT section](#data-format)
255
+
256
+ Returns one datapoint object per tag
257
+
258
+ #### Get Number of Points<a id="get-number-of-points"></a>
259
+ ###### Method: countPoints <!-- omit in toc -->
260
+
261
+ Find the number of datapoints in the given time frame
262
+ ```
263
+ demo.countPoints(tag, start, end, output)
264
+ ```
265
+ Where:
266
+ - tags is a list of IDs of tags to query
267
+ - start is the datetime object (or epoch timestamp in ms) of the beginning of the query window
268
+ - end is the datetime object (or epoch timestamp in ms) of the end of the query window
269
+ - output (optional) [See DATA FORMAT section](#data-format)
270
+ - multi-csv (optional) [See DATA FORMAT section](#data-format)
271
+ - filepath (optional) [See DATA FORMAT section](#data-format)
272
+
273
+ Returns one integer per tag
274
+
275
+ #### Get Interpolated Points in a Time Range<a id="get-interpolated-points-in-a-time-range"></a>
276
+ ###### Method: getInterpolatedRange <!-- omit in toc -->
277
+
278
+ Find a number of interpolated points of a tag, equally spaced over a set timeframe
279
+ ```
280
+ demo.getInterpolatedRange(tag, start, end, count, output)
281
+ ```
282
+ Where:
283
+ - tags is a list of IDs of the tags to query
284
+ - start is the datetime object (or epoch timestamp in ms) of the beginning of the query window
285
+ - end is the datetime object (or epoch timestamp in ms) of the end of the query window
286
+ - count is the total number of points to be returned
287
+ - output (optional) [See DATA FORMAT section](#data-format)
288
+ - multi-csv (optional) [See DATA FORMAT section](#data-format)
289
+ - filepath (optional) [See DATA FORMAT section](#data-format)
290
+
291
+ Returns a list of count-many datapoints per tag
292
+
293
+ #### Get Values at Given Times<a id="get-values-at-given-times"></a>
294
+ ###### Method: getInterpolatedpoints <!-- omit in toc -->
295
+
296
+ Find datapoints at given timestamps
297
+ ```
298
+ demo.getInterpolatedPoints(tags, timestamps, output)
299
+ ```
300
+ Where:
301
+ - tags is a list of IDs of the tags to query
302
+ - timestamps is a list of timestamps at which to query data
303
+ - output (optional) [See DATA FORMAT section](#data-format)
304
+ - multi-csv (optional) [See DATA FORMAT section](#data-format)
305
+ - filepath (optional) [See DATA FORMAT section](#data-format)
306
+
307
+ Returns a list of datapoints (one at each timestamp) per tag
308
+
309
+
310
+ #### Get Raw Points in a Time Range<a id="get-raw-points-in-a-time-range"></a>
311
+ ###### Method: getRawDataPoints <!-- omit in toc -->
312
+
313
+ Find the first n Raw datapoints from a time window
314
+ ```
315
+ demo.getRawDataPoints(tags, start, end, count, output)
316
+ ```
317
+ Where:
318
+ - tags is a list of IDs of the tags to query
319
+ - start is the datetime object (or epoch timestamp in ms) of the beginning of the query window
320
+ - end is the datetime object (or epoch timestamp in ms) of the end of the query window
321
+ - (Optional) count is the maximum number of raw datapoints to return. (default is 1000)
322
+ - output (optional) [See DATA FORMAT section](#data-format)
323
+ - multi-csv (optional) [See DATA FORMAT section](#data-format)
324
+ - filepath (optional) [See DATA FORMAT section](#data-format)
325
+
326
+ Returns a list of count-many datapoints per tag
327
+
328
+ #### Get Aggregates for a Time Range<a id="get-aggregates-for-a-time-range"></a>
329
+ ###### Method: getAggregates <!-- omit in toc -->
330
+
331
+ Finds a set of aggregate values for tags over a timeframe
332
+ ```
333
+ demo.getAggregates(tags, start, end, count, aggfields, output)
334
+ ```
335
+ Where:
336
+ - tags is a list of IDs of the tags to query
337
+ - start is the datetime object (or epoch timestamp in ms) of the beginning of the query window
338
+ - end is the datetime object (or epoch timestamp in ms) of the end of the query window
339
+ - (Optional) count is the number of divisions to split the time window into (i.e. if time window is one day, and count is 2, we return separate sets of aggregate data for first and second half of day). omit for count=1
340
+ - (Optional) aggfields is a list of aggregate functions to calculate, a subset of
341
+ ["min","max","avg","var","stddev","numgood","numbad"]. Leave blank to return all aggregates.
342
+ - output (optional) [See DATA FORMAT section](#data-format)
343
+ - multi-csv (optional) [See DATA FORMAT section](#data-format)
344
+ - filepath (optional) [See DATA FORMAT section](#data-format)
345
+
346
+ Returns a list of count-many Aggregate Data Sets per tag
347
+
348
+ #### Get Aggregates on Intervals over a Time Range<a id="get-aggregates-on-intervals-over-a-time-range"></a>
349
+ ###### Method: getAggregateInterval <!-- omit in toc -->
350
+
351
+ A variation of getAggregates which finds aggregates on fixed length intervals dividing the overall window
352
+ ```
353
+ demo.getAggregateInterval(tags, start, end, interval, aggfields, output)
354
+ ```
355
+ Where:
356
+ - tags is a list of IDs of the tags to query
357
+ - start is the datetime object (or epoch timestamp in ms) of the beginning of the query window
358
+ - end is the datetime object (or epoch timestamp in ms) of the end of the query window
359
+ - (Optional) interval is the length of the sub-intervals over which aggregates are calculated, it accepts values such as ["1s","1m","1h","1d","1M","1y"]
360
+ being 1 second, 1 minute, 1 hour etc. Default is whole time window.
361
+ - (Optional) aggfields is a list of aggregate functions to calculate, a subset of
362
+ ["min","max","avg","var","stddev","numgood","numbad"]. Default is all Aggregates.
363
+ - output (optional) [See DATA FORMAT section](#data-format)
364
+ - multi-csv (optional) [See DATA FORMAT section](#data-format)
365
+ - filepath (optional) [See DATA FORMAT section](#data-format)
366
+
367
+ Returns a list of Aggregate Data Sets (One per interval) per tag
368
+
369
+ #### List Data Tags Matching Wildcard<a id="list-data-tags-matching-wildcard"></a>
370
+ ###### Method: listDataTags <!-- omit in toc -->
371
+
372
+ Find all tags in datasource, or all tags in datasource that match a search parameter
373
+ ```
374
+ demo.listDataTags(match)
375
+ ```
376
+ Where:
377
+ - (optional) match is the regex wildcard to match tags to (i.e. DEMO* will match all tags beginning with DEMO, \*DEMO* will match
378
+ all tags containing DEMO, and *DEMO will match all tags ending with DEMO) (Leave blank to return all tags in historian)
379
+
380
+ Returns a list of strings
381
+
382
+ #### Get Tag Metadata<a id="get-tag-metadata"></a>
383
+ ###### Method: getMetaData <!-- omit in toc -->
384
+
385
+ Find units, unitMultiplier and description of each tag
386
+ ```
387
+ demo.getMetaData(tags, output)
388
+ ```
389
+ Where:
390
+ - tags is a list of IDs of tags to query
391
+ - output (optional) Does Not Accept CSV. Otherwise, [See DATA FORMAT section](#data-format)
392
+
393
+ Returns a dict with keys [units, unitMultiplier, description] per tag
394
+
395
+ ### Write Functions<a id="write-functions"></a>
396
+ The following functions are intended for users to update/create historian tags using data processed/loaded in python. They can only be run against Eigen's internal influx historians, not production systems. <!-- omit in toc -->
397
+
398
+ #### Create Or Update Data Tag<a id="create-or-update-data-tag"></a>
399
+ ###### Method: createDataTag <!-- omit in toc -->
400
+
401
+ Creates a datatag with a specified ID, Unit type/label, and Description. You can use an existing tag name to update the metadata
402
+ ```
403
+ demo.createDataTag(Name, Units, Description)
404
+ ```
405
+ Where:
406
+ - Name is the unique ID/Identifier of the tag
407
+ - Units is the unit specifier of the data in the tag e.g. "m/s","Days" etc. (This will be shown on axis in ingenuity trends)
408
+ - Description is text/metadata describing the content/purpose of the tag (This will show up in search bar for ingenuity trends)
409
+
410
+ Returns a boolean representing success/failure to create tag
411
+
412
+ #### Write Data Points to Tag<a id="write-data-points-to-tag"></a>
413
+ ###### Method: writeDataPoints <!-- omit in toc -->
414
+
415
+ Writes sets of datapoints to the historian
416
+ ```
417
+ from eigeningenuity.historian import DataPoint
418
+
419
+ dataPoints = []
420
+ point = DataPoint(value, timestamp, "OK")
421
+ dataPoint = {tagName: point}
422
+
423
+ dataPointList.append(dataPoint)
424
+
425
+ demo.writeDataPoints(dataPointList)
426
+ ```
427
+ Where:
428
+ - value if the value of the datapoint at the timestamp
429
+ - timestamp is the datetime object (or epoch timestamp in ms) of the point
430
+ - "OK" is the status we give to a point that contains non-null data
431
+
432
+ Returns a boolean representing success/failure to write data
433
+
434
+ ## Asset Model<a id="asset-model"></a>
435
+
436
+ Currently the AM tools only support direct queries using cypher queries directly with the executeRawQuery method. More structured methods are planned.
437
+
438
+ #### Execute a Raw Cypher Query<a id="execute-a-raw-cypher-query"></a>
439
+ ###### Method: executeRawQuery <!-- omit in toc -->
440
+
441
+ Executes a cypher query directly against our asset model
442
+ ```
443
+ from eigeningenuity import get_assetmodel, EigenServer
444
+
445
+ demo = EigenServer("demo.eigen.co")
446
+ am = get_assetmodel(demo)
447
+
448
+ wells = demo.executeRawQuery(query)
449
+ ```
450
+
451
+ Where:
452
+ - query is a string containing a valid neo4j/cypher language query e.g. "Match (n:Well) return n limit 25"
453
+
454
+ Returns the json response from neo4j
455
+
456
+ ---------------------------------------------------------------------------------------------------------------------------------------
457
+
458
+ # Asset Model Builder<a id="asset-model-builder"></a>
459
+
460
+ A tool for updating a Neo4j model using .csv anf .cypher files as input
461
+
462
+ ## Running the tool<a id="running-the-tool"></a>
463
+
464
+ The tool is invoked by executing, anywhere on the cli
465
+
466
+ ```
467
+ assetmodel
468
+ ```
469
+
470
+ ## Command Line options<a id="command-line-options"></a>
471
+
472
+ *-p* - sets the default path for input files. The program will look first in the current folder, and then in the default folder if it's not find locally.
473
+ Output files are always created in the default folder
474
+
475
+ *-dr* - Set the frequency of progress update messages. No effect if -v present
476
+ *-sf* - The first query to process in a .csv file. No effect on cypher files. Default is 1
477
+
478
+ *-d* - specifies the target database, as defined in the config file. Can specify the DB name (as defined in config.ini), or a position in the list
479
+ e.g. -d 0 will connect to the first database defined
480
+
481
+ *-c* - the name of the config file if not config.ini, or it's not in the default folder
482
+
483
+ *-s* - the separator used in the .csv files. Default is ";"
484
+
485
+ *-v* - run in verification mode. Queries are generated and displayed on screen, but are not processed
486
+
487
+ *-sq* - show queries on screen as they are processed. Has no effect if *-v* present
488
+
489
+ *-sr* - causes data from RETURN clauses to be displayed on screen. No effect if *-v* present
490
+
491
+ *-wq* - causes the processed queries to be writen to the specified file. This is very useful to review all the queries that have been executed.
492
+ It includes all the queries used to create and update Version nodes too. No effect if *-v* present
493
+
494
+ *-wr* - causes data from RETURN clauses to be writen to the specified file. No effect if *-v* present
495
+
496
+ *-f* - list of input files. Can be a mix of .csv and .cypher files. Also supports .lst files, which are a simple text file
497
+ containing a list of files to process (can also include more .lst files). See *-o* for information on the order the files are processed in
498
+
499
+ *-q* - list of Cypher queries explicitly entered on the command line. These are processed before any files specified with *-f*, unless the
500
+ default order is overriden by the *-o* switch
501
+
502
+ *-pre* - list of Cypher queries explicitly entered on the command line. These are processed first, before anything else
503
+
504
+ *-da* - delete all nodes with the specified labels. More than one set of labels can be specified. The delete is performed AFTER any *-pre* queries. Using *-da* with no labels will delete all nodes, so use with caution!
505
+ Examples:
506
+ * *-da :Person :EI_VERSION:Pump* deletes all nodes with a Person label, and then all nodes with both EI_VERSION and Pump labels. Note: the leading ':' is optional so *-da Person* will also delete all *Person* nodes
507
+ * *-da* (with no labels) deletes ALL nodes - be careful!
508
+
509
+ *-post* - list of Cypher queries explicitly entered on the command line. These are processed last, after everything else
510
+
511
+ *-o* - defines the order the file types are processed in. Accepts up to 5 chars: 'n' for node csv files, 'r' for relationship csv files,
512
+ 'c' for cypher files, 'q' for command line queries and 'x' for any unspecified file type, processed in the order given. The default is qnrc.
513
+ Examples:
514
+ * *-o x* processes all the inputs in the order listed
515
+ * *-o c* will process all .cypher files first (in the order listed), then others *in the default order*. This is the same as *-o cqnr*
516
+ * *-o cx* will process all .cypher files first, then others *in the order listed*
517
+ * *-o nxr* processes nodes, then cypher files and command line queries in the order listed, and finally relationship files
518
+
519
+ *-nov* - suppresses the creation and update of version nodes
520
+
521
+ *-in* - treat node columns in a relationship csv file as properties of the relationship. This allow a
522
+ relationship to have a property that is the same as that used to identify a node. Without using this
523
+ qualifier, the system will report an 'Ambiguous data' error because it cannot determine if the csv file
524
+ is intended to be a node file or a relationship file.
525
+
526
+ *-sd* - prevents the creation of a version node if none of the node properties or labels will be changed by the update
527
+
528
+ *-ab* - Update a property even if it is blank
529
+
530
+ *-b* - group queries into batches of the given size. Note: creation of version nodes is disabled in batch mode i.e. *-nov* is in effect
531
+
532
+ ### Examples <!-- omit in toc -->
533
+ ```
534
+ assetmodelbuilder -p models/Testing -d neo4j-test -f People.csv "Extended.cypher" -v
535
+ ```
536
+
537
+ Looks in a folder models/Testing for the file People.csv and config.ini. It uses this csv file to generate queries that it simulates executing against the server configured with name neo4j-test in config.ini. However the database is not written to due to -v flag.
538
+
539
+ ```
540
+ assetmodelbuilder -p models/Testing -d neo4j-test -q "MATCH (n) RETURN n" -sr
541
+ ```
542
+
543
+ Looks in a folder models/Testing for the file config.ini. Then executes cypher command "MATCH (n) RETURN n" against the server configured with name neo4j-test in config.ini and returns the neo4j response to the console due to -sr flag
544
+
545
+ ```
546
+ python src/assetmodelbuilder.py -p models/Testing -d 1 -f Rebuild.lst Versions.csv RelationVersions.csv -o x
547
+ ```
548
+
549
+ Deletes all the nodes and recreate them, with Version nodes and updated Relationships.
550
+
551
+ ## The Config File<a id="the-config-file"></a>
552
+
553
+ This file contains key information about the structure of the Asset Model. The layout is
554
+
555
+ **[DEFAULT]**
556
+
557
+
558
+
559
+ **[Database]**
560
+ #Define the database connections here. The name is used by the program to identify the db to connect to
561
+ DatabaseNames=Database0 Name,Database1 Name
562
+ URLs=Database0 URL,Database1 URL
563
+ passwords=Database0 password,Database1 password
564
+
565
+ **[Model]**
566
+
567
+ #The **PrimaryIDProperty** is the property that is used to uniquely identify it. It is created and managed
568
+ #by the model builder. The default value is **uuid**
569
+ **PrimaryIDProperty=uuid**
570
+
571
+ #The **PrimaryProperty** is the default property to use to match on when creating relationships
572
+ #This can be overriden by specifying the required property in the csv files
573
+ **PrimaryProperty=node**
574
+
575
+ #Specify any labels that are required by ALL nodes. This is a shortcut so that are not needed in the .csv file
576
+ #Labels defined in the .csv file can be REMOVED by listing them here with a leading !
577
+ #In this example, any nodes with a Person label will have that removed, and all nodes will get a People label
578
+ **RequiredLabels= !Person , People**
579
+
580
+ #Similar to labels, list any properties that a node must have together with a default value. If a value is provided
581
+ #in the input file, that value is used rather than the default value here
582
+ #Also like labels, properties can be removed by using the ! prefix (no need to give a default)
583
+ #In this example, everyone will have a Nationality property equal to British, apart from those whose Nationality is in the input
584
+ #Everyone will have their Weight property removed. Phew!
585
+ **RequiredProperties=Nationality=British , !Weight**
586
+
587
+ #All nodes are timestamped when they are created or updated. Specify the name of the node property to be used
588
+ #for these using **CreationTime** and **UpdateTime**
589
+ **CreationTime=CreationTime**
590
+ **UpdateTime=UpdatedTime**
591
+
592
+ #Sometimes there are columns in the .csv files that have the wrong name. These can be changed using a mapping
593
+ #in the format of old_name=new_name. The new_name can then be used in the **[Alias]** section (see below)
594
+ #In the example, the .csv files use as mix of _Node_ and _node_ for the name of the node. Both of these are mapped to
595
+ #_name_, so that all the nodes in the model have a _name_ property. _name_ can then be used to create relationships, for example.
596
+ **Mappings=node=name,Node=name**
597
+
598
+ #To set a default data use, use DataType=. The given format will be used, unless a format is specified in the CSV header. For example, to treat
599
+ data as strings use **DataType=str**
600
+
601
+ **[Aliases]**
602
+ #The Alias section defines how to map column headings onto meaning in the tool
603
+ #Nodes and Labels are used to define nodes in a 'Properties' type file
604
+ **Labels=Label, Code**
605
+ **Nodes=Node**
606
+ #FromNodes, ToNodes and Relationships are used to create relationships, in the obvious way
607
+ **FromNodes=From, Start Node, Start, From Node, StartNode,Start Node**
608
+ **ToNodes=To,To Node,ToNode,End**
609
+ #FromLabels and ToLables are added to the From and To nodes in the obvious way to speed up Relationship matches
610
+ **FromLabels=**
611
+ **ToLables=**
612
+ **Relationships=Relation,Relationship**
613
+
614
+ **[Versions]**
615
+
616
+
617
+ **Versions=**
618
+ **FrozenLabels=Person**
619
+ **VersionLabels=!Current,Version**
620
+ **VersionPrefix=Version**
621
+ **VersionCounterProperty=VersionCount**
622
+ **VersionNumberProperty=VersionNumber**
623
+ **FirstVersionProperty=FirstVersion**
624
+ **LastVersionProperty=LastVersion**
625
+ **VersionRelationship=HasVersion**
626
+ **NextVersionRelationship=NextVersion**
627
+ **VersionValidFromProperty=ValidFrom**
628
+ **VersionValidToProperty=ValidTo**
629
+
630
+ Leading and training spaces are ignored in all the entries in the file so feel free to add spaces to improve readability.
631
+ For example, the provided aliases for FromNode are "From", "Start Node", "Start", "From Node", "StartNode" and "Start Node"
632
+ Note: you can see "Start Node" is in the list twice - this is not a problem
633
+ The program will treat any column in the csv file with any of those headings as FromNode
634
+
635
+ ### Example Config File <!-- omit in toc -->
636
+
637
+ ```
638
+ [DEFAULT]
639
+
640
+
641
+ [Database]
642
+ DatabaseNames=lunappi,lunappd,local
643
+ URLs=https://demo.eigen.co/ei-applet/neo4j/query,https://demo.eigen.co/ei-applet/neo4j/query,bolt://localhost:7687
644
+ users=,,neo4j
645
+ passwords=,,neo4j4neo
646
+
647
+ [Model]
648
+ PrimaryProperty=name
649
+ RequiredLabels=MoviesDB
650
+ RequiredProperties=
651
+ PrimaryIDProperty=uuid
652
+ CreationTime=creationDate
653
+ UpdateTime=updatedDate
654
+ Mappings=
655
+
656
+ [Aliases]
657
+ Labels=
658
+ Nodes=name
659
+ FromNodes=
660
+ FromLabels=
661
+ ToNodes=
662
+ ToLabels=
663
+ Relationships=
664
+
665
+ [Versions]
666
+ Versions=
667
+ FrozenLabels=
668
+ VersionLabels=Version,!Current
669
+ VersionLabelPrefix=Version
670
+ VersionCounterProperty=versionCount
671
+ VersionNumberProperty=versionNumber
672
+ FirstVersionProperty=firstVersion
673
+ LastVersionProperty=lastVersion
674
+ VersionRelationship=has_version
675
+ NextVersionRelationship=next_version
676
+ VersionValidFromProperty=validFrom
677
+ VersionValidToProperty=validTo
678
+ ```
679
+
680
+ ## Project structure<a id="project-structure"></a>
681
+
682
+ ```shell
683
+ assetmodelbuilder/
684
+ ├── README.md # Project general information
685
+ ├── src/ # All source code
686
+ │ ├── connectors # Folder for the database connector code
687
+ │ │ ├── boltconnector.py # Connection for the Bolt protocol (i.e. neo4j)
688
+ │ │ ├── dbconnectors.py # Connector manager
689
+ │ │ ├── genericconnector.py # Super class for all connectors
690
+ │ │ └── httpsconnector.py # Connector for https protocol
691
+ │ ├── queries # Folder to build and manager Cypher queries
692
+ │ │ ├── cypherbuilder.py # Main class to build a query. Modified version of Cymple
693
+ │ │ ├── query.py # A custom Neo4jQuery class
694
+ │ │ └── typedefs.py # Defines the 'properties' type used by Cymple
695
+ │ ├── assetmodelbuilder.py # Main program
696
+ │ ├── assetmodelutilities.py # Miscellaneous utility functions
697
+ │ ├── configmanager.py # Reads the config.ini file and manages the model configuration
698
+ │ ├── csvcontentsmanager.py # Reads a csv file and provides the format and content
699
+ │ ├── filemanager.py # Works out the file format of each input file and arranges them in process order
700
+ │ ├── fileprocessors.py # Processors for each type of input file
701
+ │ ├── messages.py # Formats and displays all messages to the user
702
+ │ └── versionmanager.py # Create a new version of a node when it is updated
703
+ └── models/ # Tests
704
+ ├── default
705
+ │ └── config.ini # Contains default model parameters if not present in the model folder
706
+ └── Testing # Test data files, such as input/output files, mocks, etc.
707
+ ├── config.ini # Model parameters for the Test model
708
+ ├── DeleteAll.cypher # Cypher to delete all the Family nodes
709
+ ├── People.csv # File containing some data defining People nodes
710
+ ├── Relations.csv # And some relationships between them
711
+ ├── Extended Family.cypher # Some Cypher queries creating extended family members and relations
712
+ ├── Versions.csv # File with some updates to nodes to test Versioning
713
+ ├── RelationVersions.csv # File with some updates to Relations to test Versioning
714
+ └── Rebuild.lst # File listing all the input files. Use with -o x to process in the listed order
715
+
716
+ ```
717
+
718
+ # Coming soon<a id="coming-soon"></a>
719
+ ### Eigen Ingenuity <!-- omit in toc -->
720
+ - Integration of a new historian api that allows for cross-datasource requests, with more request options/methods.
721
+ - Improvements to Azure Authentication functionality, and client integration
722
+
723
+ ### Asset Model Builder <!-- omit in toc -->
724
+ - Options for special processing. For example, an option to over-write existing nodes, rather than just update them
725
+
726
+ # Planned<a id="planned"></a>
727
+
728
+ ### Eigen Ingenuity <!-- omit in toc -->
729
+ - Integration with 365 Events and Power Automate
730
+ - Sphynx/Jupyter notebook with worked examples for all functionality
731
+
732
+ ### Asset Model Builder <!-- omit in toc -->
733
+ - Options for special processing. For example, an option to over-write existing nodes, rather than just update them
734
+ - Options to remove nodes, relations and/or properties and labels from them
735
+
736
+ # License<a id="license"></a>
737
+ Apache License 2.0
738
+
739
+ Copyright 2022 Eigen Ltd.
740
+
741
+ Licensed under the Apache License, Version 2.0 (the "License");
742
+ you may not use this file except in compliance with the License.
743
+ You may obtain a copy of the License at
744
+
745
+ http://www.apache.org/licenses/LICENSE-2.0
746
+
747
+ Unless required by applicable law or agreed to in writing, software
748
+ distributed under the License is distributed on an "AS IS" BASIS,
749
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
750
+ See the License for the specific language governing permissions and
751
+ limitations under the License.