Ejemplo n.º 1
0
def migrate_brews(brew_service: BrewService, sync: SyncService,
                  measurement_service: MeasurementService):
    brews = brew_service.get_all()
    now = datetime.datetime.utcnow()
    for brew in brews:
        if not hasattr(brew, 'stages'):
            brew.stages = []
            brew.start_new_stage(Stage.FERMENTING, brew.start_time)
            brew.start_new_stage(Stage.BOTTLE_CONDITIONING,
                                 brew.start_time + datetime.timedelta(days=7))
            if brew.start_time + datetime.timedelta(days=21) < now:
                brew.complete(brew.start_time + datetime.timedelta(days=21))
            try:
                del brew.__dict__['current_stage']
            except KeyError:
                pass
            brew_service.save(brew)
            sync.sync_brew(brew)

        for series in measurement_service.get_all_series_for_brew(brew):
            if not hasattr(series, 'brew_remote_id'):
                series.brew_remote_id = brew.remote_id
                measurement_service.save_series(series)

    print('Migration complete!')
Ejemplo n.º 2
0
def new_brew(brew_service: BrewService):
    if not request.args or "name" not in request.args:
        return render_template("error.html",
                               message="You need to give a new brew a name")
    name = request.args.get("name")
    descr = request.args.get("description")
    brew_service.new(name, descr)
    brews = brew_service.get_all()
    return render_template("brews.html", all_brews=sort_brews(brews))
Ejemplo n.º 3
0
def update_brew(brew_service: BrewService):
    if not request.args or "name" not in request.args:
        return render_template("error.html",
                               message="You need to give a new brew a name")
    brew_id = request.args.get("brew_id")
    name = request.args.get("updated_name")
    descr = request.args.get("updated_description")
    brew_service.get_all()
    brew = brew_service.get_by_id(brew_id)
    brew.name = name
    brew.description = descr
    brews = brew_service.save(brew)
    return render_template("brews.html", all_brews=sort_brews(brews))
Ejemplo n.º 4
0
def complete(brew_service: BrewService, brew_id: str):
    if not brew_id:
        return render_template("error.html", message="Invalid request")
    brew = brew_service.complete(brew_id)
    return render_template(
        "success.html",
        message='Brew "%s" successfully completed' % brew.get_display_name(),
    )
Ejemplo n.º 5
0
def config(
    source_factory: TempSourceFactory,
    smell_factory: SmelloscopeFactory,
    brew_service: BrewService,
    meas_service: MeasurementService,
):
    active_brew = brew_service.get_active()
    smell_sources = smell_factory.get_all_sources()
    temp_sources = source_factory.get_all_temp_sources()
    if active_brew:
        active_series = meas_service.get_all_series_for_brew(
            brew_service.get_active())
        add_nicknames_to_source(smell_sources, active_series)
        add_nicknames_to_source(temp_sources, active_series)

    return render_template("config.html",
                           smell_sources=smell_sources,
                           temp_sources=temp_sources)
Ejemplo n.º 6
0
def change_status(brew_service: BrewService, brew_id: str):
    stage: str = str(request.args.get("stage"))
    if not brew_id or not stage:
        return render_template("error.html", message="Invalid request")
    brew = brew_service.update_stage(brew_id, Stage[stage])
    return render_template(
        "success.html",
        message='Brew "%s" successfully updated' % brew.get_display_name(),
    )
Ejemplo n.º 7
0
def set_inactive(brew_service: BrewService):
    if not request.args or "id" not in request.args:
        return render_template("error.html", message="Invalid request")
    brew_id = str(request.args.get("id"))
    brew = brew_service.set_inactive(brew_id)
    return render_template(
        "success.html",
        message='Brew "%s" successfully inactivated' % brew.get_display_name(),
    )
Ejemplo n.º 8
0
def set_nickname(measure_service: MeasurementService,
                 brew_service: BrewService):
    if not request.args or "name" not in request.args or "nickname" not in request.args:
        abort(400)
    name = request.args.get("name")
    nickname = request.args.get("nickname")

    series = measure_service.get_series_by_source(name,
                                                  brew_service.get_active().id)
    if series:
        series.nickname = nickname
        measure_service.save_series(series)
        message = name + " successfully updated nickname to " + nickname
        return render_template("success.html", message=message)

    return render_template("error.html",
                           message="Could not find probe named: " + name)
Ejemplo n.º 9
0
def alcohol_level(
    brew_service: BrewService,
    smell_factory: SmelloscopeFactory,
    historical_service: MeasurementService,
):
    current_sources = smell_factory.get_all_sources()
    active_source_names = [source.get_name() for source in current_sources]
    brew = brew_service.get_active()
    if not brew:
        return render_template("error.html", message="No active brew")

    # Pull from historical and turn into chart
    active_series = historical_service.get_all_series_for_brew(brew)
    for series in active_series:
        if series.source_name in active_source_names:
            charts.register(make_chart(series))

    add_nicknames_to_source(current_sources, active_series)
    return render_template("alcohol.html", smell_sources=current_sources)
Ejemplo n.º 10
0
def temperature_monitor(
    brew_service: BrewService,
    temperature_sources: TempSourceFactory,
    historical_service: MeasurementService,
):
    current_temp_sources = temperature_sources.get_all_temp_sources()
    active_source_names = [
        source.get_name() for source in current_temp_sources
    ]
    brew = brew_service.get_active()
    if not brew:
        return render_template("error.html", message="No active brew")

    # Pull from historical and turn into chart
    active_series = historical_service.get_all_series_for_brew(brew)
    for series in active_series:
        if series.source_name in active_source_names:
            charts.register(make_chart(series))

    add_nicknames_to_source(current_temp_sources, active_series)

    return render_template("temperature.html",
                           temp_sources=current_temp_sources)
Ejemplo n.º 11
0
def index(brew_service: BrewService):
    brew = brew_service.get_active()
    if not brew:
        return redirect(url_for("brews.view_brews"))
    return redirect(url_for("temperature_monitor"))
Ejemplo n.º 12
0
def view_brews(brew_service: BrewService):
    brews = brew_service.get_all()
    return render_template("brews.html", all_brews=sort_brews(brews))