Skip to content

Commit

Permalink
Added progress bar, fixed proportion devoted bug, slight addition to …
Browse files Browse the repository at this point in the history
…frontend
  • Loading branch information
Natedogg373 committed Apr 12, 2019
1 parent ca30a9f commit 9972fc3
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 265 deletions.
3 changes: 3 additions & 0 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/nprogress.min.js"></script>
<link rel='stylesheet' href='https://cdn.jsdelivr.net/npm/[email protected]/nprogress.css'>
<style>#nprogress .bar {background: red;}</style>
<link rel="stylesheet" href="css/mystyles.css">
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
<title>BFL</title>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/Map.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ export default {
addPushpin() {
var ref = this;
google.maps.event.addListener(this.map, 'click', function(event) {
var typeName = prompt(ref.name + " Name", this.name);
var typeName = prompt(ref.name + " Name", this.name);
// console.log(event.latLng.lat(), event.latLng.lng(), typeName);
if (typeName !== null) ref.placeMarker(event.latLng, typeName);
});
},
Expand Down
65 changes: 62 additions & 3 deletions frontend/src/components/S_BFLS.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<ListInput
v-bind:list='model.ssl_sizes'
v-on:listChange='model.ssl_sizes = $event'
v-bind:label="'SSL Sizes [small, medium, large]'"
v-bind:label="'SSL Sizes [small, medium, large] (Mg)'"
></ListInput>
<ListInput
v-bind:list='model.harvest_progress'
Expand Down Expand Up @@ -279,8 +279,61 @@ export default {
]
},
new_input: true,
op_response: {},
sim_response: {"demand": {"percent": 0, "average": 0, "stdev":0, "sem":0, "conf int":"N/a", 'range':[0,0], "conf":{'90':0, '95':0}}, "telehandler rate":{"average": 0, "stdev":0, "sem":0, "conf int":0, 'range':[0,0]}, "press rate":{"average": 0, "stdev":0, "sem":0, "conf int":0, 'range':[0,0]}, "chopper rate":{"average": 0, "stdev":0, "sem":0, "conf int":0, 'range':[0,0]}, "bagger rate":{"average": 0, "stdev":0, "sem":0, "conf int":0, 'range':[0,0]}, "module former rate":{"average": 0, "stdev":0, "sem":0, "conf int":0, 'range':[0,0]}, "module hauler rate":{"average": 0, "stdev":0, "sem":0, "conf int":0, 'range':[0,0]}}
sim_response: {
"demand": {
"percent": 0,
"average": 0,
"stdev":0,
"sem":0,
"conf int":"N/a",
'range':[0,0],
"conf":{'90':0, '95':0}
},
"telehandler rate":{
"average": 0,
"stdev":0,
"sem":0,
"conf int":0,
"range":[0,0]
},
"press rate":{
"average": 0,
"stdev":0,
"sem":0,
"conf int":0,
"range":[0,0]
},
"chopper rate":{
"average": 0,
"stdev":0,
"sem":0,
"conf int":0,
"range":[0,0]
},
"bagger rate":{
"average": 0,
"stdev":0,
"sem":0,
"conf int":0,
"range":[0,0]
},
"module former rate":{
"average": 0,
"stdev":0,
"sem":0,
"conf int":0,
"range":[0,0]
},
"module hauler rate":{
"average": 0,
"stdev":0,
"sem":0,
"conf int":0,
"range":[0,0]
}
}
};
},
methods: {
Expand Down Expand Up @@ -322,6 +375,7 @@ export default {
}
},
optimize(event) {
NProgress.start();
var mapInfo = this.$refs.map.submitLocations();
if (mapInfo == "Refinery Missing") {
Expand All @@ -331,9 +385,12 @@ export default {
this.model.Coord_s = mapInfo.Coord_s;
this.model.input_format = mapInfo.mode;
this.model.refinery_location = mapInfo.refinery_location;
this.model.new_input = this.new_input;
console.log(this.model);
axios
.post('http://localhost:5000/s-bfls/', this.model)
.then(response => {
NProgress.done();
var r = response.data
this.op_response = r.op_response;
this.$refs.csv_download.generateCsv(this.op_response.solution);
Expand All @@ -343,6 +400,8 @@ export default {
this.parseApplyRoutes(this.op_response);
this.$refs.map.show_results(this.op_response["summary"]["cost"]);
})
this.new_input = false;
}
},
Expand All @@ -351,7 +410,7 @@ export default {
this.$refs.map.hide_results();
},
changeProportion() {
this.model.proportion_devoted = (this.model.demand * 1.0) / 6666666;
this.model.field.proportion_devoted = (this.model.demand * 1.0) / 6666666;
console.log(this.model.demand);
console.log(this.model.proportion_devoted);
}
Expand Down
4 changes: 3 additions & 1 deletion myapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class CustomFlask(Flask):

# mail = Mail(app)

my_sim = Simulation()

@app.route('/s-bfls/', methods=['POST'])
@cross_origin(supports_credentials=True)
def Sbfl():
Expand All @@ -56,7 +58,7 @@ def Sbfl():
print(my_s_bfl.optimization_result)
response_dict = dict()
response_dict['op_response'] = my_s_bfl.optimization_result
my_sim = Simulation(input_data,my_s_bfl.optimization_result)
my_sim.new_input(input_data,my_s_bfl.optimization_result)
my_sim.main()
response_dict['sim_response'] = my_sim.sim_results
response = jsonify(response_dict)
Expand Down
2 changes: 1 addition & 1 deletion production.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
import myapp

if __name__ == '__main__':
serve(myapp.app, listen='*:8081')
serve(myapp.app, listen='*:5000')
64 changes: 33 additions & 31 deletions simulation/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class Simulation(object):
-this is a combination of data from the algorithms input and output
'''

def __init__(self, algo_input_data, output_data):
def __init__(self):
print(" * Created new simulation")

def new_input(self, algo_input_data, output_data):
self.algo_input_data = algo_input_data
self.output_data = output_data

Expand All @@ -43,8 +46,6 @@ def __init__(self, algo_input_data, output_data):
self.coord_s = self.output_data['params']['Coord_ssls'] # coordinates x,y for ssl (all possible)
self.ssl_configurations = self.output_data['params']['SSL_configuration'] # ssl size and equipment loadout configurations
self.harvest_schedule = np.array(self.output_data['params']['harvested']) # 26 harvest schedule (yield for each farm in each period Mg)
#self.harvest_schedule = self.harvest_schedule[1:] + [self.harvest_schedule[0]]
#print(self.harvest_schedule)
self.ue = self.output_data['params']['upperbound_equip_proc_rate'] # processing rate of non-chopping methods
self.sysnum = self.output_data['params']['Sysnum']
self.solutions = self.output_data['solution'] # holds the algorithms solution dictionary
Expand All @@ -57,25 +58,28 @@ def __init__(self, algo_input_data, output_data):
self.loadout_rates_module_jit = []
self.loadout_rate_module_new = 0
self.loadout_rate_standard_new = 0
for equipment in self.configuration:
if equipment == 'loadout':
self.loadout_rate_standard = self.equipment_data[equipment][4]/self.work_week
self.loadout_rate_standard_new = self.loadout_rate_standard
elif equipment == 'press':
self.config_rate.update({'press':self.equipment_data[equipment][4]/self.work_week})
self.press_rate = []
elif equipment == 'chopper':
self.config_rate.update({'chopper':self.equipment_data[equipment][4]/self.work_week})
self.chopper_rate = []
elif equipment == 'bagger':
self.config_rate.update({'bagger':self.equipment_data[equipment][4]/self.work_week})
self.bagger_rate = []
elif equipment == 'module_former':
self.config_rate.update({'module_former':self.equipment_data[equipment][4]/self.work_week})
self.former_rate = []
elif equipment == 'module_hauler':
self.loadout_rate_module = self.equipment_data[equipment][4]/self.work_week
self.loadout_rate_module_new = self.loadout_rate_module
print(algo_input_data["new_input"])
if algo_input_data["new_input"]:
print("new!!!!!")
for equipment in self.configuration:
if equipment == 'loadout':
self.loadout_rate_standard = self.equipment_data[equipment][4]/self.work_week
self.loadout_rate_standard_new = self.loadout_rate_standard
elif equipment == 'press':
self.config_rate.update({'press':self.equipment_data[equipment][4]/self.work_week})
self.press_rate = []
elif equipment == 'chopper':
self.config_rate.update({'chopper':self.equipment_data[equipment][4]/self.work_week})
self.chopper_rate = []
elif equipment == 'bagger':
self.config_rate.update({'bagger':self.equipment_data[equipment][4]/self.work_week})
self.bagger_rate = []
elif equipment == 'module_former':
self.config_rate.update({'module_former':self.equipment_data[equipment][4]/self.work_week})
self.former_rate = []
elif equipment == 'module_hauler':
self.loadout_rate_module = self.equipment_data[equipment][4]/self.work_week
self.loadout_rate_module_new = self.loadout_rate_module

self.breakdown ={'loadout':[], 'press':[], 'chopper':[], 'bagger':[], 'module former':[], 'module hauler': []}
for trial in range(self.num_trials):
Expand Down Expand Up @@ -247,7 +251,7 @@ def preprocessing(self, period, farm):
def use_equipment(self, period, farm, x):
i=1
for equipment in self.config_rate:
equipment_rate = max(1/10*self.config_rate[equipment],np.random.normal(self.config_rate[equipment],1/2*self.config_rate[equipment]))
equipment_rate = min(1.25*self.config_rate[equipment],max(1/10*self.config_rate[equipment],np.random.normal(self.config_rate[equipment],1/5*self.config_rate[equipment])))
if equipment == 'press':
self.press_rate.append(equipment_rate)
if equipment == 'chopper':
Expand Down Expand Up @@ -299,9 +303,7 @@ def refinery_transport(self, ssl, period):
pass
yield self.env.timeout(1)



if self.ssl_container[ssl].level > 0:
'''if self.ssl_container[ssl].level > 0:
z = self.ssl_container[ssl].level
self.ssl_container[ssl].get(z)
if 'module_hauler' in self.configuration:
Expand All @@ -312,7 +314,7 @@ def refinery_transport(self, ssl, period):
with self.ssl[ssl][0].request() as req:
yield req
yield self.env.timeout(z/(self.equip_in_ssl[ssl][0]*self.loadout_rate_standard_new))
self.refinery.put(z)
self.refinery.put(z)'''



Expand All @@ -332,9 +334,9 @@ def JIT_delivery(self, period, farm):
def create_loadout_rate(self):
for period in range(self.m):
if 'module_hauler' in self.configuration:
self.loadout_rate_module_new = max(1/10*self.loadout_rate_module,np.random.normal(self.loadout_rate_module, 1/2*self.loadout_rate_module))
self.loadout_rate_module_new = min(1.25*self.loadout_rate_module,max(1/10*self.loadout_rate_module,np.random.normal(self.loadout_rate_module, 1/5*self.loadout_rate_module)))
self.loadout_rates_module.append(self.loadout_rate_module_new)
self.loadout_rate_standard_new = max(1/10*self.loadout_rate_standard,np.random.normal(self.loadout_rate_standard, 1/2*self.loadout_rate_standard))
self.loadout_rate_standard_new = min(1.25*self.loadout_rate_standard,max(1/10*self.loadout_rate_standard,np.random.normal(self.loadout_rate_standard, 1/5*self.loadout_rate_standard)))
self.loadout_rates_standard.append(self.loadout_rate_standard_new)
yield self.env.timeout(self.work_week)

Expand Down Expand Up @@ -437,7 +439,7 @@ def schedules(self):
self.ssl_graph = np.mean(self.all_ssl_actual, axis=0)
self.farm_graph = np.mean(self.all_farm_level, axis=0)
self.harvest_actual = np.mean(self.harvest_actual, axis=0)
print(self.harvest_actual)
#print(self.harvest_actual)

def record_data(self):
total = 0
Expand All @@ -460,7 +462,7 @@ def record_data(self):
self.refinery_actual.append(self.refinery.level)
#print('harvested amount @ ',self.env.now,'acutal: ', total, ' hypothetical: ', total2)
#print('total ssl inventory @ ',self.env.now, ' acutal: ', total5, ' hypothetical: ', total4)
print('refinery level @ ',self.env.now, ' ', self.refinery.level)
#print('refinery level @ ',self.env.now, ' ', self.refinery.level)
total5 = 0
total7 = 0
self.all_farm_level.append(self.actual_farm)
Expand Down
Loading

0 comments on commit 9972fc3

Please sign in to comment.