Esempio n. 1
0
def display_type(selector):
    if selector == 'all':
        return list(WELL_TYPES.keys())
    elif selector == 'productive':
        return ['GD', 'GE', 'GW', 'IG', 'IW', 'OD', 'OE', 'OW']
    else:
        return []
Esempio n. 2
0
                     "value": "prov_name"
                 },
                 {
                     "label": "North West ",
                     "value": "custom"
                 },
             ],
             value="productive",
             labelStyle={"display": "inline-block"},
             className="dcc_control",
         ),
         dcc.Dropdown(
             id="well_types",
             options=well_type_options,
             multi=True,
             value=list(WELL_TYPES.keys()),
             className="dcc_control",
         ),
     ],
     className="pretty_container four columns",
     id="cross-filter-options",
 ),
 html.Div(
     [
         html.Div(
             [
                 html.Div(
                     [
                         html.H6(id="well_text"),
                         html.P("Current Water Use (Litres)")
                     ],
Esempio n. 3
0
def display_type(selector):
    if selector == "all":
        return list(WELL_TYPES.keys())
    elif selector == "productive":
        return ["GD", "GE", "GW", "IG", "IW", "OD", "OE", "OW"]
    return []
def display_type(selector):
    if selector == 'all':
        return list(WELL_TYPES.keys())
    elif selector == 'productive':
Esempio n. 5
0
    def __init__(self, url_base_pathname=None):
        #         server = flask.Flask(__name__)
        #         app = dgc.dash.Dash(__name__, server=server)

        #         self.app = dgc.dash.Dash(__name__)
        #         self.app = dgc.dash.Dash(__name__, url_base_pathname='/dev/')
        if url_base_pathname is None:
            self.app = dgc.dash.Dash(__name__)
        else:
            self.app = dgc.dash.Dash(__name__,
                                     url_base_pathname=url_base_pathname)

        # Create controls
        county_options = [{
            "label": str(COUNTIES[county]),
            "value": str(county)
        } for county in COUNTIES]
        well_status_options = [{
            "label": str(WELL_STATUSES[well_status]),
            "value": str(well_status)
        } for well_status in WELL_STATUSES]
        well_type_options = [{
            "label": str(WELL_TYPES[well_type]),
            "value": str(well_type)
        } for well_type in WELL_TYPES]
        # This is taken from Dash Project
        df1 = pd.read_csv(os.path.join(DATA_PATH, "wellspublic.csv"),
                          low_memory=False)
        #         df1 = get_df_from_dropbox(os.path.join(DATA_PATH,"wellspublic.csv"))
        #         df1 = get_df_from_dropbox(DATA_PATH + "/wellspublic.csv")
        df1["Date_Well_Completed"] = pd.to_datetime(df1["Date_Well_Completed"])
        df1 = df1[df1["Date_Well_Completed"] > dt.datetime(1960, 1, 1)]
        df1['Year_Well_Completed'] = df1.Date_Well_Completed.apply(
            lambda d: d.year)
        df1['Month_Well_Completed'] = df1.Date_Well_Completed.apply(
            lambda d: d.month)
        self.df1 = df1.copy()

        trim = df1[["API_WellNo", "Well_Type", "Well_Name"]]
        trim.index = trim["API_WellNo"]
        dataset = trim.to_dict(orient="index")
        points = pickle.load(open(os.path.join(DATA_PATH, "points.pkl"), "rb"))
        #         points = get_pickle_from_dropbox(os.path.join(DATA_PATH,"points.pkl"))
        #         points = get_pickle_from_dropbox(DATA_PATH+"/points.pkl")
        tgas = 'Gas Produced, MCF'
        twater = 'Water Produced, bbl'
        toil = 'Oil Produced, bbl'
        dict_list = [{
            'API_WellNo': k,
            'year': y,
            'gas': points[k][y][tgas],
            'water': points[k][y][twater],
            'oil': points[k][y][toil]
        } for k in points.keys() for y in points[k].keys()]
        df_points = pd.DataFrame(dict_list)
        df_points[
            'all_types'] = df_points.gas + df_points.water + df_points.oil
        self.df_points = df_points.copy()

        df_county = pd.DataFrame({
            'Cnty': [int(s) for s in list(COUNTIES.keys())],
            'cname':
            list(COUNTIES.values())
        })
        df2 = df1.merge(df_county, on='Cnty', how='inner')
        #     print(len(df2))
        df_well_status = pd.DataFrame({
            'Well_Status': list(WELL_STATUSES.keys()),
            'wstatus': list(WELL_STATUSES.values())
        })
        df2 = df2.merge(df_well_status, on='Well_Status', how='inner')
        df_well_type = pd.DataFrame({
            'Well_Type': list(WELL_TYPES.keys()),
            'wtype': list(WELL_TYPES.values())
        })
        df2 = df2.merge(df_well_type, on='Well_Type', how='inner')
        df_well_color = pd.DataFrame({
            'Well_Type': list(WELL_COLORS.keys()),
            'wcolor': list(WELL_COLORS.values())
        })
        df2 = df2.merge(df_well_color, on='Well_Type', how='inner')
        df = df2.copy()
        self.df = df.copy()

        # Define the static components
        # ********************** plotly logo ****************************
        img = html.Img(src=self.app.get_asset_url("dash-logo.png"),
                       className='plogo')
        #         img = html.Img(src="/static/dash-logo.png",className='plogo')
        # ********************** title div ********************************
        title = html.Div([
            html.H3("New York Oil And Gas", className='ogtitle'),
            html.H5("Production Overview", className='ogtitle')
        ])
        # *****You ************* link to plotly info ***********************
        adiv = html.A([html.Button(["Learn More"], className='ogabutton')],
                      href="https://plot.ly/dash/pricing",
                      className='adiv')

        # build row 2, column1 components that help you build your main data store
        # ********************* slider *********************************
        text_slider = html.Div([
            'Filter by construction date (or select range in histogram):',
            html.P()
        ])
        yr_slider = dgc.RangeSliderComponent(
            'yr_slider',
            text_slider,
            min_value=df.Year_Well_Completed.min(),
            max_value=df.Year_Well_Completed.max())
        slider = html.Div(yr_slider.html, className='r2_margin')

        # ********************* well status radio *****************************
        rs_op = [{
            'label': 'All',
            'value': 'all'
        }, {
            'label': 'Active only',
            'value': 'active'
        }, {
            'label': 'Customize',
            'value': 'custom'
        }]
        radio_status = dgc.RadioItemComponent(
            'radio_status',
            html.Div(['Filter by well status:',
                      html.P()]),
            rs_op,
            'active',
            style={})
        radio1 = html.Div([radio_status.html], className='r2_margin')

        # ********************* well status dropdown *****************************
        ds_op = well_status_options
        self.ds_op = ds_op.copy()

        ws_keys = [d['value'] for d in ds_op]

        dropdown_status = dgc.DropdownComponent(
            'dropdown_status',
            '',
            ds_op,
            ws_keys,
            input_tuples=[(radio_status.id, 'value')],
            callback_input_transformer=self._select_well_status_list)
        dropdown1 = html.Div(dropdown_status.html, className='d1_margin')

        # ********************* well type radio *********************************
        rt_op = [{
            'label': 'All',
            'value': 'all'
        }, {
            'label': 'Productive only',
            'value': 'productive'
        }, {
            'label': 'Customize',
            'value': 'custom'
        }]
        radio_type = dgc.RadioItemComponent(
            'radio_type',
            html.Div(['Filter by well type:', html.P()]),
            rt_op,
            'productive',
            style={})
        radio2 = html.Div([radio_type.html], className='r2_margin')

        # ********************* dropdown for well type *********************************
        dt_op = well_type_options
        wt_keys = [d['value'] for d in dt_op]

        self.ws_keys = ws_keys
        self.wt_keys = wt_keys

        dropdown_type = dgc.DropdownComponent(
            'dropdown_type',
            '',
            dt_op,
            wt_keys,
            input_tuples=[(radio_type.id, 'value')],
            callback_input_transformer=self._select_well_type_list)
        dropdown2 = html.Div(dropdown_type.html, className='d1_margin')

        # ********************* build the main_data component **********************
        lg = dgc.init_root_logger()
        input_component_list = [(yr_slider.id, 'value'),
                                (dropdown_status.id, 'value'),
                                (dropdown_type.id, 'value')]
        main_data = dgc.StoreComponent(
            'store_df',
            input_component_list=input_component_list,
            create_storage_dictionary_from_inputs_callback=lambda v: self.
            _build_main_data_dictionary(v, logger=lg))
        self.main_data = main_data
        main_data.create_storage_dictionary_from_inputs_callback = lambda v: self._build_main_data_dictionary(
            v, logger=lg)

        aggs_div_comps = [
            self._make_agg_div(tc)
            for tc in ['no_wells', 'gas_mcf', 'oil_bbl', 'water_bbl']
        ]

        # build the panels
        wells = html.Div([aggs_div_comps[0].html, html.P('Wells')])
        gas = html.Div([aggs_div_comps[1].html, html.P('Gas')])
        oil = html.Div([aggs_div_comps[2].html, html.P('Oil')])
        water = html.Div([aggs_div_comps[3].html, html.P('Water')])

        xygraph = dgc.XyGraphComponent(
            'xygraph',
            main_data,
            x_column='Year_Well_Completed',
            num_x_values=8,
            title='Completed Wells/Year',
            transform_input=lambda value_list: _trans_df(value_list))

        # ************* Build row 3: the map and pie charts ********************************
        mapbox_access_token = "pk.eyJ1IjoiamFja2x1byIsImEiOiJjajNlcnh3MzEwMHZtMzNueGw3NWw5ZXF5In0.fk8k06T96Ml9CLGgKmk81w"

        self.basic_layout = dict(
            autosize=True,
            automargin=True,
            margin=dict(l=30, r=30, b=20, t=40),
            hovermode="closest",
            plot_bgcolor="#F9F9F9",
            paper_bgcolor="#F9F9F9",
            legend=dict(font=dict(size=10), orientation="h"),
            title="Satellite Overview",
            mapbox=dict(
                accesstoken=mapbox_access_token,
                style="light",
                center=dict(lon=-78.05, lat=42.54),
                zoom=7,
            ),
        )

        mapgraph = dgc.FigureComponent('mapgraph',
                                       None,
                                       self._create_map_figure,
                                       input_tuple_list=input_component_list)
        piegraph = dgc.FigureComponent('piegraph',
                                       None,
                                       self._create_pie_figure,
                                       input_tuple_list=input_component_list)

        callback_components = [
            yr_slider, radio_status, radio_type, dropdown_status,
            dropdown_type, main_data, xygraph, mapgraph, piegraph
        ] + aggs_div_comps

        pn = 'rpanel'
        pnnc = 'rpanelnc'
        r1 = dgr('r1', [img, title, adiv], child_class=pnnc)
        r2c1 = dgr('r2c1', [slider, radio1, dropdown1, radio2, dropdown2],
                   child_class=pnnc)
        r2c2r1 = dgr('r2c2r1', [wells, gas, oil, water],
                     child_class=pn,
                     parent_class=pnnc)
        r2c2r2 = dgr('r2c2r2', [xygraph.html])
        r2c2r3 = html.Div()
        r2c2 = dgr('r2c2', [r2c2r1, r2c2r2, r2c2r3],
                   child_class=None,
                   parent_class=pnnc)
        r2 = dgr('r2', [r2c1, r2c2])
        r3 = dgr('r3',
                 [mapgraph.html, html.Div(' '), piegraph.html],
                 parent_class=pnnc)
        rbot = dgr('rbot', ['the bottom'], child_class=pn)
        rside = html.Div(' ')
        rall_rows = dgr('rall_rows', [r1, r2, r3, rbot])
        rall_cols = dgr('rall_cols', [rside, rall_rows, rside],
                        parent_class=pnnc)

        self.app.layout = html.Div([rall_cols, main_data.html])
        for c in callback_components:
            c.callback(self.app)
def layout_app(app, well_status_options, well_type_options):

    # Create app layout
    the_layout = html.Div([
        dcc.Store(id='aggregate_data'),
        html.Div(
            [
                html.Div([
                    html.H2('New York Oil and Gas', ),
                    html.H4('Production Overview', )
                ],
                         className='eight columns'),
                html.Img(
                    src=
                    "https://s3-us-west-1.amazonaws.com/plotly-tutorials/logo/new-branding/dash-logo-by-plotly-stripe.png",
                    className='two columns',
                ),
                html.A(html.Button("Learn More", id="learnMore"),
                       href="https://plot.ly/dash/pricing/",
                       className="two columns")
            ],
            id="header",
            className='row',
        ),
        html.Div([
            html.Div([
                html.
                P('Filter by construction date (or select range in histogram):',
                  className="control_label"),
                dcc.RangeSlider(id='year_slider',
                                min=1960,
                                max=2017,
                                value=[1990, 2010],
                                className="dcc_control"),
                html.P('Filter by well status:', className="control_label"),
                dcc.RadioItems(id='well_status_selector',
                               options=[{
                                   'label': 'All ',
                                   'value': 'all'
                               }, {
                                   'label': 'Active only ',
                                   'value': 'active'
                               }, {
                                   'label': 'Customize ',
                                   'value': 'custom'
                               }],
                               value='active',
                               labelStyle={'display': 'inline-block'},
                               className="dcc_control"),
                dcc.Dropdown(id='well_statuses',
                             options=well_status_options,
                             multi=True,
                             value=list(WELL_STATUSES.keys()),
                             className="dcc_control"),
                dcc.Checklist(id='lock_selector',
                              options=[{
                                  'label': 'Lock camera',
                                  'value': 'locked'
                              }],
                              values=[],
                              className="dcc_control"),
                html.P('Filter by well type:', className="control_label"),
                dcc.RadioItems(id='well_type_selector',
                               options=[{
                                   'label': 'All ',
                                   'value': 'all'
                               }, {
                                   'label': 'Productive only ',
                                   'value': 'productive'
                               }, {
                                   'label': 'Customize ',
                                   'value': 'custom'
                               }],
                               value='productive',
                               labelStyle={'display': 'inline-block'},
                               className="dcc_control"),
                dcc.Dropdown(id='well_types',
                             options=well_type_options,
                             multi=True,
                             value=list(WELL_TYPES.keys()),
                             className="dcc_control"),
            ],
                     className="pretty_container four columns"),
            html.Div([
                html.Div([
                    html.Div([
                        html.P("No. of Wells"),
                        html.H6(id="well_text", className="info_text")
                    ],
                             id="wells",
                             className="pretty_container"),
                    html.Div(
                        [
                            html.Div([
                                html.P("Gas"),
                                html.H6(id="gasText", className="info_text")
                            ],
                                     id="gas",
                                     className="pretty_container"),
                            html.Div([
                                html.P("Oil"),
                                html.H6(id="oilText", className="info_text")
                            ],
                                     id="oil",
                                     className="pretty_container"),
                            html.Div([
                                html.P("Water"),
                                html.H6(id="waterText", className="info_text")
                            ],
                                     id="water",
                                     className="pretty_container"),
                        ],
                        id="tripleContainer",
                    )
                ],
                         id="infoContainer",
                         className="row"),
                html.Div([dcc.Graph(id='count_graph', )],
                         id="countGraphContainer",
                         className="pretty_container")
            ],
                     id="rightCol",
                     className="eight columns")
        ],
                 className="row"),
        html.Div([
            html.Div(
                [dcc.Graph(id='main_graph')],
                className='pretty_container eight columns',
            ),
            html.Div(
                [dcc.Graph(id='individual_graph')],
                className='pretty_container four columns',
            ),
        ],
                 className='row'),
        html.Div([
            html.Div(
                [dcc.Graph(id='pie_graph')],
                className='pretty_container seven columns',
            ),
            html.Div(
                [dcc.Graph(id='aggregate_graph')],
                className='pretty_container five columns',
            ),
        ],
                 className='row'),
    ],
                          id="mainContainer",
                          style={
                              "display": "flex",
                              "flex-direction": "column"
                          })
    return the_layout