zepben.ewb 1.0.0b3__py3-none-any.whl → 1.0.0b5__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.
Files changed (154) hide show
  1. zepben/ewb/__init__.py +1 -1
  2. zepben/ewb/database/sql/__init__.py +4 -0
  3. zepben/ewb/database/{sqlite/tables → sql}/column.py +1 -1
  4. zepben/ewb/database/sql/sql_table.py +142 -0
  5. zepben/ewb/database/sqlite/tables/associations/table_asset_organisation_roles_assets.py +1 -1
  6. zepben/ewb/database/sqlite/tables/associations/table_assets_power_system_resources.py +1 -1
  7. zepben/ewb/database/sqlite/tables/associations/table_battery_units_battery_controls.py +1 -1
  8. zepben/ewb/database/sqlite/tables/associations/table_circuits_substations.py +1 -1
  9. zepben/ewb/database/sqlite/tables/associations/table_circuits_terminals.py +1 -1
  10. zepben/ewb/database/sqlite/tables/associations/table_customer_agreements_pricing_structures.py +1 -1
  11. zepben/ewb/database/sqlite/tables/associations/table_end_devices_end_device_functions.py +1 -1
  12. zepben/ewb/database/sqlite/tables/associations/table_equipment_equipment_containers.py +1 -1
  13. zepben/ewb/database/sqlite/tables/associations/table_equipment_operational_restrictions.py +1 -1
  14. zepben/ewb/database/sqlite/tables/associations/table_equipment_usage_points.py +1 -1
  15. zepben/ewb/database/sqlite/tables/associations/table_loops_substations.py +1 -1
  16. zepben/ewb/database/sqlite/tables/associations/table_pricing_structures_tariffs.py +1 -1
  17. zepben/ewb/database/sqlite/tables/associations/table_protection_relay_functions_protected_switches.py +1 -1
  18. zepben/ewb/database/sqlite/tables/associations/table_protection_relay_functions_sensors.py +1 -1
  19. zepben/ewb/database/sqlite/tables/associations/table_protection_relay_schemes_protection_relay_functions.py +1 -1
  20. zepben/ewb/database/sqlite/tables/associations/table_usage_points_end_devices.py +1 -1
  21. zepben/ewb/database/sqlite/tables/extensions/iec61968/assetinfo/table_reclose_delays.py +1 -1
  22. zepben/ewb/database/sqlite/tables/extensions/iec61968/assetinfo/table_relay_info.py +1 -1
  23. zepben/ewb/database/sqlite/tables/extensions/iec61968/metering/table_pan_demand_response_functions.py +1 -1
  24. zepben/ewb/database/sqlite/tables/extensions/iec61970/base/feeder/table_lv_feeders.py +1 -1
  25. zepben/ewb/database/sqlite/tables/extensions/iec61970/base/protection/table_distance_relays.py +1 -1
  26. zepben/ewb/database/sqlite/tables/extensions/iec61970/base/protection/table_protection_relay_function_thresholds.py +1 -1
  27. zepben/ewb/database/sqlite/tables/extensions/iec61970/base/protection/table_protection_relay_function_time_limits.py +1 -1
  28. zepben/ewb/database/sqlite/tables/extensions/iec61970/base/protection/table_protection_relay_functions.py +1 -1
  29. zepben/ewb/database/sqlite/tables/extensions/iec61970/base/protection/table_protection_relay_schemes.py +1 -1
  30. zepben/ewb/database/sqlite/tables/extensions/iec61970/base/protection/table_protection_relay_systems.py +1 -1
  31. zepben/ewb/database/sqlite/tables/extensions/iec61970/base/wires/table_battery_controls.py +1 -1
  32. zepben/ewb/database/sqlite/tables/extensions/iec61970/base/wires/table_power_transformer_end_ratings.py +1 -1
  33. zepben/ewb/database/sqlite/tables/iec61968/assetinfo/table_no_load_tests.py +1 -1
  34. zepben/ewb/database/sqlite/tables/iec61968/assetinfo/table_open_circuit_tests.py +1 -1
  35. zepben/ewb/database/sqlite/tables/iec61968/assetinfo/table_short_circuit_tests.py +1 -1
  36. zepben/ewb/database/sqlite/tables/iec61968/assetinfo/table_shunt_compensator_info.py +1 -1
  37. zepben/ewb/database/sqlite/tables/iec61968/assetinfo/table_switch_info.py +1 -1
  38. zepben/ewb/database/sqlite/tables/iec61968/assetinfo/table_transformer_end_info.py +1 -1
  39. zepben/ewb/database/sqlite/tables/iec61968/assetinfo/table_transformer_tank_info.py +1 -1
  40. zepben/ewb/database/sqlite/tables/iec61968/assetinfo/table_transformer_test.py +1 -1
  41. zepben/ewb/database/sqlite/tables/iec61968/assetinfo/table_wire_info.py +1 -1
  42. zepben/ewb/database/sqlite/tables/iec61968/assets/table_assets.py +1 -1
  43. zepben/ewb/database/sqlite/tables/iec61968/assets/table_streetlights.py +1 -1
  44. zepben/ewb/database/sqlite/tables/iec61968/common/table_documents.py +1 -1
  45. zepben/ewb/database/sqlite/tables/iec61968/common/table_location_street_addresses.py +1 -1
  46. zepben/ewb/database/sqlite/tables/iec61968/common/table_organisation_roles.py +1 -1
  47. zepben/ewb/database/sqlite/tables/iec61968/common/table_position_points.py +1 -1
  48. zepben/ewb/database/sqlite/tables/iec61968/common/table_street_addresses.py +1 -1
  49. zepben/ewb/database/sqlite/tables/iec61968/common/table_town_details.py +1 -1
  50. zepben/ewb/database/sqlite/tables/iec61968/customers/table_customer_agreements.py +1 -1
  51. zepben/ewb/database/sqlite/tables/iec61968/customers/table_customers.py +1 -1
  52. zepben/ewb/database/sqlite/tables/iec61968/infiec61968/infassetinfo/table_current_transformer_info.py +1 -1
  53. zepben/ewb/database/sqlite/tables/iec61968/infiec61968/infassetinfo/table_potential_transformer_info.py +1 -1
  54. zepben/ewb/database/sqlite/tables/iec61968/infiec61968/infassets/table_poles.py +1 -1
  55. zepben/ewb/database/sqlite/tables/iec61968/metering/table_end_device_functions.py +1 -1
  56. zepben/ewb/database/sqlite/tables/iec61968/metering/table_end_devices.py +1 -1
  57. zepben/ewb/database/sqlite/tables/iec61968/metering/table_usage_points.py +1 -1
  58. zepben/ewb/database/sqlite/tables/iec61970/base/auxiliaryequipment/table_auxiliary_equipment.py +1 -1
  59. zepben/ewb/database/sqlite/tables/iec61970/base/auxiliaryequipment/table_current_transformers.py +1 -1
  60. zepben/ewb/database/sqlite/tables/iec61970/base/auxiliaryequipment/table_potential_transformers.py +1 -1
  61. zepben/ewb/database/sqlite/tables/iec61970/base/core/table_base_voltages.py +1 -1
  62. zepben/ewb/database/sqlite/tables/iec61970/base/core/table_conducting_equipment.py +1 -1
  63. zepben/ewb/database/sqlite/tables/iec61970/base/core/table_curve_data.py +1 -1
  64. zepben/ewb/database/sqlite/tables/iec61970/base/core/table_equipment.py +1 -1
  65. zepben/ewb/database/sqlite/tables/iec61970/base/core/table_feeders.py +1 -1
  66. zepben/ewb/database/sqlite/tables/iec61970/base/core/table_identified_objects.py +1 -1
  67. zepben/ewb/database/sqlite/tables/iec61970/base/core/table_name_types.py +1 -1
  68. zepben/ewb/database/sqlite/tables/iec61970/base/core/table_names.py +1 -1
  69. zepben/ewb/database/sqlite/tables/iec61970/base/core/table_power_system_resources.py +1 -1
  70. zepben/ewb/database/sqlite/tables/iec61970/base/core/table_sub_geographical_regions.py +1 -1
  71. zepben/ewb/database/sqlite/tables/iec61970/base/core/table_substations.py +1 -1
  72. zepben/ewb/database/sqlite/tables/iec61970/base/core/table_terminals.py +1 -1
  73. zepben/ewb/database/sqlite/tables/iec61970/base/diagramlayout/table_diagram_object_points.py +1 -1
  74. zepben/ewb/database/sqlite/tables/iec61970/base/diagramlayout/table_diagram_objects.py +1 -1
  75. zepben/ewb/database/sqlite/tables/iec61970/base/diagramlayout/table_diagrams.py +1 -1
  76. zepben/ewb/database/sqlite/tables/iec61970/base/equivalents/table_equivalent_branches.py +1 -1
  77. zepben/ewb/database/sqlite/tables/iec61970/base/generation/production/table_battery_units.py +1 -1
  78. zepben/ewb/database/sqlite/tables/iec61970/base/generation/production/table_power_electronics_units.py +1 -1
  79. zepben/ewb/database/sqlite/tables/iec61970/base/meas/table_analogs.py +1 -1
  80. zepben/ewb/database/sqlite/tables/iec61970/base/meas/table_controls.py +1 -1
  81. zepben/ewb/database/sqlite/tables/iec61970/base/meas/table_measurements.py +1 -1
  82. zepben/ewb/database/sqlite/tables/iec61970/base/protection/table_current_relays.py +1 -1
  83. zepben/ewb/database/sqlite/tables/iec61970/base/scada/table_remote_controls.py +1 -1
  84. zepben/ewb/database/sqlite/tables/iec61970/base/scada/table_remote_sources.py +1 -1
  85. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_ac_line_segments.py +1 -1
  86. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_breakers.py +1 -1
  87. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_clamps.py +1 -1
  88. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_conductors.py +1 -1
  89. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_cuts.py +1 -1
  90. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_earth_fault_compensators.py +1 -1
  91. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_energy_consumer_phases.py +1 -1
  92. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_energy_consumers.py +1 -1
  93. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_energy_source_phases.py +1 -1
  94. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_energy_sources.py +1 -1
  95. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_fuses.py +1 -1
  96. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_grounding_impedances.py +1 -1
  97. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_linear_shunt_compensators.py +1 -1
  98. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_per_length_sequence_impedances.py +1 -1
  99. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_petersen_coils.py +1 -1
  100. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_phase_impedance_data.py +1 -1
  101. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_power_electronics_connection_phases.py +1 -1
  102. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_power_electronics_connections.py +1 -1
  103. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_power_transformer_ends.py +1 -1
  104. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_power_transformers.py +1 -1
  105. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_protected_switches.py +1 -1
  106. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_ratio_tap_changers.py +1 -1
  107. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_regulating_cond_eq.py +1 -1
  108. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_regulating_controls.py +1 -1
  109. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_rotating_machines.py +1 -1
  110. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_series_compensators.py +1 -1
  111. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_shunt_compensators.py +1 -1
  112. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_static_var_compensator.py +1 -1
  113. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_switches.py +1 -1
  114. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_synchronous_machines.py +1 -1
  115. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_tap_changer_controls.py +1 -1
  116. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_tap_changers.py +1 -1
  117. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_transformer_ends.py +1 -1
  118. zepben/ewb/database/sqlite/tables/iec61970/base/wires/table_transformer_star_impedances.py +1 -1
  119. zepben/ewb/database/sqlite/tables/iec61970/infiec61970/feeder/table_circuits.py +1 -1
  120. zepben/ewb/database/sqlite/tables/sqlite_table.py +21 -118
  121. zepben/ewb/database/sqlite/tables/table_metadata_data_sources.py +1 -1
  122. zepben/ewb/database/sqlite/tables/table_version.py +2 -1
  123. zepben/ewb/model/cim/extensions/iec61970/base/protection/power_direction_kind.py +2 -0
  124. zepben/ewb/model/cim/extensions/iec61970/base/wires/battery_control_mode.py +2 -0
  125. zepben/ewb/model/cim/extensions/iec61970/base/wires/transformer_cooling_type.py +2 -0
  126. zepben/ewb/model/cim/extensions/iec61970/base/wires/vector_group.py +2 -0
  127. zepben/ewb/model/cim/iec61968/assetinfo/wire_material_kind.py +3 -0
  128. zepben/ewb/model/cim/iec61968/customers/customer_kind.py +3 -0
  129. zepben/ewb/model/cim/iec61968/infiec61968/infassetinfo/transformer_construction_kind.py +3 -0
  130. zepben/ewb/model/cim/iec61968/infiec61968/infassetinfo/transformer_function_kind.py +3 -0
  131. zepben/ewb/model/cim/iec61968/infiec61968/infassets/streetlight_lamp_kind.py +3 -0
  132. zepben/ewb/model/cim/iec61968/metering/controlled_appliance.py +3 -0
  133. zepben/ewb/model/cim/iec61968/metering/end_device_function_kind.py +3 -0
  134. zepben/ewb/model/cim/iec61970/base/auxiliaryequipment/potential_transformer_kind.py +3 -0
  135. zepben/ewb/model/cim/iec61970/base/core/phase_code.py +2 -0
  136. zepben/ewb/model/cim/iec61970/base/diagramlayout/diagram_style.py +3 -0
  137. zepben/ewb/model/cim/iec61970/base/diagramlayout/orientation_kind.py +3 -0
  138. zepben/ewb/model/cim/iec61970/base/domain/unit_symbol.py +3 -0
  139. zepben/ewb/model/cim/iec61970/base/generation/production/battery_state_kind.py +3 -0
  140. zepben/ewb/model/cim/iec61970/base/wires/phase_shunt_connection_kind.py +3 -0
  141. zepben/ewb/model/cim/iec61970/base/wires/regulating_control_mode_kind.py +3 -0
  142. zepben/ewb/model/cim/iec61970/base/wires/single_phase_kind.py +3 -0
  143. zepben/ewb/model/cim/iec61970/base/wires/svc_control_mode.py +3 -0
  144. zepben/ewb/model/cim/iec61970/base/wires/synchronous_machine_kind.py +3 -0
  145. zepben/ewb/model/cim/iec61970/base/wires/winding_connection.py +3 -0
  146. zepben/ewb/services/network/network_state.py +3 -0
  147. zepben/ewb/streaming/get/included_energized_containers.py +3 -0
  148. zepben/ewb/streaming/get/included_energizing_containers.py +3 -0
  149. zepben/ewb/util.py +11 -0
  150. {zepben_ewb-1.0.0b3.dist-info → zepben_ewb-1.0.0b5.dist-info}/METADATA +1 -1
  151. {zepben_ewb-1.0.0b3.dist-info → zepben_ewb-1.0.0b5.dist-info}/RECORD +154 -152
  152. {zepben_ewb-1.0.0b3.dist-info → zepben_ewb-1.0.0b5.dist-info}/WHEEL +0 -0
  153. {zepben_ewb-1.0.0b3.dist-info → zepben_ewb-1.0.0b5.dist-info}/licenses/LICENSE +0 -0
  154. {zepben_ewb-1.0.0b3.dist-info → zepben_ewb-1.0.0b5.dist-info}/top_level.txt +0 -0
@@ -6,7 +6,7 @@
6
6
  __all__ = ["TableStaticVarCompensators"]
7
7
 
8
8
  from zepben.ewb import TableRegulatingCondEq
9
- from zepben.ewb.database.sqlite.tables.column import Column, Nullable
9
+ from zepben.ewb.database.sql.column import Column, Nullable
10
10
 
11
11
 
12
12
  class TableStaticVarCompensators(TableRegulatingCondEq):
@@ -7,7 +7,7 @@ __all__ = ["TableSwitches"]
7
7
 
8
8
  from abc import ABC
9
9
 
10
- from zepben.ewb.database.sqlite.tables.column import Column, Nullable
10
+ from zepben.ewb.database.sql.column import Column, Nullable
11
11
  from zepben.ewb.database.sqlite.tables.iec61970.base.core.table_conducting_equipment import TableConductingEquipment
12
12
 
13
13
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  __all__ = ["TableSynchronousMachines"]
7
7
 
8
- from zepben.ewb.database.sqlite.tables.column import Column, Nullable
8
+ from zepben.ewb.database.sql.column import Column, Nullable
9
9
  from zepben.ewb.database.sqlite.tables.iec61970.base.wires.table_rotating_machines import TableRotatingMachines
10
10
 
11
11
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  __all__ = ["TableTapChangerControls"]
7
7
 
8
- from zepben.ewb.database.sqlite.tables.column import Column, Nullable
8
+ from zepben.ewb.database.sql.column import Column, Nullable
9
9
  from zepben.ewb.database.sqlite.tables.iec61970.base.wires.table_regulating_controls import TableRegulatingControls
10
10
 
11
11
 
@@ -7,7 +7,7 @@ __all__ = ["TableTapChangers"]
7
7
 
8
8
  from abc import ABC
9
9
 
10
- from zepben.ewb.database.sqlite.tables.column import Column, Nullable
10
+ from zepben.ewb.database.sql.column import Column, Nullable
11
11
  from zepben.ewb.database.sqlite.tables.iec61970.base.core.table_power_system_resources import TablePowerSystemResources
12
12
 
13
13
 
@@ -8,7 +8,7 @@ __all__ = ["TableTransformerEnds"]
8
8
  from abc import ABC
9
9
  from typing import List, Generator
10
10
 
11
- from zepben.ewb.database.sqlite.tables.column import Column, Nullable
11
+ from zepben.ewb.database.sql.column import Column, Nullable
12
12
  from zepben.ewb.database.sqlite.tables.iec61970.base.core.table_identified_objects import TableIdentifiedObjects
13
13
 
14
14
 
@@ -7,7 +7,7 @@ __all__ = ["TableTransformerStarImpedances"]
7
7
 
8
8
  from typing import List, Generator
9
9
 
10
- from zepben.ewb.database.sqlite.tables.column import Column, Nullable
10
+ from zepben.ewb.database.sql.column import Column, Nullable
11
11
  from zepben.ewb.database.sqlite.tables.iec61970.base.core.table_identified_objects import TableIdentifiedObjects
12
12
 
13
13
 
@@ -7,7 +7,7 @@ __all__ = ["TableCircuits"]
7
7
 
8
8
  from typing import List, Generator
9
9
 
10
- from zepben.ewb.database.sqlite.tables.column import Column, Nullable
10
+ from zepben.ewb.database.sql.column import Column, Nullable
11
11
  from zepben.ewb.database.sqlite.tables.iec61970.base.wires.table_lines import TableLines
12
12
 
13
13
 
@@ -7,136 +7,39 @@ from __future__ import annotations
7
7
 
8
8
  __all__ = ["SqliteTable"]
9
9
 
10
- from abc import abstractmethod
11
- from typing import List, Optional, Type, Any, Generator
10
+ from abc import ABC
11
+ from typing import List, Generator
12
12
 
13
- from zepben.ewb.database.sqlite.tables.column import Column, Nullable
13
+ from zepben.ewb.database.sql.column import Column
14
+ from zepben.ewb.database.sql.sql_table import SqlTable
14
15
 
15
16
 
16
- # @dataclass(slots=True)
17
- class SqliteTable(object):
17
+ class SqliteTable(SqlTable, ABC):
18
18
  """
19
- Represents a table in an Sqlite Database. This class should be extended and initialised to build the DDL for a Table.
20
- Methods that need to be overridden are those marked @abstractmethod.
21
- Methods that can be optionally overridden are unique_index_columns() and non_unique_index_columns().
22
- Columns must be assigned in __init__ and column_index must be incremented for each Column created.
23
- See existing implementations such as TableVersion for examples.
19
+ Represents a table in an Sqlite Database.
24
20
  """
25
21
 
26
- column_index: int = 0
27
- """Used to specify index of the column in the table during initialisation. Always increment BEFORE creating a Column. Indices start from 1."""
28
-
29
- _column_set: Optional[List[Column]] = None
30
- _create_table_sql: Optional[str] = None
31
- _prepared_insert_sql: Optional[str] = None
32
- _prepared_update_sql: Optional[str] = None
33
- _create_indexes_sql: Optional[List[str]] = None
34
- _select_sql: Optional[str] = None
35
-
36
- @property
37
- @abstractmethod
38
- def name(self) -> str:
39
- pass
40
-
41
- #
42
- # NOTE: This function is called `description` in teh JVM SDK, but in the python SDK this
43
- # conflicts with the `description` column of `TableIdentifiedObjects`.
44
- #
45
- def describe(self) -> str:
46
- return self.name.replace("_", " ")
47
-
48
22
  @property
49
23
  def create_table_sql(self):
50
- return self._create_table_sql if self._create_table_sql else self._build_create_table_sql()
51
-
52
- @property
53
- def prepared_insert_sql(self):
54
- return self._prepared_insert_sql if self._prepared_insert_sql else self._build_prepared_insert_sql()
24
+ if self._create_table_sql is None:
25
+ self._create_table_sql = self._build_create_table_sql()
26
+ return self._create_table_sql
55
27
 
56
28
  @property
57
29
  def create_indexes_sql(self):
58
- return self._create_indexes_sql if self._create_indexes_sql else self._build_indexes_sql()
59
-
60
- @property
61
- def select_sql(self):
62
- return self._select_sql if self._select_sql else self._build_select_sql()
63
-
64
- @property
65
- def prepared_update_sql(self):
66
- return self._prepared_update_sql if self._prepared_update_sql else self._build_prepared_update_sql()
67
-
68
- @property
69
- def unique_index_columns(self) -> Generator[List[Column], None, None]:
70
- # To make this a generator we need to `yield`, but we have nothing to yield by default, so trick it by yielding from an empty for-loop.
71
- for it in []:
72
- yield it
73
-
74
- @property
75
- def non_unique_index_columns(self) -> Generator[List[Column], None, None]:
76
- # To make this a generator we need to `yield`, but we have nothing to yield by default, so trick it by yielding from an empty for-loop.
77
- for it in []:
78
- yield it
79
-
80
- @property
81
- def column_set(self) -> List[Column]:
82
- return self._column_set if self._column_set else self._build_column_set(self.__class__, self)
83
-
84
- def _build_column_set(self, clazz: Type[Any], instance: SqliteTable) -> List[Column]:
85
- """
86
- Builds the list of columns for use in DDL statements for this table.
87
-
88
- :param clazz: The class of this table.
89
- :param instance:
90
- :return:
91
- """
92
- cols = list()
93
- for field, x in instance.__dict__.items():
94
- if isinstance(x, Column):
95
- if x.query_index != len(cols) + 1:
96
- raise ValueError(
97
- f"Field {field} in SQL Table class {clazz.__name__} is using an invalid column index. "
98
- f"Did you forget to increment column_index, or did you skip one?"
99
- )
100
- cols.append(x)
101
-
102
- if len(set([c.name for c in cols])) != len(cols):
103
- raise ValueError("You have a duplicate column names, go fix that.")
104
-
105
- self._column_set = sorted(cols, key=lambda it: it.query_index)
106
- return self._column_set
107
-
108
- def _build_create_table_sql(self) -> str:
109
- self._create_table_sql = f"CREATE TABLE {self.name} ({', '.join([str(c) for c in self.column_set])})"
110
- return self._create_table_sql
111
-
112
- def _build_prepared_insert_sql(self) -> str:
113
- self._prepared_insert_sql = f"INSERT INTO {self.name} ({', '.join([c.name for c in self.column_set])}) " \
114
- f"VALUES ({', '.join(['?' for _ in self.column_set])})"
115
- return self._prepared_insert_sql
116
-
117
- def _build_indexes_sql(self) -> List[str]:
118
- statements = []
119
- for index_col in self.unique_index_columns:
120
- statements.append(self._build_index_sql(index_col, True))
121
- for index_col in self.non_unique_index_columns:
122
- statements.append(self._build_index_sql(index_col, False))
123
- self._create_indexes_sql = statements
30
+ if self._create_indexes_sql is None:
31
+ self._create_indexes_sql = list(self._build_indexes_sql())
124
32
  return self._create_indexes_sql
125
33
 
126
- def _build_index_sql(self, index_col: List[Column], is_unique: bool):
127
- id_string = f"{self.name}_{'_'.join(map(lambda c: c.name, index_col))}"
128
- col_string = ', '.join(map(lambda c: c.name, index_col))
129
- return f"CREATE {'UNIQUE ' if is_unique else ''}INDEX {id_string} ON {self.name} ({col_string})"
130
-
131
- def _build_select_sql(self) -> str:
132
- self._select_sql = f"SELECT {', '.join([c.name for c in self.column_set])} FROM {self.name}"
133
- return self._select_sql
34
+ def _build_create_table_sql(self) -> str:
35
+ return f"CREATE TABLE {self.name} ({', '.join(str(c) for c in self.column_set)})"
134
36
 
135
- def _build_prepared_update_sql(self) -> str:
136
- self._prepared_update_sql = f"UPDATE {self.name} SET {', '.join([f'{c.name} = ?' for c in self.column_set])}"
137
- return self._prepared_update_sql
37
+ def _build_indexes_sql(self) -> Generator[str, None, None]:
38
+ yield from (self._build_index_sql(index_col, True) for index_col in self.unique_index_columns)
39
+ yield from (self._build_index_sql(index_col, False) for index_col in self.non_unique_index_columns)
138
40
 
139
- def _create_column(self, name: str, type_: str, nullable: Nullable = Nullable.NONE) -> Column:
140
- self.column_index += 1
141
- # noinspection PyArgumentList
142
- return Column(self.column_index, name, type_, nullable)
41
+ def _build_index_sql(self, index_col: List[Column], is_unique: bool) -> str:
42
+ index_col_names = [c.name for c in index_col]
43
+ return (f"CREATE {'UNIQUE ' if is_unique else ''}INDEX "
44
+ f"{self.name}_{'_'.join(index_col_names)}" # id string
45
+ f" ON {self.name} ({', '.join(index_col_names)})") # col string
@@ -5,7 +5,7 @@
5
5
 
6
6
  __all__ = ["TableMetadataDataSources"]
7
7
 
8
- from zepben.ewb.database.sqlite.tables.column import Column, Nullable
8
+ from zepben.ewb.database.sql.column import Column, Nullable
9
9
  from zepben.ewb.database.sqlite.tables.sqlite_table import SqliteTable
10
10
 
11
11
 
@@ -9,7 +9,7 @@ import sqlite3
9
9
  from sqlite3 import Cursor
10
10
  from typing import Optional
11
11
 
12
- from zepben.ewb.database.sqlite.tables.column import Column, Nullable
12
+ from zepben.ewb.database.sql.column import Column, Nullable
13
13
  from zepben.ewb.database.sqlite.tables.sqlite_table import SqliteTable
14
14
 
15
15
 
@@ -17,6 +17,7 @@ class TableVersion(SqliteTable):
17
17
  SUPPORTED_VERSION = 59
18
18
 
19
19
  def __init__(self):
20
+ super().__init__()
20
21
  self.version: Column = self._create_column("version", "TEXT", Nullable.NOT_NULL)
21
22
 
22
23
  @property
@@ -8,9 +8,11 @@ __all__ = ["PowerDirectionKind"]
8
8
  from enum import Enum
9
9
 
10
10
  from zepben.ewb.model.cim.extensions.zbex import zbex
11
+ from zepben.ewb.util import unique
11
12
 
12
13
 
13
14
  @zbex
15
+ @unique
14
16
  class PowerDirectionKind(Enum):
15
17
  """
16
18
  [ZBEX]
@@ -7,10 +7,12 @@ __all__ = ["BatteryControlMode"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
  from zepben.ewb.model.cim.extensions.zbex import zbex
11
12
 
12
13
 
13
14
  @zbex
15
+ @unique
14
16
  class BatteryControlMode(Enum):
15
17
  """
16
18
  [ZBEX]
@@ -7,10 +7,12 @@ __all__ = ["TransformerCoolingType"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
  from zepben.ewb.model.cim.extensions.zbex import zbex
11
12
 
12
13
 
13
14
  @zbex
15
+ @unique
14
16
  class TransformerCoolingType(Enum):
15
17
  """
16
18
  [ZBEX]
@@ -7,10 +7,12 @@ __all__ = ["VectorGroup"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
  from zepben.ewb.model.cim.extensions.zbex import zbex
11
12
 
12
13
 
13
14
  @zbex
15
+ @unique
14
16
  class VectorGroup(Enum):
15
17
  """
16
18
  [ZBEX]
@@ -7,7 +7,10 @@ __all__ = ["WireMaterialKind"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
 
12
+
13
+ @unique
11
14
  class WireMaterialKind(Enum):
12
15
  """
13
16
  Kind of wire material.
@@ -7,7 +7,10 @@ __all__ = ["CustomerKind"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
 
12
+
13
+ @unique
11
14
  class CustomerKind(Enum):
12
15
  """
13
16
  Kind of customer.
@@ -7,7 +7,10 @@ __all__ = ["TransformerConstructionKind"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
 
12
+
13
+ @unique
11
14
  class TransformerConstructionKind(Enum):
12
15
  """
13
16
  Kind of transformer construction.
@@ -7,7 +7,10 @@ __all__ = ["TransformerFunctionKind"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
 
12
+
13
+ @unique
11
14
  class TransformerFunctionKind(Enum):
12
15
  """
13
16
  Function of a transformer.
@@ -7,7 +7,10 @@ __all__ = ["StreetlightLampKind"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
 
12
+
13
+ @unique
11
14
  class StreetlightLampKind(Enum):
12
15
  """
13
16
  Kind of lamp for a `Streetlight`
@@ -11,7 +11,10 @@ from dataclasses import dataclass
11
11
  from enum import Enum
12
12
  from typing import List, Union
13
13
 
14
+ from zepben.ewb import unique
14
15
 
16
+
17
+ @unique
15
18
  class Appliance(Enum):
16
19
  """
17
20
  The type of appliance.
@@ -7,7 +7,10 @@ __all__ = ["EndDeviceFunctionKind"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
 
12
+
13
+ @unique
11
14
  class EndDeviceFunctionKind(Enum):
12
15
  """
13
16
  Kind of end device function.
@@ -7,7 +7,10 @@ __all__ = ["PotentialTransformerKind"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
 
12
+
13
+ @unique
11
14
  class PotentialTransformerKind(Enum):
12
15
  """
13
16
  The construction kind of the potential transformer.
@@ -8,6 +8,7 @@ __all__ = ["PhaseCode", "phase_code_by_id", "phase_code_from_single_phases"]
8
8
  from enum import Enum
9
9
  from typing import List, Set, Union
10
10
 
11
+ from zepben.ewb import unique
11
12
  from zepben.ewb.model.cim.iec61970.base.wires.single_phase_kind import SinglePhaseKind
12
13
 
13
14
 
@@ -21,6 +22,7 @@ def phase_code_by_id(value: int):
21
22
  return _PHASE_CODE_VALUES[value]
22
23
 
23
24
 
25
+ @unique
24
26
  class PhaseCode(Enum):
25
27
  """
26
28
  An unordered enumeration of phase identifiers. Allows designation of phases for both transmission and distribution equipment,
@@ -7,7 +7,10 @@ __all__ = ["DiagramStyle"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
 
12
+
13
+ @unique
11
14
  class DiagramStyle(Enum):
12
15
  """
13
16
  The diagram style refer to a style used by the originating system for a diagram. A diagram style describes
@@ -7,7 +7,10 @@ __all__ = ["OrientationKind"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
 
12
+
13
+ @unique
11
14
  class OrientationKind(Enum):
12
15
  """
13
16
  The orientation of the coordinate system with respect to top, left, and the coordinate number system.
@@ -7,6 +7,8 @@ __all__ = ["UnitSymbol", "unit_symbol_from_id", "unit_symbol_from_cim_name"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
11
+
10
12
 
11
13
  def unit_symbol_from_cim_name(value: str):
12
14
  return _unitsymbol_by_cim_name[value]
@@ -16,6 +18,7 @@ def unit_symbol_from_id(value: int):
16
18
  return _unitsymbol_members_by_id[value]
17
19
 
18
20
 
21
+ # NOTE: We can't use `@unique` here, as there are duplicate unit strings.
19
22
  class UnitSymbol(Enum):
20
23
  """
21
24
  The derived units defined for usage in the CIM. In some cases, the derived unit is equal to an SI unit. Whenever possible, the standard derived symbol is
@@ -7,7 +7,10 @@ __all__ = ["BatteryStateKind"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
 
12
+
13
+ @unique
11
14
  class BatteryStateKind(Enum):
12
15
  """
13
16
  Battery state.
@@ -7,7 +7,10 @@ __all__ = ["PhaseShuntConnectionKind"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb.util import unique
10
11
 
12
+
13
+ @unique
11
14
  class PhaseShuntConnectionKind(Enum):
12
15
  """
13
16
  The configuration of phase connections for a single terminal device such as a load or capacitor.
@@ -7,7 +7,10 @@ __all__ = ["RegulatingControlModeKind"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
 
12
+
13
+ @unique
11
14
  class RegulatingControlModeKind(Enum):
12
15
  """
13
16
  The kind of regulation model. For example regulating voltage, reactive power, active power, etc.
@@ -8,6 +8,8 @@ __all__ = ["SinglePhaseKind", "single_phase_kind_by_id", "SINGLE_PHASE_KIND_VALU
8
8
  from enum import Enum
9
9
  from typing import Union
10
10
 
11
+ from zepben.ewb import unique
12
+
11
13
 
12
14
  #
13
15
  # NOTE: The following import is actually at the bottom of this file to avoid cyclic imports.
@@ -25,6 +27,7 @@ def single_phase_kind_by_id(value):
25
27
  return SINGLE_PHASE_KIND_VALUES[value]
26
28
 
27
29
 
30
+ @unique
28
31
  class SinglePhaseKind(Enum):
29
32
  """
30
33
  Enumeration of single phase identifiers. Allows designation of single phases for both transmission and distribution equipment, circuits and loads.
@@ -7,7 +7,10 @@ __all__ = ["SVCControlMode"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
 
12
+
13
+ @unique
11
14
  class SVCControlMode(Enum):
12
15
  """
13
16
  Static VAr Compensator control mode.
@@ -7,7 +7,10 @@ __all__ = ["SynchronousMachineKind"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
 
12
+
13
+ @unique
11
14
  class SynchronousMachineKind(Enum):
12
15
  """
13
16
  Synchronous machine type.
@@ -7,7 +7,10 @@ __all__ = ["WindingConnection"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
 
12
+
13
+ @unique
11
14
  class WindingConnection(Enum):
12
15
  """
13
16
  Winding connection type.
@@ -7,7 +7,10 @@ __all__ = ["NetworkState"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
 
12
+
13
+ @unique
11
14
  class NetworkState(Enum):
12
15
  """
13
16
  Indicates which state of the network an operation should be performed on.
@@ -7,7 +7,10 @@ __all__ = ["IncludedEnergizedContainers"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb import unique
10
11
 
12
+
13
+ @unique
11
14
  class IncludedEnergizedContainers(Enum):
12
15
  """
13
16
  Indicates which energized contains should be included when fetching a container.
@@ -7,7 +7,10 @@ __all__ = ["IncludedEnergizingContainers"]
7
7
 
8
8
  from enum import Enum
9
9
 
10
+ from zepben.ewb.util import unique
10
11
 
12
+
13
+ @unique
11
14
  class IncludedEnergizingContainers(Enum):
12
15
  """
13
16
  Indicates which energizing contains should be included when fetching a container.
zepben/ewb/util.py CHANGED
@@ -19,12 +19,14 @@ __all__ = [
19
19
  "datetime_to_timestamp",
20
20
  "none",
21
21
  "classproperty",
22
+ "unique",
22
23
  ]
23
24
 
24
25
  import os
25
26
  import re
26
27
  from collections.abc import Sized
27
28
  from datetime import datetime
29
+ from enum import unique as enum_unique
28
30
  from typing import List, Optional, Iterable, Callable, Any, TypeVar, Generator, Dict, Collection
29
31
  from typing import TYPE_CHECKING
30
32
  from uuid import UUID
@@ -187,3 +189,12 @@ def datetime_to_timestamp(date_time: datetime) -> PBTimestamp:
187
189
  timestamp = PBTimestamp()
188
190
  timestamp.FromDatetime(date_time)
189
191
  return timestamp
192
+
193
+
194
+ def unique(enumeration: T) -> T:
195
+ """
196
+ A wrapper for the enum.unique() wrapper to preserve typing so that undefined members are correctly
197
+ flagged by the linter.
198
+ """
199
+ enum_unique(enumeration)
200
+ return enumeration
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zepben.ewb
3
- Version: 1.0.0b3
3
+ Version: 1.0.0b5
4
4
  Summary: Python SDK for interacting with the Energy Workbench platform
5
5
  Home-page: https://github.com/zepben/evolve-sdk-python
6
6
  Author: Kurt Greaves