-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_allocation_visual.py
68 lines (52 loc) · 2.17 KB
/
create_allocation_visual.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from constants import *
from utils import *
import csv
import argparse
import pandas as pd
def task_completion_time(csv_file):
time = 0.0
with open(csv_file, newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='|')
count = 0
for row in reader:
if count == 0:
count += 1
continue
if float(row[5]) > time:
time = float(row[5])
return time
def run(arguments):
# Determine which input json file to use
f = FILENAME # default "cost_net.json"
if arguments.input_file is not None:
f = arguments.input_file
# Load petrinet data from json (transitions, places)
[_json_obj, _weights, json_task, _targets_obj, _primitives_obj, json_agents] = LOAD_JOB_FILE(f)
task_steps = [str(i) for i in range(len(list(json_task.keys())))]
tasks_ordered = [None for _ in json_task.keys()]
task_assignment = [None for _ in json_task.keys()]
for key in json_task.keys():
if tasks_ordered[json_task[key]["order"]-1] is None:
tasks_ordered[json_task[key]["order"]-1] = [json_task[key]["name"]]
else:
tasks_ordered[json_task[key]["order"]-1].append(json_task[key]["name"])
with open(arguments.csv_file, newline='') as csvfile:
reader = csv.reader(csvfile, delimiter=',', quotechar='|')
for row in reader:
if "decide" in row[0]:
task_name = row[0].split(" decide")[0].strip()
idx = -1
for eidx, i in enumerate(tasks_ordered):
if i is not None and task_name in i:
idx = eidx
task_assignment[idx] = row[3]
data = pd.DataFrame(dict(zip(task_steps, task_assignment)),
index=[0])
print(data)
print("Full task time (s): {}".format(task_completion_time(arguments.csv_file)))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--input-file", type=str, default=None, help="")
parser.add_argument("--csv-file", type=str, default=None, help="")
args = parser.parse_args()
run(args)