python-eigen-ingenuity 0.5.31b1__py3-none-any.whl → 0.5.32__py3-none-any.whl

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.
@@ -3,36 +3,37 @@
3
3
  This package deals with the Eigen Ingenuity Historian API, mostly by means
4
4
  of the JSON Bridge Historian.
5
5
 
6
- To get a historian object to work with, use get_historian(xxx) with either
6
+ To get a historianmulti object to work with, use get_historian_multi(xxx) with either
7
7
  an instance name (which will be resolved via the the usual methods in
8
8
  eigeningenuity.core) or a full URL to a JSON Bridge Historian instance.
9
9
 
10
- from eigeningenuity.historian import get_historian
10
+ from eigeningenuity.historianmulti import get_historian_multi
11
11
  from time import gmtime, asctime
12
12
 
13
- h = get_historian("pi-opc")
14
- tags = h.listDataTags()
13
+ hm = get_historian_multi("pi-opc")
14
+ tags = hm.listDataTags()
15
15
  for tag in tags:
16
- dp = h.getCurrentDataPoint(tag)
16
+ dp = hm.getCurrentDataPoints(tag)
17
17
  print(asctime(time.gmtime(dp['timestamp'])), dp['value'])
18
18
  """
19
19
 
20
- import requests
21
20
  import re
22
- from typing import Union
23
21
  from datetime import datetime
22
+ from typing import Union
23
+ from urllib.error import URLError
24
24
 
25
+ import requests
25
26
  from requests.exceptions import ConnectionError
26
- from urllib.error import URLError
27
- from eigeningenuity.core import get_default_server, EigenServer
27
+
28
+ from eigeningenuity.core import EigenServer, get_default_server
28
29
  from eigeningenuity.util import (
29
- force_list,
30
- time_to_epoch_millis,
31
30
  EigenException,
32
- merge_tags_from_response,
33
- update_keys,
34
31
  _do_historian_multi_request,
32
+ force_list,
35
33
  format_output,
34
+ merge_tags_from_response,
35
+ time_to_epoch_millis,
36
+ update_keys,
36
37
  )
37
38
 
38
39
 
@@ -88,7 +89,7 @@ class HistorianMulti(object):
88
89
  RemoteServerException: If the historian cannot be found or the API returns an error.
89
90
  RuntimeError: If no response is received from the API.
90
91
  HTTPError: If the API request fails.
91
-
92
+
92
93
  Docs:
93
94
  https://docs.eigeningenuity.co/developing-with-eigen/python-library/historian-multi/reading-data/getcurrentdatapoints
94
95
  """
@@ -132,7 +133,7 @@ class HistorianMulti(object):
132
133
  RemoteServerException: If the historian cannot be found or the API returns an error.
133
134
  RuntimeError: If no response is received from the API.
134
135
  HTTPError: If the API request fails.
135
-
136
+
136
137
  Docs:
137
138
  https://docs.eigeningenuity.co/developing-with-eigen/python-library/historian-multi/reading-data/getinterpolatedpoints
138
139
  """
@@ -188,7 +189,7 @@ class HistorianMulti(object):
188
189
  RemoteServerException: If the historian cannot be found or the API returns an error.
189
190
  RuntimeError: If no response is received from the API.
190
191
  HTTPError: If the API request fails.
191
-
192
+
192
193
  Docs:
193
194
  https://docs.eigeningenuity.co/developing-with-eigen/python-library/historian-multi/reading-data/getinterpolatedrange
194
195
  """
@@ -245,7 +246,7 @@ class HistorianMulti(object):
245
246
  RemoteServerException: If the historian cannot be found or the API returns an error.
246
247
  RuntimeError: If no response is received from the API.
247
248
  HTTPError: If the API request fails.
248
-
249
+
249
250
  Docs:
250
251
  https://docs.eigeningenuity.co/developing-with-eigen/python-library/historian-multi/reading-data/getrawdatapoints
251
252
  """
@@ -285,24 +286,24 @@ class HistorianMulti(object):
285
286
  ):
286
287
  """Get the closest raw point to one or more timestamps.
287
288
 
288
- Args:
289
- tags (Union[str, list]): Tag name or list of tags to query.
290
- timestamps (Union[int, float, str, datetime, list]): One or more timestamps to find closest raw points for.
291
- before_or_after (str, optional): Selection rule for closest point. Defaults to "AFTER_OR_AT".
292
- output (str, optional): Output format selector. Accepts "json", "df", "raw", "string". Defaults to "json".
293
-
294
- Returns:
295
- dict|list|pandas.DataFrame|str: Closest raw points to the timestamps. Format depends on output parameter.
296
-
297
- Raises:
298
- ValueError: When invalid Output Type is given
299
- URLError: If no Ingenuity instance can be reached or no internet connection is available.
300
- RemoteServerException: If the historian cannot be found or the API returns an error.
301
- RuntimeError: If no response is received from the API.
302
- HTTPError: If the API request fails.
303
-
304
- Docs:
305
- https://docs.eigeningenuity.co/developing-with-eigen/python-library/historian-multi/reading-data/getclosestrawpoint
289
+ Args:
290
+ tags (Union[str, list]): Tag name or list of tags to query.
291
+ timestamps (Union[int, float, str, datetime, list]): One or more timestamps to find closest raw points for.
292
+ before_or_after (str, optional): Selection rule for closest point. Defaults to "AFTER_OR_AT".
293
+ output (str, optional): Output format selector. Accepts "json", "df", "raw", "string". Defaults to "json".
294
+
295
+ Returns:
296
+ dict|list|pandas.DataFrame|str: Closest raw points to the timestamps. Format depends on output parameter.
297
+
298
+ Raises:
299
+ ValueError: When invalid Output Type is given
300
+ URLError: If no Ingenuity instance can be reached or no internet connection is available.
301
+ RemoteServerException: If the historian cannot be found or the API returns an error.
302
+ RuntimeError: If no response is received from the API.
303
+ HTTPError: If the API request fails.
304
+
305
+ Docs:
306
+ https://docs.eigeningenuity.co/developing-with-eigen/python-library/historian-multi/reading-data/getclosestrawpoint
306
307
  """
307
308
  before_or_after = before_or_after.upper()
308
309
 
@@ -374,7 +375,7 @@ class HistorianMulti(object):
374
375
  RemoteServerException: If the historian cannot be found or the API returns an error.
375
376
  RuntimeError: If no response is received from the API.
376
377
  HTTPError: If the API request fails.
377
-
378
+
378
379
  Docs:
379
380
  https://docs.eigeningenuity.co/developing-with-eigen/python-library/historian-multi/reading-data/getaggregates
380
381
  """
@@ -465,7 +466,7 @@ class HistorianMulti(object):
465
466
  RemoteServerException: If the historian cannot be found or the API returns an error.
466
467
  RuntimeError: If no response is received from the API.
467
468
  HTTPError: If the API request fails.
468
-
469
+
469
470
  Docs:
470
471
  https://docs.eigeningenuity.co/developing-with-eigen/python-library/historian-multi/reading-data/getaggregateintervals
471
472
  """
@@ -549,7 +550,7 @@ class HistorianMulti(object):
549
550
  RemoteServerException: If the historian cannot be found or the API returns an error.
550
551
  RuntimeError: If no response is received from the API.
551
552
  HTTPError: If the API request fails.
552
-
553
+
553
554
  Docs:
554
555
  https://docs.eigeningenuity.co/developing-with-eigen/python-library/historian-multi/metadata/listdatatags
555
556
  """
@@ -559,14 +560,20 @@ class HistorianMulti(object):
559
560
 
560
561
  return tags
561
562
 
562
- def getMetaData(self, historian: str = None, limit: int = 100, match: str = ""):
563
+ def getMetaData(
564
+ self,
565
+ historian: str = None,
566
+ limit: int = 100,
567
+ match: str = "",
568
+ output: str = "json",
569
+ ):
563
570
  """Fetch tag metadata for a historian, optionally filtered with a wildcard.
564
571
 
565
572
  Args:
566
573
  historian (str, optional): Historian name to search.
567
574
  limit (int, optional): Max number of tags returned. Defaults to 100.
568
575
  match (str, optional): Wildcard pattern for tag names. Defaults to "".
569
-
576
+ output (str, optional): Output format selector. Accepts "json", "raw". Defaults to "json".
570
577
  Returns:
571
578
  list[dict]: List of metadata dictionaries for each tag.
572
579
 
@@ -575,12 +582,16 @@ class HistorianMulti(object):
575
582
  RemoteServerException: If the historian cannot be found or the API returns an error.
576
583
  RuntimeError: If no response is received from the API.
577
584
  HTTPError: If the API request fails.
578
-
585
+
579
586
  Docs:
580
587
  https://docs.eigeningenuity.co/developing-with-eigen/python-library/historian-multi/metadata/getmetadata
581
588
  """
582
- if historian is None:
583
- historian = self.historian
589
+ if "/" in historian and match == "":
590
+ split_hist = historian.split("/")
591
+ match = split_hist[1]
592
+ historian = split_hist[0]
593
+ elif historian is None:
594
+ historian = self.historian[0:-1]
584
595
 
585
596
  resp = _do_historian_multi_request(
586
597
  self.searchurl + f"?historian={historian}&limit={limit}&search={match}",
@@ -590,7 +601,12 @@ class HistorianMulti(object):
590
601
  )
591
602
  metadata = resp["tags"]
592
603
 
593
- return metadata
604
+ if output == "raw":
605
+ return metadata
606
+ elif output == "json":
607
+ return {tag["tagName"]: tag for tag in metadata}
608
+ else:
609
+ raise ValueError(f"Invalid output format: {output}")
594
610
 
595
611
  def listHistorians(self, writable):
596
612
  """Retrieve all historians available on the Ingenuity instance.
@@ -608,7 +624,7 @@ class HistorianMulti(object):
608
624
  RemoteServerException: If the historian cannot be found or the API returns an error.
609
625
  RuntimeError: If no response is received from the API.
610
626
  HTTPError: If the API request fails.
611
-
627
+
612
628
  Docs:
613
629
  https://docs.eigeningenuity.co/developing-with-eigen/python-library/historian-multi/metadata/listhistorians
614
630
  """
@@ -619,9 +635,9 @@ class HistorianMulti(object):
619
635
  self.auth,
620
636
  get_request=True,
621
637
  )
622
-
638
+
623
639
  historians = resp["historians"]
624
-
640
+
625
641
  metadata = [x["name"] for x in historians]
626
642
 
627
643
  return metadata
@@ -651,7 +667,7 @@ class HistorianMulti(object):
651
667
  RemoteServerException: If the historian cannot be found or the API returns an error.
652
668
  RuntimeError: If no response is received from the API.
653
669
  HTTPError: If the API request fails.
654
-
670
+
655
671
  Docs:
656
672
  https://docs.eigeningenuity.co/developing-with-eigen/python-library/historian-multi/metadata/createtag
657
673
  """
@@ -706,7 +722,7 @@ class HistorianMulti(object):
706
722
  RemoteServerException: If the historian cannot be found or the API returns an error.
707
723
  RuntimeError: If no response is received from the API.
708
724
  HTTPError: If the API request fails.
709
-
725
+
710
726
  Docs:
711
727
  https://docs.eigeningenuity.co/developing-with-eigen/python-library/historian-multi/metadata/updatetag
712
728
  """
@@ -763,7 +779,7 @@ class HistorianMulti(object):
763
779
  RemoteServerException: If the historian cannot be found or the API returns an error.
764
780
  RuntimeError: If no response is received from the API.
765
781
  HTTPError: If the API request fails.
766
-
782
+
767
783
  Docs:
768
784
  https://docs.eigeningenuity.co/developing-with-eigen/python-library/historian-multi/writing-data/createandpopulatetag
769
785
  """
@@ -823,7 +839,7 @@ class HistorianMulti(object):
823
839
  RemoteServerException: If the historian cannot be found or the API returns an error.
824
840
  RuntimeError: If no response is received from the API.
825
841
  HTTPError: If the API request fails.
826
-
842
+
827
843
  Docs:
828
844
  https://docs.eigeningenuity.co/developing-with-eigen/python-library/historian-multi/writing-data/writepoints
829
845
  """
@@ -861,7 +877,7 @@ class HistorianMulti(object):
861
877
  RemoteServerException: If the historian cannot be found or the API returns an error.
862
878
  RuntimeError: If no response is received from the API.
863
879
  HTTPError: If the API request fails.
864
-
880
+
865
881
  Docs:
866
882
  https://docs.eigeningenuity.co/developing-with-eigen/python-library/historian-multi/writing-data/writepointsbatch
867
883
  """
@@ -916,7 +932,7 @@ def createPoint(
916
932
 
917
933
  Raises:
918
934
  EigenException: If status is not "OK" or "BAD".
919
-
935
+
920
936
  Docs:
921
937
  https://docs.eigeningenuity.co/developing-with-eigen/python-library/historian-multi/writing-data/createpoint
922
938
  """
@@ -937,7 +953,7 @@ def get_historian_multi(
937
953
 
938
954
  Returns:
939
955
  HistorianMulti: An object that can be used to query historian data.
940
-
956
+
941
957
  Docs:
942
958
  https://docs.eigeningenuity.co/developing-with-eigen/python-library/historian-multi/get_historian_multi
943
959
  """
@@ -265,6 +265,7 @@ class ConfigManager:
265
265
  self.no_version = True
266
266
 
267
267
  def read_csv_config(self):
268
+ self.default_encoding = self.get_config_value("DEFAULT", "Encoding", False)
268
269
  self.separators = {s: self.get_config_value(s, "Separator", self.separator, allow_comma=True) for s in self.available_sections}
269
270
  self.primary_property = {s: self.primary_property_override or self.get_config_value(s, "PrimaryProperty", "node") for s in self.available_sections}
270
271
  self.default_data_type = {s: self.get_config_value(s, "DataType", "") for s in self.available_sections}
@@ -638,7 +639,7 @@ class ConfigManager:
638
639
  return self.logger
639
640
 
640
641
  def get_force_encoding(self):
641
- return self.force_encoding
642
+ return self.force_encoding or self.default_encoding
642
643
 
643
644
  def get_detect_encoding(self):
644
645
  return self.detect_encoding
@@ -40,6 +40,7 @@ class FileManager:
40
40
  # And a list of lists for the queries in specified priority order
41
41
  self.valid_file_list = [[], [], [], [], [], []]
42
42
 
43
+ self.file_count = 0
43
44
  self.invalid_file_count = 0
44
45
 
45
46
  self.config_section = config_manager.get_config_section()
@@ -87,8 +88,10 @@ class FileManager:
87
88
  file = a_file
88
89
  this_section = section
89
90
  self.analyse_csv_file(file, this_section)
91
+ self.file_count += 1
90
92
  case 'cypher' | 'qry':
91
93
  self.analyse_cypher_file(a_file)
94
+ self.file_count += 1
92
95
  case 'lst':
93
96
  self.analyse_lst_file(a_file, section)
94
97
  case _:
@@ -106,6 +109,7 @@ class FileManager:
106
109
  self.valid_file_list[priority] += [{'processor': file_processor, 'type': file_type}]
107
110
  else:
108
111
  info_message(file_processor.get_filename(), ' not processed as requested')
112
+ self.file_count -= 1
109
113
 
110
114
  def analyse_lst_file(self, filename, def_section=''):
111
115
  recurse_dirs = self.config_manager.get_recurse_dirs()
@@ -162,12 +166,14 @@ class FileManager:
162
166
  else:
163
167
  query_processor = CypherFileProcessor(a_query, self.config_manager, True)
164
168
  self.add_file_to_process_list(query_processor, 'pre')
169
+ self.file_count += 1
165
170
 
166
171
  labels_to_delete_list = self.config_manager.get_labels_to_delete_list()
167
172
  if labels_to_delete_list == []:
168
173
  query = 'MATCH (n) DETACH DELETE n'
169
174
  query_processor = CypherFileProcessor(query, self.config_manager, True)
170
175
  self.add_file_to_process_list(query_processor, 'pre')
176
+ self.file_count += 1
171
177
  else:
172
178
  for label_list in labels_to_delete_list:
173
179
  match_list = ''
@@ -183,6 +189,7 @@ class FileManager:
183
189
  query += 'DETACH DELETE n'
184
190
  query_processor = CypherFileProcessor(query, self.config_manager, True)
185
191
  self.add_file_to_process_list(query_processor, 'pre')
192
+ self.file_count += 1
186
193
 
187
194
  # Process each file in the list, and determine its content type (ignoring any clues in the filename!)
188
195
  # Analyse each of the specified input .csv files to determine if they contain Nodes or Relationships
@@ -190,13 +197,13 @@ class FileManager:
190
197
  file_list = self.config_manager.get_input_file_list()
191
198
  dir_list = self.config_manager.get_input_dir_list()
192
199
  recurse_dirs = self.config_manager.get_recurse_dirs()
193
-
200
+
194
201
  for a_file in file_list:
195
202
  a_file_split = a_file.split(',')
196
203
  for a_split_file in a_file_split:
197
204
  if a_split_file != '':
198
205
  self.analyse_a_file(a_split_file.strip(), self.config_section)
199
-
206
+
200
207
  for a_dir in dir_list:
201
208
  a_dir_split = a_dir.split(',')
202
209
  for a_split_dir in a_dir_split:
@@ -238,6 +245,7 @@ class FileManager:
238
245
  else:
239
246
  query_processor = CypherFileProcessor(a_query, self.config_manager, True)
240
247
  self.add_file_to_process_list(query_processor, 'post')
248
+ self.file_count += 1
241
249
 
242
250
  def add_file_to_list(self, this_file_processor, this_file_type, file_errors=None):
243
251
 
@@ -317,6 +325,7 @@ class FileManager:
317
325
  def process_not_found_files(self):
318
326
  for file in self.file_not_found_list:
319
327
  warning_message(f'{file} not found')
328
+ self.file_count -= 1
320
329
 
321
330
  def process_unrecognised_file_type_files(self):
322
331
  for file in self.unrecognised_file_type_list:
@@ -325,43 +334,50 @@ class FileManager:
325
334
  def process_incorrect_files(self):
326
335
  for file in self.incorrect_file_list:
327
336
  error_message(f'{file} is not a correctly formatted .csv file - file not processed')
337
+ self.file_count -= 1
328
338
 
329
339
  def process_incorrect_sections(self):
330
340
  for file in self.incorrect_section_list:
331
341
  error_message(f'{file} has an invalid config section - file not processed')
342
+ self.file_count -= 1
332
343
 
333
344
  def process_incomplete_files(self):
334
345
  for file in self.incomplete_file_list:
335
346
  error_message(f'{file[0]} has incomplete data in rows {file[1]} - file not processed')
347
+ self.file_count -= 1
336
348
 
337
349
  def process_neither_found_files(self):
338
350
  for file in self.neither_file_list:
339
351
  error_message(f'Insufficient data in {file} to determine content type - file not processed')
352
+ self.file_count -= 1
340
353
 
341
354
  def process_both_files(self):
342
355
  for file in self.both_file_list:
343
356
  error_message(f'Ambiguous data in {file} - could be multiple content types - file not processed')
357
+ self.file_count -= 1
344
358
 
345
359
  def process_valid_files(self, db_connector):
360
+ file_count = 0
346
361
  num_queries = 0
347
362
  for group in self.valid_file_list:
348
363
  for file in group:
364
+ file_count += 1
349
365
  processor = file['processor']
350
366
  match file['type']:
351
367
  case 'n':
352
368
  if self.batch_rate == 0:
353
- queries, file_result, version_result = self.process_file(processor, NodeFileProcessor.process_node_file, db_connector)
369
+ queries, file_result, version_result = self.process_file(processor, NodeFileProcessor.process_node_file, db_connector, file_count)
354
370
  else:
355
- queries, file_result, version_result = self.process_file(processor, NodeFileProcessor.process_node_file_batch, db_connector)
371
+ queries, file_result, version_result = self.process_file(processor, NodeFileProcessor.process_node_file_batch, db_connector, file_count)
356
372
  case 'r':
357
373
  if self.batch_rate == 0:
358
- queries, file_result, version_result = self.process_file(processor, RelationshipFileProcessor.process_relationship_file, db_connector)
374
+ queries, file_result, version_result = self.process_file(processor, RelationshipFileProcessor.process_relationship_file, db_connector, file_count)
359
375
  else:
360
- queries, file_result, version_result = self.process_file(processor, RelationshipFileProcessor.process_relationship_file_batch, db_connector)
376
+ queries, file_result, version_result = self.process_file(processor, RelationshipFileProcessor.process_relationship_file_batch, db_connector, file_count)
361
377
  case 'c' | 'pre-file' | 'post-file':
362
- queries, file_result, version_result = self.process_file(processor, CypherFileProcessor.process_cypher_file, db_connector)
378
+ queries, file_result, version_result = self.process_file(processor, CypherFileProcessor.process_cypher_file, db_connector, file_count)
363
379
  case 'q' | 'pre' | 'post':
364
- queries, file_result, version_result = self.process_file(processor, CypherFileProcessor.process_query_list, db_connector)
380
+ queries, file_result, version_result = self.process_file(processor, CypherFileProcessor.process_query_list, db_connector, file_count)
365
381
  case _:
366
382
  # This should never happen!
367
383
  queries = 0
@@ -376,7 +392,7 @@ class FileManager:
376
392
 
377
393
  return num_queries
378
394
 
379
- def process_file(self, file_to_process, file_processor, db_connector):
395
+ def process_file(self, file_to_process, file_processor, db_connector, file_count):
380
396
  node_queries = 0
381
397
  num_errors = 0
382
398
  error_list = []
@@ -405,10 +421,11 @@ class FileManager:
405
421
  else:
406
422
  section = ''
407
423
 
424
+ file_message = f' {file_count} of {self.file_count}, "{file_to_process.get_filename()}"{section} at {amu.get_formatted_time_now()}'
408
425
  if file_to_process.is_inline_query():
409
- report_message(f'Processing query "{file_to_process.get_filename()}"{section} at {amu.get_formatted_time_now()}')
426
+ report_message(f'Processing query{file_message}')
410
427
  else:
411
- report_message(f'Processing file "{file_to_process.get_filename()}"{section} at {amu.get_formatted_time_now()}')
428
+ report_message(f'Processing file{file_message}')
412
429
  # Build all the queries from the file, depending on the content type of the file
413
430
  queries = file_processor(file_to_process)
414
431
  message(f'{len(queries)} queries generated from {file_to_process.get_filename()}, processing...')
@@ -428,7 +445,7 @@ class FileManager:
428
445
 
429
446
  try:
430
447
  if self.min_display_rate:
431
- display_rate = max(display_rate,int(ast.literal_eval(self.min_display_rate)))
448
+ display_rate = max(display_rate, int(ast.literal_eval(self.min_display_rate)))
432
449
  except:
433
450
  pass
434
451
  else:
@@ -124,7 +124,7 @@ def strip_quotes(quote_list):
124
124
  def merge_node_labels(merge_labels, node_labels):
125
125
  wanted, _, remove = sort_labels(merge_labels, node_labels)
126
126
  merged_labels = [i for i in merge_labels + wanted if not i in remove]
127
- return merged_labels
127
+ return list(set(merged_labels))
128
128
 
129
129
 
130
130
  def merge_labels(self, required_labels, unrequired_labels, remove_labels):
@@ -7,6 +7,7 @@ import processors.labelmanager as lm
7
7
  import processors.propertymanager as pm
8
8
  import property
9
9
  from property import Neo4jProperty
10
+ import copy
10
11
 
11
12
 
12
13
  class NodeFileProcessor:
@@ -62,9 +63,9 @@ class NodeFileProcessor:
62
63
 
63
64
  queries = []
64
65
 
65
- num_rows = num_data_rows - self.start_from + 1
66
66
  this_row = self.start_from-1
67
67
  last_row = self.get_last_row(num_data_rows)
68
+ num_rows = last_row - self.start_from + 1
68
69
  property_ref = 'n'
69
70
  property_ref_dot = property_ref + '.'
70
71
 
@@ -79,10 +80,18 @@ class NodeFileProcessor:
79
80
  # Split out those properties that are dependent on others, so that we can add them in the right order
80
81
  explicit_properties, calculated_properties = pm.split_out_functional_properties(properties)
81
82
 
83
+ param_explicit_props = self.query_manager.parameterise_dict(explicit_properties, self.section)
84
+ param_calc_props = self.query_manager.parameterise_dict(calculated_properties, self.section)
85
+
86
+ param_properties = []
87
+ for count in range(max(len(param_explicit_props), len(param_calc_props))):
88
+ param_properties += [[param_explicit_props[min(count, len(param_explicit_props) - 1)], param_calc_props[min(count, len(param_calc_props) - 1)]]]
89
+
82
90
  for primary_property in self.contents.get_property_values_list(this_row, node_columns, self.primary_property, allow_split=True, override_format='str'):
83
91
  time_now = amu.get_formatted_time_now()
84
92
  merge_labels, new_labels, remove_labels = lm.sort_node_labels(self.required_labels, validated_csv_labels)
85
93
  node_labels = lm.merge_node_labels(merge_labels, primary_property.labels)
94
+ node_labels = lm.merge_node_labels(node_labels, new_labels)
86
95
 
87
96
  # Build a simple MERGE query using queries
88
97
  query_text = (QueryBuilder()
@@ -99,21 +108,24 @@ class NodeFileProcessor:
99
108
  property_ref_dot + self.update_time_property + '=datetime("' + time_now + '")'
100
109
  query_text = query_text.on_create().set_literal(create_time).set_literal(update_id)
101
110
 
102
- if len(new_labels) > 0:
103
- query_text = query_text.set_labels(ref_name=property_ref, labels=new_labels)
111
+ # if len(new_labels) > 0:
112
+ # query_text = query_text.set_labels(ref_name=property_ref, labels=new_labels)
104
113
  if len(remove_labels) > 0:
105
114
  query_text = query_text.remove_literal(f'{property_ref}:{":".join(remove_labels)}')
106
- if len(explicit_properties) > 0:
107
- query_text = query_text.set(properties=explicit_properties, property_ref=property_ref_dot)
108
- if len(calculated_properties) > 0:
109
- query_text = query_text.set(properties=calculated_properties, property_ref=property_ref_dot)
110
115
 
111
- query_text = query_text.toStr()
112
- query_list = self.query_manager.parameterise(query_text, self.section)
113
- for a_query in query_list:
114
- query = Neo4jQuery('node', a_query, time_now, merge_labels, new_labels, primary_property, properties, self.section)
116
+ for props in param_properties:
117
+ query_text_param = query_text
118
+ param_explicit = props[0]
119
+ if len(param_explicit) > 0:
120
+ query_text_param = query_text_param.set(properties=param_explicit, property_ref=property_ref_dot)
121
+ param_calc = props[1]
122
+ if len(param_calc) > 0:
123
+ query_text_param = query_text_param.set(properties=param_calc, property_ref=property_ref_dot)
124
+
125
+ query_str = query_text_param.toStr()
126
+ query = Neo4jQuery('node', query_str, time_now, merge_labels, new_labels, primary_property, properties, self.section)
115
127
  if self.validate_only and not self.summarise:
116
- print(a_query)
128
+ print(query_str)
117
129
  queries.append(query)
118
130
 
119
131
  this_row += 1
@@ -134,9 +146,9 @@ class NodeFileProcessor:
134
146
 
135
147
  queries = []
136
148
 
137
- num_rows = num_data_rows - self.start_from + 1
138
149
  this_row = self.start_from-1
139
150
  last_row = self.get_last_row(num_data_rows)
151
+ num_rows = last_row - self.start_from + 1
140
152
  dict_size = 0
141
153
  property_ref = 'n'
142
154
  property_ref_dot = property_ref + '.'
@@ -178,8 +190,6 @@ class NodeFileProcessor:
178
190
  for count in range(max(len(param_explicit_props), len(param_calc_props))):
179
191
  query_data_list += [[param_explicit_props[min(count, len(param_explicit_props)-1)], param_calc_props[min(count, len(param_calc_props)-1)], time_now]]
180
192
 
181
- # prop_data = [explicit_properties, calculated_properties, time_now]
182
-
183
193
  # So now we know all about this particular update. Let's put it in the query dictionary
184
194
  # We'll group these by unique combinations of labels and primary key type
185
195
  # Have to use a list since a dictionary key can't be a dictionary
@@ -217,8 +227,8 @@ class NodeFileProcessor:
217
227
  while this_size < batch_size:
218
228
  # Combine all the update data...
219
229
  update = updates[(batch_num-1)*self.batch_rate + this_size]
220
- update_properties = update[0] or {}
221
- func_properties = update[1] or {}
230
+ update_properties = copy.copy(update[0]) or {}
231
+ func_properties = copy.copy(update[1]) or {}
222
232
  if self.add_system_properties:
223
233
  update_properties[self.update_time_property] = Neo4jProperty(self.update_time_property, update[2])
224
234
  payload.append(update_properties)
@@ -233,18 +243,18 @@ class NodeFileProcessor:
233
243
  property_count += len(a_payload)*len(formatted_pload)
234
244
 
235
245
  # Build a MERGE query using queries
236
- merge_labels = batch_keys[new_labels][1]
246
+ merge_labels = lm.merge_node_labels(batch_keys[new_labels][1], batch_keys[new_labels][0])
237
247
  remove_labels = batch_keys[new_labels][2]
238
248
  primary_property = batch_keys[new_labels][3][0]
239
249
  query_text = (QueryBuilder()
240
250
  .unwind_list_as(formatted_payload, payload_ref)
241
251
  .merge()
242
- .node_batch(labels=list(set(merge_labels)), ref_name=property_ref, properties=primary_property+':'+payload_ref_dot+primary_property)
252
+ .node_batch(labels=merge_labels, ref_name=property_ref, properties=primary_property+':'+payload_ref_dot+primary_property)
243
253
  .set_literal(property_ref + ' += ' + payload_ref)
244
254
  )
245
255
 
246
- if batch_keys[new_labels][0]:
247
- query_text = query_text.set_labels(ref_name=property_ref, labels=batch_keys[new_labels][0])
256
+ # if batch_keys[new_labels][0]:
257
+ # query_text = query_text.set_labels(ref_name=property_ref, labels=batch_keys[new_labels][0])
248
258
  if len(remove_labels) > 0:
249
259
  query_text = query_text.remove_literal(f'{property_ref}:{":".join(remove_labels)}')
250
260
  if func_properties:
@@ -7,6 +7,7 @@ import processors.relationshipmanager as rm
7
7
  import processors.propertymanager as pm
8
8
  import property
9
9
  from property import Neo4jProperty
10
+ import copy
10
11
 
11
12
 
12
13
  class RelationshipFileProcessor:
@@ -78,9 +79,9 @@ class RelationshipFileProcessor:
78
79
  to_ref = 'to'
79
80
  relation_ref_dot = relation_ref + '.'
80
81
 
81
- num_rows = num_data_rows - self.start_from + 1
82
82
  this_row = self.start_from-1
83
83
  last_row = self.get_last_row(num_data_rows)
84
+ num_rows = last_row - self.start_from + 1
84
85
  while this_row < last_row:
85
86
 
86
87
  combined_relationships = {**self.required_relationships, **self.contents.get_column_values_dict(this_row, relation_columns)}
@@ -93,13 +94,17 @@ class RelationshipFileProcessor:
93
94
 
94
95
  # Split out those properties that are dependent on others, so that we can add them in the right order
95
96
  explicit_properties, calculated_properties = pm.split_out_functional_properties(properties)
97
+ param_explicit_props = self.query_manager.parameterise_dict(explicit_properties, self.section)
98
+ param_calc_props = self.query_manager.parameterise_dict(calculated_properties, self.section)
96
99
 
97
100
  # If there are multiple From or To nodes, create a relationship query for each combination
98
101
  for from_node in self.contents.get_property_values_list(this_row, from_columns, self.primary_property, self.from_property, override_format='str'):
102
+ param_from_nodes = self.query_manager.parameterise_list([from_node], self.section)
99
103
  validated_csv_from_labels = lm.validate_labels(self.contents.get_column_values_list(this_row, from_label_columns))
100
104
  from_labels = lm.sort_relationship_labels(self.required_labels + self.from_required_labels, validated_csv_from_labels)
101
105
  from_node_labels = lm.merge_node_labels(from_labels, from_node.labels)
102
106
  for to_node in self.contents.get_property_values_list(this_row, to_columns, self.primary_property, self.to_property, override_format='str'):
107
+ param_to_nodes = self.query_manager.parameterise_list([to_node], self.section)
103
108
  validated_csv_to_labels = lm.validate_labels(self.contents.get_column_values_list(this_row, to_label_columns))
104
109
  to_labels = lm.sort_relationship_labels(self.required_labels + self.to_required_labels, validated_csv_to_labels)
105
110
  to_node_labels = lm.merge_node_labels(to_labels, to_node.labels)
@@ -109,36 +114,38 @@ class RelationshipFileProcessor:
109
114
  for relation in relationship.split(':'):
110
115
  if relation:
111
116
 
117
+ param_properties = []
118
+ for count in range(max(len(param_from_nodes), len(param_to_nodes), len(param_explicit_props), len(param_calc_props))):
119
+ param_properties += [[param_from_nodes[min(count, len(param_from_nodes) - 1)], param_to_nodes[min(count, len(param_to_nodes) - 1)], param_explicit_props[min(count, len(param_explicit_props) - 1)], param_calc_props[min(count, len(param_calc_props) - 1)]]]
120
+
112
121
  time_now = amu.get_formatted_time_now()
113
- query_text = (QueryBuilder()
114
- .match()
115
- .node(labels=from_node_labels, ref_name=from_ref, properties=from_node)
116
- .match()
117
- .node(labels=to_node_labels, ref_name=to_ref, properties=to_node)
118
- .merge()
119
- .node(ref_name=from_ref)
120
- .related_to(label=relation, ref_name=relation_ref)
121
- .node(ref_name=to_ref)
122
- )
123
-
124
- # Add in System properties
125
- if self.add_system_properties:
126
- create_time = relation_ref_dot + self.creation_time_property + '=datetime("' + time_now + '")'
127
- update_time = relation_ref_dot + self.update_time_property + '=datetime("' + time_now + '")'
128
- query_text = query_text.on_create().set_literal(create_time).set_literal(update_time)
129
-
130
- if len(explicit_properties) > 0:
131
- query_text = query_text.set(properties=explicit_properties, property_ref=relation_ref_dot)
132
- if len(calculated_properties) > 0:
133
- query_text = query_text.set(properties=calculated_properties, property_ref=relation_ref_dot)
134
-
135
- query_text = query_text.toStr()
136
- query_list = self.query_manager.parameterise(query_text, self.section)
137
-
138
- for a_query in query_list:
139
- query = Neo4jQuery('relationship', a_query, time_now)
122
+ for props in param_properties:
123
+ query_text = (QueryBuilder()
124
+ .match()
125
+ .node(labels=from_node_labels, ref_name=from_ref, properties=props[0])
126
+ .match()
127
+ .node(labels=to_node_labels, ref_name=to_ref, properties=props[1])
128
+ .merge()
129
+ .node(ref_name=from_ref)
130
+ .related_to(label=relation, ref_name=relation_ref)
131
+ .node(ref_name=to_ref)
132
+ )
133
+
134
+ # Add in System properties
135
+ if self.add_system_properties:
136
+ create_time = relation_ref_dot + self.creation_time_property + '=datetime("' + time_now + '")'
137
+ update_time = relation_ref_dot + self.update_time_property + '=datetime("' + time_now + '")'
138
+ query_text = query_text.on_create().set_literal(create_time).set_literal(update_time)
139
+
140
+ if len(explicit_properties) > 0:
141
+ query_text = query_text.set(properties=props[2], property_ref=relation_ref_dot)
142
+ if len(calculated_properties) > 0:
143
+ query_text = query_text.set(properties=props[3], property_ref=relation_ref_dot)
144
+
145
+ query_text = query_text.toStr()
146
+ query = Neo4jQuery('relationship', query_text, time_now)
140
147
  if self.validate_only and not self.summarise:
141
- print(a_query)
148
+ print(query_text)
142
149
  queries.append(query)
143
150
 
144
151
  this_row += 1
@@ -176,14 +183,13 @@ class RelationshipFileProcessor:
176
183
  # Since the dictionary key can't be a list, we will create a list (of lists) and use the index in that list as the key
177
184
  # When we have worked through all the input and grouped the queries by label and relationship combinations, we will create the queries
178
185
 
179
- new_labels_list = []
180
186
  batch_keys = []
181
187
  query_dictionary = {}
182
188
  dict_size = 0
183
189
 
184
- num_rows = num_data_rows - self.start_from + 1
185
190
  this_row = self.start_from-1
186
191
  last_row = self.get_last_row(num_data_rows)
192
+ num_rows = last_row - self.start_from + 1
187
193
  while this_row < last_row:
188
194
 
189
195
  combined_relationships = {**self.required_relationships, **self.contents.get_column_values_dict(this_row, relation_columns)}
@@ -216,9 +222,10 @@ class RelationshipFileProcessor:
216
222
  param_explicit_props = self.query_manager.parameterise_dict(explicit_properties, self.section)
217
223
  param_calc_props = self.query_manager.parameterise_dict(calculated_properties, self.section)
218
224
 
225
+ new_labels_list = []
219
226
  query_data_list = []
220
227
  for count in range(max(len(param_from_nodes), len(param_to_nodes), len(param_explicit_props), len(param_calc_props))):
221
- new_labels_list = [[from_node_labels, to_node_labels, relation, from_node.key, to_node.key, param_calc_props[min(count, len(param_calc_props) - 1)]]]
228
+ new_labels_list += [[from_node_labels, to_node_labels, relation, from_node.key, to_node.key, param_calc_props[min(count, len(param_calc_props) - 1)]]]
222
229
  query_data_list += [[param_from_nodes[min(count, len(param_from_nodes) - 1)].value.replace('\\\\n', '\n'), param_to_nodes[min(count, len(param_to_nodes) - 1)].value.replace('\\\\n', '\n'), param_explicit_props[min(count, len(param_explicit_props) - 1)], param_calc_props[min(count, len(param_calc_props) - 1)], time_now]]
223
230
 
224
231
  # So now we know all about this particular update. Let's put it in the query dictionary
@@ -227,12 +234,12 @@ class RelationshipFileProcessor:
227
234
  q_count += 1
228
235
  try:
229
236
  dictionary_index = batch_keys.index(new_labels_list[count])
230
- query_dictionary[dictionary_index] += query_data_list
237
+ query_dictionary[dictionary_index] += [query_data_list[count]]
231
238
  except:
232
239
  dictionary_index = len(batch_keys)
233
- query_dictionary[dictionary_index] = query_data_list
240
+ query_dictionary[dictionary_index] = [query_data_list[count]]
234
241
  batch_keys.append(new_labels_list[count])
235
- dict_size += len(query_data_list)
242
+ dict_size += len([query_data_list[count]])
236
243
 
237
244
  this_row += 1
238
245
  messages.message_no_cr(f'Analysing file... {100 * (this_row - self.start_from + 1) / num_rows:.0f}%{chr(13)}')
@@ -262,19 +269,19 @@ class RelationshipFileProcessor:
262
269
  while this_size < batch_size:
263
270
  # Combine all the update data...
264
271
  update = updates[(batch_num - 1) * self.batch_rate + this_size]
265
- update_properties = update[2] or {} # In case update_properties[2] is {}
266
- func_properties = update[3] or {} # In case update_properties[3] is {}
272
+ update_properties = copy.copy(update[2]) or {} # In case update_properties[2] is {}
273
+ func_properties = copy.copy(update[3]) or {} # In case update_properties[3] is {}
267
274
  update_properties[from_ref] = Neo4jProperty(from_ref, update[0], 'str')
268
275
  update_properties[to_ref] = Neo4jProperty(to_ref, update[1], 'str')
269
276
  if self.add_system_properties:
270
277
  update_properties[self.update_time_property] = Neo4jProperty(self.update_time_property, update[4])
271
- payload.append(update_properties)
278
+ payload.append([update_properties])
272
279
  this_size += 1
273
280
  query_count += 1
274
281
 
275
282
  formatted_payload = []
276
283
  for a_payload in payload:
277
- formatted_pload = property.format(a_payload, '', self.query_manager, self.section)
284
+ formatted_pload = property.format(a_payload[0], '', self.query_manager, self.section)
278
285
  formatted_payload += formatted_pload
279
286
 
280
287
  # Build a MERGE query using queries
@@ -1,18 +1,22 @@
1
+ import ast
1
2
  import datetime
3
+
2
4
  import messages
3
- import ast
4
- import processors.propertymanager as pm
5
5
  import processors.labelmanager as lm
6
- from querymanager import QueryManager
6
+ import processors.propertymanager as pm
7
7
 
8
- class Neo4jProperty():
9
8
 
10
- def __init__(self, key, value=None, format=None, type=None, blank_override=False, labels=[]):
9
+ class Neo4jProperty:
10
+ def __init__(
11
+ self, key, value=None, format=None, type=None, blank_override=False, labels=[]
12
+ ):
11
13
 
12
14
  self.key = pm.validate_property(key)
13
15
  # Sanitise the value
14
- self.value = value.replace('\\', '\\\\').replace('\r', '\\r').replace('"', '\\"')
15
- if labels == ['']:
16
+ self.value = (
17
+ value.replace("\\", "\\\\").replace("\r", "\\r").replace('"', '\\"')
18
+ )
19
+ if labels == [""]:
16
20
  self.labels = []
17
21
  else:
18
22
  self.labels = lm.validate_labels(labels)
@@ -30,8 +34,8 @@ class Neo4jProperty():
30
34
  self.formatted_values = {}
31
35
 
32
36
  # Now check to see if the value might be a formula
33
- if '{' in self.value or '}' in self.value:
34
- self.formula, self.is_formula, self.parameter_number = parse_value(value, 'n.')
37
+ if "{" in self.value or "}" in self.value:
38
+ self.formula, self.is_formula, self.parameter_number = parse_value(value, "n.")
35
39
  else:
36
40
  self.formula = None
37
41
  self.is_formula = False
@@ -50,8 +54,8 @@ class Neo4jProperty():
50
54
  self.value = new_value
51
55
  # And say the value hasn't been formatted using the new format
52
56
  self.formatted_values = {}
53
- if '{' in self.value or '}' in self.value:
54
- self.formula, self.is_formula, self.parameter_number = parse_value(new_value, 'n.')
57
+ if "{" in self.value or "}" in self.value:
58
+ self.formula, self.is_formula, self.parameter_number = parse_value(new_value, "n.")
55
59
  else:
56
60
  self.formula = None
57
61
  self.is_formula = False
@@ -74,12 +78,12 @@ def detect_type(value: str) -> str:
74
78
  return "bool"
75
79
 
76
80
  # Integer
77
- if value.isdigit() or (value.startswith('-') and value[1:].isdigit()):
81
+ if value.isdigit() or (value.startswith("-") and value[1:].isdigit()):
78
82
  return "int"
79
83
 
80
84
  # Float
81
85
  try:
82
- if '.' in value or 'e' in value.lower():
86
+ if "." in value or "e" in value.lower():
83
87
  float(value)
84
88
  return "float"
85
89
  except ValueError:
@@ -117,28 +121,28 @@ def format_value(self, ref):
117
121
  given_data_format = self.format
118
122
 
119
123
  # Handle formulas
120
- if self.is_formula and ref != 'n.':
124
+ if self.is_formula and ref != "n.":
121
125
  self.formula, self.is_formula, self.parameter_number = parse_value(value, ref)
122
126
  formula = self.formula
123
127
 
124
- if self.is_formula and formula != '':
128
+ if self.is_formula and formula != "":
125
129
  match given_data_format:
126
- case 'str':
127
- result = f'toString({formula})'
128
- case 'int':
129
- result = f'toInteger({formula})'
130
- case 'float':
131
- result = f'toFloat({formula})'
132
- case 'date':
133
- result = f'date({formula})'
134
- case 'datetime':
135
- result = f'datetime({formula})'
136
- case 'bool':
137
- result = f'toBoolean({formula})'
138
- case '' | _:
130
+ case "str":
131
+ result = f"toString({formula})"
132
+ case "int":
133
+ result = f"toInteger({formula})"
134
+ case "float":
135
+ result = f"toFloat({formula})"
136
+ case "date":
137
+ result = f"date({formula})"
138
+ case "datetime":
139
+ result = f"datetime({formula})"
140
+ case "bool":
141
+ result = f"toBoolean({formula})"
142
+ case "" | _:
139
143
  result = formula
140
144
  elif self.is_formula:
141
- result = ''
145
+ result = ""
142
146
  else:
143
147
  # Determine type if format is missing
144
148
  if not given_data_format:
@@ -149,91 +153,97 @@ def format_value(self, ref):
149
153
 
150
154
  # Match and format
151
155
  match detected_format:
152
- case 'str':
156
+ case "str":
153
157
  result = quote + (formula or value) + quote
154
- case 'int':
158
+ case "int":
155
159
  # remove leading zeros
156
- clean_value = value.lstrip('0') or '0'
160
+ clean_value = value.lstrip("0") or "0"
157
161
  try:
158
162
  result = int(clean_value)
159
163
  if result != int(value):
160
164
  messages.warning_message(
161
- 'Invalid data: ', f'{value} is not a valid Integer, {result} used instead'
165
+ "Invalid data: ",
166
+ f"{value} is not a valid Integer, {result} used instead",
162
167
  )
163
168
  except ValueError:
164
169
  messages.error_message(
165
- 'Invalid data: ', f'{value} is not a valid Integer'
170
+ "Invalid data: ", f"{value} is not a valid Integer"
166
171
  )
167
172
  result = '""'
168
- case 'float':
173
+ case "float":
169
174
  try:
170
175
  result = float(value)
171
176
  except ValueError:
172
177
  messages.error_message(
173
- 'Invalid data: ', f'{value} is not a valid Float'
178
+ "Invalid data: ", f"{value} is not a valid Float"
179
+ )
180
+ result = '""'
181
+ case "bool":
182
+ val = value.capitalize()
183
+ if val in ["True", "False"]:
184
+ result = val
185
+ self.value = val
186
+ else:
187
+ messages.error_message(
188
+ "Invalid data: ", f"{value} is not a valid Boolean"
174
189
  )
175
190
  result = '""'
176
- case 'bool':
191
+ case "boolean":
177
192
  val = value.capitalize()
178
- if val in ['True', 'False']:
193
+ if val in ["True", "False"]:
179
194
  result = val
180
195
  self.value = val
181
196
  else:
182
197
  messages.error_message(
183
- 'Invalid data: ', f'{value} is not a valid Boolean'
198
+ "Invalid data: ", f"{value} is not a valid Boolean"
184
199
  )
185
200
  result = '""'
186
- case 'date':
201
+ case "date":
187
202
  formatted_date = try_dates(value)
188
203
  if formatted_date:
189
204
  result = f'date("{formatted_date}")'
190
205
  else:
191
- messages.error_message(
192
- f'Invalid data: {value} is not a valid date'
193
- )
206
+ messages.error_message(f"Invalid data: {value} is not a valid date")
194
207
  result = '""'
195
- case 'datetime':
208
+ case "datetime":
196
209
  formatted_dt = try_datetimes(value)
197
210
  if formatted_dt:
198
211
  result = f'datetime("{formatted_dt}")'
199
212
  else:
200
213
  messages.error_message(
201
- f'Invalid data: {value} is not a valid datetime'
214
+ f"Invalid data: {value} is not a valid datetime"
202
215
  )
203
216
  result = '""'
204
- case 'time':
217
+ case "time":
205
218
  formatted_time = try_times(value)
206
219
  if formatted_time:
207
220
  result = f'time("{formatted_time}")'
208
221
  else:
209
- messages.error_message(
210
- f'Invalid data: {value} is not a valid time'
211
- )
222
+ messages.error_message(f"Invalid data: {value} is not a valid time")
212
223
  result = '""'
213
- case 'list' | 'tuple' | 'dict':
224
+ case "list" | "tuple" | "dict":
214
225
  result = value
215
226
  case _:
216
227
  # fallback string
217
228
  result = quote + value + quote
218
- self.format = 'str'
229
+ self.format = "str"
219
230
 
220
231
  return result
221
232
 
222
233
 
223
-
224
234
  def parse_value(formula, ref):
225
235
  num_open = 0
226
236
  num_close = 0
227
- parsed = ''
237
+ parsed = ""
228
238
  index = 0
229
239
  open = False
230
240
  param_num = -1
231
- property_name = ''
241
+ property_name = ""
232
242
  while index < len(formula):
233
243
  this_char = formula[index]
234
- next_char = (formula+' ')[index+1] # Added a space to formula, so we don't run off the end
235
- if this_char == '{':
236
- if next_char == '{':
244
+ next_char = (formula + " ")[index + 1] # Added a space to formula, so we don't run off the end
245
+ if this_char == "{":
246
+ if next_char == "{":
237
247
  if open:
238
248
  property_name += this_char
239
249
  else:
@@ -241,26 +251,26 @@ def parse_value(formula, ref):
241
251
  index += 1
242
252
  else:
243
253
  open = True
244
- property_name = ''
254
+ property_name = ""
245
255
  num_open += 1
246
- elif this_char == '$' and next_char == '{':
247
- end_parm = formula[index+1:].find('}')
256
+ elif this_char == "$" and next_char == "{":
257
+ end_parm = formula[index + 1:].find("}")
248
258
  if end_parm >= 0:
249
- parsed += formula[index:index+end_parm+2]
250
- param_num = formula[index+2:index+end_parm+1]
251
- index += end_parm+1
259
+ parsed += formula[index: index + end_parm + 2]
260
+ param_num = formula[index + 2: index + end_parm + 1]
261
+ index += end_parm + 1
252
262
  else:
253
263
  parsed += this_char
254
264
  index += 1
255
- elif this_char == '}':
256
- if next_char == '}':
265
+ elif this_char == "}":
266
+ if next_char == "}":
257
267
  if open:
258
268
  property_name += this_char
259
269
  else:
260
270
  parsed += this_char
261
271
  index += 1
262
272
  else:
263
- if open and property_name != '':
273
+ if open and property_name != "":
264
274
  # Replace {property} with n.property (assuming ref = "n.")
265
275
  parsed += ref + pm.validate_property(property_name)
266
276
  else:
@@ -282,24 +292,24 @@ def parse_value(formula, ref):
282
292
 
283
293
  def try_date_format(date, date_format):
284
294
  try:
285
- tested_date = datetime.datetime.strptime(date.replace('/', '-'), date_format).date()
295
+ tested_date = datetime.datetime.strptime(date.replace("/", "-"), date_format).date()
286
296
  except:
287
297
  tested_date = None
288
298
  return tested_date
289
299
 
290
300
 
291
301
  def try_dates(date):
292
- date1 = try_date_format(date[:10], '%Y-%m-%d')
293
- date2 = try_date_format(date[:10], '%d-%m-%Y')
302
+ date1 = try_date_format(date[:10], "%Y-%m-%d")
303
+ date2 = try_date_format(date[:10], "%d-%m-%Y")
294
304
  date_found = date1 or date2
295
305
  return date_found
296
306
 
297
307
 
298
308
  def try_datetimes(datetime):
299
309
  date = try_dates(datetime)
300
- time = try_times(datetime) or '00:00:00'
310
+ time = try_times(datetime) or "00:00:00"
301
311
  if date:
302
- datetime_found = str(date) + 'T' + str(time)
312
+ datetime_found = str(date) + "T" + str(time)
303
313
  else:
304
314
  datetime_found = None
305
315
  return datetime_found
@@ -314,7 +324,7 @@ def try_time_format(time, time_format):
314
324
 
315
325
 
316
326
  def try_times(time):
317
- time1 = try_time_format(time[11:19], '%H:%M:%S')
327
+ time1 = try_time_format(time[11:19], "%H:%M:%S")
318
328
  if time1:
319
329
  time_found = time[11:]
320
330
  else:
@@ -322,28 +332,31 @@ def try_times(time):
322
332
  return time_found
323
333
 
324
334
 
325
- def format_property_list(properties, comparison_operator = ':', boolean_operator = ',', property_ref='', key_ref=''):
335
+ def format_property_list(
336
+ properties,
337
+ comparison_operator=":",
338
+ boolean_operator=",",
339
+ property_ref="",
340
+ key_ref="",
341
+ ):
326
342
  if not isinstance(properties, dict):
327
343
  prop_list = {properties.key: properties}
328
344
  else:
329
345
  prop_list = properties
330
- pairs = [f'{key_ref}{prop_list[property].key}{comparison_operator}{prop_list[property].get_value(property_ref)}' for property in prop_list.keys()]
346
+ pairs = [f"{key_ref}{prop_list[property].key}{comparison_operator}{prop_list[property].get_value(property_ref)}" for property in prop_list.keys()]
331
347
  res = boolean_operator.join(pairs)
332
348
  return res
333
349
 
334
350
 
335
- def format(properties, property_ref='', query_manager = None, section='DEFAULT'):
351
+ def format(properties, property_ref="", query_manager=None, section="DEFAULT"):
336
352
  # Reformat using identified data types
337
353
  pairs = []
338
354
  for p in properties.keys():
339
- pairs.append(f'{properties[p].key}:{properties[p].get_value(property_ref)}')
340
- pair_data = '{' + ','.join(pairs) + '}'
341
- return QueryManager.parameterise(query_manager, pair_data, section)
342
-
355
+ pairs.append(f"{properties[p].key}:{properties[p].get_value(property_ref)}")
356
+ pair_data = "{" + ",".join(pairs) + "}"
357
+ return [pair_data]
343
358
 
344
-
345
- def to_str(properties, comparison_operator: str = ':', boolean_operator: str = ',', property_ref='', key_ref='') -> str:
346
- pairs = [f'{key_ref}{key.split(":")[0]}{comparison_operator}{Neo4jProperty(key, str(value)).get_value(property_ref)}' for key, value in properties.items()]
359
+ def to_str(properties, comparison_operator: str = ":", boolean_operator: str = ",", property_ref="", key_ref="", ) -> str:
360
+ pairs = [f"{key_ref}{key.split(':')[0]}{comparison_operator}{Neo4jProperty(key, str(value)).get_value(property_ref)}" for key, value in properties.items()]
347
361
  res = boolean_operator.join(pairs)
348
362
  return res
349
-
@@ -76,7 +76,7 @@ class QueryManager():
76
76
  if params_found:
77
77
  params_to_use = params[param_num]
78
78
  num_params = len(params_to_use)
79
- param_id = '{$' + param_num + '}'
79
+ param_id = '${' + param_num + '}'
80
80
 
81
81
  new_data = []
82
82
  for count in range(num_params):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-eigen-ingenuity
3
- Version: 0.5.31b1
3
+ Version: 0.5.32
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
@@ -5,7 +5,7 @@ eigeningenuity/commonmenu.py,sha256=iewhtyN83fVNVXMrhhu4sd2FSLtqPrg8bSlidhvl-rc,
5
5
  eigeningenuity/elastic.py,sha256=HwHyRHLw71v6wDl1VDercCRn6m0Lrh-4RzHSQxqTTJw,7960
6
6
  eigeningenuity/events.py,sha256=zo4dO23PeNBw5bt9O_F56qHIEQw5YgRrFi3yA5hYA44,13929
7
7
  eigeningenuity/historian.py,sha256=urJzCUF3OwOlXY-FZvl0tVzi3KICfptYigmf3gIklOU,43518
8
- eigeningenuity/historianmulti.py,sha256=Q65J1XGiCfEkzTXvwnp7l9YwGNFs8sqBkdlQOcF6N4M,35934
8
+ eigeningenuity/historianmulti.py,sha256=aNpwmWwuhVebTE2Iu4l__q4X8nWnePqsH0jgqzMR0C4,36236
9
9
  eigeningenuity/logformatter.py,sha256=Xy-fLbYp58XXerRKsswzquyke9ujbNYNEHivRLlet9w,6291
10
10
  eigeningenuity/settings.py,sha256=rnx4tzDN3yMQUfga-jdDoJCYhcCxa2lWSGfEAPiWdD0,3406
11
11
  eigeningenuity/sql.py,sha256=I3NwAeOT61Cnsr5e6QxDYCrwsVJ-0h3j0VxUA6uiyGc,6165
@@ -40,14 +40,14 @@ modelbuilder/src/__init__.py,sha256=bMvb-E_plw2dz9_TYIPevQuvDNmKtW0dmBgnQE9ylwc,
40
40
  modelbuilder/src/assetmodelbuilder.py,sha256=92Yu9CvmObPYDdqCpn8eBCaZ_KGBhm307YsFt6cg2Eg,8886
41
41
  modelbuilder/src/assetmodelcsvwriter.py,sha256=GKNi_fw7AlY-UG2XhwFIS34Ff3XiVRss-o5MUzyJSV0,1071
42
42
  modelbuilder/src/assetmodelutilities.py,sha256=1j-S2CKaxcde-Pj6AfgYMGOKu13kwA-sIJSIyLqMW94,6700
43
- modelbuilder/src/configmanager.py,sha256=Orwg_75Zk8Go_RdmFnEoKKRLJp6_2XZAtPRQZuD5Zmc,31937
43
+ modelbuilder/src/configmanager.py,sha256=RlfiKAlRtQnl50SrKQqBmybdRw8N3FzFZ0abxiE-fsQ,32046
44
44
  modelbuilder/src/csvcontentsmanager.py,sha256=601JuaT5rxlTlj58uK50c6vSUk4NKh4pGOrVq9ECX8o,8247
45
45
  modelbuilder/src/csvwriter.py,sha256=2Xc6kdV6cYwCjrVF6WaZfS6tVp8-oc0ksIHSOx6iqj8,14132
46
46
  modelbuilder/src/fileanalyser.py,sha256=hNwEZLlIRRLroJCxiWXwJTQHIsHbZDWbBK4BCFIMcLw,7633
47
- modelbuilder/src/filemanager.py,sha256=nfRQlW-AIp8ICu1CO0MO55OyWMWDQJrW4Z8yRRhBs-k,26454
47
+ modelbuilder/src/filemanager.py,sha256=UulYx4FDGsIVRG8oQqKCMIWBi9qlr5UVe0iIJpOL4A4,27055
48
48
  modelbuilder/src/messages.py,sha256=6JnW-ke6nHGUA4hTEBvo_kVlNJTXoV4LWw8mNwMpBCQ,1325
49
- modelbuilder/src/property.py,sha256=lwYUuN17q1g9MHE2K2yM03ArfEPWmzRP9yxfS1tYbo8,11605
50
- modelbuilder/src/querymanager.py,sha256=Wr0LcY7iCwmLyeSx8LcdbQT2xt1viltp6XFvP3Bg5v8,3270
49
+ modelbuilder/src/property.py,sha256=T0XgKEd7s7D6oa1aTxRWPatIsG1wzUbXdWou9sf5A1I,11910
50
+ modelbuilder/src/querymanager.py,sha256=rwiW56wHwhMRKn-jTAjgj5IrM277FzpQZg2Y8S6c5ak,3270
51
51
  modelbuilder/src/versionmanager.py,sha256=B8mrYY5Der0sWi1GQjduyVGZ6BuAb6rTNVAZzQlP4k4,19148
52
52
  modelbuilder/src/connectors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
53
53
  modelbuilder/src/connectors/boltconnector.py,sha256=9mFpYUqYzf--o_8gLw00BjPOmOqo1X1KsdxjFkzYRaQ,4885
@@ -56,10 +56,10 @@ modelbuilder/src/connectors/genericconnector.py,sha256=bMfnbrOWq97BC9oM7RIA58bNd
56
56
  modelbuilder/src/connectors/httpsconnector.py,sha256=DOZyxRW3JQcaiaYtnx0_Jq2dBEhgSUIubnx5jj7OY_g,6078
57
57
  modelbuilder/src/processors/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
58
58
  modelbuilder/src/processors/cypherfileprocessor.py,sha256=EmaLsBhC6gWQwvhyY7Ks2HEbGEzDoGAZfu2nBkh2hOs,2941
59
- modelbuilder/src/processors/labelmanager.py,sha256=W57GcDeCANwgWlp7uBWq0PusKDMixFEv79eBhV7LKfU,6833
60
- modelbuilder/src/processors/nodefileprocessor.py,sha256=DLzJzsl4APjX8CsKyZY7GRNtr0rJcteFi0TsdM4hAXI,14747
59
+ modelbuilder/src/processors/labelmanager.py,sha256=bDWZB7DDARtffgFsh1cgo8w738cA8ZW8b9GKCazB2dk,6844
60
+ modelbuilder/src/processors/nodefileprocessor.py,sha256=SX_By2jL-pM9vkWkMKPEd9onx_1DwGiS3ItZhO7guho,15377
61
61
  modelbuilder/src/processors/propertymanager.py,sha256=zLr8S0HPZMXeUp1RUzVXWyNa64MxLufXrOqh5uL1mwU,6978
62
- modelbuilder/src/processors/relationshipfileprocessor.py,sha256=e0YewiXMZRRFs-wl-vl7VDPI06xEoltHXHHk1SOSRuk,19515
62
+ modelbuilder/src/processors/relationshipfileprocessor.py,sha256=4m9Ve_rd0MCy4nSqtPRj60xM3noraJ7u907Ky2sf7n8,20465
63
63
  modelbuilder/src/processors/relationshipmanager.py,sha256=lDtE_5AdKzL3boq7VD8Gmpai8Uscq79vRxkzYQL8A9A,1105
64
64
  modelbuilder/src/queries/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
65
65
  modelbuilder/src/queries/cypherbuilder.py,sha256=VpUGuPo-Ba3skjCVBFjmxm4ORQBGgF5cDiQYnK67hLA,10418
@@ -88,8 +88,8 @@ regressiontests/eigeningenuity/historian-multi/test_getRawDatapoints.py,sha256=f
88
88
  regressiontests/eigeningenuity/historian-multi/test_listDataTags.py,sha256=TcceNSjCKoiK5SJcgTH2JXfKLYxIHdQdwZWlkpGnEVM,2006
89
89
  regressiontests/eigeningenuity/historian-multi/test_tagManagement.py,sha256=ylInBt453d1RaSih1eTTxGPZmb60UK4vMwI3UW-U1JY,4830
90
90
  regressiontests/eigeningenuity/historian-multi/test_writePoints.py,sha256=51tfUSLUqLKcCKJ1EyhjfzoC_4OP6n1oL3zgTSkXu4s,2696
91
- python_eigen_ingenuity-0.5.31b1.dist-info/METADATA,sha256=67CE6-9zAqULjyQ2jz6fqh05raJsLiKy-5X6C-95Gjg,8124
92
- python_eigen_ingenuity-0.5.31b1.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
93
- python_eigen_ingenuity-0.5.31b1.dist-info/entry_points.txt,sha256=G3LjFQX5xKaN4mqtqCL8uaC-gRbP5T5x9r0gBTJTXXA,70
94
- python_eigen_ingenuity-0.5.31b1.dist-info/top_level.txt,sha256=oDWOSmlNPKNBlIEKP8_JaV01O60jTcUIt2tDkq3OD18,56
95
- python_eigen_ingenuity-0.5.31b1.dist-info/RECORD,,
91
+ python_eigen_ingenuity-0.5.32.dist-info/METADATA,sha256=Wlovsv7L-nZaKJc8gGw9B3Ko2n5ZB1R5RSijnMGmazQ,8122
92
+ python_eigen_ingenuity-0.5.32.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
93
+ python_eigen_ingenuity-0.5.32.dist-info/entry_points.txt,sha256=G3LjFQX5xKaN4mqtqCL8uaC-gRbP5T5x9r0gBTJTXXA,70
94
+ python_eigen_ingenuity-0.5.32.dist-info/top_level.txt,sha256=oDWOSmlNPKNBlIEKP8_JaV01O60jTcUIt2tDkq3OD18,56
95
+ python_eigen_ingenuity-0.5.32.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (82.0.1)
2
+ Generator: setuptools (84.0.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5