Commit 6a3537ea authored by ben.eastwood's avatar ben.eastwood

First commit

parents
B# Final-Project B# Final-Project
# Built using https://towardsdatascience.com/naive-bayes-classifier-how-to-successfully-use-it-in-python-ecf76a995069
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
from sklearn.preprocessing import OrdinalEncoder
from sklearn.naive_bayes import CategoricalNB
import seaborn as sns; sns.set()
import matplotlib.pyplot as plt
import plotly.express as px
import plotly.graph_objects as go
def mfunc(X, y, typ):
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)
model = typ
clf = model.fit(X_train, y_train)
pred_labels = model.predict(X_test)
print('Classes: ', clf.classes_)
if str(typ) == 'GaussianNB()':
print('Class Priors: ', clf.class_prior_)
else:
print('Class Log Priors: ', clf.class_log_prior_)
print('--------------------------------------------------------')
score = model.score(X_test, y_test)
print('Accuracy Score: ', score)
print('--------------------------------------------------------')
print(classification_report(y_test, pred_labels))
return X_train, X_test, y_train, y_test, clf, pred_labels
df = pd.read_csv('data.csv')
df.info()
# 'Map' 'Winner' 'Team1StartingSide' 'Team2StartingSide' 'AverageACSTeam1' 'AverageACSTeam2' 'AverageKillsTeam1' 'AverageKillsTeam2' 'TotalFKTeam1' 'TotalFKTeam2'
# 'TotalFDTeam1' 'TotalFDTeam2' 'TotalKillsTeam1' 'TotalKillsTeam2' 'TotalDeathsTeam1' 'TotalDeathsTeam2' 'TotalFKFDTeam1' 'TotalFKFDTeam2' 'EntryFKFDTeam1' 'EntryFKFDTeam2'
# 'HsPercentageTeam1' 'HsPercentageTeam2'
X = df[['Map', 'Team1StartingSide']]
y = df['Winner'].values
# Encode categorical variables
enc = OrdinalEncoder()
X = enc.fit_transform(X)
frames = [df]
data = pd.concat(frames, axis=1)
#print(df.groupby(['Map', 'Team1StartingSide']).count())
#sns.scatterplot(x="HsPercentageTeam1", y="HsPercentageTeam2", hue='Winner', data=data, palette="tab10")
#sns.displot(x='Team1StartingSide', hue='Winner', col='Map', row='Winner', data=data, rug=True, palette="tab10")
plt.show()
X_train, X_test, y_train, y_test, clf, pred_labels = mfunc(X, y, CategoricalNB())
\ No newline at end of file
import csv
def ClearCsv():
f = open('data.csv', 'w+')
f.close()
def ParseCsv():
file = open('match.csv', 'r')
data = list(csv.reader(file))
file.close()
header = ['Map', 'Winner',
'Team1StartingSide', 'Team2StartingSide',
'AverageACSTeam1', 'AverageACSTeam2',
'AverageKillsTeam1', 'AverageKillsTeam2',
'TotalFKTeam1', 'TotalFKTeam2',
'TotalFDTeam1', 'TotalFDTeam2',
'TotalKillsTeam1', 'TotalKillsTeam2',
'TotalDeathsTeam1', 'TotalDeathsTeam2',
'TotalFKFDTeam1', 'TotalFKFDTeam2',
'EntryFKFDTeam1', 'EntryFKFDTeam2',
'HsPercentageTeam1', 'HsPercentageTeam2']
with open('data.csv', 'a', newline='') as f:
writer = csv.writer(f)
writer.writerow(header)
i=0
while i<len(data):
x=data[i]
if(x[0] == '-'):
map = data[i+1][0]
if(map != '/'):
i += 1
team1score = data[i][2]
team2score = data[i][4]
if(int(team1score) > int(team2score)):
winner = 1
elif(int(team1score) < int(team2score)):
winner = -1
else:
winner = 0
team1side = data[i][5]
team2side = data[i][6]
team1acs = []
team1fk = []
team1fd = []
team1kills = []
team1deaths = []
team1fkfd = []
team1entryfkfd = []
team1headshotpercentage = []
team2acs = []
team2fk = []
team2fd = []
team2kills = []
team2deaths = []
team2fkfd = []
team2entryfkfd = []
team2headshotpercentage = []
y=0
while(y != 5):
try:
i += 1
team1acs.append(data[i][4])
team1fk.append(data[i][12])
team1fd.append(data[i][13])
team1kills.append(data[i][5])
team1deaths.append(data[i][6])
team1fkfd.append(data[i][14])
team1headshotpercentage.append(data[i][11])
if(data[i][2] == 'jett' or 'neon' or 'raze'):
team1entryfkfd.append(data[i][14])
y += 1
except:
y += 1
while(y != 10):
i += 1
team2acs.append(data[i][4])
team2fk.append(data[i][12])
team2fd.append(data[i][13])
team2kills.append(data[i][5])
team2deaths.append(data[i][6])
team2fkfd.append(data[i][14])
team2headshotpercentage.append(data[i][11])
if(data[i][2] == 'jett' or 'neon' or 'raze'):
team2entryfkfd.append(data[i][14])
y += 1
team1AverageAcs, team1AverageKills, team1TotalFk, team1TotalFd, team1TotalKills, team1TotalDeaths, team1TotalFkFd, team1AverageHS = 0, 0, 0, 0, 0, 0, 0, 0
team2AverageAcs, team2AverageKills, team2TotalFk, team2TotalFd, team2TotalKills, team2TotalDeaths, team2TotalFkFd, team2AverageHS = 0, 0, 0, 0, 0, 0, 0, 0
team1AverageEntryFkFd, team2AverageEntryFkFd, iteration1, iteration2 = 0, 0, 0, 0
for duelist in team1entryfkfd:
try:
team1AverageEntryFkFd += int(duelist)
iteration1 += 1
except:
team1AverageEntryFkFd = 0
for duelist in team2entryfkfd:
try:
team2AverageEntryFkFd += int(duelist)
iteration2 += 1
except:
team2AverageEntryFkFd = 0
try:
team1AverageEntryFkFd = team1AverageEntryFkFd/iteration1
team2AverageEntryFkFd = team2AverageEntryFkFd/iteration2
except:
print("0 duelist comp")
try:
y=0
while(y != 5):
team1AverageAcs += int(team1acs[y])
team1AverageKills += int(team1kills[y])
team1AverageHS += int(team1headshotpercentage[y])
team1TotalFk += int(team1fk[y])
team1TotalFd += int(team1fd[y])
team1TotalKills += int(team1kills[y])
team1TotalDeaths += int(team1deaths[y])
team1TotalFkFd += int(team1fkfd[y])
team2AverageAcs += int(team2acs[y])
team2AverageKills += int(team2kills[y])
team2AverageHS += int(team2headshotpercentage[y])
team2TotalFk += int(team2fk[y])
team2TotalFd += int(team2fd[y])
team2TotalKills += int(team2kills[y])
team2TotalDeaths += int(team2deaths[y])
team2TotalFkFd += int(team2fkfd[y])
y += 1
team1AverageAcs = team1AverageAcs/5
team2AverageAcs = team2AverageAcs/5
team1AverageKills = team1AverageKills/5
team2AverageKills = team2AverageKills/5
team1AverageHS = team1AverageHS/5
team2AverageHS = team2AverageHS/5
row = [map, winner, team1side, team2side, team1AverageAcs, team2AverageAcs, team1AverageKills, team2AverageKills, team1TotalFk, team2TotalFk,
team1TotalFd, team2TotalFd, team1TotalKills, team2TotalKills, team1TotalDeaths, team2TotalDeaths, team1TotalFkFd, team2TotalFkFd, team1AverageEntryFkFd, team2AverageEntryFkFd,
team1AverageHS, team2AverageHS]
with open('data.csv', 'a', newline='') as f:
writer = csv.writer(f)
writer.writerow(row)
except:
pass
else:
i += 1
else:
i += 1
ClearCsv()
ParseCsv()
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
https://www.vlr.gg/event/1015
https://www.vlr.gg/event/1111
https://www.vlr.gg/event/1130
https://www.vlr.gg/event/1117
https://www.vlr.gg/event/1083
https://www.vlr.gg/event/1084
https://www.vlr.gg/event/1014
https://www.vlr.gg/event/1113
https://www.vlr.gg/event/1085
https://www.vlr.gg/event/1086
https://www.vlr.gg/event/800
https://www.vlr.gg/event/911
https://www.vlr.gg/event/984
https://www.vlr.gg/event/1063
https://www.vlr.gg/event/1013
https://www.vlr.gg/event/998
https://www.vlr.gg/event/988
https://www.vlr.gg/event/983
https://www.vlr.gg/event/996
https://www.vlr.gg/event/1012
https://www.vlr.gg/event/882
https://www.vlr.gg/event/991
https://www.vlr.gg/event/972
https://www.vlr.gg/event/977
https://www.vlr.gg/event/965
https://www.vlr.gg/event/963
https://www.vlr.gg/event/960
https://www.vlr.gg/event/997
https://www.vlr.gg/event/926
https://www.vlr.gg/event/955
https://www.vlr.gg/event/885
https://www.vlr.gg/event/948
https://www.vlr.gg/event/829
https://www.vlr.gg/event/925
https://www.vlr.gg/event/799
https://www.vlr.gg/event/854
https://www.vlr.gg/event/853
https://www.vlr.gg/event/850
https://www.vlr.gg/event/884
https://www.vlr.gg/event/845
https://www.vlr.gg/event/852
https://www.vlr.gg/event/844
https://www.vlr.gg/event/842
https://www.vlr.gg/event/841
https://www.vlr.gg/event/840
https://www.vlr.gg/event/883
https://www.vlr.gg/event/851
https://www.vlr.gg/event/823
https://www.vlr.gg/event/858
https://www.vlr.gg/event/879
https://www.vlr.gg/event/830
https://www.vlr.gg/event/812
https://www.vlr.gg/event/796
https://www.vlr.gg/event/797
https://www.vlr.gg/event/795
https://www.vlr.gg/event/792
https://www.vlr.gg/event/793
https://www.vlr.gg/event/794
import csv
import matchStatsFunction as f
import urlGetFunction as u
import time
import csvParse as c
print("Operation Started")
startTime = time.time()
eventUrls = []
f.ClearCsv()
u.ClearUrls()
c.ClearCsv()
u.GetEvents('https://www.vlr.gg/vct-2022')
file = open('eventUrl.csv', 'r')
data = list(csv.reader(file))
file.close()
i=0
while i<len(data):
x = data[i]
z = x[0]
eventUrls.append(z)
i += 1
u.GetUrls(eventUrls)
file = open('urls.csv', 'r')
data = list(csv.reader(file))
file.close()
print("Match Stats Gathering Started")
i=0
while i<len(data):
x = data[i]
z = x[0]
f.GetMatchStats(z)
i += 1
print("Parsing Data")
c.ParseCsv()
endTime = time.time()
finalTime = endTime - startTime
finalTimeStr = str(finalTime)
print("Operation Successful")
print("Operation took " + finalTimeStr + " to complete.")
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
import requests
from bs4 import BeautifulSoup
import re
import csv
def ClearUrls():
f = open('urls.csv', 'w+')
f.close()
f = open('eventUrl.csv', 'w+')
f.close()
def GetUrls(urlToScrapeList):
for url in urlToScrapeList:
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
gameCodeList = []
#Get Urls on Page
for a in soup.find_all('a', href=True):
parsedLink = a['href'].split('/')
try:
if(parsedLink[1].isdigit()):
gameCodeList.append(parsedLink[1])
except:
pass
i = 0
while i<len(gameCodeList):
tempString = 'https://www.vlr.gg/'
tempString += gameCodeList[i]
with open('urls.csv', 'a', newline='') as f:
writer = csv.writer(f)
writer.writerow([tempString])
i += 1
def GetEvents(eventUrl):
response = requests.get(eventUrl)
soup = BeautifulSoup(response.text, 'html.parser')
eventCodeList = []
#Get Urls on Page
for a in soup.find_all('a', href=True):
parsedLink = a['href'].split('/')
try:
if(parsedLink[1] == 'event'):
eventCodeList.append(parsedLink[2])
except:
pass
i = 0
while(i < len(eventCodeList)):
tempString = 'https://www.vlr.gg/event/'
tempString += eventCodeList[i]
with open('eventUrl.csv', 'a', newline='') as f:
writer = csv.writer(f)
writer.writerow([tempString])
i += 1
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment