-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproject.py
105 lines (84 loc) · 2.76 KB
/
project.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import json
import unittest
import os
import requests
import team_stats as ts
import nbaapi as nba
import sqlite3
import twitterapi as ta
import advancednba as an
import regressionmodeling as rm
import numpy
import tweepy
from tweepy import API
from tweepy import Cursor
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
import datetime as dt
from datetime import date
from textblob import TextBlob
from pandasql import sqldf
import pandasql as ps
import numpy as np
import pandas as pd
from sqlalchemy import create_engine
import re
import matplotlib.pyplot as plt
#
# Your name: Grant Marshall
# Who you worked with:
#
#commit
path = os.path.dirname(os.path.abspath(__file__))
conn = sqlite3.connect(path+'/'+'stats.db')
cur = conn.cursor()
team = input("Enter a team name with capitalized first letters and the city (ex. Washington Wizards): ")
print("")
abrevs = ts.team_abrevs()
cur.execute('CREATE TABLE IF NOT EXISTS Teams (id INTEGER PRIMARY KEY, Team TEXT, Abbreviation TEXT)')
cur.execute("SELECT * FROM Teams")
result = cur.fetchone()
if not result:
for key in abrevs:
cur.execute('INSERT INTO Teams (Team, Abbreviation) VALUES (?, ?)', (key, abrevs[key]))
conn.commit()
opponent = ""
siteList = nba.odds_finder(team)
if siteList != None:
oddsList = []
for i in siteList:
oddsList.append((i[0], i[1], nba.winPercCalc(i[1]), i[2], i[3]))
nba.outputter(team, oddsList)
opponent = oddsList[0][4]
if len(oddsList) < 17:
print("Game has likely already started, so the lines above are LIVE LINES")
else:
nba.dbMaker(cur, conn)
nba.dbAddition(team, oddsList, cur, conn)
print("")
stats = ts.stats(team)
for keys in stats:
print(keys + ": " + str(stats[keys]))
print("")
ostats = ts.stats(opponent)
for keys in ostats:
print(keys + ": " + str(ostats[keys]))
print("")
ts.compare_teams(team, opponent)
print("")
twitter_client = ta.TwitterClient()
tweet_analyzer = ta.TweetAnalyzer()
api = twitter_client.get_twitter_client_api()
tweets = twitter_client.keywords_search(team, 3000, dt.date.today()-dt.timedelta(days=30), dt.date.today())
df = tweet_analyzer.tweets_to_dataframe(tweets)
df['sentiment'] = np.array([tweet_analyzer.analyze_sentiment(tweet) for tweet in df['tweets']])
df['pop'] = tweet_analyzer.tweet_pop(df['likes'], df['retweets'])
df['score'] = tweet_analyzer.actual_score(df['sentiment'], df['likes'], df['retweets'])
out = tweet_analyzer.date_grouper(df)
print(out)
# Time Series
time_likes = pd.Series(data=out['Relevance'])
time_likes.plot(figsize=(16, 4), color='r')
out.plot(x='day', y=['Relevance', 'Popularity'], grid=True)
rm.modelMaker(team)