Commit e9646e8d authored by Nicolas Seydoux's avatar Nicolas Seydoux
Browse files

Fixed factories generation

parent 94490306
......@@ -56,31 +56,54 @@ def generate_factory(floor_count, presence_conveyors_per_floor, regular_conveyor
def build_factory_description(factory, target_file):
floor_counter = 0
output = {"floors":[]}
with open(target_file, "w") as f:
f.write(PREFIXES+"\n")
for floor in factory["floors"]:
floorURL = ":Floor"+str(floor_counter)
floor["url"] = BASE_PREFIX+floorURL[1:]
f.write(floorURL+" rdf:type :Floor ; :locatedIn :myFactory.\n")
conveyor_counter = 0
for conveyor in floor["conveyors"]:
conveyorURL = ":Conveyor{0}{1}".format(floor_counter, conveyor_counter)
conveyor["url"] = BASE_PREFIX+conveyorURL[1:]
f.write(conveyorURL+" rdf:type :Conveyor ; :locatedIn {0}.\n".format(floorURL))
machine_counter = 0
for machine in conveyor["machines"]:
machineURL = ":Machine{0}{1}{2}".format(floor_counter, conveyor_counter, machine_counter)
machine["url"] = BASE_PREFIX+machineURL[1:]
f.write(machineURL+" :onConveyor {0}.\n".format(conveyorURL))
if machine["type"] == "temperature_machine":
f.write(machineURL+" rdf:type :ColdSensitiveMachine.\n")
elif machine["type"] == "spark_machine":
f.write(machineURL+" rdf:type :SparkGeneratingMachine.\n")
else:
f.write(machineURL+" rdf:type :Machine.")
machine_counter+=1
conveyor_counter+=1
floor_counter+=1
for i in range(floor["count"]):
# A new representation is created, with all counter at one and features explicited
new_floor = {}
new_floor["sensors"] = floor["sensors"]
new_floor["conveyors"] = []
new_floor["type"] = floor["type"]
new_floor["count"]=1
output["floors"].append(new_floor)
floorURL = ":Floor"+str(floor_counter)
new_floor["url"] = BASE_PREFIX+floorURL[1:]
f.write(floorURL+" rdf:type :Floor ; :locatedIn :myFactory.\n")
conveyor_counter = 0
for conveyor in floor["conveyors"]:
for j in range(conveyor["count"]):
new_conveyor = {}
new_conveyor["sensors"] = conveyor["sensors"]
new_conveyor["count"]=1
new_conveyor["machines"]=[]
new_conveyor["type"] = conveyor["type"]
new_floor["conveyors"].append(new_conveyor)
conveyorURL = ":Conveyor{0}{1}".format(floor_counter, conveyor_counter)
new_conveyor["url"] = BASE_PREFIX+conveyorURL[1:]
f.write(conveyorURL+" rdf:type :Conveyor ; :locatedIn {0}.\n".format(floorURL))
machine_counter = 0
for machine in conveyor["machines"]:
for k in range(machine["count"]):
new_machine = {}
new_machine["type"]=machine["type"]
new_machine["count"]=1
new_machine["sensors"]=machine["sensors"]
new_conveyor["machines"].append(new_machine)
machineURL = ":Machine{0}{1}{2}".format(floor_counter, conveyor_counter, machine_counter)
new_machine["url"] = BASE_PREFIX+machineURL[1:]
f.write(machineURL+" :onConveyor {0}.\n".format(conveyorURL))
if machine["type"] == "temperature_machine":
f.write(machineURL+" rdf:type :ColdSensitiveMachine.\n")
elif machine["type"] == "spark_machine":
f.write(machineURL+" rdf:type :SparkGeneratingMachine.\n")
else:
f.write(machineURL+" rdf:type :Machine.")
machine_counter+=1
conveyor_counter+=1
floor_counter+=1
return output
def instanciate_sensor(sensor_type):
return {"type":"sensor", "count":1, "host":SENSOR_HOST, "measures":sensor_type}
......@@ -118,7 +141,9 @@ description_file = args.desc_file
factory = {}
with open(args.blueprint, "r") as f:
factory = json.load(f)
build_factory_description(factory, description_file)
topology = generate_topology(factory, description_file)
factory_desc = build_factory_description(factory, description_file)
with open("test", "w") as f:
json.dump(factory_desc, f, indent=2)
topology = generate_topology(factory_desc, description_file)
with open(args.output, "w") as f:
json.dump(topology, f, indent=2)
python3 factory_generator.py -b scala_syndream/clone_f_0_blueprint.json -d scala_syndream/clone_f_0.ttl -o scala_syndream/clone_f_0.json
echo "scalability 0"
# python3 factory_generator.py -b scala_syndream/clone_f_0_blueprint.json -d scala_syndream/clone_f_0.ttl -o scala_syndream/clone_f_0.json
echo "scalability 1"
python3 factory_generator.py -b scala_syndream/clone_f_1_blueprint.json -d scala_syndream/clone_f_1.ttl -o scala_syndream/clone_f_1.json
python3 factory_generator.py -b scala_syndream/clone_f_2_blueprint.json -d scala_syndream/clone_f_2.ttl -o scala_syndream/clone_f_2.json
echo "scalability 2"
# python3 factory_generator.py -b scala_syndream/clone_f_2_blueprint.json -d scala_syndream/clone_f_2.ttl -o scala_syndream/clone_f_2.json
#
# echo "spe baseline"
# python3 factory_generator.py -b specialisation/specialisation_baseline_blueprint.json -d specialisation/specialisation_baseline.ttl -o specialisation/specialisation_baseline.json
# echo "spe implem"
# python3 factory_generator.py -b specialisation/specialisation_implementation_blueprint.json -d specialisation/specialisation_implementation.ttl -o specialisation/specialisation_implementation.json
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment