156 lines
5.5 KiB
Python
156 lines
5.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Script to initialize and persist sample tag metadata
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
import json
|
|
|
|
# Add the src directory to the Python path
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src'))
|
|
|
|
from src.core.tag_metadata_manager import tag_metadata_manager
|
|
|
|
def create_and_save_sample_metadata():
|
|
"""Create sample tag metadata and save to file"""
|
|
|
|
print("Initializing Sample Tag Metadata...")
|
|
print("=" * 60)
|
|
|
|
# Create sample stations
|
|
print("\n🏭 Creating Stations...")
|
|
station1_id = tag_metadata_manager.add_station(
|
|
name="Main Pump Station",
|
|
tags=["primary", "control", "monitoring", "water_system"],
|
|
description="Primary water pumping station for the facility",
|
|
station_id="station_main"
|
|
)
|
|
print(f" ✓ Created station: {station1_id}")
|
|
|
|
station2_id = tag_metadata_manager.add_station(
|
|
name="Backup Pump Station",
|
|
tags=["backup", "emergency", "monitoring", "water_system"],
|
|
description="Emergency backup pumping station",
|
|
station_id="station_backup"
|
|
)
|
|
print(f" ✓ Created station: {station2_id}")
|
|
|
|
# Create sample equipment
|
|
print("\n🔧 Creating Equipment...")
|
|
equipment1_id = tag_metadata_manager.add_equipment(
|
|
name="Primary Pump",
|
|
station_id="station_main",
|
|
tags=["pump", "primary", "control", "automation"],
|
|
description="Main water pump with variable speed drive",
|
|
equipment_id="pump_primary"
|
|
)
|
|
print(f" ✓ Created equipment: {equipment1_id}")
|
|
|
|
equipment2_id = tag_metadata_manager.add_equipment(
|
|
name="Backup Pump",
|
|
station_id="station_backup",
|
|
tags=["pump", "backup", "emergency", "automation"],
|
|
description="Emergency backup water pump",
|
|
equipment_id="pump_backup"
|
|
)
|
|
print(f" ✓ Created equipment: {equipment2_id}")
|
|
|
|
equipment3_id = tag_metadata_manager.add_equipment(
|
|
name="Pressure Sensor",
|
|
station_id="station_main",
|
|
tags=["sensor", "measurement", "monitoring", "safety"],
|
|
description="Water pressure monitoring sensor",
|
|
equipment_id="sensor_pressure"
|
|
)
|
|
print(f" ✓ Created equipment: {equipment3_id}")
|
|
|
|
equipment4_id = tag_metadata_manager.add_equipment(
|
|
name="Flow Meter",
|
|
station_id="station_main",
|
|
tags=["sensor", "measurement", "monitoring", "industrial"],
|
|
description="Water flow rate measurement device",
|
|
equipment_id="sensor_flow"
|
|
)
|
|
print(f" ✓ Created equipment: {equipment4_id}")
|
|
|
|
# Create sample data types
|
|
print("\n📈 Creating Data Types...")
|
|
data_type1_id = tag_metadata_manager.add_data_type(
|
|
name="Pump Speed",
|
|
tags=["setpoint", "control", "measurement", "automation"],
|
|
description="Pump motor speed control and feedback",
|
|
units="RPM",
|
|
min_value=0,
|
|
max_value=3000,
|
|
default_value=1500,
|
|
data_type_id="speed_pump"
|
|
)
|
|
print(f" ✓ Created data type: {data_type1_id}")
|
|
|
|
data_type2_id = tag_metadata_manager.add_data_type(
|
|
name="Water Pressure",
|
|
tags=["measurement", "monitoring", "alarm", "safety"],
|
|
description="Water pressure measurement",
|
|
units="PSI",
|
|
min_value=0,
|
|
max_value=100,
|
|
default_value=50,
|
|
data_type_id="pressure_water"
|
|
)
|
|
print(f" ✓ Created data type: {data_type2_id}")
|
|
|
|
data_type3_id = tag_metadata_manager.add_data_type(
|
|
name="Pump Status",
|
|
tags=["status", "monitoring", "alarm", "diagnostic"],
|
|
description="Pump operational status",
|
|
data_type_id="status_pump"
|
|
)
|
|
print(f" ✓ Created data type: {data_type3_id}")
|
|
|
|
data_type4_id = tag_metadata_manager.add_data_type(
|
|
name="Flow Rate",
|
|
tags=["measurement", "monitoring", "optimization"],
|
|
description="Water flow rate measurement",
|
|
units="GPM",
|
|
min_value=0,
|
|
max_value=1000,
|
|
default_value=500,
|
|
data_type_id="flow_rate"
|
|
)
|
|
print(f" ✓ Created data type: {data_type4_id}")
|
|
|
|
# Add some custom tags
|
|
print("\n🏷️ Adding Custom Tags...")
|
|
custom_tags = ["water_system", "industrial", "automation", "safety", "municipal"]
|
|
for tag in custom_tags:
|
|
tag_metadata_manager.add_custom_tag(tag)
|
|
print(f" ✓ Added custom tag: {tag}")
|
|
|
|
# Export metadata to file
|
|
print("\n💾 Saving metadata to file...")
|
|
metadata_file = os.path.join(os.path.dirname(__file__), 'sample_metadata.json')
|
|
metadata = tag_metadata_manager.export_metadata()
|
|
|
|
with open(metadata_file, 'w') as f:
|
|
json.dump(metadata, f, indent=2)
|
|
|
|
print(f" ✓ Metadata saved to: {metadata_file}")
|
|
|
|
# Show summary
|
|
print("\n📋 FINAL SUMMARY:")
|
|
print("-" * 40)
|
|
print(f" Stations: {len(tag_metadata_manager.stations)}")
|
|
print(f" Equipment: {len(tag_metadata_manager.equipment)}")
|
|
print(f" Data Types: {len(tag_metadata_manager.data_types)}")
|
|
print(f" Total Tags: {len(tag_metadata_manager.all_tags)}")
|
|
|
|
print("\n✅ Sample metadata initialization completed!")
|
|
print("\n📝 Sample metadata includes:")
|
|
print(" - 2 Stations: Main Pump Station, Backup Pump Station")
|
|
print(" - 4 Equipment: Primary Pump, Backup Pump, Pressure Sensor, Flow Meter")
|
|
print(" - 4 Data Types: Pump Speed, Water Pressure, Pump Status, Flow Rate")
|
|
print(" - 33 Total Tags including core and custom tags")
|
|
|
|
if __name__ == "__main__":
|
|
create_and_save_sample_metadata() |