You are on page 1of 35

Madhya Pradesh SLDC Electricity load forecasting

Project Code Documentation

A web application to forecast electricity power data.


We are using very high level Python web framework Django for server as well
as frontend. Django model view template we are using here. For storing and
retrieving data we are using Postgres database.

We are forecasting different type of time data from 15min to year based on
Machin learning models.
Our Machine learning models are using previous actual data to forecast power
data.

Basically the method we are using is, we are taking previous input data from
postgres database saving into csv file inside test folder. We are using scheduler
python library In order to run models. We are using test file as input in ML
models and save output as predict file inside predict folder. Then final we’ll use
this forecasted data to store and display.
For displaying we are using javascript chart.js.

Starting from database structur in django called models.


Basic model fields are there and not too much complex structur -

DOCUMENTATION - STLF DATABASE

In this documentation, we have discussed 22 tables, and each table has their own
constraints and indexes.
● Auth_group :- this table contains the information of the authorized group.
Columns of auth_group :-
1. Id :- id of authorized group.
2. Name :- name of authorized group.
Constraints:-
1. name should be unique
2. id is used to uniquely identifies each record in table

● auth_group_permissions :- this table contains the permissions of all


authorized groups.
Columns of auth_group_permissions:-
1. Id:- id for each group permissions.
2. Group_id:- id assigned to group
3. Permissions_id:- id assigned for the permission.
Constraints:-
1. Group_id, permissions_id should be unique
2. id is used to uniquely identify each record in the table.
3.Permissions_id is referred from the id column of Auth_permissions.
4. Group_id is referred from the id column of auth_group.

● Auth_permissions:- this table defines the permissions and their permissions


has been defined in the form of codename
Columns of Auth_permissions:-
1. Id:- id for the permissions
2. Name:- name of the permissions
3. Content_type_id:- id assigned to the type of content
4. Codename:- codename of the permissions.
Constraints:-
1. Content_type_id, Codename should be unique
2. id is used to uniquely identifies each record in table
3. Content_type_id is referred from the id column of django_content_type.

● Auth_user:- this table contains the list of authorized user


Columns of auth_user:-
1. Id:- id assigned to authorized user
2. Password:- password assigned to/given by authorized user.
3. Last login:- date and time of last login by the user.
4. Is_supervisor:- it tells whether the user is supervisor or not.
5. Username
6. First_name:- first name of user.
7. Last_name:- last name of user.
8. Email:- email address of user.
9. Is_staff:- whether the user is staff or not.
10. Is_active:- whether the user is active or not.
11. Date_joined:- joining date of user.
Constraints:-
1. Username should be unique
2. id is used to uniquely identifies each record in table

● Auth_user_groups:- this table defines a list of users representing their


groups.
Columns of Auth_user_groups:-
1. Id:- id assigned to the execution
2. User_id :- id of user
3. Group_id:- id of user’s respective group.
Constraint:-
1. User_id,group_id should be unique
2. id is used to uniquely identifies each record in table
3. Group_id is referred from the id column of auth_group.
4. User_id is referred from the id_column of auth_user.

● Auth_user_user_permissions:- it defines users with their respective


permissions.
Columns of auth_user_user_permissions:-
1. Id:- id assigned to the execution.
2. User_id:- id of the user
3. Permissions_id:- id of the permission.
Constraint:-
1. User_id, permissions_id should be unique
2. id is used to uniquely identifies each record in the table
3. Permission_id is referred from the id column of auth_permission.
4. User_id is referred from the id column of auth_user.

● Django_admin_log:- it contains the log data of changes done by a Django


admin user.
Columns of Django_admin_log:-
1. Id:- id assigned to the execution.
2. Action_time:- date & time of the action taken by administrator.
3. Object_id:- The textual representation of the modified object’s primary key
4. Object_repr:-The object`s representation after the modification
5. Action_flag:- id of the action.(1 for Addition, 2 for update, 3 for delete).
6. Change_message:- defines the change the django admin user has made.
7. Content_type_id:-id assigned to the type of contents.
8. User_id:-id of the user that performs an action.
Constraint:-
1. User_id, permissions_id should be unique
2. id is used to uniquely identifies each record in table
3. Action flag should be equal or more than 0
4. Content_type_id is referred from the id column of
django_content_type.
5. User_id is referred from the id column of auth_user.

● Django_content_type:- this table defines the contents belonging to their


applications.
Columns of Django_content_type:-
1. Id:- id assigned to the content.
2. App_label:- the application where content has been labeled.
3. Model:-content which is associated with the applications.
Constraint:-
1. app_label, model should be unique
2. id is used to uniquely identifies each record in table

● Django_migrations:- this table contains all the migration data that take place
in this application.
Columns of django_migrations:-
1. Id :- id assigned to the migration data.
2. App:- the application where migration has been labeled.
3. Name:- the changes have been made in the application.
4. Applied:- date & time of applied migration task.

● Django_sessions:- this table contains the sessions and their expiry date
Columns of django_sessions:-
1. Session_key:- key for particular session.
2. Session_data:- data of the particular session.
3. Expire_date:- date of session expiry.

● Stlf_main_empmast:- this table contains all the employees email and their
role
Columns of stlf_main_empmast:-
1. Id:- id of employee
2. Email:-email id of employee
3. role:- role of employee

● Stlf_main_forecast:- this table contains the main forecast details of each


region with their respective blocks.
Columns of stlf_main_forecast:-
1. Id:- id for the forecast.
2. Date:- date of the forecast.
3. Block:- the hour where forecasting takes place.
4. Block_type:- the data taken in the specific interval (e.g.:- one hour.)
5. Insertion_ts:-id assigned for inserting the records.
6. Region:- region for the forecast data.
7. Load:- expected load for the region during that block.
8. H3rr:- Rainfall of the region during the block in mm.
9. Ht :-Temperature of the region during the block in degree fahrenheit.
10. Hu:- Humidity of the region during the block.
11. HVP:- Wind speed of the region during the block
12. Hpsl:- Air Pressure of the region during the block.
13. User:- data uploaded in block wise or hourwise by the system.
14. Revision:- it is used for marking/tagging morning slot & evening slot.

● stlf_main_forecast_monthly:-this table contains the monthly forecast


details of each region with their respective blocks.
Columns of stlf_main_forecast_monthly:-
1. Id:- id of the forecast
2. Date:- date of the forecast
3. Block_type:- the data taken in the specific interval (e.g.:- one hour.)
4. Insertion_ts:- id assigned for inserting the records.
5. Load:- expected load supplied in the region during the block.
6. Revision:- it is used for marking/tagging morning slot & evening slot
forecast.
7. Region:- region for the monthly forecast data

● stlf_main_forecast_weekly:-this table contains the weekly forecast details of


each region with their respective blocks.
Columns of stlf_main_forecast_weekly:-
1. Id:- id of the forecast
2. Date:- date for the forecast
3. Block_type:- the data taken in the specific interval (e.g.:- one hour.)
4. Insertion_ts:- id assigned for inserting the records.
5. Load:- expected load supplied in the region during the block.
6. Revision:- it is used for marking/tagging morning slot & evening slot.
7. Region:- region for the weekly forecast data

● Stlf_main_forecast_yearly:-this table contains the yearly forecast details


Columns of stlf_main_forecast_weekly:-
1. Id:- id of forecast data
2. Year:-year of forecast data
3. Month:-month of forecast data
4. Energy requirement:- expected average amount of electricity demand
required over a period of an hour.
5. Peak load:-expected maximum level of electricity demand required over
a period of an hour.
6. Base load:- expected minimum level of electricity demand required over
a period of an hour.
7. Revision:- it is used for marking/tagging morning slot & evening slot.

● Stlf_main_loadactual:-this table contains the actual load data


Columns of stlf_main_loadactual:-
1. Date:- date of the actual data
2. Block_type:- the data taken in the specific interval (e.g.:- one hour,
fifteen minutes.)
3. Insertion_ts:- id assigned for inserting the records.
4. Region:- region of the actual data
5. Load:- load supplied in the region during the block.
6. Event_type:- any event occurred/going to be occur in the region
7. Id:- id assigned to the actual load data

● Stlf_main_menu:- this table defines that a user with their assigned role can
access specific tasks.
Columns of stlf_main_menu:-
1. Id:- id assigned to the options accessed by the role user.
2. Role:- role of the user.
3. Link:- link assigned to the particular role
4. Options:- task assigned to the particular role through the given link.
5. Parent:- the task belongs to a particular application.(e.g. Change
password is the part of account application)
● Stlf_main_onehour_missing_blocks:-this table contains the missing blocks
and their date and time.
Columns of stlf_main_onehour_missing_blocks:-
1. Id:- id for missing blocks
2. Timestamp:- time blocks of that missing blocks

● Stlf_main_roles:- this table contains the role for the stlf task.
Columns of stlf_main_roles:-
1. Id:- id for role
2. Roles:- name of the role

● Stlf_main_todaydatetype:- this table contains the festival and events in a


particular region for today’s and upcoming date’s data.
Columns of stlf_main_todaydatetype:-
1. Id:- id for data
2. Date:- date assigned to data.
3. Region:- region assigned to data.
4. Festival_holiday:- any festival organized on that date
5. Day_event:- any event happened in that date
6. insertion_ts:-id assigned for inserting the records.

● Stlf_main_viewurlpermission :- this table contains the url and it’s permission


Columns of stlf_main_viewurlpermission:-
1. Id:- unique id assigned to the options
2. Options:- the task executed by the assigned role user.
3. Link:- the weblink of the options
4. role _permission:- the role, which can execute the task(options)

● Stlf_main_weatheractual:- this table contains the actual weather data.


Columns of stlf_main_weatheractual:-
1. Id:- id assigned for actual weather data
2. Date:- date and time of the actual weather data
3. Block_type:- the data taken in the specific interval (e.g.:- one hour.)
4. Insertion_ts:-id assigned for inserting the records.
5. Region:- region of the actual weather data.
6. H3rr:- Rainfall of the region during the block
7. Ht:- Temperature of the region during the block in degree fahrenheit.
8. Hu:- Humidity of the region during the block in mm.
9. HVP:- Wind speed of the region during the block
10. Hpsl:- Air Pressure of the region during the block.
At first We are scheduling all our function to run, So we have scheduler.py

SLDC-Schedulers.py
Function:
1) start()
2) backup_files
3) forecast_daily
4) forecast_hourly
5) weather_forecast
6) hourly_weather
7) SCADA_Load
8) SCADA_Load_to_one_hour
9) forecast_daily_v2
10) forecast_daily_6pm_v2
11) forecast_hourly_v2
12) forecast_weekly
13) run_forecast_for_year
14) run_missing_data_check
15) run_backup_db

Function summary
1)start() : This function is starting schedulers at different time intervals. Common schedulers (line 29
-36) , 15 minutes model scheduler(line 43-46) ,weekly model schedulers (line 49) ,monthly model
schedulers (line 52) , missing data in load actual (line 55) , automatic database backup(line 58)

2)backup_files() : calling and returning file_function() (test.py line 9-15)

3)forecast_daily() : calling and returning daily_forecast_model() (views.py line 2836-2850) ,


insert_forecast_24Hr() (handlers.py line 631-691) , get_daily_forecast_v1() (handlers.py line 174-210),
get_day_ahead_forecast_v1() (handlers.py line 266-297)
4) forecast_hourly() : calling and returning hourly_forecast_model() (views.py line 2875-2888) ,
insert_forecast_3Hr() ( handlers.py line 770 -823) , get_hour_ahead_forecast_v1() (handlers.py line
114-144) , get_daily_forecast_v1() ( handlers.py line 174-210)

5) weather_forecast() : This function is common for 15 min and 1 hr models . this function is calling
and returning get_weather_forecast()(handlers.py 1232 -1322)

6) hourly_weather() : This function is calling and returning get_hourly_weather(handlers.py line


1138-1226)

7) SCADA_Load() : This function is calling and returning get_SCADA_data_v1()(handlers.py line


892-1012) , get_hour_ahead_forecast_v2() (handlers.py line 149-168),
get_daily_forecast_v2()(handlers.py line 216 -260)

8) SCADA_Load_to_one_hour() : This function is calling and returning


insert_onehour_block_actual_data()(handlers.py 1018-1097)

9) forecast_daily_v2() : This is a scheduler for 6am model


This function is calling and returning daily_forecast_model_v2()(views.py line 2853-2872) ,
insert_forecast_24Hr_v2()(handlers.py line 697-764), get_daily_forecast_v2()(handlers.py line 216-260),
get_day_ahead_forecast_v2()(handlers.py line 303-335)

10) forecast_daily_6pm_v2() : This is a scheduler for 6 pm model


This function is calling and returning daily_forecast_model_v2('6pm')(views.py line 2853-2872) ,
insert_forecast_24Hr_v2('6pm') (handlers.py line 697-764), get_day_ahead_forecast_v2()(handlers.py
line 303-335)

11) forecast_hourly_v2() : This function is calling and returning hourly_forecast_model_v2()


(views.py line 2891-2908), insert_forecast_3Hr_v2()(handlers.py line 829-886) ,
get_hour_ahead_forecast_v2() (handlers.py line 149-168), get_daily_forecast_v2()( handlers.py line
216-260)

12) forecast_weekly() : This function is calling and returning


create_input_csv_weekly_model()(handlers.py line 1328-1421) ,
get_and_insert_weekly_forecast()(handlers.py line 1427-1466)

13) run_forecast_for_year() : This function is calling and returning forecast_for_year()


(handlers.py line 1653-1658)

14) run_missing_data_check() : This function is calling and returning (handlers.py line 1939
-1955)
15) run_backup_db() : This function is calling and returning backup_db() (handlers.py line
1961-1979)

All your functions of one schedule, located inside handlers.py and views.py
So look at handles.py first.

SLDC – Handlers.py

This module contains brings together and houses all functions that perform
any computational or database related tasks.

Functions listed:

1. get_hour_ahead_forecast v1

2. get_hour_ahead_forecast v2

3. get_hour_ahead_forecast v5

4. get_daily_forecast v1

5. get_daily_forecast v2

6. get_day_ahead_forecast v1

7. get_day_ahead_forecast v2

8. reformat_day_ahead_forecast

9. reformat_hour_ahead_forecast
10. reformat_daily_forecast

11. reformat_daily_forecast_only_total

12. create_input_csv_model

13. insert_forecast_24Hr

14. insert_forecast_24Hr_v2

15. insert_forecast_3Hr

16. insert_forecast_3Hr_v2

17. remove_outliers

18. remove_outliers_from_database

19. get_SCADA_data_v1

20. insert_onehour_block_actual_data

21. display_weather_forecast

22. get_hourly_weather

23. get_weather_forecast

24. create_input_csv_weekly_model

25. get_and_insert_weekly_forecast

26. create_input_csv_yearly_model

27. get_and_insert_yearly_forecast

28. forecast_for_year

29. get_and_insert_monthly_actual

30. actual_for_month_lgbr
31. input_for_month_lgbr_stag2

32. forecast_for_month_lgbr_stag2

33. input_for_month_lgbr_stag1

34. forecast_for_month_lgbr_stag1

35. input_for_month_lgbr_stag1_april

36. forecast_for_month_lgbr_stag1_april

37. update_missing_data

38. check_loadactual

39. missing_data_check

40. backup_db

Types of functions:

o Display Functions: 1-7

o Helper Functions: 8-11

o Model Functions (CSV create and read): 12-16,24-29

o SCADA Function(s): 19

o Weather Functions: 21-23

o Database Operating Functions: 17,18,20,37-40

o LGBR Functions: 30-36

Function Definitions and Summaries:

· get_hour_ahead_forecast:
Obtains hour ahead forecast

get_hour_ahead_forecast_v1()

Line: 116

->obtains data from db (one hour frame)

get_hour_ahead_forecast_v2()

Line: 151

->obtains data from db (15 min frame)

get_hour_ahead_forecast_v5()

Line: 132

Same as V1 except, db query parameters

· get_daily_forecast

Obtains forecast for current day.

Get_daily_forecast_v1()

Line: 176

obtains data from db (one hour frame)

get_daily_forecast_v2()

Line: 218

obtains data from db (15 min frame)

· get_day_ahead_forecast

Obtains forecast for next day using day ahead prediction models.
get_day_ahead_forecast_v1()

Line: 268

obtains data from db (one hour frame)

get_day_ahead_forecast_v2()

Line: 305

obtains data from db (15 min frame)

· reformat_day_ahead_forecast()

Line: 343

Reformats the data in the format of day_ahead_forecast_v2.csv

Achieves so by obtaining data from db and performing a sequence of


operations: rounding off and dropping columns

· reformat_hour_ahead_forecast()

Line: 382

Reformats data in the format of hour_ahead_forecast_v2.csv

· reformat_daily_forecast()

Line: 423

Reformats data in the format of daily_forecast_v2.csv, includes data


formatting for individual Discoms.

· reformat_daily_forecast_only_total()
Line: 491

Reformats data for saving into CSV file but only for total load and not
individual Discoms.

· create_input_csv_model()

Line: 531

Creates a csv file for any given model i.e., daily/hourly

· insert_forecast_24Hr()

Creates 24Hr forecast objects and stores/updates them as necessary

Insert_forecast_24Hr():

Line: 633

**Not in use**

Insert_forecast_24Hr_v2():

Line: 699

Inserts 24Hr model prediction output in database

· insert_forecast_3Hr()

Creates 3Hr forecast objects and stores/updates them as necessary

Insert_forecast_3Hr():

Line: 772

**Not in use**

Insert_forecast_3Hr_v2():
Line: 894

Inserts 3Hr model prediction output in database

· remove_outliers()

Line: 967

Takes in DataFrame of load and detects outliers by doing mathematical


computations

· remove_outliers_from_database()

Line: 894

Detects and removes outliers in the entire database.

· get_SCADA_data_v1()

Line: 1062

Function for communicating with SCADA server, obtaining data, and


storing it in database. SCADA data arrives in 15-minute blocks.

· insert_onehour_block_actual_data()

Line: 1201

Saves actual usage data (one hour block) to database, if data is missing,
saves that as well

· display_weather_forecast()

Line: 1286
Obtains weather data from forecast object and returns a weather object

**Not in use**

· get_hourly_weather()

Line: 1321

Obtains hourly weather data from Darksky API and stores to database

· get_weather_forecast()

Line: 1415

Obtains 24Hr weather data from Darksky API and stores to database

· create_input_csv_weekly_model()

Line: 1511

Creates CSV for the weekly model of Total

· get_and_insert_weekly_forecast()

Line: 1610

Calculates weekly forecast data using prediction function defined for


weekly model and then saves it to database

· create_input_csv_yearly_model()

Line: 1655
Creates CSV file for yearly model

· get_and_insert_yearly_forecast()

Line: 1766

Calculates yearly forecast data using prediction function defined for


yearly model and then saves it to database

· forecast_for_year()

Line: 1836

Automatically calculates yearly forecast for current year using


get_and_insert_yearly_forecast function()

LGBR system explanation:

LBGR stands for Load Generation Balance Report, it is a yearly report


that is automatically calculated by schedulers twice a year, once in April
and once in October.

We predict data for the next year i.e. In April 2022 we will make
predictions for the time frame April 2023 – March 2024 using the data of
April 2022-March 2023, and two other data parameters.

The models that calculate LGBR report need to be fed data on a monthly
block basis, this is done by making a list of the months and then feeding
in data, the two other data parameters are dependent on the month in
concern, for month August 2022, we will use data of April 2022-March
2023 + August 2021 + August 2020.

Feeding this data month wise to the models generates LGBR predictions.

Function Execution sequence:


In April : input_for_month_lgbr_stag1_april() ->
forecast_for_month_lgbr_stag1_april()

In October:

input_for_month_lgbr_stag2() ->

forecast_for_month_lgbr_stag2() ->

input_for_month_lgbr_stag1()->

forecast_for_month_lgbr_stag1()

· get_and_insert_monthly_actual()

Line: 1847

Creates actual_lgbr objects from actual load data and saves them to
database.

· actual_for_month_lgbr()

Line: 1881

Automatically imports monthly actual load for current month using


get_and_insert_monthly_actual function()

· input_for_month_lgbr_stag2()

Line:1890

This function preps and formats the input for the prediction models of
LGBR, but since in October, the data till April is missing, we first make
prediction for the next 6 months i.e., till April. This functions preps and
formats data for feeding as input to those models and saves it as a CSV
file.
· forecast_for_month_lgbr_stag2()

Line: 1949

This function takes data prepped and saved by


input_for_month_lgbr_stag2() function and feeds it to prediction
models and saves their response to a CSV file so it can be used to
calculate a full yearly LGBR prediction.

· input_for_month_lgbr_stag1()

Line: 2010

Uses file saved by forecast_for_month_lgbr_stag2() i.e., prediction of


6 months and 6 months of actual data that already exists, preps and
formats it for feeding to LGBR models for prediction, saves it to a CSV
file.

· forecast_for_month_lgbr_stag1()

Line: 2075

Takes CSV file saved by input_for_month_lgbr_stag1() and feeds it to


LGBR prediction models to generate LGBR for next year. Saves it in
Display_forecast_lgbr objects.

· input_for_month_lgbr_stag1_april()

Line: 2136

Takes all available data i.e., current year + last year + second last year as
required by LGBR models (requirement specified above in LGBR system
explanation), formats it for input as required. Saves it into a CSV file.
· forecast_for_month_lgbr_stag1_april

Line: 2197

Takes CSV file saved by input_for_month_lgbr_stag1() and feeds it to


LGBR prediction models to generate LGBR for next year. Saves it in
Display_forecast_lgbr objects.

· update_missing_data

Line: 2259

Every time some SCADA data is not transferred, that data is missing
from the actual load data, this function is used to upload this data
manually.

· check_loadactual

Line: 2443

Checks for missing data in the actual load data from given start time.

· missing_data_check

Line: 2534

Calls check_loadactual for a time of around 8 weeks from current time.

· backup_db():

Line: 2545

Creates backup of current state of the database.


Your handles.py and views.py functions are using some of function to formate data,
located inside helpers.py

SLDC- helpers.py
Functions:
datetime_list_hour

datetime_list_15min

past_datetime_list_hour

next_datetime_list_hour

past_datetime_list_15min

next_datetime_list_15min

clear_file

number_of_days

send_email

Function definition and summary:


1)def datetime_list_hour(date_time, blocks, skip_blocks=0):
    date_time - starting timestamp

    blocks - number of hourly blocks => blocks = 3 (at time 00:00) with start_time true will give 00:00,
01:00, 02:00

  skip_blocks - number of hourly blocks to skip

  skip_blocks = 0 when we want blocks starting from the date_time

eg. if now time is 00:00 and we want time for 01:00 and so on then skip_blocks = 1

This function is updating datetime_list hourly covering all the blocks and returning the datetime_list

list in string format.

2)def datetime_list_15min(date_time, blocks, skip_blocks=0):

    date_time - starting timestamp

    blocks - number of 15 min blocks => blocks = 3 (at time 00:00) with start_time true will give 00:00,

00:15, 00:30

skip_blocks - number 15 min blocks to skip

   skip_blocks = 0 when we want blocks starting from the date_time

   eg. if now time is 00:00 and we want time for 01:00 and so on then skip_blocks = 4

   # range(3) - 0,1,2  | range(1,3) 1,2 SO if start_time is false need to add a value to hours

   # if skip_blocks = 4 | now = 00:15 range(4, 7) - 4,5,6 : 01:15, 01:30, 01:45

This function is updating datetime_list every 15 minutes , covering all the blocks and returning the

datetime_list list in string format.

3)def past_datetime_list_hour(date_time, blocks, skip_blocks=0):


This function is updating datetime_list hourly covering all the blocks and returning the datetime_list

list in string format.

4)def next_datetime_list_hour(date_time, blocks, skip_blocks=0):


This function is updating datetime_list hourly covering all the blocks and returning the datetime_list

list in string format.


5)def past_datetime_list_15min(date_time, blocks, skip_blocks=0):
This function is updating datetime_list every 15 minutes covering all the blocks and returning the

datetime_list list in string format.

6)def next_datetime_list_15min(date_time, blocks, skip_blocks=0):


This function is updating datetime_list every 15 minutes covering all the blocks and returning the

datetime_list list in string format.

7)def clear_file(filename,message) :
This function is deleting the content of a file named filename and printing a message. From line 96-99

8)def number_of_days(y,m):
This function is a simple function to calculate which year is the leap year.

9)def send_email(for_database=False):
This function is used to debug mail .
AT last your views function will work for display.

SLDC – Views.py
We have one function to detect outlier from data.

SLDC - Outlier Case Handling

Outlier Case Handling involves detecting and removing outliers from data for better
prediction results.

Function Definition and Summary :

- remove_outliers(df_load , time_for_outlier) :

Located in handlers.py file Line 1009.

df_load : dataframe containing current 15 min block data from which


we use three values :
df_load[‘load’] : load data which is checked if it is an outlier or
not and replaced if it is.
df_load[‘region’] : related discom region
df_load[‘block_type’] : block type of current data,i.e,15 min.
time_for_outlier : datetime representation of 15 min block just preceding the
current block.

The function uses a list of load data of last 287 15 min blocks of data and the
df_load[‘load’] is appended to the list.Moving averages with a window size of
48 and interquartile range is calculated for the above list of data and this is
used to create a list of upper and lower bounds using a mean_threshold
parameter of value 2.5 using the formulas :
upper_bounds[ ] = moving_averages[ ] + mean_threshold*interquartile_range
lower_bounds[ ] = moving_averages[ ] - mean_threshold*interquartile_range

Then,the current load data is checked if it lies within the upper bound and
lower bound and df_load[‘load’] is modified if it does not and the updated
dataframe is returned.
  

You might also like