Skip to content

Commit

Permalink
fixed MMR = -1 error, and a couple other bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
majikat768 committed Dec 24, 2022
1 parent 3ec289e commit 02d2655
Show file tree
Hide file tree
Showing 16 changed files with 147 additions and 83 deletions.
28 changes: 25 additions & 3 deletions src/DbHandler.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sqlite3
import ctypes
from resources import *


Expand Down Expand Up @@ -111,7 +112,9 @@ def GetTotalHuntCount():
return -1
return n[0][0]

def GetCurrentMmr(pid = settings.value("profileid")):
def GetCurrentMmr(pid = None):
if pid == None or pid < 0:
pid = settings.value("profileid")
mmr = execute_query("select mmr from 'hunters' where profileid is '%s' and timestamp is %d" % (pid, GetLastHuntTimestamp()))
if len(mmr) == 0:
return -1
Expand All @@ -120,7 +123,9 @@ def GetCurrentMmr(pid = settings.value("profileid")):
return -1
return mmr

def GetBestMmr(pid = settings.value("profileid")):
def GetBestMmr(pid = None):
if pid == None or pid < 0:
pid = settings.value("profileid")
mmr = execute_query("select max(mmr) from 'hunters' where profileid is '%s'" % pid)
if len(mmr) == 0:
return -1
Expand Down Expand Up @@ -148,6 +153,7 @@ def GetTopKilled():
def GetTopNHunters(n):
cols = ['frequency','name', 'profileid', 'mmr','killedme','killedbyme']
vals = execute_query("select count(profileid) as frequency, blood_line_name, profileid, mmr, killedme+downedme as killedme, killedbyme+downedbyme as killedbyme from 'hunters' where profileid is not '%s' group by profileid order by frequency desc limit %d" % (settings.value("profileid"), n))
#vals = execute_query("select count(profileid) as frequency, blood_line_name, profileid, mmr, killedme+downedme as killedme, killedbyme+downedbyme as killedbyme from 'hunters' group by profileid order by frequency desc limit %d" % (n))
results = []
if len(vals) > 0:
for v in vals:
Expand Down Expand Up @@ -491,4 +497,20 @@ def getKillData(ts):
"team_kills": team_kills,
"your_deaths": your_deaths,
"assists": assists
}
}


def SameTeamCount(name):
res = execute_query("select count(*) from 'hunters' join 'teams' on 'teams'.ownteam = 'true' and 'hunters'.team_num = 'teams'.team_num and 'hunters'.timestamp = 'teams'.timestamp where 'hunters'.blood_line_name = '%s'" % name)
res = 0 if len(res) == 0 else res[0][0]
return res

def getAllUsernames(pid):
allnamesarray = execute_query(
"select blood_line_name from 'hunters' where profileid is %d group by blood_line_name" % pid)
allnames = []
if len(allnamesarray) <= 0:
return allnames
for n in allnamesarray:
allnames.append(n[0])
return allnames
8 changes: 2 additions & 6 deletions src/Logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from PyQt6.QtCore import QObject, pyqtSignal
from resources import *
from DbHandler import *
from Widgets.Toast import Toast

def file_changed(ts):
return os.stat(settings.value("xml_path")).st_mtime != ts
Expand All @@ -33,7 +32,6 @@ def __init__(self,parent):
if not tables_exist():
create_tables()
self.running = False
self.toast = Toast("New Hunt Recorded.",parent=self.mainframe.window())
super().__init__()

def run(self):
Expand Down Expand Up @@ -73,10 +71,10 @@ def run(self):
self.mainframe.setStatus("writing new record to database....")
json_to_db(new_data)
last_hunt = last_change
log('successfully recorded hunt')
self.progress.emit()
self.toast.show()
except Exception as e:
log('building json error')
log('building json error, trying again')
log(e)
continue

Expand Down Expand Up @@ -180,7 +178,6 @@ def clean_data(obj):


def build_json_from_xml(ts):
#print('building json object')
with open(settings.value("xml_path"),'r',encoding='utf-8') as xf:
teams = {}
hunters = {}
Expand Down Expand Up @@ -248,7 +245,6 @@ def build_json_from_xml(ts):
if settings.value("HunterLevel","") != "" and int(val) < int(settings.value("HunterLevel")):
log("prestiged")
settings.setValue("HunterLevel",val)

return clean_data({
"teams":teams,
"hunters":hunters,
Expand Down
43 changes: 28 additions & 15 deletions src/MainWindow/Chart/Bars.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from PyQt6.QtWidgets import QWidget, QLabel, QVBoxLayout
from PyQt6.QtCore import QRectF
from PyQt6.QtGui import QCursor, QColor
from PyQt6.QtWidgets import QWidget, QLabel, QVBoxLayout, QGraphicsItem, QGraphicsRectItem, QGraphicsOpacityEffect, QGraphicsObject
from PyQt6.QtCore import QRectF, QAbstractAnimation, QPropertyAnimation, QObject
from PyQt6.QtGui import QCursor, QColor, QBrush
import pyqtgraph
from Widgets.Popup import Popup

# for this to work I have to make sure the constructor contains:
# x0 [], x1 [], height [], brushes []
# y0 []
class Bars(pyqtgraph.BarGraphItem):
def __init__(self, **opts):
super().__init__(**opts)
Expand All @@ -24,16 +24,17 @@ def __init__(self, **opts):
if 'y0' not in opts:
opts['y0'] = [0]*len(opts['x0'])
for i in range(len(opts['x0'])):
self.bars.append(QRectF(
bar = Bar(
opts['x0'][i],
opts['y0'][i],
self.width,
opts['height'][i]
))
)
self.bars.append(bar)
self.hoverable = True

def hoverEnterEvent(self,ev):
return None#super().hoverEnterEvent(ev)
return super().hoverEnterEvent(ev)

def hoverMoveEvent(self,ev):
if not self.hoverable:
Expand All @@ -43,6 +44,7 @@ def hoverMoveEvent(self,ev):
b = self.bars[i]
if b.contains(ev.pos()):
contained = True
self.brushes[i].setAlpha(255)
if self.popup == None or not self.popup.isVisible():
w = self.getViewWidget().window()
self.brushes[i].setAlpha(255)
Expand All @@ -58,23 +60,34 @@ def hoverMoveEvent(self,ev):
self.popup.current = b
w.raise_()
w.activateWindow()
self.setOpts()
elif self.popup.current != b:
self.popup.close()
self.popup.hide()
else:
self.brushes[i].setAlpha(200)
self.setOpts()
self.setOpts()
if not contained:
try:
self.popup.close()
self.popup.hide()
except:
self.popup = None
self.scene().update()
return None#super().hoverEnterEvent(ev)
return super().hoverEnterEvent(ev)

def hoverLeaveEvent(self,ev):
for i in range(len(self.bars)):
self.brushes[i].setAlpha(200)
self.setOpts()
try:
self.popup.close()
self.popup.hide()
except:
self.popup = None
return super().hoverEnterEvent(ev)
return
return super().hoverEnterEvent(ev)

class Bar(QGraphicsRectItem, QObject):
def __init__(self,*args):
super().__init__(*(args))
self.setAcceptHoverEvents(True)

def hoverEnterEvent(self, event):
print('h')
return super().hoverEnterEvent(event)
4 changes: 2 additions & 2 deletions src/MainWindow/Chart/Chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ def setWinLoss(self):
)
) + 32
'''
height = 120
height = winLoss.ymax+10

self.plot.addItem(winLoss.bountyBars)
self.plot.addItem(winLoss.quickplayBars)
self.plot.addItem(winLoss.survivalBars)
self.plot.setLabel('left','Win/Loss %')
self.plot.setLabel('left','# of Hunts')
self.plot.setLimits(xMin=0, xMax=80,yMin=0, yMax=height)
self.plot.setXRange(0,80)
self.plot.setYRange(0,height)
Expand Down
2 changes: 1 addition & 1 deletion src/MainWindow/Chart/KdaData.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self,parent=None):

self.line = PlotDataItem(data,pen="#ffffff88")
self.qpPoints = ScatterItem(
[{'x': pt['x'], 'y': pt['y'], 'data':unix_to_datetime(pt['ts'])} for pt in data if pt['qp'] == 'true'],
[{'x': pt['x'], 'y': pt['y'], 'data':pt['ts']} for pt in data if pt['qp'] == 'true'],
pen="#000000",brush="#00ffff",name="Quick Play",tip="{data}<br>KDA: {y:.2f}".format, parent=self.parent
)
self.bhPoints = ScatterItem(
Expand Down
2 changes: 1 addition & 1 deletion src/MainWindow/Chart/MmrData.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self,parent=None) -> None:
)
lastTs = GetLastHuntTimestamp()
spots = [{'x': GetTotalHuntCount(), 'y': prediction,
'data': -1}]
'data': lastTs}]

self.nextPoint = ScatterItem(
spots, symbol='t1', pen="#ffffff", brush="#000000", tip=("Predicted MMR: %d" % (prediction)).format)
Expand Down
9 changes: 4 additions & 5 deletions src/MainWindow/Chart/ScatterItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,13 @@ def mouseOver(self,obj,pts,ev):

elif self.isHovered and not ptHovered:
self.isHovered = False
self.popup.close()
self.popup.hide()
else:
self.isHovered = False
try:
self.popup.close()
self.popup.deleteLater()
self.popup.hide()
except:
self.popup = None
return

def handleClick(self,obj,pts,ev):
if self.parent == None:
Expand All @@ -77,6 +76,6 @@ def handleClick(self,obj,pts,ev):
pt = pts[0]
mainframe = self.parent.window().mainframe
GoToHuntPage(pt.data(),mainframe)
self.popup.close()
self.popup.hide()
self.popup = None
self.stop = False
27 changes: 18 additions & 9 deletions src/MainWindow/Chart/WinLoss.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@ def __init__(self) -> None:
QColor("#c8ff0000")
]
self.pen = None#QPen(QColor("#000000"))
self.ymax = 10
self.update()

def update(self):
self.data = self.GetData()
self.ymax = max(
self.data['winRate']['bounty']['total'],
max(
self.data['winRate']['qp']['total'],
self.data['survivalRate']['total']
)
)

self.bountyBars = Bars(
x0 = [10,10],
x1 = [20,20],
height=[
self.data['winRate']['bounty']['winPrc'],
self.data['winRate']['bounty']['lossPrc']
self.data['winRate']['bounty']['wins'],
self.data['winRate']['bounty']['losses']
],
y0 = [0,self.data['winRate']['bounty']['winPrc']],
y0 = [0,self.data['winRate']['bounty']['wins']],
brushes=self.brushes,
pens=[self.pen]*2
)
Expand All @@ -31,10 +39,10 @@ def update(self):
x0 = [30,30],
x1 = [40,40],
height=[
self.data['winRate']['qp']['winPrc'],
self.data['winRate']['qp']['lossPrc']
self.data['winRate']['qp']['wins'],
self.data['winRate']['qp']['losses']
],
y0 = [0,self.data['winRate']['qp']['winPrc']],
y0 = [0,self.data['winRate']['qp']['wins']],
brushes=self.brushes,
pens=[self.pen]*2
)
Expand All @@ -43,10 +51,10 @@ def update(self):
x0 = [50,50],
x1 = [60,60],
height=[
self.data['survivalRate']['winPrc'],
self.data['survivalRate']['lossPrc']
self.data['survivalRate']['survived'],
self.data['survivalRate']['died']
],
y0 = [0,self.data['survivalRate']['winPrc']],
y0 = [0,self.data['survivalRate']['survived']],
brushes=self.brushes,
pens=[self.pen]*2
)
Expand Down Expand Up @@ -123,6 +131,7 @@ def GetSurvival(self):
survived = 0 if len(survived) == 0 else survived[0][0]
total = execute_query("select count(*) from 'games' where MissionBagIsQuickPlay = 'false'")
total = 0 if len(total) == 0 else total[0][0]
total = max(1,total)
return {
'survived':survived,
'died':total - survived,
Expand Down
Loading

0 comments on commit 02d2655

Please sign in to comment.