70 lines
2.3 KiB
Python
70 lines
2.3 KiB
Python
"""
|
|
Query InfluxDB to see what data exists
|
|
"""
|
|
|
|
from influxdb_client import InfluxDBClient
|
|
from datetime import datetime, timedelta
|
|
|
|
def check_influxdb_data():
|
|
url = "http://localhost:8086"
|
|
token = "kNFfXEpPQoWrk5Tteowda21Dzv6xD3jY7QHSHHQHb5oYW6VH6mkAgX9ZMjQJkaHHa8FwzmyVFqDG7qqzxN09uQ=="
|
|
org = "smart-intersection-org"
|
|
bucket = "traffic_monitoring"
|
|
|
|
try:
|
|
client = InfluxDBClient(url=url, token=token, org=org)
|
|
query_api = client.query_api()
|
|
|
|
print("Checking InfluxDB data...")
|
|
|
|
# Check traffic light status
|
|
query = f'''
|
|
from(bucket: "{bucket}")
|
|
|> range(start: -1h)
|
|
|> filter(fn: (r) => r["_measurement"] == "traffic_light_status")
|
|
|> limit(n: 5)
|
|
'''
|
|
|
|
result = query_api.query(org=org, query=query)
|
|
print("\n=== Traffic Light Status Data ===")
|
|
for table in result:
|
|
for record in table.records:
|
|
print(f"Time: {record.get_time()}, Field: {record.get_field()}, Value: {record.get_value()}")
|
|
|
|
# Check violation events
|
|
query = f'''
|
|
from(bucket: "{bucket}")
|
|
|> range(start: -1h)
|
|
|> filter(fn: (r) => r["_measurement"] == "violation_events")
|
|
|> limit(n: 5)
|
|
'''
|
|
|
|
result = query_api.query(org=org, query=query)
|
|
print("\n=== Violation Events Data ===")
|
|
for table in result:
|
|
for record in table.records:
|
|
print(f"Time: {record.get_time()}, Field: {record.get_field()}, Value: {record.get_value()}")
|
|
|
|
# Check device info
|
|
query = f'''
|
|
from(bucket: "{bucket}")
|
|
|> range(start: -1h)
|
|
|> filter(fn: (r) => r["_measurement"] == "device_info")
|
|
|> limit(n: 5)
|
|
'''
|
|
|
|
result = query_api.query(org=org, query=query)
|
|
print("\n=== Device Info Data ===")
|
|
for table in result:
|
|
for record in table.records:
|
|
print(f"Time: {record.get_time()}, Field: {record.get_field()}, Value: {record.get_value()}")
|
|
|
|
except Exception as e:
|
|
print(f"Error querying data: {e}")
|
|
finally:
|
|
if 'client' in locals():
|
|
client.close()
|
|
|
|
if __name__ == "__main__":
|
|
check_influxdb_data()
|