Brandon Cornejo
5 years ago
3 changed files with 165 additions and 8 deletions
-
67orna_tools.py
-
102templates/index.html
-
4wsgi.py
@ -0,0 +1,67 @@ |
|||
from flask import Flask, render_template, jsonify, request |
|||
|
|||
app = Flask(__name__) |
|||
|
|||
@app.route('/') |
|||
def index(): |
|||
return render_template('index.html') |
|||
|
|||
@app.route('/results', methods=['POST']) |
|||
def results(): |
|||
combinations = calculate_combinations(request.get_json()) |
|||
return jsonify(combinations) |
|||
|
|||
|
|||
# Data Methods |
|||
def calculate_combinations(equipment, do_print=False): |
|||
# name, defense, resistance |
|||
eq_headware = equipment["head"] |
|||
eq_chestware = equipment["chest"] |
|||
eq_legwear = equipment["legs"] |
|||
|
|||
# Create a list of all possible eq combinations |
|||
results = [] |
|||
for hw in eq_headware: |
|||
for cw in eq_chestware: |
|||
for lw in eq_legwear: |
|||
result = {} |
|||
result["eq"] = [hw[0], cw[0], lw[0]] |
|||
result["def"] = hw[1] + cw[1] + lw[1] |
|||
result["res"] = hw[2] + cw[2] + lw[2] |
|||
results.append(result) |
|||
|
|||
# Sort the combinations by combined total of def anf res |
|||
results.sort(key=lambda i: i["def"] + i["res"]) |
|||
|
|||
if do_print: |
|||
for result in results: |
|||
print("{} ({} def {} res) -".format(result["def"] + result["res"], result["def"], result["res"])) |
|||
for eq in result["eq"]: |
|||
print("\t{}".format(eq)) |
|||
|
|||
return results |
|||
|
|||
|
|||
""" |
|||
eq_headware = [ |
|||
["Ljosalfar Hood", 98, 510], |
|||
["Kobold Hood", 0, 614], |
|||
["Northern Cowl", 584, 130], |
|||
["High Fomorian Hood", 487, 112] |
|||
] |
|||
|
|||
eq_chestware = [ |
|||
["Ljosalfar Robe", 121, 528], |
|||
["High Fomorian Garb", 544, 0], |
|||
["Darkest Garb", 514, 169], |
|||
["Northern Garb", 535, 119], |
|||
["Northern Robe", 486, 108] |
|||
] |
|||
|
|||
eq_legwear = [ |
|||
["Northern Boots", 636, 142], |
|||
["Terra Boots", 129, 369], |
|||
["High Fomorian Boots", 516, 0], |
|||
["Ljosalfar Boots", 280, 280] |
|||
] |
|||
""" |
@ -0,0 +1,4 @@ |
|||
from orna_tools import app as application |
|||
|
|||
if __name__ == "__main__": |
|||
application.run() |
Write
Preview
Loading…
Cancel
Save
Reference in new issue