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