Ejemplo n.º 1
0
def TWT_graph(n_clicks, input_value):
    andf = top_results(input_value)
    andf = analyse_sentiment(andf, "text")
    andf['Date'] = andf.apply(lambda row: str(row.timestamp).split(" ", 1)[0],
                              axis=1)
    andf['RoundPolarity'] = round(andf['sentiment'], 1)
    andf2 = andf.groupby('Date', as_index=False)[['sentiment']].sum()
    # ansdf3 = ansdf.groupby('RoundPolarity', as_index=False)[['Likes']].sum()

    data = []
    trace_close = go.Scatter(x=list(andf2.Date),
                             y=list(andf2.sentiment),
                             name="Close",
                             line=dict(color="#ff3333"))
    data.append(trace_close)
    figure1 = go.Figure(data)
    figure1.update_layout(
        title="Date-Wise Cumulative Sentiment Score Line Plot",
        xaxis_title="Date",
        yaxis_title="Cumulative Score",
        template='plotly_dark',
        plot_bgcolor='rgba(0, 0, 0, 0)')

    data = []
    trace_close = go.Scatter(x=list(andf.timestamp),
                             y=list(andf.sentiment),
                             mode='markers',
                             name="markers",
                             marker_color=andf['sentiment'])
    data.append(trace_close)
    figure2 = go.Figure(data)
    figure2.update_layout(
        title=
        "Date-Wise Sentiment Score Scatter Plot [negative(-1) to positive(+1)]",
        xaxis_title="Date",
        yaxis_title="(-ve) Sentiment Score (+ve)",
        template='plotly_dark',
        plot_bgcolor='rgba(0, 0, 0, 0)')

    data = []
    trace_close = go.Box(x=list(andf.Date),
                         y=list(andf.sentiment),
                         name="Close",
                         line=dict(color="#ff3333"))
    data.append(trace_close)
    figure3 = go.Figure(data)
    figure3.update_layout(
        title=
        "Date-Wise Sentiment Score Box Plot [negative(-1) to positive(+1)]",
        xaxis_title="Date",
        yaxis_title="(-ve) Sentiment Score (+ve)",
        template='plotly_dark',
        plot_bgcolor='rgba(0, 0, 0, 0)')

    data = []
    trace_close = go.Pie(labels=list(andf.roundoff), name="Close")
    data.append(trace_close)
    figure4 = go.Figure(data)
    figure4.update_layout(title="Pie-Chart",
                          template='plotly_dark',
                          plot_bgcolor='rgba(0, 0, 0, 0)')
    figure = (figure1, figure2, figure3, figure4)

    return figure
Ejemplo n.º 2
0
def YT_graph(n_clicks, input_value):
    videoid_list = search_vidid(begin_date, end_date, input_value)
    ansdf = all_cmt(videoid_list)
    ansdf = analyse_sentiment(ansdf, "comments")
    #answt = analyse_sentimentwt(ansdf,"comments")
    ansdf['Date'] = ansdf.apply(
        lambda row: str(row.CommentPublishDate).split("T", 1)[0], axis=1)
    ansdf['RoundPolarity'] = round(ansdf['sentiment'], 1)
    ansdf2 = ansdf.groupby('Date', as_index=False)[['sentiment']].sum()
    #yaha tkk toh bss dataframe creation hai jo tere paas hai
    data = []
    trace_close = go.Scatter(x=list(ansdf2.Date),
                             y=list(ansdf2.sentiment),
                             name="Close")
    data.append(trace_close)
    figure1 = go.Figure(data)
    figure1.update_layout(
        title="Date-Wise Cumulative Sentiment Score Line Plot",
        xaxis_title="Date",
        yaxis_title="Cumulative Score",
        template='plotly_dark',
        plot_bgcolor='rgba(0, 0, 0, 0)')

    data = []
    trace_close = go.Scatter(x=list(ansdf.CommentPublishDate),
                             y=list(ansdf.sentiment),
                             mode='markers',
                             name='markers',
                             marker_color=ansdf['sentiment'])

    data.append(trace_close)
    figure2 = go.Figure(data)
    figure2.update_layout(
        title=
        "Date-Wise Sentiment Score Scatter Plot [negative(-1) to positive(+1)]",
        xaxis_title="Date",
        yaxis_title="(-ve) Sentiment Score (+ve)",
        template='plotly_dark',
        plot_bgcolor='rgba(0, 0, 0, 0)')

    data = []
    trace_close = go.Box(x=list(ansdf.Date),
                         y=list(ansdf.sentiment),
                         name="Close",
                         line=dict(color="#ff3333"))
    data.append(trace_close)
    figure3 = go.Figure(data)
    figure3.update_layout(
        title=
        "Date-Wise Sentiment Score Box Plot [negative(-1) to positive(+1)]",
        xaxis_title="Date",
        yaxis_title="(-ve) Sentiment Score (+ve)",
        template='plotly_dark',
        plot_bgcolor='rgba(0, 0, 0, 0)')

    data = []
    trace_close = go.Pie(labels=list(ansdf.roundoff), name="Close")
    data.append(trace_close)
    figure4 = go.Figure(data)
    figure4.update_layout(title="Pie-Chart",
                          template='plotly_dark',
                          plot_bgcolor='rgba(0, 0, 0, 0)')
    figure = (figure1, figure2, figure3, figure4)

    return figure
Ejemplo n.º 3
0
def REDDIT_graph(n_clicks, input_value):
    input_value = pretty_txt(input_value)
    df1 = top_posts(input_value)
    list1 = to_id_list(df1)
    comment = mine_comments(list1)
    comment = analyse_sentiment(comment, "comments")
    comment['Date'] = comment.apply(
        lambda row: str(row.c_date).split(" ", 1)[0], axis=1)
    comment2 = comment.groupby('Date', as_index=False)[['sentiment']].sum()
    data = []
    trace_close = go.Scatter(x=list(comment2.Date),
                             y=list(comment2.sentiment),
                             mode='lines',
                             name="Close",
                             line=dict(color="#ff3333"))
    data.append(trace_close)
    figure1 = go.Figure(data)
    figure1.update_layout(
        title="Date-Wise Cumulative Sentiment Score Line Plot",
        xaxis_title="Date",
        yaxis_title="Cumulative Score",
        template='plotly_dark',
        plot_bgcolor='rgba(0, 0, 0, 0)')

    data = []
    trace_close = go.Scatter(x=list(comment.c_date),
                             y=list(comment.sentiment),
                             mode='markers',
                             name="markers",
                             marker_color=comment['sentiment'])
    data.append(trace_close)
    figure2 = go.Figure(data)
    figure2.update_layout(
        title=
        "Date-Wise Sentiment Score Scatter Plot [negative(-1) to positive(+1)]",
        xaxis_title="Date",
        yaxis_title="(-ve) Sentiment Score (+ve)",
        template='plotly_dark',
        plot_bgcolor='rgba(0, 0, 0, 0)')

    data = []
    trace_close = go.Box(x=list(comment.Date),
                         y=list(comment.sentiment),
                         name="Close",
                         line=dict(color="#ff3333"))
    data.append(trace_close)
    figure3 = go.Figure(data)
    figure3.update_layout(
        title=
        "Date-Wise Sentiment Score Box Plot [negative(-1) to positive(+1)]",
        xaxis_title="Date",
        yaxis_title="(-ve) Sentiment Score (+ve)",
        template='plotly_dark',
        plot_bgcolor='rgba(0, 0, 0, 0)')

    data = []
    trace_close = go.Pie(labels=list(comment.roundoff), name="Close")
    data.append(trace_close)
    figure4 = go.Figure(data)
    figure4.update_layout(title="Pie-Chart",
                          template='plotly_dark',
                          plot_bgcolor='rgba(0, 0, 0, 0)')
    figure = (figure1, figure2, figure3, figure4)

    return figure