otlmow-template 1.4__py3-none-any.whl → 1.6__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.
@@ -9,6 +9,7 @@ from collections import defaultdict
9
9
  from concurrent.futures import ThreadPoolExecutor, as_completed, ALL_COMPLETED
10
10
  from pathlib import Path
11
11
 
12
+ from openpyxl.cell import Cell
12
13
  from openpyxl.reader.excel import load_workbook
13
14
  from openpyxl.styles import PatternFill, Alignment
14
15
  from openpyxl.utils import get_column_letter
@@ -31,11 +32,6 @@ from otlmow_modelbuilder.SQLDataClasses.OSLOClass import OSLOClass
31
32
 
32
33
  ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
33
34
 
34
- enumeration_validation_rules = {
35
- "valid_uri_and_types": {},
36
- "valid_regexes": [
37
- "^https://wegenenverkeer.data.vlaanderen.be/ns/.+"]
38
- }
39
35
 
40
36
  short_to_long_ns = {
41
37
  'ond': 'https://wegenenverkeer.data.vlaanderen.be/ns/onderdeel#',
@@ -47,12 +43,13 @@ short_to_long_ns = {
47
43
  'proefenmeting': 'https://wegenenverkeer.data.vlaanderen.be/ns/proefenmeting#',
48
44
  'pro': 'https://wegenenverkeer.data.vlaanderen.be/ns/proefenmeting#',
49
45
  'lev': 'https://wegenenverkeer.data.vlaanderen.be/ns/levenscyclus#',
50
- 'levenscyclus': 'https://wegenenverkeer.data.vlaanderen.be/ns/levenscyclus#',
51
-
46
+ 'levenscyclus': 'https://wegenenverkeer.data.vlaanderen.be/ns/levenscyclus#'
52
47
  }
53
48
 
54
49
 
55
50
  class SubsetTemplateCreator:
51
+ green_fill = PatternFill(start_color="90EE90", fill_type="solid")
52
+
56
53
  @classmethod
57
54
  def _load_collector_from_subset_path(cls, subset_path: Path) -> OSLOCollector:
58
55
  collector = OSLOCollector(subset_path)
@@ -186,18 +183,6 @@ class SubsetTemplateCreator:
186
183
  otl_objects.append(otl_object)
187
184
  return otl_objects
188
185
 
189
- @classmethod
190
- def get_number_of_cpus(cls) -> int:
191
- import multiprocessing
192
- cpu_count = multiprocessing.cpu_count()
193
- if cpu_count is None or cpu_count == 0:
194
- import os
195
- cpu_count = os.cpu_count()
196
- if cpu_count is None or cpu_count == 0:
197
- cpu_count = 8
198
- return cpu_count
199
-
200
-
201
186
  @classmethod
202
187
  def generate_objects_for_template(
203
188
  cls, subset_path: Path, class_uris_filter: [str], filter_attributes_by_subset: bool,
@@ -208,13 +193,15 @@ class SubsetTemplateCreator:
208
193
  """
209
194
  collector = cls._load_collector_from_subset_path(subset_path=subset_path)
210
195
  filtered_class_list = cls.filters_classes_by_subset(collector=collector, class_uris_filter=class_uris_filter)
196
+ if filtered_class_list == []:
197
+ raise ValueError('Something went wrong, as the class_uri filter list is empty')
211
198
  cls.relation_dict = get_hardcoded_relation_dict(model_directory=model_directory)
212
199
 
213
200
  amount_objects_to_create = max(1, dummy_data_rows)
214
201
  otl_objects = []
215
202
 
216
203
  while True:
217
- with ThreadPoolExecutor(max_workers=cls.get_number_of_cpus()) as executor:
204
+ with ThreadPoolExecutor() as executor:
218
205
  futures = [
219
206
  executor.submit(cls.create_x_objects, oslo_class, add_geometry, collector,
220
207
  filter_attributes_by_subset, model_directory, amount_objects_to_create)
@@ -274,6 +261,8 @@ class SubsetTemplateCreator:
274
261
  collector = cls._load_collector_from_subset_path(subset_path=subset_path)
275
262
  await sleep(0)
276
263
  filtered_class_list = cls.filters_classes_by_subset(collector=collector, class_uris_filter=class_uris_filter)
264
+ if filtered_class_list == []:
265
+ raise ValueError('Something went wrong, as the class_uri filter list is empty')
277
266
  await sleep(0)
278
267
  cls.relation_dict = get_hardcoded_relation_dict(model_directory=model_directory)
279
268
 
@@ -499,7 +488,7 @@ class SubsetTemplateCreator:
499
488
  collected_attribute_info = []
500
489
  deprecated_attributes_row = []
501
490
  header_row = next(sheet.iter_rows(min_row=1, max_row=1))
502
- for index, header_cell in enumerate(header_row):
491
+ for header_cell in header_row:
503
492
  header = header_cell.value
504
493
  if header is None or header == '':
505
494
  continue
@@ -527,16 +516,19 @@ class SubsetTemplateCreator:
527
516
 
528
517
  if generate_choice_list:
529
518
  if issubclass(attribute.field, BooleanField):
530
- boolean_validation.add(f'{header_cell.column_letter}{2}:{header_cell.column_letter}1000')
531
- continue
519
+ boolean_validation.add(f'{header_cell.column_letter}2:{header_cell.column_letter}1000')
520
+ cls.color_choice_lists_green(sheet=sheet, header_cell_column=header_cell)
532
521
 
533
- if issubclass(attribute.field, KeuzelijstField):
522
+ elif issubclass(attribute.field, KeuzelijstField):
534
523
  cls.generate_choice_list_in_excel(
535
524
  attribute=attribute, choice_list_dict=choice_list_dict, column=header_cell.column,
536
525
  row_nr=1, sheet=sheet, workbook=workbook)
526
+ cls.color_choice_lists_green(sheet=sheet, header_cell_column=header_cell)
537
527
 
538
528
  if dummy_data_rows == 0:
539
- sheet.delete_rows(idx=2)
529
+ instance_count = len([x for x in instances if x.typeURI == type_uri])
530
+ if instance_count > 0:
531
+ sheet.delete_rows(idx=2, amount=instance_count)
540
532
 
541
533
  if add_deprecated and any(deprecated_attributes_row):
542
534
  cls.add_deprecated_row_to_sheet(deprecated_attributes_row, sheet)
@@ -546,6 +538,12 @@ class SubsetTemplateCreator:
546
538
 
547
539
  cls.set_fixed_column_width(sheet=sheet, width=25)
548
540
 
541
+ @classmethod
542
+ def color_choice_lists_green(cls, sheet: Worksheet, header_cell_column: Cell):
543
+ for cell in sheet.iter_rows(min_col=header_cell_column.column, max_col=header_cell_column.column,
544
+ min_row=2, max_row=1000):
545
+ cell[0].fill = cls.green_fill
546
+
549
547
  @classmethod
550
548
  def add_deprecated_row_to_sheet(cls, deprecated_attributes_row, sheet):
551
549
  sheet.insert_rows(idx=1)
@@ -582,13 +580,6 @@ class SubsetTemplateCreator:
582
580
  data_val.add(f'{get_column_letter(column)}{row_nr + 1}:'
583
581
  f'{get_column_letter(column)}1000')
584
582
 
585
-
586
- @classmethod
587
- def determine_multiplicity_csv(cls, template_file_path: Path, subset_path: Path,
588
- instances: list, temporary_path: Path, **kwargs):
589
- pass
590
-
591
-
592
583
  @classmethod
593
584
  def filters_classes_by_subset(cls, collector: OSLOCollector,
594
585
  class_uris_filter: [str] = None) -> list[OSLOClass]:
@@ -596,86 +587,6 @@ class SubsetTemplateCreator:
596
587
  return collector.classes
597
588
  return [x for x in collector.classes if x.objectUri in class_uris_filter]
598
589
 
599
- @classmethod
600
- def add_type_uri_choice_list_in_excel(cls, sheet, instances, add_attribute_info: bool):
601
- starting_row = '3' if add_attribute_info else '2'
602
- if sheet.title == 'Keuzelijsten':
603
- return
604
- type_uri_found = False
605
- for row in sheet.iter_rows(min_row=1, max_row=1):
606
- for cell in row:
607
- if cell.value == 'typeURI':
608
- type_uri_found = True
609
- break
610
- if type_uri_found:
611
- break
612
- if not type_uri_found:
613
- return
614
-
615
- sheet_name = sheet.title
616
- type_uri = ''
617
- if sheet_name.startswith('http'):
618
- type_uri = sheet_name
619
- else:
620
- split_name = sheet_name.split("#")
621
- subclass_name = split_name[1]
622
-
623
- possible_classes = [x for x in instances if x.typeURI.endswith(subclass_name)]
624
- if len(possible_classes) == 1:
625
- type_uri = possible_classes[0].typeURI
626
-
627
- if type_uri == '':
628
- return
629
-
630
- data_validation = DataValidation(type="list", formula1=f'"{type_uri}"', allow_blank=True)
631
- for rows in sheet.iter_rows(min_row=1, max_row=1, min_col=1, max_col=1):
632
- for cell in rows:
633
- column = cell.column
634
- sheet.add_data_validation(data_validation)
635
- data_validation.add(f'{get_column_letter(column)}{starting_row}:{get_column_letter(column)}1000')
636
-
637
- @classmethod
638
- async def add_type_uri_choice_list_in_excel_async(cls, sheet, instances, add_attribute_info: bool):
639
- starting_row = '3' if add_attribute_info else '2'
640
- await sleep(0)
641
- if sheet.title == 'Keuzelijsten':
642
- return
643
- type_uri_found = False
644
- for row in sheet.iter_rows(min_row=1, max_row=1):
645
- for cell in row:
646
- if cell.value == 'typeURI':
647
- type_uri_found = True
648
- break
649
- if type_uri_found:
650
- break
651
- if not type_uri_found:
652
- return
653
-
654
- await sleep(0)
655
- sheet_name = sheet.title
656
- type_uri = ''
657
- if sheet_name.startswith('http'):
658
- type_uri = sheet_name
659
- else:
660
- split_name = sheet_name.split("#")
661
- subclass_name = split_name[1]
662
-
663
- possible_classes = [x for x in instances if x.typeURI.endswith(subclass_name)]
664
- if len(possible_classes) == 1:
665
- type_uri = possible_classes[0].typeURI
666
-
667
- if type_uri == '':
668
- return
669
-
670
- data_validation = DataValidation(type="list", formula1=f'"{type_uri}"', allow_blank=True)
671
- await sleep(0)
672
- for rows in sheet.iter_rows(min_row=1, max_row=1, min_col=1, max_col=1):
673
- for cell in rows:
674
- await sleep(0)
675
- column = cell.column
676
- sheet.add_data_validation(data_validation)
677
- data_validation.add(f'{get_column_letter(column)}{starting_row}:{get_column_letter(column)}1000')
678
-
679
590
  @classmethod
680
591
  def set_fixed_column_width(cls, sheet, width: int):
681
592
  dim_holder = DimensionHolder(worksheet=sheet)
@@ -719,6 +630,8 @@ class SubsetTemplateCreator:
719
630
  if class_uri != relation.bron_uri:
720
631
  continue
721
632
  for i, bron_instance in enumerate(class_dict[relation.bron_uri]):
633
+ if relation.doel_uri not in class_dict:
634
+ continue
722
635
  doel_instance = class_dict[relation.doel_uri][i]
723
636
  if relation.objectUri == 'https://wegenenverkeer.data.vlaanderen.be/ns/onderdeel#HeeftBetrokkene':
724
637
  relation_instance = create_betrokkenerelation(rol='toezichter', source=bron_instance,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: otlmow_template
3
- Version: 1.4
3
+ Version: 1.6
4
4
  Author-email: David Vlaminck <david.vlaminck@mow.vlaanderen.be>, Jasper Berton <jasperberton1@telenet.be>
5
5
  License: GNU GENERAL PUBLIC LICENSE
6
6
  Version 3, 29 June 2007
@@ -0,0 +1,7 @@
1
+ otlmow_template/SubsetTemplateCreator.py,sha256=yvRxRRmOnWrMdyALG9q3HaADoQwiUh-sTki7Ui_oudM,33140
2
+ otlmow_template/Exceptions/MissingTypeUriException.py,sha256=DSKwywmP9Bq8n7rzBoDcEPlxvC1IChx18QIHFUCTtdA,51
3
+ otlmow_template-1.6.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
4
+ otlmow_template-1.6.dist-info/METADATA,sha256=yL3w0hRhDAYHBDBy56HFy-BMuCXBj3w5vP-tbERc478,44220
5
+ otlmow_template-1.6.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
6
+ otlmow_template-1.6.dist-info/top_level.txt,sha256=zPgBoaTLG-avoOLySlwOUEtHaFyA5Vc5wJqkSeX1l6A,16
7
+ otlmow_template-1.6.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (78.1.0)
2
+ Generator: setuptools (80.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,7 +0,0 @@
1
- otlmow_template/SubsetTemplateCreator.py,sha256=iZD2kjhOnymQ9tgqU6zq2ZCD8KVIT232mbrxTSR4fQ8,35845
2
- otlmow_template/Exceptions/MissingTypeUriException.py,sha256=DSKwywmP9Bq8n7rzBoDcEPlxvC1IChx18QIHFUCTtdA,51
3
- otlmow_template-1.4.dist-info/licenses/LICENSE,sha256=ixuiBLtpoK3iv89l7ylKkg9rs2GzF9ukPH7ynZYzK5s,35148
4
- otlmow_template-1.4.dist-info/METADATA,sha256=MqaUUEubb-DhKErKteUljO6Z3lxjGlaJoDL4a0cam-k,44220
5
- otlmow_template-1.4.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
6
- otlmow_template-1.4.dist-info/top_level.txt,sha256=zPgBoaTLG-avoOLySlwOUEtHaFyA5Vc5wJqkSeX1l6A,16
7
- otlmow_template-1.4.dist-info/RECORD,,