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 9:50', '2015-02-3 12:10'),
('2015-02-5 9:50', '2015-02-5 12:10'),
('2015-02-10 9:50', '2015-02-10 12:10'),
('2015-02-12 9:50', '2015-02-12 12:10'),
('2015-02-17 9:50', '2015-02-17 12:10'),
('2015-02-19 9:50', '2015-02-19 12:10'),
('2015-02-24 9:50', '2015-02-24 12:10'),
('2015-02-26 9:50', '2015-02-26 12:10'),
)
for begin, end in class_starts:
process_data(begin, end, data, plot=True)