示例#1
0
    def on_data(self, data):
        fullData = json.loads(data)
        try:
            #Controleer aantal tweets in db en max aantal tweets
            if DatabaseNieuw.getAantalTweets() != aantalTweets:
                #data maken en filteren
                timestamp = fullData['timestamp_ms']
                tweet = fullData['text']
                userData = fullData['user']
                user = userData['screen_name']

                #Mentions en Retweets uitsluiten
                if tweet.startswith("RT @") or tweet.startswith("@"):
                    return True
                if '"' in tweet:
                    tweet.replace('"', '')
                if '"' in user:
                    user.replace('"', '')

                #plaats data in de db
                DatabaseNieuw.setTweetsDatabase(tweet, user, timestamp)
            else:
                #Max aantal tweets is bereikt, doe analyse en stop daarna.
                AnalyseNieuw.startAnalyse()
                return False

        except KeyError:
            return True
示例#2
0
def createTimechart():
    plt.figure(figsize=(30,10))
    tijdLijst = []
    scoreLijst = []

    data = DatabaseNieuw.getTimeChart()
    for rij in data:
        tijdLijst.append(datetime.datetime.fromtimestamp(rij[0]/1000.0))
        scoreLijst.append(rij[1])

    plt.plot(tijdLijst, scoreLijst)
    plt.show()
示例#3
0
def createPiechart():
    plt.title('ISCP - Daniël Vercouteren: Pie Chart')

    dataLabels = "Negatief", "Neutraal", "Positief"
    dataSize = DatabaseNieuw.getAnalysis()
    colors = "firebrick", "darkorange", "forestgreen"
    explode = (0, 0, 0)

    plt.pie(dataSize, explode=explode, labels=dataLabels, colors=colors,
        autopct='%1.1f%%', shadow=True, startangle=90)
    plt.axis('equal')

    plt.show()
示例#4
0
def createBarchart():
    plt.xlabel('Sentiment')
    plt.ylabel('Aantal')
    plt.title('ISCP - Daniël Vercouteren: Bar Chart')

    #X is negatief, neutraal, positief
    #Y is het aantal
    data = ['Negatief', 'Neutraal', 'Positief']
    x = np.arange(len(data))
    y = DatabaseNieuw.getAnalysis()
    width = 0.8

    plt.bar(x, y, width, color = "darkblue")
    plt.xticks(x + 0.4, data)

    plt.tight_layout()
    plt.show()
示例#5
0
def scoring(tweetScore, tweetNummer):
    print("Dit is tweet #" + str(tweetNummer))
    sys.stdout.write("Deze tweet is: ")
    if tweetScore > 0:
        print("positief")
        DatabaseNieuw.setAnalysis(tweetNummer, '2')

    elif tweetScore < 0:
        print("negatief")
        DatabaseNieuw.setAnalysis(tweetNummer, '0')

    else:
        print("neutraal")
        DatabaseNieuw.setAnalysis(tweetNummer, '1')
示例#6
0
def startAnalyse():
    tweetNummer = 0
    tweetLijst = DatabaseNieuw.getTweets()
    for tweet in tweetLijst:
        tweetNummer += 1
        analyse(tweet, tweetNummer)