def station_name_corrector():
    check_bulk_run = False
    check_bulk_op = g.mongo.db.jf_routes.initialize_unordered_bulk_op()
    caches.stations()
    station_db = g.mongo.db.stations.find().distinct("name")
    for route in g.mongo.db.jf_routes.find():
        if route["start"] not in station_db or route["end"] not in station_db:
            start_id = int(route["_id"] / 100000000)
            end_id = route["_id"] % 100000000
            start_db = g.mongo.db.stations.find_one({"_id": start_id})
            end_db = g.mongo.db.stations.find_one({"_id": end_id})
            check_bulk_run = True
            check_bulk_op.find({"_id": route["_id"]}).update({"$set": {
                "start": start_db["name"],
                "end": end_db["name"]
            }})
    if check_bulk_run:
        check_bulk_op.execute()
示例#2
0
def station_name_corrector():
    check_bulk_run = False
    check_bulk_op = g.mongo.db.jf_routes.initialize_unordered_bulk_op()
    caches.stations()
    station_db = g.mongo.db.stations.find().distinct("name")
    for route in g.mongo.db.jf_routes.find():
        if route["start"] not in station_db or route["end"] not in station_db:
            start_id = int(route["_id"] / 100000000)
            end_id = route["_id"] % 100000000
            start_db = g.mongo.db.stations.find_one({"_id": start_id})
            end_db = g.mongo.db.stations.find_one({"_id": end_id})
            check_bulk_run = True
            check_bulk_op.find({
                "_id": route["_id"]
            }).update(
                {"$set": {
                    "start": start_db["name"],
                    "end": end_db["name"]
                }})
    if check_bulk_run:
        check_bulk_op.execute()
def home():
    corp_rate = 0
    collateral_rate = 0
    general_rate = 0
    volume = ""
    corp_volume_cost = 0
    volume_cost = 0
    collateral = ""
    collateral_cost = 0
    price = ""
    corp_price = ""

    start_list = []
    end_list = []
    for station in g.mongo.db.jf_routes.distinct("start"):
        if request.args.get("start") == station:
            start_list.append([station, True])
        elif not request.args.get("start") and station == "Jita IV - Moon 4 - Caldari Navy Assembly Plant":
            start_list.append([station, True])
        else:
            start_list.append([station, False])
    for station in g.mongo.db.jf_routes.distinct("end"):
        if request.args.get("end") == station:
            end_list.append([station, True])
        elif not request.args.get("end") and station == "3KNA-N II - We have top men working on it":
            end_list.append([station, True])
        else:
            end_list.append([station, False])
    start_list.sort()
    end_list.sort()

    # Contract Calculations
    selected_route = "Not selected."
    input_error = False
    if request.args.get("start") and request.args.get("end"):
        start_station_id = g.mongo.db.stations.find_one({"name": request.args.get("start").strip()})["_id"]
        end_station_id = g.mongo.db.stations.find_one({"name": request.args.get("end").strip()})["_id"]
        selected_route = g.mongo.db.jf_routes.find_one({"_id": int(str(start_station_id) + str(end_station_id))})
        if selected_route:
            last_time = 0
            corp_rate = 0
            collateral_rate = 0
            general_rate = 0
            for price_history in selected_route["prices"]:
                if price_history["valid_after"] > last_time:
                    corp_rate = price_history["corp"]
                    general_rate = price_history["general"]
                    collateral_rate = price_history["collateral"]
                    last_time = price_history["valid_after"]

            try:
                volume = request.args.get("volume")
                volume = float(volume.replace(",", "") if volume else 0)
                collateral = request.args.get("collateral")
                collateral = float(collateral.replace(",", "") if collateral else 0)
            except ValueError:
                input_error = True
            else:
                volume_cost = general_rate * volume
                corp_volume_cost = corp_rate * volume
                collateral_cost = collateral * collateral_rate / 100.0
                price = volume_cost + collateral_cost
                corp_price = corp_volume_cost + collateral_cost

                # Mark Non-Inputted Values
                if not request.args.get("volume"):
                    volume = ""
                if not request.args.get("collateral"):
                    collateral = ""

    # Warnings
    warning_list = []
    if session.get("UI_Corporation"):
        compare_price = corp_price
    else:
        compare_price = price

    if input_error:
        warning_list.append("One of your inputs was not a number.")
    else:
        if compare_price and compare_price < 1000000:
            warning_list.append("Rewards must be at least 1M Isk")
            if session.get("UI_Corporation"):
                corp_price = 1000000
            else:
                price = 1000000
        if volume and volume > 300000:
            warning_list.append("Contracts must be less than 300k M3")
        if compare_price and compare_price > 1000000000:
            warning_list.append("Contracts should be below 1B isk")
        if not selected_route:
            warning_list.append("We do not service this route.")

        # Formatting
        corp_rate = "{:0,.2f}".format(corp_rate)
        volume_cost = "{:0,.2f}".format(volume_cost)
        corp_volume_cost = "{:0,.2f}".format(corp_volume_cost)
        collateral_cost = "{:0,.2f}".format(collateral_cost)
        collateral_rate = "{:0,.2f}".format(collateral_rate)
        price = "{:0,.2f}".format(price) if price else ""
        corp_price = "{:0,.2f}".format(corp_price) if price else ""
        volume = "{:0.2f}".format(volume) if volume else ""
        collateral = "{:0.2f}".format(collateral) if collateral else ""

    # Contract History

    next_update_query = g.mongo.db.caches.find_one({"_id": "jf_service"})
    next_update = next_update_query.get("next_check", "Not Scheduled") if next_update_query else "Unknown"

    if session.get("UI_Alliance"):
        # Check Caches
        caches.stations()

        users_set = set()
        # Find all users
        for contract in g.mongo.db.contracts.find({"_id.service": "jf_service",
                                                   "issued_int": {"$gt": int(time.time()) - 2629743}}):
            users_set.update([contract["issuer_id"], contract["acceptor_id"]])
        caches.character(users_set)

        contract_list = [["Issuer", "Acceptor", "Start", "End", "Status", "Date Issued", "Expiration Date", "Volume"]]
        personal_contract_list = [["Acceptor", "Start", "End", "Status", "Date Issued", "Expiration Date", "Volume",
                                   "Reward", "Collateral"]]

        # All related characters for personal list
        alt_characters_db = g.mongo.db.api_keys.find_one({"_id": session.get("CharacterOwnerHash")})
        alt_characters_list = []
        if alt_characters_db:
            for api_key in alt_characters_db["keys"]:
                alt_characters_list.append(api_key["character_name"])

        for contract in g.mongo.db.contracts.find({"_id.service": "jf_service", "type": "Courier",
                                                   "issued_int": {"$gt": int(time.time()) - 2629743}}):
            if contract["status"] not in ["Deleted", "Canceled"]:
                # Perform ID Conversions
                start_station = g.mongo.db.stations.find_one({"_id": contract["start_station_id"]})
                start_station = start_station.get("name") if start_station else "Unknown"
                end_station = g.mongo.db.stations.find_one({"_id": contract["end_station_id"]})
                end_station = end_station.get("name") if end_station else "Unknown"
                acceptor = conversions.character(contract["acceptor_id"])
                issuer = conversions.character(contract["issuer_id"])

                color = validator(contract)

                contract_list.append([
                    color,
                    issuer,
                    acceptor,
                    start_station,
                    end_station,
                    contract["status"],
                    contract["date_issued"],
                    contract["date_expired"],
                    "{:0,.2f}".format(contract["volume"])
                ])

                if session.get("CharacterOwnerHash") and (
                                issuer == session["CharacterName"] or issuer in alt_characters_list):
                    personal_contract_list.append([
                        color,
                        acceptor,
                        start_station,
                        end_station,
                        contract["status"],
                        contract["date_issued"],
                        contract["date_expired"],
                        "{:0,.2f}".format(contract["volume"]),
                        "{:0,.2f}".format(contract["reward"]),
                        "{:0,.2f}".format(contract["collateral"])
                    ])
    else:
        contract_list = []
        personal_contract_list = []

    # Check auth
    if session.get("CharacterOwnerHash"):
        jf_admin = auth_check("jf_admin")
        jf_pilot = auth_check("jf_pilot")
    else:
        jf_admin = None
        jf_pilot = None

    # Images
    with open("configs/base.json", "r") as base_config_file:
        base_config = json.load(base_config_file)
    corporation_logo = base_config["image_server"] + "/Corporation/" + str(base_config["corporation_id"]) + "_128.png"
    alliance_logo = base_config["image_server"] + "/Alliance/" + str(base_config["alliance_id"]) + "_128.png"

    return render_template("jf.html", start_list=start_list, end_list=end_list, general_rate=general_rate,
                           volume=volume, contract_list=contract_list, next_update=next_update, admin=jf_admin,
                           collateral=collateral, volume_cost=volume_cost, collateral_cost=collateral_cost,
                           warning_list=warning_list, personal_contract_list=personal_contract_list, pilot=jf_pilot,
                           corp_volume_cost=corp_volume_cost, corp_price=corp_price, corp_rate=corp_rate, price=price,
                           corporation_logo=corporation_logo, alliance_logo=alliance_logo,
                           collateral_rate=collateral_rate)
示例#4
0
def home():
    corp_rate = 0
    collateral_rate = 0
    general_rate = 0
    volume = ""
    corp_volume_cost = 0
    volume_cost = 0
    collateral = ""
    collateral_cost = 0
    price = ""
    corp_price = ""

    start_list = []
    end_list = []
    for station in g.mongo.db.jf_routes.distinct("start"):
        if request.args.get("start") == station:
            start_list.append([station, True])
        elif not request.args.get(
                "start"
        ) and station == "Jita IV - Moon 4 - Caldari Navy Assembly Plant":
            start_list.append([station, True])
        else:
            start_list.append([station, False])
    for station in g.mongo.db.jf_routes.distinct("end"):
        if request.args.get("end") == station:
            end_list.append([station, True])
        elif not request.args.get(
                "end"
        ) and station == "3KNA-N II - We have top men working on it":
            end_list.append([station, True])
        else:
            end_list.append([station, False])
    start_list.sort()
    end_list.sort()

    # Contract Calculations
    selected_route = "Not selected."
    input_error = False
    if request.args.get("start") and request.args.get("end"):
        start_station_id = g.mongo.db.stations.find_one(
            {"name": request.args.get("start").strip()})["_id"]
        end_station_id = g.mongo.db.stations.find_one(
            {"name": request.args.get("end").strip()})["_id"]
        selected_route = g.mongo.db.jf_routes.find_one(
            {"_id": int(str(start_station_id) + str(end_station_id))})
        if selected_route:
            last_time = 0
            corp_rate = 0
            collateral_rate = 0
            general_rate = 0
            for price_history in selected_route["prices"]:
                if price_history["valid_after"] > last_time:
                    corp_rate = price_history["corp"]
                    general_rate = price_history["general"]
                    collateral_rate = price_history["collateral"]
                    last_time = price_history["valid_after"]

            try:
                volume = request.args.get("volume")
                volume = float(volume.replace(",", "") if volume else 0)
                collateral = request.args.get("collateral")
                collateral = float(
                    collateral.replace(",", "") if collateral else 0)
            except ValueError:
                input_error = True
            else:
                volume_cost = general_rate * volume
                corp_volume_cost = corp_rate * volume
                collateral_cost = collateral * collateral_rate / 100.0
                price = volume_cost + collateral_cost
                corp_price = corp_volume_cost + collateral_cost

                # Mark Non-Inputted Values
                if not request.args.get("volume"):
                    volume = ""
                if not request.args.get("collateral"):
                    collateral = ""

    # Warnings
    warning_list = []
    if session.get("UI_Corporation"):
        compare_price = corp_price
    else:
        compare_price = price

    if input_error:
        warning_list.append("One of your inputs was not a number.")
    else:
        if compare_price and compare_price < 1000000:
            warning_list.append("Rewards must be at least 1M Isk")
            if session.get("UI_Corporation"):
                corp_price = 1000000
            else:
                price = 1000000
        if volume and volume > 300000:
            warning_list.append("Contracts must be less than 300k M3")
        if compare_price and compare_price > 1000000000:
            warning_list.append("Contracts should be below 1B isk")
        if not selected_route:
            warning_list.append("We do not service this route.")

        # Formatting
        corp_rate = "{:0,.2f}".format(corp_rate)
        volume_cost = "{:0,.2f}".format(volume_cost)
        corp_volume_cost = "{:0,.2f}".format(corp_volume_cost)
        collateral_cost = "{:0,.2f}".format(collateral_cost)
        collateral_rate = "{:0,.2f}".format(collateral_rate)
        price = "{:0,.2f}".format(price) if price else ""
        corp_price = "{:0,.2f}".format(corp_price) if price else ""
        volume = "{:0.2f}".format(volume) if volume else ""
        collateral = "{:0.2f}".format(collateral) if collateral else ""

    # Contract History

    next_update_query = g.mongo.db.caches.find_one({"_id": "jf_service"})
    next_update = next_update_query.get(
        "next_check", "Not Scheduled") if next_update_query else "Unknown"

    if session.get("UI_Alliance"):
        # Check Caches
        caches.stations()

        users_set = set()
        # Find all users
        for contract in g.mongo.db.contracts.find({
                "_id.service": "jf_service",
                "issued_int": {
                    "$gt": int(time.time()) - 2629743
                }
        }):
            users_set.update([contract["issuer_id"], contract["acceptor_id"]])
        caches.character(users_set)

        contract_list = [[
            "Issuer", "Acceptor", "Start", "End", "Status", "Date Issued",
            "Expiration Date", "Volume"
        ]]
        personal_contract_list = [[
            "Acceptor", "Start", "End", "Status", "Date Issued",
            "Expiration Date", "Volume", "Reward", "Collateral"
        ]]

        # All related characters for personal list
        alt_characters_db = g.mongo.db.api_keys.find_one(
            {"_id": session.get("CharacterOwnerHash")})
        alt_characters_list = []
        if alt_characters_db:
            for api_key in alt_characters_db["keys"]:
                alt_characters_list.append(api_key["character_name"])

        for contract in g.mongo.db.contracts.find({
                "_id.service": "jf_service",
                "type": "Courier",
                "issued_int": {
                    "$gt": int(time.time()) - 2629743
                }
        }):
            if contract["status"] not in ["Deleted", "Canceled"]:
                # Perform ID Conversions
                start_station = g.mongo.db.stations.find_one(
                    {"_id": contract["start_station_id"]})
                start_station = start_station.get(
                    "name") if start_station else "Unknown"
                end_station = g.mongo.db.stations.find_one(
                    {"_id": contract["end_station_id"]})
                end_station = end_station.get(
                    "name") if end_station else "Unknown"
                acceptor = conversions.character(contract["acceptor_id"])
                issuer = conversions.character(contract["issuer_id"])

                color = validator(contract)

                contract_list.append([
                    color, issuer, acceptor, start_station, end_station,
                    contract["status"], contract["date_issued"],
                    contract["date_expired"],
                    "{:0,.2f}".format(contract["volume"])
                ])

                if session.get("CharacterOwnerHash") and (
                        issuer == session["CharacterName"]
                        or issuer in alt_characters_list):
                    personal_contract_list.append([
                        color, acceptor, start_station, end_station,
                        contract["status"], contract["date_issued"],
                        contract["date_expired"],
                        "{:0,.2f}".format(contract["volume"]),
                        "{:0,.2f}".format(contract["reward"]),
                        "{:0,.2f}".format(contract["collateral"])
                    ])
    else:
        contract_list = []
        personal_contract_list = []

    # Check auth
    if session.get("CharacterOwnerHash"):
        jf_admin = auth_check("jf_admin")
        jf_pilot = auth_check("jf_pilot")
    else:
        jf_admin = None
        jf_pilot = None

    # Images
    with open("configs/base.json", "r") as base_config_file:
        base_config = json.load(base_config_file)
    corporation_logo = base_config["image_server"] + "/Corporation/" + str(
        base_config["corporation_id"]) + "_128.png"
    alliance_logo = base_config["image_server"] + "/Alliance/" + str(
        base_config["alliance_id"]) + "_128.png"

    return render_template("jf.html",
                           start_list=start_list,
                           end_list=end_list,
                           general_rate=general_rate,
                           volume=volume,
                           contract_list=contract_list,
                           next_update=next_update,
                           admin=jf_admin,
                           collateral=collateral,
                           volume_cost=volume_cost,
                           collateral_cost=collateral_cost,
                           warning_list=warning_list,
                           personal_contract_list=personal_contract_list,
                           pilot=jf_pilot,
                           corp_volume_cost=corp_volume_cost,
                           corp_price=corp_price,
                           corp_rate=corp_rate,
                           price=price,
                           corporation_logo=corporation_logo,
                           alliance_logo=alliance_logo,
                           collateral_rate=collateral_rate)