<jupyter_start><jupyter_text>Demo grid object with functions<jupyter_code>import pandas as pd
import pandapower as pp
import os,sys,inspect
import matplotlib
import matplotlib.pyplot as pyplt
import plotly.graph_objs as go
import datetime
from datetime import date, timedelta
import copy
currentdir = os.path.abspath(os.getcwd())
parentdir = os.path.dirname(currentdir)
sys.path.insert(0,parentdir)
from capacitymap.analysis import analysis_check
from capacitymap import controllers
analysis_check.check_violations.counter=0
from capacitymap.grid import grid<jupyter_output><empty_output><jupyter_text>Create grid object and plot grid at normal operation<jupyter_code>#create a grid instance for testing
empt_df = pd.DataFrame(columns=['Start', 'End', 'Object_type','ObjectID', 'Status'])
net = pp.from_json( os.path.join(currentdir,'data\svedala\svedala.json'))
network = grid.Grid('test',net, {}, empt_df)
go.Figure(network.plot_traces())
network.project_df #empty tabel
network.config_dict #no configuration changes planned<jupyter_output><empty_output><jupyter_text>Store new project<jupyter_code>#new incoming project, here one line will be taken out-of-service for a time period
new_request = {'Start':datetime.datetime(2021,9,1), 
                'End':datetime.datetime(2021,9,3), 
                'Object_type':'line',
                'ObjectID':network.grid.line.name.loc[3], 
                'Status':False}

new_request2 = {'Start':datetime.datetime(2021,9,5), 
                'End':datetime.datetime(2021,9,15), 
                'Object_type':'line',
                'ObjectID':network.grid.line.name.loc[9], 
                'Status':False}

#project is stored
network.store_project_and_update_config(new_request)
network.store_project_and_update_config(new_request2)
network.project_df

#a record for every timestep, here 1 day is created for the stored project and the configuration change is stored on every timestep
network.config_dict<jupyter_output><empty_output><jupyter_text>Get grid model for specific date<jupyter_code>date = datetime.datetime(2021,9,1)
network.active_config = network.config_dict[date]
network.config()
go.Figure(network.plot_traces())
network.restore() #restore grid mdel back to normal grid<jupyter_output><empty_output><jupyter_text>Remove planned project<jupyter_code>project_to_drop = new_request
network.remove_project_and_update_config(project_to_drop)
network.project_df
network.config_dict<jupyter_output><empty_output><jupyter_text>Test new request before saving<jupyter_code>new_proj = {'Start':datetime.datetime(2021,9,1), 
                'End':datetime.datetime(2021,9,3), 
                'Object_type':'line',
                'ObjectID':network.grid.line.name.loc[4], 
                'Status':False}
#Generate dict of configuration related to new project
conf1 = grid.generate_config_from_project(new_proj)
conf1
#combine new project dict with already saved projects from config_dict
config_to_test = grid.combine_dict(conf1,network.config_dict)

# select active config based on time and config_dict with approved plans and new plan
test_date = datetime.datetime(2021,9,1)
network.active_config = config_to_test[test_date]
network.config()

# Analyse active config
analysis_res, exp = analysis_check.check_violations(network.grid)
print(analysis_res)

# Restore to normal before proceeding
network.restore()<jupyter_output>(True, True, True, True, False, False, False)
{'fraction_non_alphanumeric': 0.10064177362893816, 'fraction_numerical': 0.01750291715285881, 'mean_word_length': 5.469811320754717, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '88695', 'license': 'Apache-2.0', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1051, 'n_words': 235, 'path': 'tutorials/Demo grid object.ipynb', 'repo_name': 'gridcapacitymap/gridcapacitymap', 'size': '3428'}