예제 #1
0
def subset():
    key = session["key"]
    entity = json.loads(key)
    touch(entity["file_spec"])
    dobj = Dobject(entity)
    choices = list()
    no = 0
    for key in dobj.keys:
        choices.append((no, key))
        no += 1
    form = Subset()
    form.attributes.choices = choices
    if form.validate_on_submit():
        columns = form.attributes.data
        r_start = form.row_start.data
        r_end = form.row_end.data
        df = dobj.subset(columns, r_start, r_end)
        table = dobject.get_head(df, 20)
        with open(dobj.file_path + "/subset.tbl", "w") as f:
            f.write(table)
        head = f"{Config.HOST}/subset_head"
        return render_template("subset.html", df=df, h=head)
    else:
        form.row_start.data = 0
        form.row_end.data = dobj.rows
        return render_template("subset_form.html", form=form, dobj=dobj)
예제 #2
0
def head():
    key = session.get("key")
    entity = json.loads(key)
    touch(entity["file_spec"])
    dobj = Dobject(entity)
    table = dobj.head
    return render_template("table.html", table=table)
예제 #3
0
def info():
    key = session["key"]
    entity = json.loads(key)
    touch(entity["file_spec"])
    dobj = Dobject(entity)
    head = f"{Config.HOST}/head"
    stats = f"{Config.HOST}/stats"
    return render_template("info.html", h=head, s=stats, dobj=dobj)
예제 #4
0
def subset_head():
    key = session.get("key")
    entity = json.loads(key)
    touch(entity["file_spec"])
    dobj = Dobject(entity)
    file_path = dobj.file_path
    with open(file_path + "/subset.tbl", "r") as f:
        table = f.read()
    return render_template("table.html", table=table)
예제 #5
0
def download():
    key = session.get("key")
    entity = json.loads(key)
    touch(entity["file_spec"])
    dobj = Dobject(entity)
    file_path = dobj.file_path + "/subset.csv"
    return send_file(
        file_path,
        mimetype="text/csv",
        as_attachment=True,
        attachment_filename="subset.csv",
    )
예제 #6
0
def plot():
    key = session["key"]
    entity = json.loads(key)
    touch(entity["file_spec"])
    dobj = Dobject(entity)
    choices = list()
    no = 0
    for key in dobj.keys:
        choices.append((no, key))
        no += 1
    form = Plot()
    form.x_attr.choices = choices
    form.y_attr.choices = choices
    if form.validate_on_submit():
        x_attr = form.x_attr.data
        date_x = form.x_date.data
        y_attr = form.y_attr.data
        df = dobj.plot([x_attr, y_attr], date_x)
        file_name = str(uuid.uuid4()) + ".html"
        file_spec = Config.ROOT_DIR + "/static/" + file_name
        dplot.plot_xy(df, date_x, file_spec)
        return render_template("plot.html", f=file_name)
    else:
        return render_template("plot_form.html", form=form, dobj=dobj)
예제 #7
0
def index(purl: str = None):
    if purl is not None:
        if purl == "favicon.ico":
            return '<link rel="shortcut icon" href="about:blank">'
        r = requests.get(purl)
        if r.status_code == requests.codes.ok:
            file_name = get_file_name(r.headers)
            file_path = purl[8:]
            table = r.text
            file_spec = datatable.write(file_path, file_name, table)
            key = (
                f'{{"file_spec": "{file_spec}", "file_name": "{file_name}", '
                f'"purl": "{purl}"}}'
            )
            session["key"] = key
            entity = json.loads(key)
            dobj = Dobject(entity)
            head = f"{Config.HOST}/head"
            stats = f"{Config.HOST}/stats"
            return render_template("info.html", h=head, s=stats, dobj=dobj)
        else:
            return f"Data not found at URL: {purl}", 404

    return "No data link provided in request!", 400
예제 #8
0
def keys():
    file_spec = session.get("key")
    dobj = Dobject(file_spec)
    k = dobj.keys
    return render_template("keys.html", keys=k)