Example #1
0
def update(load_data, start_date, end_date, models,
           characteristics_y_axis_selection, highlight_variable,
           highlight_value):
    children = []
    style = calculate_style(
        models)  #calculates the layout style for the characteristics graph
    if (characteristics_y_axis_selection !=
            'None'):  # if a y axis value is chosen to compare
        x_axis_layout = {
            'title': 'Date',
            'tickformat': '%a %Y-%m-%d %H:%M',
            'automargin': True
        }  #format of x axis
        children.append(
            dcc.Graph(id=f'characteristics-graph-{datetime.now()}',
                      figure=add_visualised_graph(
                          load_data,
                          start_date,
                          end_date,
                          models,
                          x_axis_layout,
                          characteristics_y_axis_selection,
                          highlight_variable=highlight_variable,
                          highlight_value=highlight_value),
                      style=style))
    return children
Example #2
0
 def test_return_highlighted_holidays(self):
     start_date = datetime(1999, 1, 1)
     end_date = datetime(2019, 1, 1)
     highlight_variable = 'Holiday'
     highlight_value = 'All'
     output = add_visualised_graph(self.load_data,
                                   start_date,
                                   end_date,
                                   highlight_variable=highlight_variable,
                                   highlight_value=highlight_value)
     assert_array_equal(output['data'][0]['x'], [
         datetime(2018, 1, 1, 0),
         datetime(2018, 1, 2, 0),
         datetime(2018, 1, 3, 0),
         datetime(2018, 1, 4, 0),
         datetime(2018, 1, 5, 0)
     ])
     # assert_array_equal(output['data'][1]['x'], [datetime(2018, 1, 1, 0), datetime(
     #     2018, 1, 1, 1), datetime(2018, 1, 2, 0), NaT, datetime(2018, 1, 4, 0)])
     # Pandas internal NAT type does not work with assert_array_equal
     self.assertEqual(len(output['data'][1]['x']), 5)
     self.assertEqual(output['data'][1]['x'][0], datetime(2018, 1, 1, 0))
     self.assertEqual(output['data'][1]['x'][1], datetime(2018, 1, 2, 0))
     self.assertEqual(output['data'][1]['x'][2], datetime(2018, 1, 3, 0))
     self.assertIsInstance(output['data'][1]['x'][3],
                           pd._libs.tslibs.nattype.NaTType)
     self.assertEqual(output['data'][1]['x'][4], datetime(2018, 1, 5, 0))
     assert_array_equal(output['data'][1]['y'],
                        [111., 222., 333., None, 555])
     self.assertEqual(output['data'][1]['name'], 'Highlighted Load')
     self.assertEqual(output['data'][1]['marker']['color'], 'red')
     self.assertEqual(output['data'][1]['line']['width'], 2)
Example #3
0
 def test_return_ranged_and_1_displaced_model_out_of_range_and_1_in_range(
         self):
     start_date = '2018-01-02'
     end_date = '2018-01-04'
     models = [
         dict(model_name='model 1',
              model_type='displacement',
              model_color='red',
              displacement_value=96,
              displacement_unit='Half Hours'),
         dict(model_name='model 2',
              model_type='displacement',
              model_color='red',
              displacement_value=48,
              displacement_unit='Half Hours')
     ]
     output = add_visualised_graph(self.load_data, start_date, end_date,
                                   models, {})
     assert_array_equal(output['data'][0]['x'], [
         datetime(2018, 1, 2, 0),
         datetime(2018, 1, 3, 0),
         datetime(2018, 1, 4, 0)
     ])
     assert_array_equal(output['data'][0]['y'], [222, 333, 444])
     assert_array_equal(output['data'][1]['x'], [
         datetime(2018, 1, 2, 0),
         datetime(2018, 1, 3, 0),
         datetime(2018, 1, 4, 0)
     ])
     assert_array_equal(output['data'][1]['y'], [111, 222, 333])
     self.assertEqual(len(output['data']), 2)
Example #4
0
 def test_return_multiple_date_range(self):
     start_date = datetime(2018, 1, 1)
     end_date = datetime(2018, 1, 2)
     output = add_visualised_graph(self.load_data, start_date, end_date)
     assert_array_equal(output['data'][0]['x'],
                        [datetime(2018, 1, 1, 0),
                         datetime(2018, 1, 2, 0)])
     self.assertEqual(output['data'][0]['name'], 'Actual Load')
Example #5
0
 def test_return_all_date_range(self):
     start_date = datetime(1999, 1, 1)
     end_date = datetime(2019, 1, 1)
     output = add_visualised_graph(self.load_data, start_date, end_date)
     assert_array_equal(output['data'][0]['x'], [
         datetime(2018, 1, 1, 0),
         datetime(2018, 1, 2, 0),
         datetime(2018, 1, 3, 0),
         datetime(2018, 1, 4, 0),
         datetime(2018, 1, 5, 0)
     ])
Example #6
0
 def test_return_highlighted_weekends(self):
     start_date = datetime(1999, 1, 1)
     end_date = datetime(2019, 1, 1)
     highlight_variable = 'Day'
     highlight_value = 'Weekend'
     output = add_visualised_graph(self.load_data,
                                   start_date,
                                   end_date,
                                   highlight_variable=highlight_variable,
                                   highlight_value=highlight_value)
     assert_array_equal(output['data'][1]['y'],
                        [111., 222., None, None, 555])
Example #7
0
 def test_return_none_start_date_none(self):
     start_date = None
     end_date = datetime(2019, 1, 1)
     models = [
         dict(model_name='model 1',
              model_color='red',
              displacement_value=96,
              displacement_unit='Half Hours')
     ]
     output = add_visualised_graph(self.load_data, start_date, end_date,
                                   models, {})
     self.assertEqual(output, None)
Example #8
0
 def test_return_highlighted_workdays(self):
     start_date = datetime(1999, 1, 1)
     end_date = datetime(2019, 1, 1)
     highlight_variable = 'Day'
     highlight_value = 'Workday'
     output = add_visualised_graph(self.load_data,
                                   start_date,
                                   end_date,
                                   highlight_variable=highlight_variable,
                                   highlight_value=highlight_value)
     assert_array_equal(output['data'][1]['y'],
                        [None, None, 333., 444., None])
Example #9
0
 def test_return_ranged_and_regression_error(self, mock_function):
     mock_function.side_effect = Exception()
     start_date = '2018-01-02'
     end_date = '2018-01-03'
     models = [
         dict(model_name='model1',
              model_type='regression',
              model_color='red',
              coefficients=[111.0],
              intercept=0,
              x_columns=["Temperature Last Week"],
              corrected_column=None)
     ]
     output = add_visualised_graph(self.load_data, start_date, end_date,
                                   models, {})
     assert_array_equal(output['data'][0]['x'],
                        [datetime(2018, 1, 2, 0),
                         datetime(2018, 1, 3, 0)])
     assert_array_equal(output['data'][0]['y'], [222, 333])
     self.assertEqual(len(output['data']), 1)
def update(load_data, start_date, end_date, models,
           characteristics_y_axis_selection, highlight_variable,
           highlight_value):
    children = []
    style = calculate_style(models, characteristics_y_axis_selection
                            )  #calculate layout style for load graph
    x_axis_layout = calculate_x_axis_layout(
        characteristics_y_axis_selection
    )  #calculate the x axis layout for load graph
    children.append(
        dcc.Graph(id=f'load-data-graph-{datetime.now()}',
                  figure=add_visualised_graph(
                      load_data,
                      start_date,
                      end_date,
                      models,
                      x_axis_layout,
                      highlight_variable=highlight_variable,
                      highlight_value=highlight_value),
                  style=style))
    return children
Example #11
0
 def test_return_no_date_range_start_after_end(self):
     start_date = datetime(2019, 1, 1)
     end_date = datetime(2018, 1, 1)
     output = add_visualised_graph(self.load_data, start_date, end_date)
     assert_array_equal(output['data'][0]['x'], [])
Example #12
0
 def test_return_single_date_range(self):
     start_date = datetime(2018, 1, 1)
     end_date = datetime(2018, 1, 1)
     output = add_visualised_graph(self.load_data, start_date, end_date)
     assert_array_equal(output['data'][0]['x'], [datetime(2018, 1, 1, 0)])