Skip to content

Commit

Permalink
updated examples for csv data source on ahu ipynb. still working on b…
Browse files Browse the repository at this point in the history
…rick method
  • Loading branch information
bbartling committed Aug 29, 2024
1 parent aaee4fd commit c0143fd
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 693 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ The following are key objectives to enhance this project into a fully interactiv

### In Progress
- [ ] Create IPython notebook tutorials showcasing AHU FDD examples, incorporating BRICK metadata integration.
- [ ] Develop a comprehensive guide on a github.io website (or other?) for defining fault parameters, including error thresholds and other critical settings.
- [ ] Extend the project to include `central_plant` fault conditions, IPython reports, and example applications for boiler and chiller systems.


### Upcoming
- [ ] Extend the project to include `central_plant` fault conditions, IPython reports, and example applications.
- [ ] Design `energy_efficiency` fault detection modules, including IPython reports and examples focused on optimizing energy consumption.
- [ ] Develop `metering` fault conditions, along with IPython reports and examples, potentially modeling utility metering data.
- [ ] Implement SQL integration examples for reading data from a time series database, writing back to SQL, and visualizing faults in Grafana.

### Future Considerations
Explore additional features and enhancements as the project evolves.
- [ ] Explore additional features and enhancements as the project evolves.
- [ ] Develop a comprehensive guide on a github.io website (or other?) for defining fault parameters, including error thresholds and other critical settings.


## Contribute
Expand Down
65 changes: 44 additions & 21 deletions examples/brick_model_and_sqlite/1_make_db.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sqlite3
import pandas as pd
import re

# Step 1: Connect to SQLite database (or create it)
conn = sqlite3.connect("brick_timeseries.db")
Expand Down Expand Up @@ -48,30 +49,49 @@
)

# Step 4: Load the CSV data
csv_file = r"C:\Users\bbartling\Documents\WPCRC_July.csv"
csv_file = r"C:\Users\bbartling\Documents\brick_data_July_2024.csv"
df = pd.read_csv(csv_file)
print("df.columns", df.columns)
print("Original df.columns", df.columns)

# Ensure that the 'timestamp' column is properly parsed as a datetime object
if "timestamp" in df.columns:
df["timestamp"] = pd.to_datetime(df["timestamp"])
else:
raise ValueError("The CSV file does not contain a 'timestamp' column.")

print("Starting step 5")
# Step 4.1: Remove specific strings from the tail of the sensor names using regex
pattern = (
r"(\/|inwc|\(\)|galmin|\(%\)|\(°F\)|\(A\)|\(Δpsi\)|\(cfm\)|\(in\/wc\)|\(gal\/min\))"
)
df.columns = df.columns.str.replace(pattern, "", regex=True)

# Print columns after modification to verify changes
print("Modified df.columns", df.columns)

# Step 5: Insert CSV data into the TimeseriesData table
for column in df.columns:
if column != "timestamp": # Skip the timestamp column itself
for index, row in df.iterrows():
cursor.execute(
"""
INSERT INTO TimeseriesData (sensor_name, timestamp, value)
VALUES (?, ?, ?)
""",
(column, row["timestamp"].strftime("%Y-%m-%d %H:%M:%S"), row[column]),
)
print(f"Doing {column} in step 5")
# Only process columns related to AHU fan VFD speed, static pressure sensor, and setpoint
if "StaticSPt" in column or "SaStatic" in column or "SaFanSpeedAO" in column:
for index, row in df.iterrows():
cursor.execute(
"""
INSERT INTO TimeseriesData (sensor_name, timestamp, value)
VALUES (?, ?, ?)
""",
(
column,
row["timestamp"].strftime("%Y-%m-%d %H:%M:%S"),
row[column],
),
)
if index < 5: # Print the first 5 rows only
print(
f"Inserted sensor name {column} with value {row[column]} at {row['timestamp']}"
)
print(f"Processed {column} in step 5")
else:
pass

conn.commit()

Expand All @@ -80,15 +100,18 @@
# Step 6: Insert timeseries references based on sensor names
for column in df.columns:
if column != "timestamp": # Skip the timestamp column itself
cursor.execute(
"""
INSERT INTO TimeseriesReference (timeseries_id, stored_at)
VALUES (?, ?)
""",
(column, "SQLite Timeseries Storage"),
)

print(f"Doing {column} in step 6")
# Only process columns related to AHU fan VFD speed, static pressure sensor, and setpoint
if "StaticSPt" in column or "SaStatic" in column or "SaFanSpeedAO" in column:
cursor.execute(
"""
INSERT INTO TimeseriesReference (timeseries_id, stored_at)
VALUES (?, ?)
""",
(column, "SQLite Timeseries Storage"),
)
print(f"Inserted reference for {column} in step 6")
else:
pass

conn.commit()

Expand Down
39 changes: 0 additions & 39 deletions examples/brick_model_and_sqlite/2_testout_step_1.py

This file was deleted.

80 changes: 0 additions & 80 deletions examples/brick_model_and_sqlite/3_make_rdf.py

This file was deleted.

Loading

0 comments on commit c0143fd

Please sign in to comment.