コード例 #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)
コード例 #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)
コード例 #3
0
ファイル: views.py プロジェクト: opengridcc/website
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)
コード例 #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)
コード例 #5
0
ファイル: views.py プロジェクト: opengridcc/website
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
    )
コード例 #6
0
ファイル: views.py プロジェクト: opengridcc/website
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
    )