def admin(): # # Settings refine_character = g.mongo.db.preferences.find_one({"_id": "refine_character"}) if request.method == "POST": if request.form.get("action") == "refresh_character": caches.character_sheet([[refine_character["key_id"], refine_character["vcode"], refine_character["character_id"]]]) elif request.form.get("action") == "general_settings": current_settings = g.mongo.db.preferences.find_one({"_id": "buyback_yield"}) if not current_settings: current_settings = {} g.mongo.db.preferences.update({"_id": "buyback_yield"}, { "base": float(request.form.get("general_base")) if request.form.get("general_base") else current_settings.get("base", 0), "implant": float(request.form.get("general_implant")) if request.form.get("general_implant") else current_settings.get("implant", 0), "tax": float(request.form.get("general_tax")) if request.form.get("general_tax") else current_settings.get("tax", 0), "tax_refine": float(request.form.get("general_refine")) if request.form.get("general_refine") else current_settings.get("tax_refine", 0) }, upsert=True) elif request.form.get("action") == "specific_settings": db_item = g.mongo.db.items.find_one({"name": request.form.get("name").strip()}) current_settings = g.mongo.db.taxes.find_one({"_id": db_item["_id"]}) if not current_settings: current_settings = {} if db_item: g.mongo.db.taxes.update({"_id": db_item["_id"]}, { "name": request.form.get("name").strip(), "base": float(request.form.get("specific_base")) if request.form.get("specific_base") else current_settings.get("base", 0), "implant": float(request.form.get("specific_implant")) if request.form.get("specific_implant") else current_settings.get("implant", 0), "tax": float(request.form.get("specific_tax")) if request.form.get("specific_tax") else current_settings.get("tax", 0), "tax_refine": float(request.form.get("specific_refine")) if request.form.get("specific_refine") else current_settings.get("tax_refine", 0) }, upsert=True) elif request.form.get("delete"): g.mongo.db.taxes.remove({"_id": int(request.form.get("delete"))}) # Specific Rates Table specific_rates_table = [["Name", "Base", "Implant", "Tax", "Action"]] specific_rates_db = g.mongo.db.taxes.find() for rate in specific_rates_db: specific_rates_table.append([rate["name"], rate["base"], rate["implant"], rate["tax"], rate["_id"]]) general_rates = g.mongo.db.preferences.find_one({"_id": "buyback_yield"}) if general_rates: general_base = "{:,.02f}".format(general_rates["base"]) general_implant = "{:,.02f}".format(general_rates["implant"]) general_tax = "{:,.02f}".format(general_rates["tax"]) general_refine = "{:,.02f}".format(general_rates["tax_refine"]) else: general_base = 0 general_implant = 0 general_tax = 0 general_refine = 0 character_list = [] current_user = g.mongo.db.api_keys.find_one({"_id": session["CharacterOwnerHash"]}) # Set Refine Character current_refine_character = refine_character["character_name"] if refine_character else None if current_user: for key in current_user["keys"]: selected = False if request.method == "POST" and request.form.get("action") == "refine_character": if request.form.get("character") and key["character_id"] == int(request.form.get("character")): selected = True current_refine_character = key["character_name"] g.mongo.db.preferences.update({"_id": "refine_character"}, { "key_id": key["key_id"], "vcode": key["vcode"], "character_id": key["character_id"], "character_name": key["character_name"] }, upsert=True) caches.character_sheet([[key["key_id"], key["vcode"], key["character_id"]]]) elif refine_character and refine_character["character_id"] == key["character_id"]: # Fix front end view selected = True character_list.append([key["character_id"], key["character_name"], selected]) # # Refine Quick-Look with open("configs/definitions.json") as groups_file: groups_definitions = json.load(groups_file) ore_market_group_ids = groups_definitions["ore_market_group_ids"] ice_market_group_ids = groups_definitions["ice_market_group_ids"] material_list = g.mongo.db.items.find({"market_group_id": { "$in": ore_market_group_ids + ice_market_group_ids }}).distinct("materials.type_id") material_db = g.mongo.db.items.find({"_id": {"$in": material_list}}) ice_material_list = g.mongo.db.items.find({"market_group_id": { "$in": ice_market_group_ids }}).distinct("materials.type_id") ice_material_groups = g.mongo.db.items.find({"_id": {"$in": ice_material_list}}).distinct("market_group_id") refine_quick = g.mongo.db.items.find({"market_group_id": {"$in": ore_market_group_ids + ice_market_group_ids}}) refine_quick_ids = g.mongo.db.items.find({"market_group_id": { "$in": ore_market_group_ids + ice_market_group_ids}}).distinct("_id") material_conversion = {} ore_headers = [] ice_headers = [] for material in material_db: material_conversion[material["_id"]] = material["name"] if material["market_group_id"] in ice_material_groups: ice_headers.append((material["_id"], material["name"])) else: ore_headers.append((material["_id"], material["name"])) ore_headers.sort(key=lambda x: x[0]) ice_headers.sort(key=lambda x: x[0]) refine_character = g.mongo.db.preferences.find_one({"_id": "refine_character"}) if refine_character: refine_id = refine_character["character_id"] else: refine_id = 0 character_refines = conversions.refine_calc(refine_quick_ids, refine_id) ore_table = [] ice_table = [] for item in refine_quick: qty = {} row = [item["name"]] for material in item["materials"]: qty[material["type_id"]] = material["amount"] if item["market_group_id"] == 1855: # Ice for header in ice_headers: row.append(character_refines[item["_id"]].get(header[0], 0)) ice_table.append(row) else: for header in ore_headers: row.append(character_refines[item["_id"]].get(header[0], 0)) ore_table.append(row) # Formatting ore_table = [["Name"] + [x[1] for x in ore_headers]] + [ ["{:,.02f}".format(value) if not isinstance(value, str) else value for value in row] for row in ore_table] ice_table = [["Name"] + [x[1] for x in ice_headers]] + [ ["{:,.02f}".format(value) if not isinstance(value, str) else value for value in row] for row in ice_table] return render_template("buyback_admin.html", ore_table=ore_table, ice_table=ice_table, character_list=character_list, refine_character=current_refine_character, general_base=general_base, general_implant=general_implant, general_tax=general_tax, specific_rates_table=specific_rates_table, general_refine=general_refine)
def admin(): # # Settings refine_character = g.mongo.db.preferences.find_one( {"_id": "refine_character"}) if request.method == "POST": if request.form.get("action") == "refresh_character": caches.character_sheet([[ refine_character["key_id"], refine_character["vcode"], refine_character["character_id"] ]]) elif request.form.get("action") == "general_settings": current_settings = g.mongo.db.preferences.find_one( {"_id": "buyback_yield"}) if not current_settings: current_settings = {} g.mongo.db.preferences.update({"_id": "buyback_yield"}, { "base": float(request.form.get("general_base")) if request.form.get("general_base") else current_settings.get( "base", 0), "implant": float(request.form.get("general_implant")) if request.form.get("general_implant") else current_settings.get( "implant", 0), "tax": float(request.form.get("general_tax")) if request.form.get("general_tax") else current_settings.get( "tax", 0), "tax_refine": float(request.form.get("general_refine")) if request.form.get("general_refine") else current_settings.get( "tax_refine", 0) }, upsert=True) elif request.form.get("action") == "specific_settings": db_item = g.mongo.db.items.find_one( {"name": request.form.get("name").strip()}) current_settings = g.mongo.db.taxes.find_one( {"_id": db_item["_id"]}) if not current_settings: current_settings = {} if db_item: g.mongo.db.taxes.update({"_id": db_item["_id"]}, { "name": request.form.get("name").strip(), "base": float(request.form.get("specific_base")) if request.form.get("specific_base") else current_settings.get("base", 0), "implant": float(request.form.get("specific_implant")) if request.form.get("specific_implant") else current_settings.get("implant", 0), "tax": float(request.form.get("specific_tax")) if request.form.get("specific_tax") else current_settings.get( "tax", 0), "tax_refine": float(request.form.get("specific_refine")) if request.form.get("specific_refine") else current_settings.get("tax_refine", 0) }, upsert=True) elif request.form.get("delete"): g.mongo.db.taxes.remove({"_id": int(request.form.get("delete"))}) # Specific Rates Table specific_rates_table = [["Name", "Base", "Implant", "Tax", "Action"]] specific_rates_db = g.mongo.db.taxes.find() for rate in specific_rates_db: specific_rates_table.append([ rate["name"], rate["base"], rate["implant"], rate["tax"], rate["_id"] ]) general_rates = g.mongo.db.preferences.find_one({"_id": "buyback_yield"}) if general_rates: general_base = "{:,.02f}".format(general_rates["base"]) general_implant = "{:,.02f}".format(general_rates["implant"]) general_tax = "{:,.02f}".format(general_rates["tax"]) general_refine = "{:,.02f}".format(general_rates["tax_refine"]) else: general_base = 0 general_implant = 0 general_tax = 0 general_refine = 0 character_list = [] current_user = g.mongo.db.api_keys.find_one( {"_id": session["CharacterOwnerHash"]}) # Set Refine Character current_refine_character = refine_character[ "character_name"] if refine_character else None if current_user: for key in current_user["keys"]: selected = False if request.method == "POST" and request.form.get( "action") == "refine_character": if request.form.get( "character") and key["character_id"] == int( request.form.get("character")): selected = True current_refine_character = key["character_name"] g.mongo.db.preferences.update( {"_id": "refine_character"}, { "key_id": key["key_id"], "vcode": key["vcode"], "character_id": key["character_id"], "character_name": key["character_name"] }, upsert=True) caches.character_sheet( [[key["key_id"], key["vcode"], key["character_id"]]]) elif refine_character and refine_character["character_id"] == key[ "character_id"]: # Fix front end view selected = True character_list.append( [key["character_id"], key["character_name"], selected]) # # Refine Quick-Look with open("configs/definitions.json") as groups_file: groups_definitions = json.load(groups_file) ore_market_group_ids = groups_definitions["ore_market_group_ids"] ice_market_group_ids = groups_definitions["ice_market_group_ids"] material_list = g.mongo.db.items.find({ "market_group_id": { "$in": ore_market_group_ids + ice_market_group_ids } }).distinct("materials.type_id") material_db = g.mongo.db.items.find({"_id": {"$in": material_list}}) ice_material_list = g.mongo.db.items.find({ "market_group_id": { "$in": ice_market_group_ids } }).distinct("materials.type_id") ice_material_groups = g.mongo.db.items.find({ "_id": { "$in": ice_material_list } }).distinct("market_group_id") refine_quick = g.mongo.db.items.find({ "market_group_id": { "$in": ore_market_group_ids + ice_market_group_ids } }) refine_quick_ids = g.mongo.db.items.find({ "market_group_id": { "$in": ore_market_group_ids + ice_market_group_ids } }).distinct("_id") material_conversion = {} ore_headers = [] ice_headers = [] for material in material_db: material_conversion[material["_id"]] = material["name"] if material["market_group_id"] in ice_material_groups: ice_headers.append((material["_id"], material["name"])) else: ore_headers.append((material["_id"], material["name"])) ore_headers.sort(key=lambda x: x[0]) ice_headers.sort(key=lambda x: x[0]) refine_character = g.mongo.db.preferences.find_one( {"_id": "refine_character"}) if refine_character: refine_id = refine_character["character_id"] else: refine_id = 0 character_refines = conversions.refine_calc(refine_quick_ids, refine_id) ore_table = [] ice_table = [] for item in refine_quick: qty = {} row = [item["name"]] for material in item["materials"]: qty[material["type_id"]] = material["amount"] if item["market_group_id"] == 1855: # Ice for header in ice_headers: row.append(character_refines[item["_id"]].get(header[0], 0)) ice_table.append(row) else: for header in ore_headers: row.append(character_refines[item["_id"]].get(header[0], 0)) ore_table.append(row) # Formatting ore_table = [["Name"] + [x[1] for x in ore_headers]] + [[ "{:,.02f}".format(value) if not isinstance(value, str) else value for value in row ] for row in ore_table] ice_table = [["Name"] + [x[1] for x in ice_headers]] + [[ "{:,.02f}".format(value) if not isinstance(value, str) else value for value in row ] for row in ice_table] return render_template("buyback_admin.html", ore_table=ore_table, ice_table=ice_table, character_list=character_list, refine_character=current_refine_character, general_base=general_base, general_implant=general_implant, general_tax=general_tax, specific_rates_table=specific_rates_table, general_refine=general_refine)
def price_calc(names, character_id, jf_rate=0): item_list = g.mongo.db.items.find({"name": {"$in": names}}) id_list = g.mongo.db.items.find({"name": {"$in": names}}).distinct("_id") mineral_list = {} item_materials = conversions.refine_calc(id_list, character_id) material_id_list = set() non_refine_list = [] for item in item_list: if item["materials"] and (not item["meta"] or item["meta"] < 4): for material_id, material_amount in item_materials[item["_id"]].items(): material_id_list.add(material_id) mineral_list.setdefault(material_id, 0) mineral_list[material_id] += material_amount else: item_materials[item["_id"]] = {} non_refine_list.append(item["_id"]) market_prices, prices_usable = eve_central.market_hub_prices(list(mineral_list.keys()) + list(item_materials.keys()) + non_refine_list) # Material info for volume material_info_db = g.mongo.db.items.find({"_id": {"$in": list(material_id_list)}}) material_volumes = {} for material_info in material_info_db: material_volumes[material_info["_id"]] = material_info.get("volume", 0) # Tax Checks taxes_list = g.mongo.db.taxes.find({"_id": {"$in": list(item_materials.keys()) + non_refine_list}}) tax_definition = {} for tax_item in taxes_list: tax_definition[tax_item["_id"]] = tax_item["tax"] refine_preferences = g.mongo.db.preferences.find_one({"_id": "buyback_yield"}) if refine_preferences: default_tax = refine_preferences.get("tax", 0) default_refine_tax = refine_preferences.get("tax_refine", 0) else: default_tax = 0 default_refine_tax = 0 # Refined Calculations calculations = {} for key, value in item_materials.items(): item_cost = 0 volume = 0 for material_id, material_amount in value.items(): item_cost += material_amount * market_prices[material_id]["buy"] volume += material_amount * material_volumes[material_id] jf_price = jf_rate * volume calculations[key] = {"total": item_cost * (1 - tax_definition.get(key, default_refine_tax) / 100), "no_tax": item_cost, "sell": market_prices[key]["sell"], "buy": market_prices[key]["buy"], "volume": volume, "jf_price": jf_price, "delta_sell": item_cost - (market_prices[key]["sell"] - jf_price), "delta_buy": item_cost - (market_prices[key]["buy"] - jf_price), "tax": tax_definition.get(key, default_refine_tax)} # Info for non-refined non_refine_info_db = g.mongo.db.items.find({"_id": {"$in": non_refine_list}}) # Non-refined modules for non_refine_item in non_refine_info_db: calculations[non_refine_item["_id"]] = { "total": market_prices[non_refine_item["_id"]]["buy"] * ( 1 - tax_definition.get(non_refine_item["_id"], default_tax) / 100), "no_tax": market_prices[non_refine_item["_id"]]["buy"], "sell": market_prices[non_refine_item["_id"]]["sell"], "buy": market_prices[non_refine_item["_id"]]["buy"], "volume": non_refine_item["volume"], "jf_price": non_refine_item["volume"] * jf_rate, "delta_sell": item_cost - (market_prices[non_refine_item["_id"]]["sell"] - jf_price), "delta_buy": item_cost - (market_prices[non_refine_item["_id"]]["buy"] - jf_price), "tax": tax_definition.get(non_refine_item["_id"], default_tax) } mineral_prices = {} for mineral in mineral_list.keys(): mineral_prices[mineral] = market_prices[mineral] return calculations, mineral_prices, item_materials, prices_usable
def price_calc(names, character_id, jf_rate=0): item_list = g.mongo.db.items.find({"name": {"$in": names}}) id_list = g.mongo.db.items.find({"name": {"$in": names}}).distinct("_id") mineral_list = {} item_materials = conversions.refine_calc(id_list, character_id) material_id_list = set() non_refine_list = [] for item in item_list: if item["materials"] and (not item["meta"] or item["meta"] < 4): for material_id, material_amount in item_materials[ item["_id"]].items(): material_id_list.add(material_id) mineral_list.setdefault(material_id, 0) mineral_list[material_id] += material_amount else: item_materials[item["_id"]] = {} non_refine_list.append(item["_id"]) market_prices, prices_usable = eve_central.market_hub_prices( list(mineral_list.keys()) + list(item_materials.keys()) + non_refine_list) # Material info for volume material_info_db = g.mongo.db.items.find( {"_id": { "$in": list(material_id_list) }}) material_volumes = {} for material_info in material_info_db: material_volumes[material_info["_id"]] = material_info.get("volume", 0) # Tax Checks taxes_list = g.mongo.db.taxes.find( {"_id": { "$in": list(item_materials.keys()) + non_refine_list }}) tax_definition = {} for tax_item in taxes_list: tax_definition[tax_item["_id"]] = tax_item["tax"] refine_preferences = g.mongo.db.preferences.find_one( {"_id": "buyback_yield"}) if refine_preferences: default_tax = refine_preferences.get("tax", 0) default_refine_tax = refine_preferences.get("tax_refine", 0) else: default_tax = 0 default_refine_tax = 0 # Refined Calculations calculations = {} for key, value in item_materials.items(): item_cost = 0 volume = 0 for material_id, material_amount in value.items(): item_cost += material_amount * market_prices[material_id]["buy"] volume += material_amount * material_volumes[material_id] jf_price = jf_rate * volume calculations[key] = { "total": item_cost * (1 - tax_definition.get(key, default_refine_tax) / 100), "no_tax": item_cost, "sell": market_prices[key]["sell"], "buy": market_prices[key]["buy"], "volume": volume, "jf_price": jf_price, "delta_sell": item_cost - (market_prices[key]["sell"] - jf_price), "delta_buy": item_cost - (market_prices[key]["buy"] - jf_price), "tax": tax_definition.get(key, default_refine_tax) } # Info for non-refined non_refine_info_db = g.mongo.db.items.find( {"_id": { "$in": non_refine_list }}) # Non-refined modules for non_refine_item in non_refine_info_db: calculations[non_refine_item["_id"]] = { "total": market_prices[non_refine_item["_id"]]["buy"] * (1 - tax_definition.get(non_refine_item["_id"], default_tax) / 100), "no_tax": market_prices[non_refine_item["_id"]]["buy"], "sell": market_prices[non_refine_item["_id"]]["sell"], "buy": market_prices[non_refine_item["_id"]]["buy"], "volume": non_refine_item["volume"], "jf_price": non_refine_item["volume"] * jf_rate, "delta_sell": item_cost - (market_prices[non_refine_item["_id"]]["sell"] - jf_price), "delta_buy": item_cost - (market_prices[non_refine_item["_id"]]["buy"] - jf_price), "tax": tax_definition.get(non_refine_item["_id"], default_tax) } mineral_prices = {} for mineral in mineral_list.keys(): mineral_prices[mineral] = market_prices[mineral] return calculations, mineral_prices, item_materials, prices_usable