Esempio n. 1
0
def download(guid=None):
    form = DownloadForm()

    if request.method == 'POST' and form.validate():
        s = hp.find_device(form.guid.data)
        if s is None:
            s = hp.find_sensor(form.guid.data)

        if s is None:
            flash("ID not found")
        else:
            try:
                df = s.get_data(head=pd.Timestamp(form.start.data),
                                tail=pd.Timestamp(form.end.data),
                                resample=form.resample.data)
            except:
                flash(
                    "Error connecting to the data storage, please try again later"
                )
            else:
                filename = '{}.csv'.format(s.key)
                filepath = safe_join(download_path, filename)
                df.to_csv(filepath, encoding='utf-8')
                del df
                gc.collect()
                return send_file(filepath, as_attachment=True)

    if guid is not None:
        form.guid.data = guid

    return render_template('download.html', form=form)
Esempio n. 2
0
def search():
    form = SearchForm()
    if request.method == 'POST' and form.validate():
        f = hp.find_device(form.search_string.data)
        if f is not None:  # flukso was found
            return redirect(url_for('flukso', fluksoid=f.key))
        else:
            flash("Sorry, we couldn't find that Fluksometer")

    return render_template("search.html", form=form)
Esempio n. 3
0
def search():
    form = SearchForm()
    if request.method == 'POST' and form.validate():
        f = hp.find_device(form.search_string.data)
        if f is not None:  # flukso was found
            return redirect(url_for('flukso', fluksoid=f.key))
        else:
            flash("Sorry, we couldn't find that Fluksometer")

    return render_template(
        "search.html",
        form=form)
Esempio n. 4
0
def flukso(fluksoid):
    f = hp.find_device(fluksoid)

    if f is None:
        flash('Your FluksoID was not found in our database.\
        If you want to see OpenGrid analyses for your Flukso, please fill in the form below.'
              )
        return redirect(url_for('development'))

    sensors = f.get_sensors()
    sensors.sort(key=lambda x: x.type)

    return render_template('flukso.html', flukso=f, sensors=sensors)
Esempio n. 5
0
def flukso(fluksoid):
    f = hp.find_device(fluksoid)

    if f is None:
        flash('Your FluksoID was not found in our database.\
        If you want to see OpenGrid analyses for your Flukso, please fill in the form below.')
        return redirect(url_for('development'))

    sensors = f.get_sensors()
    sensors.sort(key=lambda x: x.type)

    return render_template(
        'flukso.html',
        flukso=f,
        sensors=sensors
    )
Esempio n. 6
0
def download(guid=None):
    form = DownloadForm()

    if request.method == 'POST' and form.validate():
        s = hp.find_device(form.guid.data)
        if s is None:
            s = hp.find_sensor(form.guid.data)

        if s is None:
            flash("ID not found")
        else:
            try:
                df = s.get_data(
                    head=pd.Timestamp(form.start.data),
                    tail=pd.Timestamp(form.end.data),
                    resample=form.resample.data
                )
            except:
                flash("Error connecting to the data storage, please try again later")
            else:
                filename = '{}.csv'.format(s.key)
                filepath = safe_join(download_path, filename)
                df.to_csv(filepath, encoding='utf-8')
                del df
                gc.collect()
                return send_file(
                    filepath,
                    as_attachment=True
                )

    if guid is not None:
        form.guid.data = guid

    return render_template(
        'download.html',
        form=form
    )