diff --git a/app.py b/app.py index c7bee7d..a00775c 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,4 @@ -from flask import Flask, render_template, request, jsonify, json +from flask import Flask, render_template, request, jsonify, json, redirect, url_for from optlang import Model, Variable, Constraint, Objective from formulator_service import INGREDIENT_DB from formulator_service import INGREDIENT_PRICE @@ -31,7 +31,7 @@ def result(): # print(ration) # Computation starts here--- - + # animal ration(nutrient requirement) animal_ration = ANIMAL_FEED_REQUIREMENT_DB[animal_type] @@ -85,6 +85,8 @@ def result(): except Exception as e: print(e) # print(len(constraints)) + #{{ ingredient_db[selected_ingredients[i]]["Price"] }} + #{% for i in range( 0, lengthOfIngredients): %} # for name in ingredient_names: @@ -98,7 +100,7 @@ def result(): obj = Objective( sum(INGREDIENT_PRICE[name] * variables[name][ration] for name in ingredient_names), direction='min' - ) + ) # Objective( 58*x1+150*x2+60*x3+15*x4+50*x5+90*x6+700*x7+1300*x8+550*x9) # print(obj) @@ -113,37 +115,9 @@ def result(): for var_name , var in model.variables.items(): print(var_name, "=", var.primal) # result = model.objective.value - - # Calculate results for template - variable_quantity = model.variables - objValue = round(model.objective.value, 2) - - variables_list = [] - for a, n in variable_quantity.items(): - value = a, round(n.primal, 2) - variables_list.append(value) - - price = [] - for i in ingredient_names: - value = i, INGREDIENT_PRICE[i] - price.append(value) - - collection = dict(zip(variables_list, price)) - return render_template("result.html", - animal_type = animal_type, - selected_ingredients = selected_ingredients, - ingredient_db = INGREDIENT_DB, - lengthOfIngredients = len(selected_ingredients), - collection = collection, - objValue = objValue) - else: - return render_template("result.html", - animal_type = None, - selected_ingredients = {}, - ingredient_db = INGREDIENT_DB, - lengthOfIngredients = 0, - collection = {}, - objValue = 0) + return render_template("result.html", animal_type = animal_type) + + return redirect(url_for('form')) app.run(debug=True) diff --git a/main.py b/main.py index 05241a7..961bbf5 100644 --- a/main.py +++ b/main.py @@ -110,20 +110,16 @@ def result(): # print("=",animal_db[animal_selected][selected_animal_stage][nutrient][bound]) if bound == "Min": - contraints_list.append(Constraint(temp_var_sum, lb= - animal_db[animal_selected][selected_animal_stage][nutrient][bound])) + contraints_list.append(Constraint(temp_var_sum, lb=animal_db[animal_selected][selected_animal_stage][nutrient][bound])) print(temp_var_sum, ">=", animal_db[animal_selected][selected_animal_stage][nutrient][bound]) elif bound == "Max": - contraints_list.append(Constraint(temp_var_sum, ub= - animal_db[animal_selected][selected_animal_stage][nutrient][bound])) + contraints_list.append(Constraint(temp_var_sum, ub=animal_db[animal_selected][selected_animal_stage][nutrient][bound])) print(temp_var_sum, "<=", animal_db[animal_selected][selected_animal_stage][nutrient][bound]) elif bound == "Equal": - contraints_list.append(Constraint(temp_var_sum, lb= - animal_db[animal_selected][selected_animal_stage][nutrient][bound])) - contraints_list.append(Constraint(temp_var_sum, ub= - animal_db[animal_selected][selected_animal_stage][nutrient][bound])) + contraints_list.append(Constraint(temp_var_sum, lb=animal_db[animal_selected][selected_animal_stage][nutrient][bound])) + contraints_list.append(Constraint(temp_var_sum, ub=animal_db[animal_selected][selected_animal_stage][nutrient][bound])) print(temp_var_sum, ">=", animal_db[animal_selected][selected_animal_stage][nutrient][bound]) print(temp_var_sum, "<=", animal_db[animal_selected][selected_animal_stage][nutrient][bound]) diff --git a/templates/feed_form.html b/templates/feed_form.html index 85f11f9..8850855 100644 --- a/templates/feed_form.html +++ b/templates/feed_form.html @@ -1,99 +1,312 @@ - + +
+ +