def testAccuracyRlai(self): #Test if hour when max people in room is 7pm ie 19hr for 14 feb 2019 r = Reinforcement('2019-02-14.csv', True) sen_files = r.get_sensor_original_file() r.parse_file(sen_files) out = r.q_learning() self.assertEqual(out, "19")
def testCalcPeakTimeMethod(self): r = Reinforcement('2019-02-14.csv', True) sen_files = r.get_sensor_original_file() r.parse_file(sen_files) time = r.calc_peak_time(r.humiditydict['2019-02-14.csv']) expectedDate = datetime(2019, 2, 14, 19, 47, 1) self.assertEqual(time, expectedDate)
def update_humidity_graph(selcted_date): file_name = file_download_csv(selcted_date) df = pd.read_csv(file_name, sep=',', parse_dates=['Time']) df = df.sort_values(by='Time') r = Reinforcement(file_name, False) sen_files = r.get_sensor_original_file() r.parse_file(sen_files) out = r.q_learning() time = selcted_date + " " + str(out) + ":00:00" qdate = datetime.strptime(time, "%Y-%m-%d %H:%M:%S") endtime = selcted_date + " " + str(int(out) + 1) + ":00:00" endtime = datetime.strptime(endtime, "%Y-%m-%d %H:%M:%S") df1 = df[(df.Time > qdate) & (df.Time < endtime)] return { 'data': [{ 'x': df.Time, 'y': df.Humidity, 'name': 'Humidity', 'scatter': { 'width': 1 } }, { 'x': df1.Time, 'y': df1.Humidity, 'name': 'Max people', 'scatter': { 'width': 1 } }], 'layout': { 'title': 'Humidity', 'xaxis': { 'title': 'Time' }, 'yaxis': { 'title': 'Humidity' } } }
def update_temp_graph(selcted_date, tab): file_name = file_download_csv(selcted_date) df = pd.read_csv(file_name, sep=',', parse_dates=['Time']) df = df.sort_values(by='Time') r = Reinforcement(file_name, True) sen_files = r.get_sensor_original_file() result = r.parse_file(sen_files) if result: out = r.q_learning() time = selcted_date + " " + str(out) + ":00:00" qdate = datetime.strptime(time, "%Y-%m-%d %H:%M:%S") endtime = selcted_date + " " + str(int(out) + 1) + ":00:00" endtime = datetime.strptime(endtime, "%Y-%m-%d %H:%M:%S") df1 = df[(df.Time > qdate) & (df.Time < endtime)] if tab == 'tab-1': return html.Div([ dcc.Graph(id='graph-1-tabs', figure={ 'data': [{ 'x': df.Time, 'y': df.Temperature, 'scatter': { 'width': 1, 'shape': 'spline' } }], 'layout': { 'xaxis': { 'title': 'Time' }, 'yaxis': { 'title': 'Temperature' } } }) ]) elif tab == 'tab-2': return html.Div([ dcc.Graph(id='graph-2-tabs', figure={ 'data': [{ 'x': df.Time, 'y': df.Humidity, 'name': 'Humidity', 'scatter': { 'width': 1 } }, { 'x': df1.Time, 'y': df1.Humidity, 'name': 'Max people', 'scatter': { 'width': 1 } }], 'layout': { 'xaxis': { 'title': 'Time' }, 'yaxis': { 'title': 'Humidity' } } }) ]) elif tab == 'tab-3': return html.Div([ dcc.Graph(id='graph-1-tabs', figure={ 'data': [{ 'x': df.Time, 'y': df.Pressure, 'line': { 'width': 1, 'shape': 'spline' } }], 'layout': { 'xaxis': { 'title': 'Time' }, 'yaxis': { 'title': 'Pressure' } } }) ])
def testValidFile(self): #Test if valid file is read and return r = Reinforcement("2019-02-14.csv", False) result = r.get_sensor_original_file() self.assertEqual("2019-02-14.csv", result.name)
def testInvalidFile(self): #Test if system exit with code 1 on invalid file name with self.assertRaises(SystemExit) as context: r = Reinforcement("Badfile123.txt", False) r.get_sensor_original_file() self.assertEqual(context.exception.code, 1)
def testDataPresent(self): #Test if data present for selected date r = Reinforcement('2019-02-14.csv', False) sen_files = r.get_sensor_original_file() result = r.parse_file(sen_files) self.assertEqual(result, True)