python-eigen-ingenuity 0.5.21b3__tar.gz → 0.5.22__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 (102) hide show
  1. {python_eigen_ingenuity-0.5.21b3/python_eigen_ingenuity.egg-info → python_eigen_ingenuity-0.5.22}/PKG-INFO +1 -1
  2. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/eigeningenuity/historianmulti.py +174 -2
  3. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/eigeningenuity/util.py +45 -8
  4. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/assetmodelutilities.py +6 -1
  5. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/configmanager.py +25 -3
  6. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/csvcontentsmanager.py +1 -1
  7. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/fileanalyser.py +0 -1
  8. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/filemanager.py +11 -2
  9. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/processors/cypherfileprocessor.py +3 -0
  10. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/processors/labelmanager.py +3 -2
  11. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/processors/nodefileprocessor.py +3 -0
  12. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/processors/propertymanager.py +1 -1
  13. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/processors/relationshipfileprocessor.py +16 -11
  14. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/property.py +2 -3
  15. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22/python_eigen_ingenuity.egg-info}/PKG-INFO +1 -1
  16. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/MANIFEST.in +0 -0
  17. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/README-nocli.md +0 -0
  18. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/README.md +0 -0
  19. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/eigeningenuity/__init__.py +0 -0
  20. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/eigeningenuity/assetmodel.py +0 -0
  21. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/eigeningenuity/auth.py +0 -0
  22. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/eigeningenuity/commonmenu.py +0 -0
  23. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/eigeningenuity/core/__init__.py +0 -0
  24. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/eigeningenuity/elastic.py +0 -0
  25. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/eigeningenuity/events.py +0 -0
  26. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/eigeningenuity/historian.py +0 -0
  27. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/eigeningenuity/settings.py +0 -0
  28. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/eigeningenuity/sql.py +0 -0
  29. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/__init__.py +0 -0
  30. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/common.py +0 -0
  31. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/config.py +0 -0
  32. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/demo.py +0 -0
  33. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historian/__init__.py +0 -0
  34. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historian/test_getCurrentDataPoints.py +0 -0
  35. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historian/test_getInterpolatedPoints.py +0 -0
  36. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historian/test_getInterpolatedRange.py +0 -0
  37. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historian/test_getMetaData.py +0 -0
  38. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historian/test_getRawDataPoints.py +0 -0
  39. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historian/test_listDataTags.py +0 -0
  40. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historian/test_writePoints.py +0 -0
  41. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historianmulti/__init__.py +0 -0
  42. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historianmulti/common_multi.py +0 -0
  43. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historianmulti/test_getClosestRawPoint.py +0 -0
  44. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historianmulti/test_getCurrentDataPoints.py +0 -0
  45. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historianmulti/test_getInterpolatedPoints.py +0 -0
  46. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historianmulti/test_getInterpolatedRange.py +0 -0
  47. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historianmulti/test_getMetaData.py +0 -0
  48. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historianmulti/test_getRawDatapoints.py +0 -0
  49. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historianmulti/test_listDataTags.py +0 -0
  50. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historianmulti/test_tagManagement.py +0 -0
  51. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/historianmulti/test_writePoints.py +0 -0
  52. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/local-tests/run_tests.py +0 -0
  53. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/__init__.py +0 -0
  54. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/__init__.py +0 -0
  55. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/assetmodelbuilder.py +0 -0
  56. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/assetmodelcsvwriter.py +0 -0
  57. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/connectors/__init__.py +0 -0
  58. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/connectors/boltconnector.py +0 -0
  59. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/connectors/dbconnectors.py +0 -0
  60. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/connectors/genericconnector.py +0 -0
  61. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/connectors/httpsconnector.py +0 -0
  62. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/csvwriter.py +0 -0
  63. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/messages.py +0 -0
  64. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/processors/__init__.py +0 -0
  65. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/processors/relationshipmanager.py +0 -0
  66. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/queries/__init__.py +0 -0
  67. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/queries/cypherbuilder.py +0 -0
  68. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/queries/query.py +0 -0
  69. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/modelbuilder/src/versionmanager.py +0 -0
  70. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/pyproject.toml +0 -0
  71. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/python_eigen_ingenuity.egg-info/SOURCES.txt +0 -0
  72. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/python_eigen_ingenuity.egg-info/dependency_links.txt +0 -0
  73. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/python_eigen_ingenuity.egg-info/entry_points.txt +0 -0
  74. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/python_eigen_ingenuity.egg-info/requires.txt +0 -0
  75. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/python_eigen_ingenuity.egg-info/top_level.txt +0 -0
  76. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/__init__.py +0 -0
  77. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/__init__.py +0 -0
  78. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/common.py +0 -0
  79. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/common_multi.py +0 -0
  80. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian/__init__.py +0 -0
  81. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian/common.py +0 -0
  82. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian/test_getCurrentDataPoints.py +0 -0
  83. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian/test_getInterpolatedPoints.py +0 -0
  84. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian/test_getInterpolatedRange.py +0 -0
  85. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian/test_getMetaData.py +0 -0
  86. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian/test_getRawDataPoints.py +0 -0
  87. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian/test_listDataTags.py +0 -0
  88. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian/test_writePoints.py +0 -0
  89. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian-multi/__init__.py +0 -0
  90. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian-multi/common_multi.py +0 -0
  91. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian-multi/test_getClosestRawPoint.py +0 -0
  92. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian-multi/test_getCurrentDataPoints.py +0 -0
  93. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian-multi/test_getInterpolatedPoints.py +0 -0
  94. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian-multi/test_getInterpolatedRange.py +0 -0
  95. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian-multi/test_getMetaData.py +0 -0
  96. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian-multi/test_getRawDatapoints.py +0 -0
  97. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian-multi/test_listDataTags.py +0 -0
  98. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian-multi/test_tagManagement.py +0 -0
  99. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/regressiontests/eigeningenuity/historian-multi/test_writePoints.py +0 -0
  100. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/requirements.txt +0 -0
  101. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/setup.cfg +0 -0
  102. {python_eigen_ingenuity-0.5.21b3 → python_eigen_ingenuity-0.5.22}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-eigen-ingenuity
3
- Version: 0.5.21b3
3
+ Version: 0.5.22
4
4
  Summary: A python library used to query data from the Eigen Ingenuity system
5
5
  Home-page: https://www.eigen.co/
6
6
  Author: Murray Callander
@@ -18,6 +18,7 @@ eigeningenuity.core) or a full URL to a JSON Bridge Historian instance.
18
18
  """
19
19
 
20
20
  import requests
21
+ import re
21
22
  from typing import Union
22
23
  from datetime import datetime
23
24
 
@@ -309,6 +310,179 @@ class HistorianMulti(object):
309
310
  output, items, tags, timestamps, timestamp_format=self.timestamp_format
310
311
  )
311
312
 
313
+ # SECTION - Tag Aggregation Requests
314
+
315
+ def getAggregates(
316
+ self,
317
+ tags: Union[str, list],
318
+ start: Union[int, float, str, datetime],
319
+ end: Union[int, float, str, datetime],
320
+ intervals: int = 1,
321
+ aggregates: Union[str, list] = None,
322
+ output: str = "json",
323
+ ):
324
+ """Get aggregates/statistics for one or more tags over a time range
325
+
326
+ Args:
327
+ tags: A datatag, or list of datatags
328
+ start: Start of the time range. Accepts epoch milliseconds, python datetime objects, or strings of format dd-mm-YYYYTHH:MM:DD
329
+ end: End of the time range. Accepts epoch milliseconds, python datetime objects, or strings of format dd-mm-YYYYTHH:MM:DD
330
+ intervals (Optional): Number of equal time intervals to split the time range into. One aggregate will be returned per interval. Defaults to 1
331
+ aggregates (Optional): A string, or list of strings of the aggregates to return. Allowed values are: "FIRST", "AVG", "NUMGOOD", "MAX", "LAST", "VAR", "MEDIAN", "NUMBAD", "MIN", "COUNT", "STDDEV". Defaults to all aggregates.
332
+ output (Optional): The format in which to return the data. Accepts one of:
333
+ - "raw" - The raw json returned by the API
334
+ - "json" - A processed version of the json response
335
+ - "df" - A formatted pandas dataframe object. Defaults to "json".
336
+ Returns:
337
+ An Object that can be used to query historian data.
338
+ """
339
+ body = {"requests": {}}
340
+ allowed_aggregates = [
341
+ "FIRST",
342
+ "AVG",
343
+ "NUMGOOD",
344
+ "MAX",
345
+ "LAST",
346
+ "VAR",
347
+ "MEDIAN",
348
+ "NUMBAD",
349
+ "MIN",
350
+ "COUNT",
351
+ "STDDEV",
352
+ ]
353
+
354
+ if aggregates is None:
355
+ aggregates = allowed_aggregates
356
+ aggregates = list(map(lambda x: x.upper(), aggregates))
357
+ aggregates = list(filter(lambda x: x in allowed_aggregates, aggregates))
358
+
359
+ if aggregates == []:
360
+ raise EigenException(
361
+ "No valid aggregates provided. Allowed aggregates are: "
362
+ + ", ".join(allowed_aggregates)
363
+ )
364
+
365
+ tags = force_list(tags)
366
+ aggregates = force_list(aggregates)
367
+
368
+ for tag in tags:
369
+ fulltag = tag
370
+ if "/" not in tag:
371
+ fulltag = self.historian + tag
372
+ request = {
373
+ "type": "MULTIPLE_AGGREGATED_POINTS",
374
+ "tag": fulltag,
375
+ "details": {
376
+ "from": time_to_epoch_millis(start),
377
+ "to": time_to_epoch_millis(end),
378
+ "aggregates": aggregates,
379
+ "count": intervals,
380
+ },
381
+ }
382
+
383
+ body["requests"][tag] = request
384
+
385
+ response = _do_historian_multi_request(self.serverurl, body, self.auth)
386
+
387
+ return format_output(
388
+ output,
389
+ response,
390
+ tags,
391
+ timestamp_format=self.timestamp_format,
392
+ is_aggregate=True,
393
+ aggregates=aggregates,
394
+ )
395
+
396
+ def getAggregateIntervals(
397
+ self,
398
+ tags: Union[str, list],
399
+ start: Union[int, float, str, datetime],
400
+ end: Union[int, float, str, datetime],
401
+ interval_size: str = None,
402
+ aggregates: Union[str, list] = None,
403
+ final_interval_behavior: str = "EXCLUDE",
404
+ output: str = "json",
405
+ ):
406
+ """Get aggregates/statistics for one or more tags, split into specified time intervals, over a time range
407
+
408
+ Args:
409
+ tags: A datatag, or list of datatags
410
+ start: Start of the time range. Accepts epoch milliseconds, python datetime objects, or strings of format dd-mm-YYYYTHH:MM:DD
411
+ end: End of the time range. Accepts epoch milliseconds, python datetime objects, or strings of format dd-mm-YYYYTHH:MM:DD
412
+ interval_size (Optional): Duration of each sub time interval to calculate aggregates for. Format like e.g. ["1s", "1m", "1h", "1w", "1y"]. Defaults to the entire time range
413
+ final_interval_behavior (Optional): Behavior for the final interval if it would extend beyond the total window. Options include "INCLUDE", "EXCLUDE", etc. Defaults to "EXCLUDE".
414
+ aggregates (Optional): A string, or list of strings of the aggregates to return. Allowed values are: "FIRST", "AVG", "NUMGOOD", "MAX", "LAST", "VAR", "MEDIAN", "NUMBAD", "MIN", "COUNT", "STDDEV". Defaults to all aggregates.
415
+ output (Optional): The format in which to return the data. Accepts one of:
416
+ - "raw" - The raw json returned by the API
417
+ - "json" - A processed version of the json response
418
+ - "df" - A formatted pandas dataframe object. Defaults to "json".
419
+ Returns:
420
+ An Object that can be used to query historian data.
421
+ """
422
+ start_ms = time_to_epoch_millis(start)
423
+ end_ms = time_to_epoch_millis(end)
424
+
425
+ allowed_final_interval_behaviors = ["INCLUDE", "EXCLUDE"]
426
+ final_interval_behavior = final_interval_behavior.upper()
427
+ if final_interval_behavior not in allowed_final_interval_behaviors:
428
+ raise EigenException(
429
+ f"final_interval_behavior must be one of: {', '.join(allowed_final_interval_behaviors)}"
430
+ )
431
+
432
+ # Calculate window duration in ms
433
+ window_duration_ms = end_ms - start_ms
434
+
435
+ # Parse interval_size (e.g., "1h", "30m", "5s")
436
+ match = re.match(r"(\d+)(s|m|h|d|w|y)", interval_size)
437
+ if not match:
438
+ raise ValueError(f"Invalid interval_size format: {interval_size}")
439
+
440
+ amount, unit = int(match.group(1)), match.group(2)
441
+
442
+ # Convert interval to milliseconds
443
+ unit_to_ms = {
444
+ "s": 1000,
445
+ "m": 60 * 1000,
446
+ "h": 60 * 60 * 1000,
447
+ "d": 24 * 60 * 60 * 1000,
448
+ "w": 7 * 24 * 60 * 60 * 1000,
449
+ "y": 365 * 24 * 60 * 60 * 1000, # approximate
450
+ }
451
+ interval_ms = amount * unit_to_ms[unit]
452
+
453
+ # Calculate number of intervals
454
+ num_intervals = window_duration_ms / interval_ms
455
+
456
+ # Adjust based on final_interval_behavior
457
+ if final_interval_behavior == "INCLUDE":
458
+ num_intervals = int(num_intervals) + (
459
+ 1 if num_intervals % 1 > 0 else 0
460
+ ) # Ceiling
461
+ elif final_interval_behavior == "EXCLUDE":
462
+ num_intervals = int(num_intervals) # Floor
463
+
464
+ adjusted_end_ms = start_ms + (num_intervals * interval_ms)
465
+
466
+ if num_intervals <= 0:
467
+ raise EigenException(
468
+ "Calculated number of intervals is zero or negative. Please check the interval_size and time range."
469
+ )
470
+ elif num_intervals > 1000:
471
+ raise EigenException(
472
+ f"Calculated number of intervals exceeds maximum limit of 1,000 ({num_intervals}). Please increase interval_size or reduce time range."
473
+ )
474
+
475
+ return self.getAggregates(
476
+ tags,
477
+ start_ms,
478
+ adjusted_end_ms,
479
+ intervals=num_intervals,
480
+ aggregates=aggregates,
481
+ output=output,
482
+ )
483
+
484
+ # SECTION - Tag Metadata Requests
485
+
312
486
  def listDataTags(self, historian: str = None, limit: int = 100, match: str = ""):
313
487
  """List all tags in a historian, or those matching a wildcard
314
488
 
@@ -389,8 +563,6 @@ class HistorianMulti(object):
389
563
 
390
564
  return metadata
391
565
 
392
- # SECTION - Tag Metadata Requests
393
-
394
566
  def createTag(
395
567
  self,
396
568
  tag: str,
@@ -166,7 +166,7 @@ def number_to_string(n):
166
166
 
167
167
  def time_to_epoch_millis(t):
168
168
  if type(t) == datetime:
169
- epochmillis = t.timestamp()
169
+ epochmillis = t.timestamp() * 1000
170
170
  elif type(t) == int or type(t) == float:
171
171
  if t > 100000000000:
172
172
  epochmillis = int(t)
@@ -613,7 +613,9 @@ def _do_historian_multi_request(
613
613
  return resp
614
614
 
615
615
 
616
- def _reformat_multi_response(original_dict):
616
+ def _reformat_multi_response(original_dict, is_aggregate=False):
617
+ if is_aggregate:
618
+ return original_dict
617
619
  reformatted_dict = {}
618
620
 
619
621
  for key, value in original_dict.items():
@@ -625,15 +627,37 @@ def _reformat_multi_response(original_dict):
625
627
  continue
626
628
  else:
627
629
  # Extract the list of data points from either 'dataPoints' or 'dataPoint' key
628
- data_points = value.get("dataPoints") or value.get("dataPoint") or value
630
+ data_points = (
631
+ value.get("dataPoints", None) or value.get("dataPoint", None) or value
632
+ )
629
633
  # Assign the data points list directly to the top-level key
630
634
  reformatted_dict[key] = data_points
631
635
 
632
636
  return reformatted_dict
633
637
 
634
638
 
635
- def format_output(output, response, tags, timestamps=False, timestamp_format="iso"):
636
- if not timestamps:
639
+ def format_output(
640
+ output,
641
+ response,
642
+ tags,
643
+ timestamps=False,
644
+ timestamp_format="iso",
645
+ is_aggregate=False,
646
+ aggregates=[],
647
+ ):
648
+ if is_aggregate:
649
+ items = {}
650
+ aggregates_lower = [agg.lower() for agg in aggregates]
651
+ for tag, data in response["results"].items():
652
+ items[tag] = []
653
+ for agg in data["aggregates"]:
654
+ filtered_agg = {
655
+ k: v
656
+ for k, v in agg.items()
657
+ if k.lower() in ["from", "to", "tag", *aggregates_lower]
658
+ }
659
+ items[tag].append(filtered_agg)
660
+ elif not timestamps:
637
661
  items = response["results"]
638
662
  else:
639
663
  items = response
@@ -642,19 +666,32 @@ def format_output(output, response, tags, timestamps=False, timestamp_format="is
642
666
  return response
643
667
  elif output == "json":
644
668
  if len(tags) == 1 and (not timestamps or len(timestamps) == 1):
645
- return _reformat_multi_response(items[tags[0]])
669
+ return _reformat_multi_response(items[tags[0]], is_aggregate)
646
670
  else:
647
- return _reformat_multi_response(items)
671
+ return _reformat_multi_response(items, is_aggregate)
648
672
  elif output == "string":
649
673
  return json.dumps(items, indent=4)
650
674
  elif output == "df":
651
- return multi_response_to_df(items)
675
+ if is_aggregate:
676
+ return aggregate_response_to_df(items)
677
+ else:
678
+ return multi_response_to_df(items)
652
679
 
653
680
  raise EigenException(
654
681
  "Unrecognised Output Type. Must be one of ['raw','json','string','df']"
655
682
  )
656
683
 
657
684
 
685
+ def aggregate_response_to_df(items):
686
+ rows = []
687
+ for tag, data in items.items():
688
+ data = force_list(data)
689
+ for entry in data:
690
+ rows.append({"tag": tag, **entry})
691
+ df = pd.DataFrame(rows).set_index("tag")
692
+ return df
693
+
694
+
658
695
  class EigenException(Exception):
659
696
  pass
660
697
 
@@ -24,23 +24,28 @@ def find_file(path, filename):
24
24
  full_name = None
25
25
  return full_name
26
26
 
27
+
27
28
  def get_formatted_time_now():
28
29
  now = datetime.datetime.now(timezone.utc).astimezone().strftime("%Y-%m-%dT%H:%M:%S.%f%z")
29
30
  return now
30
31
 
32
+
31
33
  def get_formatted_time_now_noms():
32
34
  now = datetime.datetime.now(timezone.utc).astimezone().strftime("%Y-%m-%dT%H:%M:%S%z")
33
35
  return now
34
36
 
37
+
35
38
  def get_formatted_future_time():
36
39
  future = datetime.datetime(2199, 12, 31).strftime("%Y-%m-%dT%H:%M:%S.%f%z")
37
40
  return future
38
41
 
42
+
39
43
  def get_time_for_filename():
40
44
  now = datetime.datetime.now(timezone.utc).astimezone().strftime("%Y-%m-%d %H-%M-%S-%f")[0:-3]
41
45
  return now
42
46
 
43
- def validate(input, prefix = ''):
47
+
48
+ def validate(input, prefix=''):
44
49
  output = f'{prefix}{input}'
45
50
  if input:
46
51
  if input.startswith('`!'):
@@ -43,7 +43,7 @@ class ConfigManager:
43
43
  parser.add_argument('-rb', '--replaceblanks', default=None, type=str, help='Used in combination with allowblanks. Write a specific value instead of blank e.g "__NULL"')
44
44
  parser.add_argument('-b', '--batch', default=0, type=int, help='Number of queries to batch together when processing a node .csv file')
45
45
  parser.add_argument('-a', '--auth', action='store_true', help='Enable Azure Authentication')
46
- default_order = 'qnrc'
46
+ default_order = 'qncr'
47
47
  parser.add_argument('-o', '--order', default=default_order, help='Order in which to process the input files. Default is ' + default_order)
48
48
  parser.add_argument('-ft', '--filetypes', default=default_order, help='File types to process. Default is all')
49
49
 
@@ -276,6 +276,10 @@ class ConfigManager:
276
276
  self.required_relationship_properties_dict = {}
277
277
  self.unrequired_relationship_properties_list = {}
278
278
  self.required_relationships_dict = {}
279
+ self.from_property_list = {}
280
+ self.to_property_list = {}
281
+ self.from_required_labels_list = {}
282
+ self.to_required_labels_list = {}
279
283
 
280
284
  self.no_system_properties = self.get_config_value(self.common_section, "SystemProperties", "on").lower() != 'on' or self.no_system_properties
281
285
  if self.no_system_properties:
@@ -293,6 +297,10 @@ class ConfigManager:
293
297
  self.required_properties_dict[s], self.unrequired_properties_list[s] = pm.combine_required_properties(self.get_config_value_list(s, "RequiredProperties", ""), [self.required_properties_override], self.default_data_type[s])
294
298
  self.required_relationship_properties_dict[s], self.unrequired_relationship_properties_list[s] = pm.combine_required_properties(self.get_config_value_list(s, "RequiredRelationshipProperties", ""), [self.required_relationship_properties_override], self.default_data_type[s])
295
299
  self.required_relationships_dict[s] = self.get_config_value_dict(s, "RequiredRelationships", "")
300
+ self.from_property_list[s] = self.get_config_value(s, "FromProperty", "")
301
+ self.to_property_list[s] = self.get_config_value(s, "ToProperty", "")
302
+ self.from_required_labels_list[s] = self.get_config_value_list(s, "FromRequiredLabels", "")
303
+ self.to_required_labels_list[s] = self.get_config_value_list(s, "ToRequiredLabels", "")
296
304
 
297
305
  try:
298
306
  self.header_mappings_dict[s] = {i.replace('=', '->').split('->')[0].rstrip(): i.replace('=', '->').split('->')[1].lstrip() for i in header_mappings[s]}
@@ -328,7 +336,8 @@ class ConfigManager:
328
336
  if allow_comma and raw_value == ',':
329
337
  return [',']
330
338
  else:
331
- return [i.strip() for i in raw_value.split(',')]
339
+ # Remove any Zero-width white spaces ([ZWSP] from the mapping Key in config == \u200b in UTF-16 used in csvmanagerconfig == ​ in UTF-8 here)
340
+ return [i.strip() for i in raw_value.replace('​', '').split(',')]
332
341
  else:
333
342
  return []
334
343
 
@@ -345,7 +354,8 @@ class ConfigManager:
345
354
  # Reformat from a single string of comma separated values to a Dictionary
346
355
  # removing leading and trailing spaces while we're at it
347
356
  if raw_value:
348
- values = [(i.strip()+':').split(':') for i in raw_value.split(',')]
357
+ # Remove any Zero-width white spaces ([ZWSP] from the mapping Key in config == \u200b in UTF-16 used in csvmanagerconfig == ​ in UTF-8 here)
358
+ values = [(i.strip()+':').split(':') for i in raw_value.replace('​', '').split(',')]
349
359
  # If v[1] is blank, it means no key was provided, only a value (in v[0]), so use it for both key and value
350
360
  return {v[0]: v[1] if v[1] != '' else v[0] for v in values}
351
361
  else:
@@ -468,6 +478,18 @@ class ConfigManager:
468
478
  def get_required_relationships_dict(self):
469
479
  return self.required_relationships_dict
470
480
 
481
+ def get_from_properties_list(self):
482
+ return self.from_property_list
483
+
484
+ def get_to_properties_list(self):
485
+ return self.to_property_list
486
+
487
+ def get_from_required_labels_list(self):
488
+ return self.from_required_labels_list
489
+
490
+ def get_to_required_labels_list(self):
491
+ return self.to_required_labels_list
492
+
471
493
  def get_unique_id_property(self):
472
494
  return self.unique_id_property
473
495
 
@@ -24,7 +24,7 @@ class CSVContentsManager:
24
24
  format = ''
25
25
  type = ''
26
26
  header_parts = header.split(':')
27
- key = header_parts[0].replace('\ufeff', '')
27
+ key = header_parts[0].replace('\ufeff', '').replace('\u200b', '').strip()
28
28
  if len(header_parts) == 3:
29
29
  format = header_parts[1]
30
30
  type = header_parts[2]
@@ -30,7 +30,6 @@ class FileAnalyser():
30
30
  self.label_types = amu.label_types
31
31
  self.all_types = amu.all_types
32
32
 
33
-
34
33
  def determine_file_type(self, filename, file_format):
35
34
 
36
35
  contents = None
@@ -349,10 +349,19 @@ class FileManager:
349
349
  else:
350
350
  self.error_file = None
351
351
 
352
+ config_section = file_to_process.get_section()
353
+ if config_section:
354
+ if config_section != "DEFAULT":
355
+ section = f' (using config section {config_section})'
356
+ else:
357
+ section = ''
358
+ else:
359
+ section = ''
360
+
352
361
  if file_to_process.is_inline_query():
353
- report_message(f'Processing query "{file_to_process.get_filename()}" at {amu.get_formatted_time_now()}')
362
+ report_message(f'Processing query "{file_to_process.get_filename()}"{section} at {amu.get_formatted_time_now()}')
354
363
  else:
355
- report_message(f'Processing file "{file_to_process.get_filename()}" at {amu.get_formatted_time_now()}')
364
+ report_message(f'Processing file "{file_to_process.get_filename()}"{section} at {amu.get_formatted_time_now()}')
356
365
  # Build all the queries from the file, depending on the content type of the file
357
366
  queries = file_processor(file_to_process)
358
367
  message(f'{len(queries)} queries generated from {file_to_process.get_filename()}, processing...')
@@ -69,5 +69,8 @@ class CypherFileProcessor:
69
69
  def get_filename(self):
70
70
  return self.filename
71
71
 
72
+ def get_section(self):
73
+ return None
74
+
72
75
  def is_inline_query(self):
73
76
  return self.inline_query
@@ -25,7 +25,6 @@ def validate_label_string(label_string):
25
25
  if result.startswith(':'):
26
26
  result = result[1:]
27
27
 
28
- ## print(f'Validating {label_string}... "{result}"')
29
28
  return result
30
29
 
31
30
 
@@ -106,8 +105,9 @@ def sort_relationship_labels(required_labels, input_labels):
106
105
 
107
106
  return list(set(relationship_labels))
108
107
 
108
+
109
109
  def sort_output_labels(node_labels, version_labels):
110
- # We need the specifed node labels, but not any version labels
110
+ # We need the specified node labels, but not any version labels
111
111
  # This means that any version nodes will not be processed
112
112
  input_labels = node_labels + ['!' + label for label in version_labels if not label.startswith('!')]
113
113
  # Use the same sort algorithm, but we don't use any required labels
@@ -138,6 +138,7 @@ def combine_required_labels(config_labels, override_labels):
138
138
 
139
139
  return combined_list
140
140
 
141
+
141
142
  def validate_output_labels(label_list):
142
143
  output_list = ['`'+label+'`' if label.startswith('!') else label for label in label_list]
143
144
  return ':'.join(output_list)
@@ -262,5 +262,8 @@ class NodeFileProcessor:
262
262
  def get_filename(self):
263
263
  return self.filename
264
264
 
265
+ def get_section(self):
266
+ return self.section
267
+
265
268
  def is_inline_query(self):
266
269
  return False
@@ -66,7 +66,7 @@ def sort_properties(properties, default_type):
66
66
  if property:
67
67
  for prop in property.strip().split(','):
68
68
  # prop has the format key[[:format]:|=value]
69
- split_prop = (prop.replace('=', ':')+':').split(':')
69
+ split_prop = (prop+':').split(':')
70
70
  num_fields = len(split_prop)-1
71
71
  key = split_prop[0]
72
72
  # Normally, there will 2 fields (property and value) or 3 (property, type and value)
@@ -14,6 +14,7 @@ class RelationshipFileProcessor:
14
14
  def __init__(self, filename, config, contents, section):
15
15
  self.filename = filename
16
16
  self.contents = contents
17
+ self.section = section
17
18
 
18
19
  self.primary_property = config.get_primary_property()[section]
19
20
  self.add_system_properties = not config.get_no_system_properties()
@@ -22,6 +23,10 @@ class RelationshipFileProcessor:
22
23
  self.required_properties = config.get_required_relationship_properties_dict()[section]
23
24
  self.unrequired_properties = config.get_unrequired_relationship_properties_list()[section]
24
25
  self.required_relationships = config.get_required_relationships_dict()[section]
26
+ self.from_property = config.get_from_properties_list()[section] or self.primary_property
27
+ self.to_property = config.get_to_properties_list()[section] or self.primary_property
28
+ self.from_required_labels = lm.validate_labels_to_list(config.get_from_required_labels_list()[section])
29
+ self.to_required_labels = lm.validate_labels_to_list(config.get_to_required_labels_list()[section])
25
30
  self.creation_time_property = config.get_creation_time_property()[section]
26
31
  self.update_time_property = config.get_update_time_property()[section]
27
32
 
@@ -45,7 +50,6 @@ class RelationshipFileProcessor:
45
50
  self.relation_types = amu.relation_types
46
51
  self.all_types = amu.all_types
47
52
 
48
-
49
53
  def get_last_row(self, num_rows):
50
54
  if self.last_row < 0:
51
55
  last_row = num_rows
@@ -53,7 +57,6 @@ class RelationshipFileProcessor:
53
57
  last_row = min(num_rows, self.last_row)
54
58
  return last_row
55
59
 
56
-
57
60
  def process_relationship_file(self):
58
61
 
59
62
  # For each line in the file, build a cypher query to MERGE a relationship
@@ -91,12 +94,12 @@ class RelationshipFileProcessor:
91
94
  explicit_properties, calculated_properties = pm.split_out_functional_properties(properties)
92
95
 
93
96
  # If there are multiple From or To nodes, create a relationship query for each combination
94
- for from_node in self.contents.get_property_values_list(this_row, from_columns, self.primary_property, self.primary_property, override_format='str'):
97
+ for from_node in self.contents.get_property_values_list(this_row, from_columns, self.primary_property, self.from_property, override_format='str'):
95
98
  validated_csv_from_labels = lm.validate_labels(self.contents.get_column_values_list(this_row, from_label_columns))
96
- from_labels = lm.sort_relationship_labels(self.required_labels, validated_csv_from_labels)
97
- for to_node in self.contents.get_property_values_list(this_row, to_columns, self.primary_property, self.primary_property, override_format='str'):
99
+ from_labels = lm.sort_relationship_labels(self.required_labels + self.from_required_labels, validated_csv_from_labels)
100
+ for to_node in self.contents.get_property_values_list(this_row, to_columns, self.primary_property, self.to_property, override_format='str'):
98
101
  validated_csv_to_labels = lm.validate_labels(self.contents.get_column_values_list(this_row, to_label_columns))
99
- to_labels = lm.sort_relationship_labels(self.required_labels, validated_csv_to_labels)
102
+ to_labels = lm.sort_relationship_labels(self.required_labels + self.to_required_labels, validated_csv_to_labels)
100
103
 
101
104
  # Build a MERGE query for the relationship(s)
102
105
  for relationship in relationships:
@@ -140,7 +143,6 @@ class RelationshipFileProcessor:
140
143
  messages.message('', False)
141
144
  return queries
142
145
 
143
-
144
146
  def process_relationship_file_batch(self):
145
147
 
146
148
  # For each line in the file, build a cypher query to MERGE a relationship
@@ -188,12 +190,12 @@ class RelationshipFileProcessor:
188
190
  temp = properties.pop(unwanted, None)
189
191
 
190
192
  # If there are multiple From or To nodes, create a relationship query for each combination
191
- for from_node in self.contents.get_property_values_list(this_row, from_columns, self.primary_property, self.primary_property, override_format='str'):
193
+ for from_node in self.contents.get_property_values_list(this_row, from_columns, self.primary_property, self.from_property, override_format='str'):
192
194
  validated_csv_from_labels = lm.validate_labels(self.contents.get_column_values_list(this_row, from_label_columns))
193
- from_labels = lm.sort_relationship_labels(self.required_labels, validated_csv_from_labels)
194
- for to_node in self.contents.get_property_values_list(this_row, to_columns, self.primary_property, self.primary_property, override_format='str'):
195
+ from_labels = lm.sort_relationship_labels(self.required_labels + self.from_required_labels, validated_csv_from_labels)
196
+ for to_node in self.contents.get_property_values_list(this_row, to_columns, self.primary_property, self.to_property, override_format='str'):
195
197
  validated_csv_to_labels = lm.validate_labels(self.contents.get_column_values_list(this_row, to_label_columns))
196
- to_labels = lm.sort_relationship_labels(self.required_labels, validated_csv_to_labels)
198
+ to_labels = lm.sort_relationship_labels(self.required_labels + self.to_required_labels, validated_csv_to_labels)
197
199
 
198
200
  # Build a MERGE query for the relationship(s)
199
201
  for relationship in relationships:
@@ -302,5 +304,8 @@ class RelationshipFileProcessor:
302
304
  def get_filename(self):
303
305
  return self.filename
304
306
 
307
+ def get_section(self):
308
+ return self.section
309
+
305
310
  def is_inline_query(self):
306
311
  return False
@@ -9,7 +9,6 @@ class Neo4jProperty():
9
9
 
10
10
  self.key = pm.validate_property(key)
11
11
  # Sanitise the value
12
- # self.value = value.replace('\\', '\\\\').replace('\r', '\\r').replace('\n', '\\n').replace('"', '\\"')
13
12
  self.value = value.replace('\\', '\\\\').replace('\r', '\\r').replace('"', '\\"')
14
13
 
15
14
  if self.value == "":
@@ -31,7 +30,6 @@ class Neo4jProperty():
31
30
  self.formula = None
32
31
  self.is_formula = False
33
32
 
34
-
35
33
  def set_format(self, new_format):
36
34
  # If the format has changed, update it (otherwise, no need to do anything)
37
35
  if new_format != self.format:
@@ -54,7 +52,6 @@ class Neo4jProperty():
54
52
  return self.formatted_values[ref]
55
53
 
56
54
 
57
-
58
55
  def format_value(self, ref):
59
56
 
60
57
  quote = '"'
@@ -293,6 +290,7 @@ def format_property_list(properties, comparison_operator = ':', boolean_operator
293
290
  res = boolean_operator.join(pairs)
294
291
  return res
295
292
 
293
+
296
294
  def format(properties, property_ref=''):
297
295
  # Reformat using identified data types
298
296
  pairs = []
@@ -300,6 +298,7 @@ def format(properties, property_ref=''):
300
298
  pairs.append(f'{properties[p].key}:{properties[p].get_value(property_ref)}')
301
299
  return '{' + ','.join(pairs) + '}'
302
300
 
301
+
303
302
  def to_str(properties, comparison_operator: str = ':', boolean_operator: str = ',', property_ref='', key_ref='') -> str:
304
303
  pairs = [f'{key_ref}{key.split(":")[0]}{comparison_operator}{Neo4jProperty(key, str(value)).get_value(property_ref)}' for key, value in properties.items()]
305
304
  res = boolean_operator.join(pairs)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-eigen-ingenuity
3
- Version: 0.5.21b3
3
+ Version: 0.5.22
4
4
  Summary: A python library used to query data from the Eigen Ingenuity system
5
5
  Home-page: https://www.eigen.co/
6
6
  Author: Murray Callander