Bear_room / scripts /caption_control_channel.py
Anonymous Authors
Init
266e6c4
import pandas as pd
import json
import os
import argparse
from tqdm import tqdm
def describe_cooling_setpoint(value, timestamp):
"""Describes the cooling setpoint status based on value and timestamp."""
month = timestamp.month
if month <= 6 or month == 12:
if 79 < value < 90:
return "It is not Summer now. A cooling setpoint is active at high level."
elif 60 < value < 79:
return "It is not Summer now. A cooling setpoint is active at low level."
else:
if 75 < value < 90:
return "It is Summer now. A cooling setpoint is active at high level."
elif 60 < value < 75:
return "It is Summer now. A cooling setpoint is active at low level."
return "Cooling setpoint is outside the defined operational ranges."
def describe_heating_setpoint(value, timestamp):
"""Describes the heating setpoint status based on value and timestamp."""
month = timestamp.month
if month <= 6 or month == 12:
if 71 < value < 90:
return "It is not Summer now. A heating setpoint is active at high level."
elif 60 < value < 71:
return "It is not Summer now. A heating setpoint is active at low level."
else:
if 67 < value < 90:
return "It is Summer now. A heating setpoint is active at high level."
elif 60 < value < 67:
return "It is Summer now. A heating setpoint is active at low level."
return "Heating setpoint is outside the defined operational ranges."
def describe_damper_position(value):
"""Describes the actual damper position."""
abs_value = abs(value)
if abs_value <= 30:
return "The damper is currently almost closed, restricting most of the airflow."
elif 30 < abs_value <= 60:
return "The damper is slightly open, providing minimum ventilation."
elif 60 < abs_value <= 90:
return "The damper is moderately open to meet normal demands."
elif 90 < abs_value:
return "The damper is wide open to deliver maximum airflow."
return "Damper position is in an unhandled state."
def describe_reheat_valve_command(value):
"""Describes the reheat valve command."""
if value < 0 or value > 100:
return "Invalid data: The reheat valve command is outside the valid 0-100% range."
elif 0 <= value <= 33:
return "The reheat system is active with a gentle heating command."
elif 33 < value <= 66:
return "The reheat system is operating with a significant heating command."
else:
return "The reheat system is operating at full capacity."
def describe_damper_command(value):
"""Describes the damper command."""
if value > 5 or value < -5:
return "Invalid data: The damper command signal is outside its expected operational range."
elif value <= 0:
return "The system is commanding the damper to close or reduce its opening."
elif 0 < value <= 1:
return "The system is commanding the damper to a low open position."
elif 1 < value <= 2:
return "The system is commanding the damper to a moderate open position."
else:
return "The system is commanding the damper to a high open position."
def describe_sup_flow_sp(value):
"""Describes the supply airflow setpoint."""
if value < 0 or value > 2000:
return "Invalid data: The target supply airflow is outside the physically expected range."
elif 0 <= value <= 400:
return "The target supply airflow is set to a low level."
elif 400 < value <= 800:
return "The target supply airflow is set to a medium level."
else:
return "The target supply airflow is set to a high level."
def describe_cooling_command(value):
"""Describes the cooling command."""
if value < 0 or value > 100:
return "Invalid data: The cooling command is outside the valid 0-100% range."
elif value < 25:
return "The cooling demand is very low."
elif 25 <= value <= 50:
return "The cooling demand is at low level."
elif 50 < value <= 75:
return "The cooling demand is at medium level."
else:
return "The cooling demand is high."
def describe_heating_command(value):
"""Describes the heating command."""
if value < 0 or value > 100:
return "Invalid data: The heating command is outside the valid 0-100% range."
elif value < 25:
return "The heating demand is very low."
elif 25 <= value <= 50:
return "The heating demand is at low level."
elif 50 < value <= 75:
return "The heating demand is at medium level."
else:
return "The heating demand is high."
def describe_occupied_status(value):
"""Describes the occupied status."""
if value == 1:
return "The system is in 'Unoccupied' mode."
elif value == 3:
return "The system is in 'Occupied' mode."
else:
return "Invalid data: The occupied command is not a recognized mode."
def main(args):
"""Main function to load data, generate consolidated descriptions for each room,
and save them as separate JSON files."""
print("Loading data...")
try:
df = pd.read_csv(args.input_file, parse_dates=['Timestamp'])
except FileNotFoundError:
print(f"Error: Input file not found at '{args.input_file}'")
return
except KeyError:
print("Error: 'Timestamp' column not found in the input file. Please check the column name.")
return
# Create the output directory
os.makedirs(args.output_dir, exist_ok=True)
print(f"Output directory '{args.output_dir}' is ready.")
# Get all unique room numbers
unique_rooms = df['Room'].unique()
print(f"Found {len(unique_rooms)} unique rooms to process.")
# Loop through each room
for room_num in tqdm(unique_rooms, desc="Processing all rooms"):
room_df = df[df['Room'] == room_num].copy()
if room_df.empty:
continue
room_descriptions = {}
for index, row in room_df.iterrows():
timestamp = row['Timestamp']
# Change the timestamp format for the JSON key
timestamp_key = timestamp.strftime('%Y%m%d%H%M')
# Generate and combine descriptions
desc_cool_sp = describe_cooling_setpoint(row['Actual Cooling Setpt'], timestamp)
desc_cool_cmd = describe_cooling_command(row['Cooling Command'])
desc_heat_sp = describe_heating_setpoint(row['Actual Heating Setpt'], timestamp)
desc_heat_cmd = describe_heating_command(row['Heating Command'])
desc_sup_flow_sp = describe_sup_flow_sp(row['Actual Sup Flow SP'])
desc_damp_cmd = describe_damper_command(row['Damper Command'])
desc_damp_pos = describe_damper_position(row['Actual Damper Position'])
current_descriptions = {
"Occupied_Status_Description": describe_occupied_status(row['Occupied Status']),
"cooling_command": desc_cool_cmd,
"cooling_setpoint": desc_cool_sp,
"heating_command": desc_heat_cmd,
"heating_setpoint": desc_heat_sp,
"supply_air_flow_setpoint": desc_sup_flow_sp,
"damper_command": desc_damp_cmd,
"damper_position": desc_damp_pos,
}
room_descriptions[timestamp_key] = current_descriptions
# Save the JSON file at the end of each room's loop
output_filename = f"{room_num}.json"
output_path = os.path.join(args.output_dir, output_filename)
with open(output_path, 'w', encoding='utf-8') as f:
json.dump(room_descriptions, f, indent=4, ensure_ascii=False)
print(f"\nProcessing complete. All JSON files have been saved to '{args.output_dir}'.")
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Generate consolidated textual descriptions for all HVAC rooms and save to separate JSON files.')
parser.add_argument('--input_file', type=str, default='./Bear.csv',
help='Path to the input CSV file containing HVAC data.')
parser.add_argument('--output_dir', type=str, default='Temperature_Control_Descriptions',
help='Path to the directory where output JSON files will be saved.')
args = parser.parse_args()
main(args)