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 @@ - + + + + Feed Formulation Software + - - -
- - | - - - | - - - - -

-
- -
- -
+
+
+

Feed Formulator

+

Optimize your animal feed formulation with precision

+
-
-
- Maize
- Soybean meal
- Oyster shell
- Bone meal
- Table salt
- Lysine
- Methionine
- Wheat Bran
- Broiler Premix
+
+ +
+

Animal Selection

+
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
+

Select Ingredients

+
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+
+ +
+ +
+
-

- - - -g \ No newline at end of file + \ No newline at end of file diff --git a/templates/home.html b/templates/home.html index 657321f..7203181 100644 --- a/templates/home.html +++ b/templates/home.html @@ -1,9 +1,156 @@ - + + Login + + -

Hello Flask

-

{{ result }}

+ - + diff --git a/templates/result.html b/templates/result.html index 48b5486..c95b7f0 100644 --- a/templates/result.html +++ b/templates/result.html @@ -1,106 +1,275 @@ - - - + + + + + + Feed Formulation Results + - - - -
- -

Formulation for {{ animal_type }}

-
-

{{ ingredient }}

-
- - - - - - - - {% for var_name, var in collection.items(): %} - - - - - - {% endfor %} - -
IngredientsQuantityPriceCost
{{ var[0], var_name[0] }}{{ var_name[1] }}{{ var[1] }}{{ var_name[1] * var[1]}}
+ transition: all 0.3s ease; + text-decoration: none; + display: inline-block; + text-align: center; + min-width: 150px; + } + + .btn-primary { + background: linear-gradient(135deg, #007bff 0%, #0056b3 100%); + color: white; + box-shadow: 0 5px 15px rgba(0, 123, 255, 0.3); + } + + .btn-primary:hover { + transform: translateY(-2px); + box-shadow: 0 8px 25px rgba(0, 123, 255, 0.4); + } + + .btn-secondary { + background: linear-gradient(135deg, #6c757d 0%, #545b62 100%); + color: white; + box-shadow: 0 5px 15px rgba(108, 117, 125, 0.3); + } + + .btn-secondary:hover { + transform: translateY(-2px); + box-shadow: 0 8px 25px rgba(108, 117, 125, 0.4); + } + + .btn:active { + transform: translateY(0); + } + + @media (max-width: 768px) { + .header h1 { + font-size: 2rem; + } + + .content { + padding: 20px; + } + + .results-table { + font-size: 0.9rem; + } + + .results-table th, + .results-table td { + padding: 12px 15px; + } + + .total-amount { + font-size: 2rem; + } -
- Total: {{ objValue }} + .buttons-section { + flex-direction: column; + align-items: center; + } + } + + + + +
+
+

Feed Formulation Results

+

Optimized formulation for {{ animal_type }}

+
+ +
+
+

Formulation Details

+ + + + + + + + + + + {% for var_name, var in collection.items(): %} + + + + + + + {% endfor %} + +
IngredientsQuantity (kg)Price (per kg)Total Cost
{{ var[0] }}{{ var_name[1] }}₦{{ var[1] }}₦{{ "%.2f"|format(var_name[1] * var[1]) }}
+
+ +
+

Total Formulation Cost

+
₦{{ objValue }}
-
- - + +
+ +
+
- - + +