%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
data = pd.read_csv('202February',
skiprows=3, # ignore the first 3 rows of data
sep=';', # semicolon is used to separate data values
index_col=1, # use column 1 as the dates to index the data
parse_dates=True) # convert the date string into a date object
data['CO2'].plot()
def process_data(begin, end, data, plot=False):
x = data['Timestamp'][begin:end]
x = x - x[0]
y = data['CO2'][begin:end]
fit = np.polyfit(x,y,1)
room_ppm_per_second = fit[0]
room_ppm_per_minute = room_ppm_per_second * 60
ppm_per_student_per_minute = 0.176
num_students = room_ppm_per_minute / ppm_per_student_per_minute
if plot:
yfit = np.polyval(fit, x)
plt.plot(x, y)
plt.plot(x, yfit)
plt.xlabel ("seconds")
plt.ylabel ("ppm")
print('Start time = {}'.format(begin))
print('End time = {}'.format(end))
print('Carbon dioxide rate of increase {:.2f} ppm per minute'.format(room_ppm_per_minute))
print('Estimated number of students: {:.0f}'.format(num_students))
print()
class_starts = (
('2015-02-2 10:35', '2015-02-2 12:10'),
('2015-02-4 10:35', '2015-02-4 12:10'),
('2015-02-9 10:35', '2015-02-9 12:10'),
('2015-02-11 10:35', '2015-02-11 12:10'),
('2015-02-16 10:35', '2015-02-16 12:10'),
('2015-02-18 10:35', '2015-02-18 12:10'),
('2015-02-23 10:35', '2015-02-23 12:10'),
('2015-02-25 10:35', '2015-02-25 12:10'),
)
for begin, end in class_starts:
process_data(begin, end, data, plot=True)
def process_data(begin, end, data, plot=False):
x = data['Timestamp'][begin:end]
x = x - x[0]
y = data['CO2'][begin:end]
fit = np.polyfit(x,y,1)
room_ppm_per_second = fit[0]
room_ppm_per_minute = room_ppm_per_second * 60
ppm_per_student_per_minute = 0.176
num_students = room_ppm_per_minute / ppm_per_student_per_minute
if plot:
yfit = np.polyval(fit, x)
plt.plot(x, y)
plt.plot(x, yfit)
plt.xlabel ("seconds")
plt.ylabel ("ppm")
print('Start time = {}'.format(begin))
print('End time = {}'.format(end))
print('Carbon dioxide rate of increase {:.2f} ppm per minute'.format(room_ppm_per_minute))
print('Estimated number of students: {:.0f}'.format(num_students))
print()
class_starts = (
('2015-02-3 12:50', '2015-02-3 2:40'),
('2015-02-5 12:50', '2015-02-5 2:40'),
('2015-02-10 12:50', '2015-02-10 2:40'),
('2015-02-12 12:50', '2015-02-12 2:40'),
('2015-02-17 12:50', '2015-02-17 2:40'),
('2015-02-19 12:50', '2015-02-19 2:40'),
('2015-02-24 12:50', '2015-02-24 2:40'),
('2015-02-26 12:50', '2015-02-26 2:40'),
)
for begin, end in class_starts:
process_data(begin, end, data, plot=True)