-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexampleIntegration.py
41 lines (34 loc) · 1.44 KB
/
exampleIntegration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#input will be an array of the form [0 1 0 1 1 0 1 0 0 1 0 ... 0 1 0 1 1 0 0 1]
import EmoteModel
import time
import TwitterParser
def weigh(prediction):
listpred = prediction.tolist()
#print(listpred)
#print(listpred.count(0), listpred.count(1))
happyRatio = listpred.count(1) / len(listpred)
return happyRatio
def clock():
logreg, count_vectors = EmoteModel.init_model()
ratioDict = {}
while True:
tweets = TwitterParser.fetchTweets(language='en', numTweets=10) #grab 10 tweets from the last 10 seconds
print(tweets[0])
prediction = EmoteModel.make_prediction(logreg, count_vectors, tweets)
#update_color(weigh(prediction))
#ratioDict[time.time()] = weigh(prediction)
print(str(int(weigh(prediction)*100)) + "% happy")
time.sleep(15)
def cycle(logreg, count_vectors):
tweets = TwitterParser.fetchTweets(language='en', numTweets=10) #grab 10 tweets from the last 10 seconds
#print(tweets[0])
prediction = EmoteModel.make_prediction(logreg, count_vectors, tweets)
#update_color(weigh(prediction))
#ratioDict[time.time()] = weigh(prediction)
return int(weigh(prediction)*100)
def findAnomalies(baseline, ratioDict):
ratios = ratioDict.values()
baseline = sum(ratios) / len(ratios)
distances = lambda x: abs(ratios[x] - baseline)
maxValue = max(distances)
return list(ratioDict.keys())[list(ratioDict.values()).index(maxValue)]