Skip to content

Commit

Permalink
figuring out boxplots
Browse files Browse the repository at this point in the history
  • Loading branch information
jadecodes8191 committed Jun 27, 2020
1 parent 3cf1ed4 commit 4757e2d
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 33 deletions.
82 changes: 82 additions & 0 deletions boxplot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import matplotlib.pyplot as plt
import pandas as pd
import datetime
import numpy as np

df = pd.read_csv("graph_tester.csv")

cold = pd.read_excel("cold.xlsx")
warm = pd.read_excel("warm.xlsx")
high_co2 = pd.read_excel("high_co2.xlsx")
low_co2 = pd.read_excel("low_co2.xlsx")
orig_db = pd.read_csv("basic_weekly.csv")
print(orig_db)
co2_or_temp = int(input("1 for High CO2, 2 for Warm, 3 for Low CO2, 4 for Cold"))

temp_df = pd.DataFrame()
if co2_or_temp == 1:
temp_df = high_co2
elif co2_or_temp == 2:
temp_df = warm
elif co2_or_temp == 3:
temp_df = low_co2
else:
temp_df = cold

plt.figure()
temp_df = temp_df.set_index("Room #").drop("Outside Air", errors='ignore')
temp_df = temp_df.drop("Field House NW", errors='ignore')
temp_df = temp_df.drop("Field House NE", errors='ignore')
temp_df = temp_df.drop("Field House SW", errors='ignore')
temp_df = temp_df.drop("Field House SE", errors='ignore')
# TODO: Should we drop Field House numbers?
temp_factor = temp_df.head()
print(temp_factor)
temp_factor = temp_factor.T
i_df_list = []
room_num_list = []
for i in temp_factor:
i_df = orig_db.set_index("Room #").T[i]
if co2_or_temp % 2 == 0:
i_df_list.append(i_df.T['Temperature'])
else:
i_df_list.append(i_df.T['CO2'])
room_num_list.append(i)

print(i_df_list)
ax = plt.axes()
if co2_or_temp == 1:
ax.set_title("CO2 in 5 rooms w/ highest CO2")
elif co2_or_temp == 2:
ax.set_title("Temperature in warmest 5 rooms")
elif co2_or_temp == 3:
ax.set_title("CO2 in 5 rooms w/ lowest CO2")
else:
ax.set_title("Temperature in coldest 5 rooms")
room_num_list.reverse()
i_df_list.reverse()
print(room_num_list)
ax.set_yticklabels(room_num_list)
plt.boxplot(i_df_list, vert=False)
plt.show()

#try:
#orig_db = orig_db[orig_db["Room #"] == room_number]
#print(orig_db)
#print(orig_db["Timestamp"])
#orig_db = orig_db.reset_index()
#first_time = orig_db["Timestamp"][0]
#orig_db["Edited Timestamp"] = orig_db["Timestamp"].apply(lambda x: int((datetime.datetime.strptime(x, "%Y-%m-%d %H:%M:%S")).timestamp()))
#print(first_time)

#print("This is running")
#plt.figure()
#if co2_or_temp == 1:
#plt.boxplot(orig_db["CO2"])

#else:
#plt.boxplot(orig_db["Temperature"])
#plt.show()

#except IndexError:
#print("Your room is not in the list, sorry")
92 changes: 59 additions & 33 deletions mpl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,63 @@
room_number = input("What room?")
co2_or_temp = int(input("1 for CO2, 2 for Temp"))

orig_db = orig_db[orig_db["Room #"] == room_number]
print(orig_db)
print(orig_db["Timestamp"])
orig_db = orig_db.reset_index()
first_time = orig_db["Timestamp"][0]
orig_db["Edited Timestamp"] = orig_db["Timestamp"].apply(lambda x: int((datetime.datetime.strptime(x, "%Y-%m-%d %H:%M:%S")).timestamp()))
print(first_time)

print("This is running")
plt.figure()

new_list = []
int_list = []
for i in range(6):
temp = datetime.datetime.strptime(first_time, "%Y-%m-%d %H:%M:%S") + datetime.timedelta(i)
new_list.append(datetime.datetime.strftime(temp, "%Y-%m-%d"))
int_list.append(int(temp.timestamp()))

ax = plt.axes()
ax.set_xticks(int_list)# the problem with this is the scale
ax.set_xlabel("Time")
ax.set_ylabel("CO2 (ppm)")
if co2_or_temp == 1:
ax.set_title("CO2 vs. Time in room " + room_number)
else:
ax.set_title("Temperature vs. Time in room " + room_number)
ax.set_xlim(left=int_list[0], right=int_list[5])
ax.set_xticklabels(new_list)
if co2_or_temp == 1:
plt.plot(orig_db['Edited Timestamp'], orig_db["CO2"])
else:
plt.plot(orig_db["Edited Timestamp"], orig_db["Temperature"])
plt.show()
try:

orig_db = orig_db[orig_db["Room #"] == room_number]
print(orig_db)
print(orig_db["Timestamp"])
orig_db = orig_db.reset_index()
first_time = orig_db["Timestamp"][0]
orig_db["Edited Timestamp"] = orig_db["Timestamp"].apply(lambda x: int((datetime.datetime.strptime(x, "%Y-%m-%d %H:%M:%S")).timestamp()))
print(first_time)

print("This is running")
plt.figure()

new_list = []
int_list = []
for i in range(6):
temp = datetime.datetime.strptime(first_time, "%Y-%m-%d %H:%M:%S") + datetime.timedelta(i)
new_list.append(datetime.datetime.strftime(temp, "%Y-%m-%d"))
int_list.append(int(temp.timestamp()))

ax = plt.axes()
ax.set_xticks(int_list)
ax.set_xlabel("Time")
ax.set_ylabel("CO2 (ppm)")
if co2_or_temp == 1:
ax.set_title("CO2 vs. Time in room " + room_number)
ax.set_ylim(0, 2000) # should there be y-limits here or no?
else:
ax.set_title("Temperature vs. Time in room " + room_number)
ax.set_ylim(0, 90) # should there be y-limits here or no?
ax.set_xlim(left=int_list[0], right=int_list[5])
ax.set_xticklabels(new_list)
if co2_or_temp == 1:
plt.scatter(orig_db['Edited Timestamp'], orig_db["CO2"]) # line plot probably worked best but like...
else:
plt.scatter(orig_db["Edited Timestamp"], orig_db["Temperature"])
plt.show()

except IndexError:
print("Your room is not in the list, sorry")

# Scatter plot over time is good to see just one room
# End goal/result = dashboard
# !!box-and-whisker plots by room for a 1-d kind of view!!
# sensor issues --> 1 category? same numbers over time/165 intervals with problems/low co2 probably
# actually low/high co2/temperature
# bar charts for different groups
# 5 subplots with each day
# add into Word/PDF


# TODO: categorize sensor issues based on tells such as 165 problem intervals, the same numbers over time, and low co2

# TODO: turn weekly plots above into 5 daily subplots

# TODO: figure out how to add into a word doc/pdf

# TODO: update co2 minimum based on outside air values

# TODO: update task 0 to specify parameters

0 comments on commit 4757e2d

Please sign in to comment.