Beispiel #1
0
def make_table_layout():
    filename = "../examples/datatables/project/static/data.json"
    df = get_data(filename)

    ui = UILayout("SimpleChart")
    ui.add_chart(create_datatable(df))
    return ui
Beispiel #2
0
def make_table_layout():
    filename = "../examples/datatables/project/static/data.json"
    df = get_data(filename)

    ui = UILayout("SimpleChart")
    ui.add_chart(create_datatable(df))
    return ui
Beispiel #3
0
def make_datamaps_ui(filename):
    # Make a UI
    ui = UILayout("SimpleChart")

    df = pd.read_csv(filename)
    df.month = df.month.astype('str')

    sldr = SliderInput("Month", 1, 13, "month", "1")
    ui.add_filter(sldr)

    dm = DatamapUSA("/data_map/", "mapid", df,
        "state", "color1", init_params={"month": "1"})
    ui.add_chart(dm)
    return ui
Beispiel #4
0
def build_filter_props(buttons):
    """ build filter props

        return props for a list of buttons.

        Args:
            buttons (list): list of pyxley.Filter components.
    """
    ui = UILayout("PyxleyChart")

    for b in buttons:
        ui.add_filter(b)

    return ui.build_props()
Beispiel #5
0
def make_mg_layout():
    # load a dataframe
    filename = "../examples/metricsgraphics/project/fitbit_data.csv"
    df = pd.read_csv(filename)

    # Make a UI
    ui = UILayout("FilterChart")

    # Make a Button
    cols = [c for c in df.columns if c != "Date"]
    btn = SelectButton("Data", cols, "Data", "Steps")

    # add the button to the UI
    ui.add_filter(btn)

    # stack the dataframe
    _stack = df.set_index("Date").stack().reset_index()
    _stack = _stack.rename(columns={"level_1": "Data", 0: "value"})

    # Make a Figure, add some settings, make a line plot
    ui.add_chart(create_line_plot(_stack))
    ui.add_chart(create_histogram(_stack))
    ui.add_chart(create_scatterplot(df))

    return ui
Beispiel #6
0
def build_filter_props(buttons):
    """ build filter props

        return props for a list of buttons.

        Args:
            buttons (list): list of pyxley.Filter components.
    """
    ui = UILayout("PyxleyChart")

    for b in buttons:
        ui.add_filter(b)

    return ui.build_props()
Beispiel #7
0
    def build_ui(self, save):
        self.ui = UILayout(
            "FilterChart",
            "./jsx/SimpleChart",
            "component_id")


        sldr = SliderInput("play_index", 1,
            int(self.on_field["play_index"].max()),
            "play_index", "1")
        self.ui.add_filter(sldr)

        # Add a plotly chart
        self.ui.add_chart(
            add_plotly_chart(self.locations, self.init_params)
        )

        # Add the image panel
        self.ui.add_chart(
            add_image_panel(self.on_field, self.off_field,
                self.init_params)
        )

        if save:
            self.ui.render_layout(self.mod,
                self.static_ + "/layout.js",
                alias="Main")
        else:
            self.ui.assign_routes(self.mod)
Beispiel #8
0
    def build_ui(self, save):

        # Make a UI
        self.ui = UILayout(
            "RunLayout",
            "custom",
            "component_id")

        choices = ["Heart Rate", "Pace", "Distance"]
        btn = SelectButton("Data", choices, "Data", "Heart Rate")
        self.ui.add_filter(btn)

        """
            Add a download button,
            I typically use this to trigger a download, but
            it could be used to trigger another action
        """
        dlbtn = DownloadButton("Download", "/download/", self.download)
        self.ui.add_filter(dlbtn)

        self.add_chart()
        if save:
            self.ui.render_layout(self.mod, self.static_ + "/layout.js")
        else:
            self.ui.assign_routes(self.mod)
Beispiel #9
0
def make_mg_layout():
    # load a dataframe
    filename = "../examples/metricsgraphics/project/fitbit_data.csv"
    df = pd.read_csv(filename)

    # Make a UI
    ui = UILayout("FilterChart")

    # Make a Button
    cols = [c for c in df.columns if c != "Date"]
    btn = SelectButton("Data", cols, "Data", "Steps")

    # add the button to the UI
    ui.add_filter(btn)

    # stack the dataframe
    _stack = df.set_index("Date").stack().reset_index()
    _stack = _stack.rename(columns={"level_1": "Data", 0: "value"})

    # Make a Figure, add some settings, make a line plot
    ui.add_chart(create_line_plot(_stack))
    ui.add_chart(create_histogram(_stack))
    ui.add_chart(create_scatterplot(df))

    return ui
Beispiel #10
0
    def build_ui(self, save):
        self.ui = UILayout("FilterChart", "./jsx/SimpleChart", "component_id")

        sldr = SliderInput("play_index", 1,
                           int(self.on_field["play_index"].max()),
                           "play_index", "1")
        self.ui.add_filter(sldr)

        # Add a plotly chart
        self.ui.add_chart(add_plotly_chart(self.locations, self.init_params))

        # Add the image panel
        self.ui.add_chart(
            add_image_panel(self.on_field, self.off_field, self.init_params))

        if save:
            self.ui.render_layout(self.mod,
                                  self.static_ + "/layout.js",
                                  alias="Main")
        else:
            self.ui.assign_routes(self.mod)
Beispiel #11
0
def make_nv_layout(filename):
    # load the data
    df = pd.read_csv(filename)

    ui = UILayout("FilterChart")

    # Make a button
    choices = ["Heart Rate", "Pace", "Distance"]
    btn = SelectButton("Data", choices, "Data", "Heart Rate")
    ui.add_filter(btn)

    # Add the chart
    ui.add_chart(two_axis_focus(df))
    ui.add_chart(pie_chart(df))
    return ui
Beispiel #12
0
def make_nv_layout():
    # load the data
    filename = "../examples/nvd3/project/static/formatted_run.csv"
    df = pd.read_csv(filename)

    ui = UILayout("FilterChart")

    # Make a button
    choices = ["Heart Rate", "Pace", "Distance"]
    btn = SelectButton("Data", choices, "Data", "Heart Rate")
    ui.add_filter(btn)

    # Add the chart
    ui.add_chart(two_axis_focus(df))
    ui.add_chart(pie_chart(df))
    return ui
Beispiel #13
0
def make_ui(datafiles):
    # Make a UI
    ui = UILayout(
        "FilterChart",
        "pyxley",
        "component_id",
        filter_style="''")

    ff = fatigue(datafiles["scores"])
    pf = load_players(datafiles["players"])
    sf = distance_measures(datafiles["distance"], ff, pf)

    df, _ids = split_teams(datafiles["locations"], pf, sf)

    sf = pd.merge(sf, _ids, on=["game", "ngsId"], how='inner', sort=False)
    _onfield = sf.loc[sf.isOnField == True].reset_index(drop=True)
    _offfield = sf.loc[sf.isOnField == False].reset_index(drop=True)

    sldr = SliderInput("new_index", 1, int(df["new_index"].max()), "new_index", "0")

    # Read in the data and stack it, so that we can filter on columns

    # Make a Button
    games = ["game1", "game2", "game3"]
    btnG = SelectButton("Game", games, "game", "game1")
    # Make a FilterFrame and add the button to the UI
    ui.add_filter(sldr)
    ui.add_filter(btnG)

    init_params = {
        "game": "game1",
        "new_index": "1"
    }

    dm = PlotlyLines([["y", "x"], ["y_away", "x_away"]], df,
        labels=["position", "position_away"],
        names=["Home", "Away"],
        init_params=init_params,
        layout={
            "hovermode": "closest",
            "plot_bgcolor": 'rgba(44,94,79,0.7)',
            "xaxis": {"range": [0, 53]},
            "paper_bgcolor": 'rgba(44, 94, 79, 0.0)',
        })
    ui.add_chart(dm)

    imgs = Images(init_params, _onfield, _offfield)
    ui.add_chart(imgs)
    return ui
Beispiel #14
0
def make_nv_layout(filename):
    # load the data
    df = pd.read_csv(filename)

    ui = UILayout("FilterChart")

    # Make a button
    choices = ["Heart Rate", "Pace", "Distance"]
    btn = SelectButton("Data", choices, "Data", "Heart Rate")
    ui.add_filter(btn)

    # Add the chart
    ui.add_chart(two_axis_focus(df))
    ui.add_chart(pie_chart(df))
    return ui
Beispiel #15
0
def make_nv_layout():
    # load the data
    filename = "../examples/nvd3/project/static/formatted_run.csv"
    df = pd.read_csv(filename)

    ui = UILayout("FilterChart")

    # Make a button
    choices = ["Heart Rate", "Pace", "Distance"]
    btn = SelectButton("Data", choices, "Data", "Heart Rate")
    ui.add_filter(btn)

    # Add the chart
    ui.add_chart(two_axis_focus(df))
    ui.add_chart(pie_chart(df))
    return ui
Beispiel #16
0
def make_datamaps_ui(filename):
    # Make a UI
    ui = UILayout("SimpleChart")

    df = pd.read_csv(filename)
    df.month = df.month.astype('str')

    sldr = SliderInput("Month", 1, 13, "month", "1")
    ui.add_filter(sldr)

    dm = DatamapUSA("/data_map/",
                    "mapid",
                    df,
                    "state",
                    "color1",
                    init_params={"month": "1"})
    ui.add_chart(dm)
    return ui
Beispiel #17
0
def make_datamaps_ui():
    # Make a UI
    ui = UILayout("PyxleyChart")

    datafile = "../examples/datamaps/project/Colorful_State.csv"
    df = pd.read_csv(datafile)
    df.month = df.month.astype('str')

    sldr = SliderInput("Month", 1, 13, "month", "1")
    ui.add_filter(sldr)

    dm = DatamapUSA("/data_map/",
                    "mapid",
                    df,
                    "state",
                    "color1",
                    init_params={"month": "1"})
    ui.add_chart(dm)
    return ui
Beispiel #18
0
def make_ui(datafile):
    # Make a UI
    ui = UILayout("FilterChart", "pyxley", "component_id", filter_style="''")

    df = pd.read_csv(datafile)

    # Read in the data and stack it, so that we can filter on columns
    sf = df.set_index("Date").stack().reset_index()
    sf = sf.rename(columns={"level_1": "Data", 0: "value"})

    # Make a Button
    cols = [c for c in df.columns if c != "Date"]
    btn = SelectButton("Data", cols, "Data", "Steps")

    # Make a FilterFrame and add the button to the UI
    ui.add_filter(btn)

    dm = PlotlyLines([["Date", "value"]], sf, init_params={"Data": "Steps"})
    ui.add_chart(dm)
    return ui
Beispiel #19
0
def make_plotly_ui():
    filename = "../examples/metricsgraphics/project/fitbit_data.csv"
    df = pd.read_csv(filename)

    # Make a UI
    ui = UILayout("PyxleyChart")

    # Read in the data and stack it, so that we can filter on columns
    _stack = df.set_index("Date").stack().reset_index()
    _stack = _stack.rename(columns={"level_1": "Data", 0: "value"})

    # Make a Button
    cols = [c for c in df.columns if c != "Date"]
    btn = SelectButton("Data", cols, "Data", "Steps")

    # add the button to the UI
    ui.add_filter(btn)

    init_params = {"Data": "Steps"}
    def get_data():
        args = {}
        for c in init_params:
            if request.args.get(c):
                args[c] = request.args[c]
            else:
                args[c] = init_params[c]
        return jsonify(
            PlotlyAPI.line_plot(
                PlotlyAPI.apply_filters(_stack, args),
                [("Date", "value")],
                "lines+markers",
                {}
            ))
    _plot = PlotlyAPI(
        "plotly_chart",
        "/api/plotly_line_plot/",
        get_data,
        init_params=init_params
    )
    ui.add_chart(_plot)
    return ui
Beispiel #20
0
def make_mg_layout(filename):
    # load a dataframe
    df = pd.read_csv(filename)
    # Make a UI
    ui = UILayout("FilterChart")
    # Make a Button
    cols = [c for c in df.columns if c != "Year"]
    btn = SelectButton("Abschlussprüfungsleistungen", cols, "Data",
                       "Abschlussprüfungsleistungen")

    # add the button to the UI
    ui.add_filter(btn)

    # stack the dataframe
    _stack = df.set_index("Year").stack().reset_index()
    _stack = _stack.rename(columns={"level_1": "Data", 0: "value"})

    # Make a Figure, add some settings, make a line plot
    ui.add_chart(
        create_line_plot(_stack,
                         i=0,
                         name="Abschlussprüfungsleistungen",
                         n=3,
                         titel="KPMG Umsätze"))

    here = path.abspath(path.dirname(__file__))

    df1 = pd.read_csv(here + "/file")
    # Make a Button
    cols1 = [c for c in df1.columns if c != "Year"]
    btn1 = SelectButton("Professionals", cols1, "Data", "Professionals")

    # add the button to the UI
    ui.add_filter(btn1)
    _stack1 = df1.set_index("Year").stack().reset_index()
    _stack1 = _stack1.rename(columns={"level_1": "Data", 0: "value"})

    # Make a Figure, add some settings, make a line plot
    ui.add_chart(
        create_line_plot(
            _stack1,
            i=1,
            name="Professionals",
            n=8,
            titel="Employees of KPMG worldwide by position 2010-2017"))

    # stack the dataframe
    df2 = pd.read_csv(here + "/file1")
    cols2 = [c for c in df2.columns if c != "Year"]
    btn2 = SelectButton("Revenue in billion $", cols2, "Data",
                        "Revenue in billion $")
    btn2.__setattr__("margin", 50)
    ui.add_filter(btn2)
    # Make a Button
    _stack2 = df2.set_index("Year").stack().reset_index()
    _stack2 = _stack2.rename(columns={"level_1": "Data", 0: "value"})

    # Make a Figure, add some settings, make a line plot
    ui.add_chart(
        create_line_plot(
            _stack2,
            i=2,
            name="Revenue in billion U.S. dollars",
            n=6,
            titel="Big data and business analytics revenue worldwide 2015-2020"
        ))

    return ui
Beispiel #21
0
    "./bower_components/react/react.js",
    "./bower_components/react-bootstrap/react-bootstrap.min.js",
    "./bower_components/pyxley/build/pyxley.js",
]

css = [
    "./bower_components/bootstrap/dist/css/bootstrap.min.css",
    "./bower_components/metrics-graphics/dist/metricsgraphics.css",
    "./bower_components/datatables/media/css/jquery.dataTables.min.css",
    "./css/main.css"
]

# Make a UI
ui = UILayout(
    "FilterChart",
    "./static/bower_components/pyxley/build/pyxley.js",
    "component_id",
    filter_style="''")

# Read in the data and stack it, so that we can filter on columns
df = pd.read_csv("fitbit_data.csv")
sf = df.set_index("Date").stack().reset_index()
sf = sf.rename(columns={"level_1": "Data", 0: "value"})

# Make a Button
cols = [c for c in df.columns if c != "Date"]
btn = SelectButton("Data", cols, "Data", "Steps")

# Make a FilterFrame and add the button to the UI
ui.add_filter(btn)
Beispiel #22
0
from flask import Flask, render_template
import pandas as pd

# Import pyxley stuff
from pyxley import UILayout
from pyxley.filters import SelectButton
from pyxley.charts.mg import LineChart, Figure

# Read in the data and stack it, so that we can filter on columns
df = pd.read_csv("fitbit_data.csv")
sf = df.set_index("Date").stack().reset_index()
sf = sf.rename(columns={"level_1": "Data", 0: "value"})

# Make a UI
ui = UILayout(
    "FilterChart",
    "./static/bower_components/pyxley/build/pyxley.js",
    "component_id")

app = Flask(__name__)

# Make a Button
cols = [c for c in df.columns if c != "Date"]
btn = SelectButton("Data", cols, "Data", "Steps")

# Make a FilterFrame and add the button to the UI
ui.add_filter(btn)

# Make a Figure, add some settings, make a line plot
fig = Figure("/mgchart/", "mychart")
fig.graphics.transition_on_update(True)
fig.graphics.animate_on_load()
Beispiel #23
0
def make_table_layout(filename):
    df = get_data(filename)

    ui = UILayout("SimpleChart")
    ui.add_chart(create_datatable(df))
    return ui
Beispiel #24
0
from pyxley.charts.mg import LineChart, Figure, ScatterPlot, Histogram
from pyxley.charts.datatables import DataTable
from collections import OrderedDict

parser = argparse.ArgumentParser(description="Flask Template")
parser.add_argument("--env", help="production or local", default="local")
args = parser.parse_args()

TITLE = "Pyxley"

scripts = []

css = ["./css/main.css"]

# Make a UI
ui = UILayout("FilterChart", "pyxley", "component_id", filter_style="''")

# Read in the data and stack it, so that we can filter on columns
df = pd.read_csv("project/fitbit_data.csv")
sf = df.set_index("Date").stack().reset_index()
sf = sf.rename(columns={"level_1": "Data", 0: "value"})

# Make a Button
cols = [c for c in df.columns if c != "Date"]
btn = SelectButton("Data", cols, "Data", "Steps")

# Make a FilterFrame and add the button to the UI
ui.add_filter(btn)

# Make a Figure, add some settings, make a line plot
fig = Figure("/mgchart/", "mychart")
Beispiel #25
0
parser.add_argument("--env", help="production or local", default="local")
args = parser.parse_args()

TITLE = "Pyxley"

scripts = [
    "./chartfunc.js"
]

css = [
    "./css/main.css"
]

# Make a UI
ui = UILayout(
    "RunLayout",
    "./jsx/custom",
    "component_id")

# Read in the data and stack it, so that we can filter on columns
df = pd.read_csv("./project/static/formatted_run.csv")

# Make a Button
choices = ["Heart Rate", "Pace", "Distance"]
btn = SelectButton("Data", choices, "Data", "Heart Rate")
ui.add_filter(btn)

# Add our new chart
colors = ["#847c77", "#ff5c61"];
nc = NewChart("Seconds", "value", "Altitude", df,
    init_params={"Data": "Heart Rate"}, colors=colors)
ui.add_chart(nc)
Beispiel #26
0
class MainView(MainModel):

    def __init__(self, cache, save=False):
        super(MainView, self).__init__(cache)

        self.mod = Blueprint("main", __name__)
        self.mod.add_url_rule("/", view_func=self.index)

        self.ins_, self.static_ = get_static_folder()

        self.init_params = {
            "play_index": "1"
        }

        self.build_ui(save)

    def index(self):

        return render_template('index.html',
            title="Main",
            base_scripts=config.JS,
            css=config.CSS,
            page_scripts=["bundle.js"])

    def build_ui(self, save):
        self.ui = UILayout(
            "FilterChart",
            "./jsx/SimpleChart",
            "component_id")


        sldr = SliderInput("play_index", 1,
            int(self.on_field["play_index"].max()),
            "play_index", "1")
        self.ui.add_filter(sldr)

        # Add a plotly chart
        self.ui.add_chart(
            add_plotly_chart(self.locations, self.init_params)
        )

        # Add the image panel
        self.ui.add_chart(
            add_image_panel(self.on_field, self.off_field,
                self.init_params)
        )

        if save:
            self.ui.render_layout(self.mod,
                self.static_ + "/layout.js",
                alias="Main")
        else:
            self.ui.assign_routes(self.mod)

    def check_args(self):
        args = {}
        for c in self.init_params:
            if request.args.get(c):
                args[c] = request.args[c]
            else:
                args[c] = self.init_params[c]
        return args

    def chart_data(self):
        args = self.check_args()
        df = PlotlyLines.apply_filters(
            self.locations, args)
        return jsonify(
            PlotlyLines.to_json(
                df,
                xypairs,
                mode,
                ptype,
                labels,
                layout,
                names
            ))

    def image_data(self):
        args = self.check_args()

        _in = Images.apply_filters(self.on_field, args)
        _out = Images.apply_filters(self.off_field, args)

        return jsonify(
            Images.to_json(
                _in, _out, Images.imgs
            ))
Beispiel #27
0
def make_table_layout(filename):
    df = get_data(filename)

    ui = UILayout("SimpleChart")
    ui.add_chart(create_datatable(df))
    return ui
Beispiel #28
0
def uploaded_file(filename):
    extension = get_extension(filename)
    path = os.path.join(app.config['UPLOAD_FOLDER'], extension, filename)
    txt_path = os.path.join(app.config['UPLOAD_FOLDER'], 'txt', filename)
    if extension == "pdf":
        txt_path += '.txt'
        if not os.path.isfile(txt_path):
            #Layout preservation crucial to preserve clues about tabular data
            cmd = "pdftotext -layout %s %s" % (path, txt_path)
            os.system(cmd)

    min_columns = request.args.get('min_columns')
    tables = return_tables(txt_path)

    #Construct histogram
    lines_per_page = 80
    nr_data_rows = []
    for b, t in tables.iteritems():
        e = t['end_line']
        #print b, e
        for l in range(b, e):
            page = l / lines_per_page
            if len(nr_data_rows) <= page:
                nr_data_rows += ([0] * (page - len(nr_data_rows) + 1))
            nr_data_rows[page] += 1
    dr = pd.DataFrame()
    dr['value'] = nr_data_rows
    dr['page'] = range(0, len(dr))

    js_layout = filename + ".js"

    ui_show = UILayout("FilterChart",
                       "../static/bower_components/pyxley/build/pyxley.js",
                       "component_id",
                       filter_style="''")

    if filename in all_charts:
        print "old/update ui", filename
        path_to_fig = '/show/line/' + filename
        #del all_charts[filename]
        #hFig = Figure(path_to_fig, "line")
        #bc = LineChart(dr, hFig, "page", ["page"], "Rows containing Data per Page")
    elif True:
        print "new ui", filename

        # Make a Button
        cols = ["page"]
        btn = SelectButton("Data", cols, "Data", "Data Rows per Page")

        # Make a FilterFrame and add the button to the UI
        ui_show.add_filter(btn)

        # Now make a FilterFrame for the histogram
        path_to_fig = '/show/line/' + filename
        hFig = Figure(path_to_fig, "line")
        hFig.layout.set_size(width=1000, height=300)
        hFig.layout.set_margin(left=80, right=80)
        #hFig.graphics.animate_on_load()

        bc = LineChart(dr, hFig, "page", ["value"],
                       "Rows containing Data per Page")
        ui_show.add_chart(bc)
        all_charts[filename] = bc

        sb = ui_show.render_layout(app, "./static/ug/" + js_layout)

    _scripts = ["ug/" + js_layout]
    notices = ['Extraction Results for ' + filename, 'Ordered by lines']

    dfs = (table_to_df(table).to_html() for table in tables.values())
    headers = []
    for t in tables.values():
        if 'header' in t:
            headers.append(t['header'])
        else:
            headers.append('-')

    line_nrs = [('line %i-%i' % (t['begin_line'], t['end_line']))
                for t in tables.values()]
    #headers = ['aslkdfjas', ' alsdkfjasoedf']

    return render_template('index.html',
                           title=TITLE + ' - ' + filename,
                           base_scripts=scripts,
                           page_scripts=_scripts,
                           css=css,
                           notices=notices,
                           tables=dfs,
                           headers=headers,
                           line_nrs=line_nrs)
Beispiel #29
0
from collections import OrderedDict

parser = argparse.ArgumentParser(description="Flask Template")
parser.add_argument("--env", help="production or local", default="local")
args = parser.parse_args()

TITLE = "Pyxley"

scripts = []

css = ["./css/main.css"]

# Make a UI
ui = UILayout(
    "FilterChart",
    "pyxley",
    "component_id",
    filter_style="''")

# Read in the data and stack it, so that we can filter on columns
df = pd.read_csv("project/fitbit_data.csv")
sf = df.set_index("Date").stack().reset_index()
sf = sf.rename(columns={"level_1": "Data", 0: "value"})

# Make a Button
cols = [c for c in df.columns if c != "Date"]
btn = SelectButton("Data", cols, "Data", "Steps")

# Make a FilterFrame and add the button to the UI
ui.add_filter(btn)
Beispiel #30
0
class MainView(MainModel):
    _FILES = ["data"]
    def __init__(self, cache, save=False):
        super(MainView, self).__init__(cache)

        self.mod = Blueprint("main", __name__)
        self.mod.add_url_rule("/", view_func=self.index)

        self.ins_, self.static_ = get_static_folder()
        self.build_ui(save)

    def index(self):

        shims = {
            "custom": ["twoAxisLinePlot", "pyxley"],
            "main": ["custom"]
        }

        _module_list = [
            ["navbar", "main"]
        ]
        _modules = OrderedDict([(",".join(m), m) for m in _module_list])
        _baseUrl = "./static/js"
        _paths = {
            "pyxley": "../bower_components/pyxley/build/pyxley",
            "main": "../layout"
        }
        return render_template('index.html',
            title="Main",
            base_scripts=config.JS,
            css=config.CSS,
            baseUrl=_baseUrl,
            modules=_modules,
            paths=json.dumps(_paths),
            shims=json.dumps(shims))

    def build_ui(self, save):

        # Make a UI
        self.ui = UILayout(
            "RunLayout",
            "custom",
            "component_id")

        choices = ["Heart Rate", "Pace", "Distance"]
        btn = SelectButton("Data", choices, "Data", "Heart Rate")
        self.ui.add_filter(btn)

        """
            Add a download button,
            I typically use this to trigger a download, but
            it could be used to trigger another action
        """
        dlbtn = DownloadButton("Download", "/download/", self.download)
        self.ui.add_filter(dlbtn)

        self.add_chart()
        if save:
            self.ui.render_layout(self.mod, self.static_ + "/layout.js")
        else:
            self.ui.assign_routes(self.mod)

    def download(self):
        print "Change this to do something else"
        print "For now it will reload"
        self.cache.load()
        return jsonify({"data": "Success!"})

    def chart_data(self):
        args = {}
        for c in self.init_params:
            if request.args.get(c):
                args[c] = request.args[c]
            else:
                args[c] = self.init_params[c]
        return jsonify(NewChart.to_json(
                NewChart.apply_filters(self.data, args),
                "Seconds",
                "value",
                "Altitude"
            ))

    def add_chart(self):
        colors = ["#847c77", "#ff5c61"]
        self.init_params = {
            "Data": "Heart Rate"
        }
        nc = NewChart("Seconds", "value", "Altitude",
            self.data,
            init_params=self.init_params, colors=colors,
            route_func=self.chart_data)
        self.ui.add_chart(nc)
Beispiel #31
0
from pyxley import UILayout
from pyxley.filters import SelectButton, SliderInput
from pyxley.charts.datamaps import DatamapUSA

TITLE = "Pyxley"

scripts = []

css = [
    "./css/main.css"
]

# Make a UI
ui = UILayout(
    "FilterChart",
    "pyxley",
    "component_id",
    filter_style="''")


df = pd.read_csv("./project/static/Colorful_State.csv")
df.month = df.month.astype('str')

sldr = SliderInput("Month", 1, 13, "month", "1")
ui.add_filter(sldr)

dm = DatamapUSA("/data_map/", "mapid", df,  "state", "color1", init_params={"month": "1"})
ui.add_chart(dm)

app = Flask(__name__)
sb = ui.render_layout(app, "./project/static/layout.js")
Beispiel #32
0
def uploaded_file(filename):
    extension = get_extension(filename)
    path = os.path.join(app.config['UPLOAD_FOLDER'], extension, filename)
    txt_path = os.path.join(app.config['UPLOAD_FOLDER'], 'txt', filename)
    if extension == "pdf":
        txt_path += '.txt'
        if not os.path.isfile(txt_path):
        #Layout preservation crucial to preserve clues about tabular data
            cmd = "pdftotext -layout %s %s" % (path, txt_path)
            os.system(cmd)
            
    min_columns = request.args.get('min_columns')
    tables = return_tables(txt_path)

    #Construct histogram
    lines_per_page = 80
    nr_data_rows = []
    for b, t in tables.iteritems():
        e = t['end_line']
        #print b, e
        for l in range(b, e):
            page = l / lines_per_page
            if len(nr_data_rows) <= page:
                nr_data_rows += ([0]*(page-len(nr_data_rows)+1))
            nr_data_rows[page] += 1
    dr = pd.DataFrame()
    dr['value'] = nr_data_rows
    dr['page'] = range(0, len(dr))
    
    js_layout = filename+".js"
      
    ui_show = UILayout(
    "FilterChart",
    "../static/bower_components/pyxley/build/pyxley.js",
    "component_id",
    filter_style="''")
    
    if filename in all_charts:
        print "old/update ui", filename        
        path_to_fig = '/show/line/'+filename
        #del all_charts[filename]
        #hFig = Figure(path_to_fig, "line")        
        #bc = LineChart(dr, hFig, "page", ["page"], "Rows containing Data per Page")    
    elif True:
        print "new ui", filename
        
        # Make a Button
        cols = ["page"]
        btn = SelectButton("Data", cols, "Data", "Data Rows per Page")

        # Make a FilterFrame and add the button to the UI
        ui_show.add_filter(btn)
        
        # Now make a FilterFrame for the histogram
        path_to_fig = '/show/line/'+filename
        hFig = Figure(path_to_fig, "line")
        hFig.layout.set_size(width=1000, height=300)
        hFig.layout.set_margin(left=80, right=80)
        #hFig.graphics.animate_on_load()

        bc = LineChart(dr, hFig, "page", ["value"], "Rows containing Data per Page")
        ui_show.add_chart(bc)
        all_charts[filename] = bc

        sb = ui_show.render_layout(app, "./static/ug/"+js_layout)
                
    _scripts = ["ug/"+js_layout]
    notices = ['Extraction Results for ' + filename, 'Ordered by lines']
    
    dfs = (table_to_df(table).to_html() for table in tables.values())
    headers = []
    for t in tables.values():
        if 'header' in t:
            headers.append(t['header'])
        else:
            headers.append('-')
            
    line_nrs = [('line %i-%i' % (t['begin_line'], t['end_line'])) for t in tables.values() ]
    #headers = ['aslkdfjas', ' alsdkfjasoedf']
    
    return render_template('index.html',
        title=TITLE + ' - ' + filename,
        base_scripts=scripts,
        page_scripts=_scripts,
        css=css, notices = notices, tables = dfs, headers=headers, line_nrs=line_nrs)
Beispiel #33
0
class MainView(MainModel):
    def __init__(self, cache, save=False):
        super(MainView, self).__init__(cache)

        self.mod = Blueprint("main", __name__)
        self.mod.add_url_rule("/", view_func=self.index)

        self.ins_, self.static_ = get_static_folder()

        self.init_params = {"play_index": "1"}

        self.build_ui(save)

    def index(self):

        return render_template('index.html',
                               title="Main",
                               base_scripts=config.JS,
                               css=config.CSS,
                               page_scripts=["bundle.js"])

    def build_ui(self, save):
        self.ui = UILayout("FilterChart", "./jsx/SimpleChart", "component_id")

        sldr = SliderInput("play_index", 1,
                           int(self.on_field["play_index"].max()),
                           "play_index", "1")
        self.ui.add_filter(sldr)

        # Add a plotly chart
        self.ui.add_chart(add_plotly_chart(self.locations, self.init_params))

        # Add the image panel
        self.ui.add_chart(
            add_image_panel(self.on_field, self.off_field, self.init_params))

        if save:
            self.ui.render_layout(self.mod,
                                  self.static_ + "/layout.js",
                                  alias="Main")
        else:
            self.ui.assign_routes(self.mod)

    def check_args(self):
        args = {}
        for c in self.init_params:
            if request.args.get(c):
                args[c] = request.args[c]
            else:
                args[c] = self.init_params[c]
        return args

    def chart_data(self):
        args = self.check_args()
        df = PlotlyLines.apply_filters(self.locations, args)
        return jsonify(
            PlotlyLines.to_json(df, xypairs, mode, ptype, labels, layout,
                                names))

    def image_data(self):
        args = self.check_args()

        _in = Images.apply_filters(self.on_field, args)
        _out = Images.apply_filters(self.off_field, args)

        return jsonify(Images.to_json(_in, _out, Images.imgs))