Skip to content

Commit

Permalink
Merge pull request #16 from edwardoughton/update_demo
Browse files Browse the repository at this point in the history
Update demo
  • Loading branch information
edwardoughton committed Jan 5, 2021
2 parents 5fce6f9 + f819811 commit 3905124
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
59 changes: 51 additions & 8 deletions scripts/demo.py
Expand Up @@ -11,7 +11,7 @@
import random
import pandas as pd

from osira.sim import simulation, allocate_probabilities
from osira.sim import simulation, allocate_probabilities, cascading_failures

CONFIG = configparser.ConfigParser()
CONFIG.read(os.path.join(os.path.dirname(__file__), 'script_config.ini'))
Expand All @@ -20,6 +20,51 @@
RESULTS = os.path.join(BASE_PATH, '..', 'results')


def load_data():
"""
Produce demo data.
"""
random.seed(42)

data = {}

for i in range(0, total_substation):
data[i] = {
'id': i,
'population': random.randint(1e4, 1e5)
}

return data


def load_indirect_data():
"""
Produce indirect demo lookup table data.
"""
random.seed(42)

data_indirect = {}

for i in range(0, 100):

rand = random.randint(1, 2)

if rand == 1:
function = 'Railway Station'
elif rand == 2:
function = 'Gas Distribution or Storage'
else:
print('Did not recognize selected int')

data_indirect[i] = {
'dest_func': function,
}

return data_indirect


if __name__ == '__main__':

if not os.path.exists(RESULTS):
Expand All @@ -30,16 +75,14 @@
iterations = 1000
probabilities = [0.5, 0.1, 0.01]

data = {}

for i in range(0, total_substation):
data[i] = {
'id': i,
'population': random.randint(1e4, 1e5)
}
data = load_data()

all_results = simulation(data, num_substations, probabilities, iterations)

data_indirect = load_indirect_data()

all_results = cascading_failures(all_results, data_indirect)

cp_scenarios = allocate_probabilities(all_results, num_substations, probabilities)

all_results = pd.DataFrame(all_results)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sim.py
Expand Up @@ -58,7 +58,7 @@ def test_cascading_failures():

for i in range(0, 100):

rand = random.randint(0, 2)
rand = random.randint(1, 2)

if rand == 1:
function = 'Railway Station'
Expand Down

0 comments on commit 3905124

Please sign in to comment.