Пример #1
0
def page_3_booyah(candidates, metric):
    guys = list()
    gals = list()
    rule = list()
    if candidates:
        for i in candidates:
            query = "SELECT " + str(metric) + " FROM Twitter_Metrics " + "WHERE [name] = '" + str(i) + "'"
            the_goods = db.select_database(query)

            guys.append(i)
            gals.append(the_goods[metric].values[0])

        data = plotly.graph_objs.Bar(
            x=guys,
            y=gals,
            name='Bar'
        )

        return {'data': [data], 'layout': go.Layout(xaxis=dict(range=(0-1, len(guys))),
                                                    yaxis=dict(range=[0, max(gals)]), )}

    all_info_baby = {
        'x': [],
        'y': [],
        'type': 'bar'
    }
    layout = {
        'xaxis': {'title': 'Candidate'},
        'yaxis': {'title': 'Y axis'},
        'barmode': 'relative',
        'title': metric
    };
    rule.append(all_info_baby)

    return {'data': rule, 'layout': layout}
Пример #2
0
def page_5_radios(candidates):
    try:
        lines = list()
        if candidates:
            print(candidates)
            for i in candidates:
                #query = "SELECT sentiment_date, ((positive_tweet_count * 1.) / " \
                #        + "(positive_tweet_count + negative_tweet_count + neutral_tweet_count)) * 100. as score" \
                query = "SELECT sentiment_date, compound_sentiment_vadersentiment * 100. as score" \
                        + " FROM Candidate_Sentiment" \
                        + " WHERE name = '" \
                        + str(i) \
                        + "';"

                dates = list()
                score = list()

                the_goods = db.select_database(query)

                for index, row in the_goods.iterrows():
                    dates.append(row['sentiment_date'])
                    score.append(row['score'])
                lines.append(plotly.graph_objs.Scatter(
                    x=np.asarray(dates),
                    y=np.asarray(score),
                    name=i,
                    mode='lines+markers'
                    ))
                print(lines)
            data = lines
            lines = list()
            layout = dict(title='Candidate Sentiment By Date',
                          xaxis=dict(title='Date'),
                          yaxis=dict(title='Sentiment Score -- (0-100%)'),
                          )

            return {'data': data, 'layout': layout}
        else:
            data = {
                'x': [],
                'y': [],
                'type': 'line'
            }
            layout = dict(title='Candidate Sentiment By Date',
                          xaxis=dict(title='Date'),
                          yaxis=dict(title='Sentiment Score -- (0-100%)'),
                          )
            return {'data': [data], 'layout': layout}

    except Exception as e:
        with open('errors.txt', 'a') as f:
            f.write(str(e))
            f.write('\n')
Пример #3
0
import dash_core_components as dcc
import dash_html_components as html
import database as db

candidates = db.select_database(
    "SELECT Candidate.name as [name], average_favorites, " +
    "average_retweets, average_tweets_per_day " +
    "FROM Candidate JOIN Twitter_Metrics ON Twitter_Metrics.name = Candidate.name "
    + "WHERE date_dropped IS NULL ")
all_candidates = {'candidates': candidates['name']}

tab_3_layout = html.Div([
    html.Div([
        dcc.Dropdown(id='candidate-dropdown',
                     options=[{
                         'label': i,
                         'value': i
                     } for i in all_candidates['candidates']],
                     multi=True,
                     placeholder="Select Candidates"),
    ],
             style={
                 'width': '50%',
                 'display': 'inline-block'
             }),
    html.Div([
        dcc.Dropdown(id='metric-dropdown',
                     options=[{
                         'label': 'Average Favorites Per Tweet',
                         'value': 'average_favorites'
                     }, {
Пример #4
0
import dash_core_components as dcc
import dash_html_components as html
import database as db

candidates = db.select_database("SELECT Candidate.name as [name] "
                                + "FROM Candidate"
                                + " WHERE Candidate.date_dropped IS NULL")
all_candidates = {
    'candidates': candidates['name']
}

tab_5_layout = html.Div(
    [
        html.Div([
        dcc.Dropdown(
            id='candidate-dropdown',
            options=[{'label': i, 'value': i} for i in all_candidates['candidates']],
            multi=True,
            placeholder="Select Candidates"
            ),
            ],
            style={'width': '50%', 'display': 'inline-block'}),
        html.Hr(),
        html.Div(id='display-selected-values'),
        dcc.Graph(id='line-graph', animate=True)
    ]
)
Пример #5
0
import dash
import dash_core_components as dcc
import dash_html_components as html
import pyodbc
import database as db

candidates = db.select_database(
    "SELECT name FROM Candidate WHERE date_dropped != ")

tab_3_layout = html.Div([
    html.H1('Page 3'),
    dcc.Checklist(options=[{
        'label': 'New York City',
        'value': 'NYC'
    }, {
        'label': 'Montréal',
        'value': 'MTL'
    }, {
        'label': 'San Francisco',
        'value': 'SF'
    }],
                  value=['MTL', 'SF'])
])