Exemple #1
0
    def print_results(self):
        
        # Print every players top 10 most common words
        for speaker, count in self.speakers.items():
            wordFreqPairs = count.most_common(10)
            table = generate_table(wordFreqPairs)
            print(f"\n{speaker}:")
            print(table)
        
        totalWords = PrettyTable()
        totalWords.field_names = ["Words", "Player"]
        totalWords.sortby = "Words"
        totalWords.reversesort = True
        for player, count in self.totalWords.items():
            totalWords.add_row([count, player])
        print(f"\nTotal Words by Player")
        print(totalWords)

        table = generate_table(self.allSpeakers.most_common(20))
        print(f"\nMost Common Words:")
        print(table)
Exemple #2
0
def create_layout(app):
    return html.Div(
        [
            Header(app),
            # page 2
            html.Div(
                [
                    # Row
                    html.Div(
                        [
                            html.Div(
                                [
                                    html.H6(["Team Location"],
                                            className="subtitle padded"),
                                    # scatter geo plot of nba teams' location
                                    dcc.Graph(
                                        id='scatter_geo',
                                        className='my_graph',
                                        figure={
                                            'data': [{
                                                # Setting coordinate and description for each team
                                                'lon': [
                                                    -98.37, -97.52, -87.90,
                                                    -75.16, -118.24, -122.27,
                                                    -79.38, -112.07, -90.07,
                                                    -122.675, -80.84, -77.04,
                                                    -83.05, -93.265, -71,
                                                    -111.89, -87.63
                                                ],
                                                'lat': [
                                                    29.76, 35.47, 43, 39.95,
                                                    34.05, 37.8, 43.65, 33.45,
                                                    29.95, 45.5, 35.23, 38.91,
                                                    42.33, 44.98, 42.37, 40.76,
                                                    41.88
                                                ],
                                                'text': [
                                                    'HOU, Houston Rocket',
                                                    'OKC, Oklahoma Thunder',
                                                    'MIL, Milwaukee Bucks,',
                                                    'PHI, Philadelphia 76ers',
                                                    'LAL, Los Angeles Lakers',
                                                    'GSW, Golden State Warriors',
                                                    'TOR, Toronto Raptors',
                                                    'PHX, Phoenix Suns',
                                                    'NOP, New Orleans Pelicans',
                                                    'POR, Portland Trail Blazers',
                                                    'CHA, Charlotte Hornets',
                                                    'WAS, Washington Wizards',
                                                    'DET, Detroit Pistons',
                                                    'MIN, Minnesota Timberwolves',
                                                    'BOS, Boston Celtics',
                                                    'UTA, Utah Jazz',
                                                    'CHI, Chicago Bulls'
                                                ],
                                                'type':
                                                'scattergeo',
                                                'mode':
                                                'markers',
                                                "marker": {
                                                    "size": 10,
                                                    "opacity": 10.0,
                                                },
                                            }],
                                            'layout': {
                                                'title': 'NBA teams location',
                                                'height': 600,
                                                'yaxis': {
                                                    'hoverformat': '.2%'
                                                },
                                                'margin': {
                                                    'l': 35,
                                                    'r': 35,
                                                    't': 50,
                                                    'b': 80
                                                },
                                                "geo": {
                                                    "scope": "usa",
                                                    'showframe': True,
                                                    'showcoastlines': True,
                                                },
                                                "colorbar": True,
                                            }
                                        },
                                        config={'displayModeBar': True})
                                ],
                                className="six columns",
                            ),
                            html.Div(
                                [
                                    html.H6(
                                        ["Salary Distribution"],
                                        className="subtitle padded",
                                    ),

                                    # Scatter plot of player's salaries
                                    dcc.Graph(
                                        id='graph-scatter',
                                        className='my_graph',
                                        figure={
                                            'data': [{
                                                # Name of each player on x axis and their corresponding salary on y axis
                                                'x': df['Name'],
                                                'y': df['Salary'],
                                                'type': 'scatter',
                                                'mode': 'markers',
                                            }],
                                            # Description of the plot
                                            'layout': {
                                                'title':
                                                'Distribution of NBA players salaries',
                                                'height': 600,
                                                'yaxis': {
                                                    'hoverformat': '.2%'
                                                },
                                                'margin': {
                                                    'l': 35,
                                                    'r': 35,
                                                    't': 50,
                                                    'b': 80
                                                },
                                            }
                                        },
                                        config={'displayModeBar': False})
                                ],
                                className="six columns",
                            ),
                        ],
                        className="row ",
                    ),
                    # Row 2
                    html.Div(
                        [
                            html.Div(
                                [
                                    html.H6("LeBron James choose Lakers",
                                            className="subtitle padded"),
                                    # Plot image from web for a overall sleek design
                                    html.Img(
                                        src=
                                        'https://i.pinimg.com/originals/9f/15/98/9f15989577e13555c75031ee72d9c9a5.jpg',
                                        style={
                                            'height': '100%',
                                            'width': '100%',
                                            'float': 'right',
                                            'position': 'relative',
                                            'padding-top': 0,
                                            'padding-right': 0
                                        })
                                ],
                                className="twelve columns",
                            )
                        ],
                        className="row ",
                    ),
                    # Row 3
                    html.Div(
                        [
                            html.Div(
                                [
                                    html.H6(
                                        ["plot4"],
                                        className="subtitle padded",
                                    ),
                                    html.Div(
                                        [generate_table(df)],
                                        style={"overflow-x": "auto"},
                                    ),
                                ],
                                className="twelve columns",
                            )
                        ],
                        className="row ",
                    ),

                    #end
                ],
                className="sub_page",
            ),
        ],
        className="page",
    )
Exemple #3
0
def show_table(input_value):
    if input_value:
        return generate_table(query_db(get_query(input_value)))
    def quick_info_update(sym):
        '''Updates tables on dashboards.

        Section 4 requirement queries.

        args:
            sym: Stock symbol for "any" argument in requirements.

        returns:
            list: HTML headers and DCC tables
        '''
        # Really lazy hack to prevent SQL injection
        valid_syms = [val for val, _ in GetStockSymbols()]
        if sym not in valid_syms:
            return "ERROR: Invalid symbol selection"

        # Query 4.1 in requirements
        qh1 = html.H3("Company Prices")
        header = 'Price'
        df = pd.read_sql(
            '''
        SELECT stock_price_minute.sym AS "Company", close AS "{}"                       
        FROM stock_price_minute                                                         
                                                                                        
        JOIN (                                                                          
          SELECT sym, MAX(dateid) as mdate                                              
          FROM stock_price_minute                                                       
          GROUP BY sym                                                                  
        ) as sub                                                                        
          ON stock_price_minute.dateid = sub.mdate AND stock_price_minute.sym = sub.sym 
        ORDER BY dateid DESC, stock_price_minute.sym ASC                                
        '''.format(header), db.engine)
        df[header] = df[header].apply(money_format)
        sym_table = generate_table(df, 10)

        # Query 4.2 in requirements
        qh2 = html.H3("Highest Price in 10 Days")
        header = 'Highest Price'
        df = pd.read_sql(
            '''
        SELECT sym AS "Company", MAX(close) AS "{}"
        FROM stock_price_minute
        WHERE dateid >= DATE_SUB(CURDATE(), INTERVAL 365 DAY)
          AND sym = '{}';
        '''.format(header, sym), db.engine)
        df[header] = df[header].apply(money_format)
        max_table = generate_table(df, 10)

        # Query 4.3 in requirements
        qh3 = html.H3("Year Average Price")
        header = 'Average Price'
        df = pd.read_sql(
            '''
        SELECT sym AS "Company", AVG(close) AS "{}"
        FROM stock_price_minute
        WHERE dateid >= DATE_SUB(CURDATE(), INTERVAL 365 DAY)
          AND sym = '{}';
        '''.format(header, sym), db.engine)
        df[header] = df[header].apply(money_format)
        avg_table = generate_table(df, 1)

        # Query 4.4 in requirements
        qh4 = html.H3("Year Lowest Price")
        header = 'Lowest Price'
        df = pd.read_sql(
            '''
        SELECT sym AS "Company", MIN(close) AS "{}"
        FROM stock_price_minute
        WHERE dateid >= DATE_SUB(CURDATE(), INTERVAL 365 DAY)
          AND sym = '{}';
        '''.format(header, sym), db.engine)
        df[header] = df[header].apply(money_format)
        low_table = generate_table(df, 1)

        # Query 4.5 in requirements
        qh5 = html.H3("Average Less Than Lowest of {}".format(sym.upper()))
        header = 'Average Price'
        df = pd.read_sql(
            '''
        SELECT sym AS "Company", sub1.close AS "{}"

        FROM (
            SELECT sym, AVG(close) AS "close"
            FROM stock_price_minute
            WHERE dateid >= DATE_SUB(CURDATE(), INTERVAL 365 DAY)
            GROUP BY sym
        ) as sub1

        LEFT JOIN (
          SELECT MIN(close) AS criteria
          FROM stock_price_minute
          WHERE dateid >= DATE_SUB(CURDATE(), INTERVAL 365 DAY)
            AND sym = '{}'
        ) AS sub2
          ON 1 = 1

        GROUP BY sym, criteria
        HAVING sub1.close < criteria
        ORDER BY sym ASC;'''.format(header, sym), db.engine)
        df[header] = df[header].apply(money_format)
        avglow_table = generate_table(df, 100)

        if len(dash_data['y_preds']['_all']) <= 0:
            display_val = 'Loading...'
        else:
            display_val = '  ${0:.2f}'.format(dash_data['y_preds']['_all'][-1])
            display_val = '  ${0:.2f}'.format(dash_data['y_preds']['_all'][-1])

        # Buy sell summary
        pred_list = [html.H3("Predicted Value")]
        if len(dash_data['y_preds']['_all']) <= 0:
            pred_list.append(
                html.Img(src=load_img_url, style={'height': '50px'}))
        elif dash_data['y_preds']['_all'][-1] > dash_data['closes'][-1]:
            pred_list.append(
                html.Img(src=buy_img_url, style={'height': '50px'}))
        else:
            pred_list.append(
                html.Img(src=sell_img_url, style={'height': '50px'}))
        pred_list.append(display_val)
        pred_data = html.Div(pred_list)

        return [
            pred_data, qh1, sym_table, qh2, max_table, qh3, avg_table, qh4,
            low_table, qh5, avglow_table
        ]
                                # 'title': 'Comments are clustered into 10 topics',
                                # 'xaxis':{'title':'x-axis label'},
                                'yaxis': {
                                    'title': 'Number of comments per topic'
                                },
                            }
                        },
                    ),
                ],
                className="six columns"),

            # View individual comments
            html.Div([
                html.H6('Top 5 words in each topic:'),
                html.Br(),
                generate_table(df.drop(['Comments'], axis=1))
            ],
                     className="six columns"),
        ],
        className="Row"),

    # Pick a selected comment to view highlighting
    html.Div([
        html.H6('Input a comment number to view highlighting by topic:'),
        dcc.Input(id='number-in', value=1, style={'fontSize': 20}),
        html.Button(id='submit-button',
                    n_clicks=0,
                    children='Submit',
                    style={'fontSize': 20}),
        html.H4('Highlighting indicates topic area:'),
        html.Iframe(
Exemple #6
0
import utils
import numpy as np
import matplotlib.pyplot as plt

country = 'France'

sol1 = "Data/sol_jan (2).xls"
sol2 = "Data/sol_feb (2).xls"
sol3 = "Data/sol_march (2).xls"

win1 = "Data/win_jan (2).xls"
win2 = "Data/win_feb (2).xls"
win3 = "Data/win_march (2).xls"

price1 = "Data/price_jan.xlsx"
price2 = "Data/price_feb.xlsx"
price3 = "Data/price_march.xlsx"

#t = read_generated_energy(sol1,win1);

tab1 = utils.generate_table(sol1, win1, price1, country)
tab2 = utils.generate_table(sol2, win2, price2, country)
tab3 = utils.generate_table(sol3, win3, price3, country)
tab = tab1 + tab2 + tab3

sol, win, price = utils.sort_by_hour(tab)
plt.hist(sol[10])  #histogramme de la production solaire à 10h
Exemple #7
0
                              figure={
                                  'data': get_data_of_count_words(),
                                  'layout': {
                                      'title': 'Dash Data Visualization'
                                  }
                              }),
                ],
                className="six columns",
                style={
                    'width': '49%',
                    'display': 'inline-block',
                    'vertical-align': 'middle'
                }),
        ],
        className="row"),
    html.Div([generate_table(user_df)])
])


@app.callback(dash.dependencies.Output('user-indicator-scatter', 'figure'), [
    dash.dependencies.Input('user-dropdown', 'value'),
])
def update_graph(owner_id):
    print('owner_id %s' % str(owner_id))

    owner_id = int(owner_id)
    user_df_updated = user_df[user_df['ownerId'] == owner_id]

    return {
        'data': [
            go.Scatter(