示例#1
0
def miners():
    # Init variables
    start = time.clock()
    miners = Miner.query.all()
    active_miners = []
    inactive_miners = []
    warnings = []
    errors = []
    total_hash_rate_per_model = {}
    miner_objects = []

    # lookup table for total_hash_rate_per_model
    for id, miner in MODELS.items():
        total_hash_rate_per_model[id] = {"value": 0, "unit": miner.get('unit')}

    # create miner objects to pass to executor.map
    for miner in miners:
        module = MODELS[miner.model_id]['model_module']
        cls = MODELS[miner.model_id]['model_classname']
        obj = getattr(sys.modules[module], cls)(miner)
        miner_objects.append(obj)

    # pass this method to executor.map to poll the miner
    def poll(obj):
        obj.poll()
        return obj

    # run with ThreadPoolExecutor
    with concurrent.futures.ThreadPoolExecutor(
            max_workers=NUM_THREADS) as executor:
        results = executor.map(poll, miner_objects)
        for miner in results:
            if miner is not None:
                if miner.is_inactive:
                    inactive_miners.append(miner)
                else:
                    active_miners.append(miner)

                    for warning in miner.warnings:
                        warnings.append(warning)
                    for error in miner.errors:
                        errors.append(error)
                    total_hash_rate_per_model[
                        miner.model_id]["value"] += miner.hash_rate_ghs5s

    # Flash notifications
    if not miners:
        error_message = ("[INFO] No miners added yet. "
                         "Please add miners using the above form.")
        current_app.logger.info(error_message)
        flash(error_message, "info")
    elif not errors:
        error_message = ("[INFO] All miners are operating normal. "
                         "No errors found.")
        current_app.logger.info(error_message)
        flash(error_message, "info")

    for error in errors:
        current_app.logger.error(error)
        flash(error, "error")

    for warning in warnings:
        current_app.logger.error(warning)
        flash(warning, "warning")

    # flash("[INFO] Check chips on your miner", "info")
    # flash("[SUCCESS] Miner added successfully", "success")
    # flash("[WARNING] Check temperatures on your miner", "warning")
    # flash("[ERROR] Check board(s) on your miner", "error")

    # Convert the total_hash_rate_per_model into a data structure that the
    # template can consume.
    total_hash_rate_per_model_temp = {}
    for key in total_hash_rate_per_model:
        value, unit = update_unit_and_value(
            total_hash_rate_per_model[key]["value"],
            total_hash_rate_per_model[key]["unit"])
        if value > 0:
            total_hash_rate_per_model_temp[key] = "{:3.2f} {}".format(
                value, unit)

    end = time.clock()
    loading_time = end - start
    return render_template(
        'asicminer/home.html',
        version=current_app.config['__VERSION__'],
        models=MODELS,
        errors=errors,
        warnings=warnings,
        active_miners=active_miners,
        inactive_miners=inactive_miners,
        loading_time=loading_time,
        total_hash_rate_per_model=total_hash_rate_per_model_temp)
示例#2
0
def miners():
    # Init variables
    start = time.clock()
    miners = Miner.query.all()
    active_miners = []
    inactive_miners = []
    warnings = []
    errors = []

    total_hash_rate_per_model = {}

    for id, miner in MODELS.items():
        total_hash_rate_per_model[id] = {"value": 0, "unit": miner.get('unit')}

    # running single threaded
    for miner in miners:
        antminer = ASIC_ANTMINER(miner)

        if antminer.is_inactive:
            inactive_miners.append(antminer)
        else:
            active_miners.append(antminer)
            for warning in antminer.warnings:
                warnings.append(warning)
            for error in antminer.errors:
                errors.append(error)
            total_hash_rate_per_model[
                antminer.model_id]["value"] += antminer.hash_rate_ghs5s

    # Flash notifications
    if not miners:
        error_message = ("[INFO] No miners added yet. "
                         "Please add miners using the above form.")
        current_app.logger.info(error_message)
        flash(error_message, "info")
    elif not errors:
        error_message = ("[INFO] All miners are operating normal. "
                         "No errors found.")
        current_app.logger.info(error_message)
        flash(error_message, "info")

    for error in errors:
        current_app.logger.error(error)
        flash(error, "error")

    for warning in warnings:
        current_app.logger.error(warning)
        flash(warning, "warning")

    # flash("[INFO] Check chips on your miner", "info")
    # flash("[SUCCESS] Miner added successfully", "success")
    # flash("[WARNING] Check temperatures on your miner", "warning")
    # flash("[ERROR] Check board(s) on your miner", "error")

    # Convert the total_hash_rate_per_model into a data structure that the
    # template can consume.
    total_hash_rate_per_model_temp = {}
    for key in total_hash_rate_per_model:
        value, unit = update_unit_and_value(
            total_hash_rate_per_model[key]["value"],
            total_hash_rate_per_model[key]["unit"])
        if value > 0:
            total_hash_rate_per_model_temp[key] = "{:3.2f} {}".format(
                value, unit)

    end = time.clock()
    loading_time = end - start
    return render_template(
        'asicminer/home.html',
        MODELS=MODELS,
        active_miners=active_miners,
        inactive_miners=inactive_miners,
        loading_time=loading_time,
        total_hash_rate_per_model=total_hash_rate_per_model_temp)