You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.9 KiB

4 years ago
  1. from flask import Flask, render_template, jsonify, request
  2. app = Flask(__name__)
  3. @app.route('/')
  4. def index():
  5. return render_template('index.html')
  6. @app.route('/results', methods=['POST'])
  7. def results():
  8. combinations = calculate_combinations(request.get_json())
  9. return jsonify(combinations)
  10. # Data Methods
  11. def calculate_combinations(equipment, do_print=True):
  12. # name, defense, resistance
  13. eq_headware = equipment["head"]
  14. eq_chestware = equipment["chest"]
  15. eq_legwear = equipment["legs"]
  16. # Create a list of all possible eq combinations
  17. results = []
  18. for hw in eq_headware:
  19. print('Headware: {}'.format(hw))
  20. for cw in eq_chestware:
  21. print('Chestware: {}'.format(cw))
  22. for lw in eq_legwear:
  23. print('legware: {}'.format(lw))
  24. result = {}
  25. result["eq"] = [hw[0], cw[0], lw[0]]
  26. result["def"] = hw[1] + cw[1] + lw[1]
  27. result["res"] = hw[2] + cw[2] + lw[2]
  28. results.append(result)
  29. # Sort the combinations by combined total of def anf res
  30. results.sort(key=lambda i: i["def"] + i["res"])
  31. if do_print:
  32. for result in results:
  33. print("{} ({} def {} res) -".format(result["def"] + result["res"], result["def"], result["res"]))
  34. for eq in result["eq"]:
  35. print("\t{}".format(eq))
  36. return results
  37. """
  38. eq_headware = [
  39. ["Ljosalfar Hood", 98, 510],
  40. ["Kobold Hood", 0, 614],
  41. ["Northern Cowl", 584, 130],
  42. ["High Fomorian Hood", 487, 112]
  43. ]
  44. eq_chestware = [
  45. ["Ljosalfar Robe", 121, 528],
  46. ["High Fomorian Garb", 544, 0],
  47. ["Darkest Garb", 514, 169],
  48. ["Northern Garb", 535, 119],
  49. ["Northern Robe", 486, 108]
  50. ]
  51. eq_legwear = [
  52. ["Northern Boots", 636, 142],
  53. ["Terra Boots", 129, 369],
  54. ["High Fomorian Boots", 516, 0],
  55. ["Ljosalfar Boots", 280, 280]
  56. ]
  57. """