Skip to content

Commit

Permalink
Fixed a bug when geting the new rank field.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kraust committed Mar 5, 2024
1 parent a54e11b commit 949a848
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
61 changes: 40 additions & 21 deletions OSCRUI/leagueconnector.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
"""Backend inteface to the OSCR web server"""

import gzip
import tempfile
import os
import tempfile

import OSCR_django_client
from OSCR.utilities import logline_to_str
from OSCR_django_client.api import CombatlogApi, LadderApi, LadderEntriesApi
from PySide6.QtWidgets import QMessageBox

from .datafunctions import CustomThread
from .datamodels import LeagueTableModel, SortingProxy
from .textedit import format_datetime_str
from .style import theme_font
from .datafunctions import CustomThread
from .textedit import format_datetime_str

LADDER_HEADER = (
"Name",
"Handle",
"DPS",
"Total Damage",
"Deaths",
"Combat Time",
"Date",
"Max One Hit",
"Debuff",
)

LADDER_HEADER = ('Name', 'Handle', 'DPS', 'Total Damage', 'Deaths', 'Combat Time', 'Date', 'Max One Hit',
'Debuff')

def establish_league_connection(self, fetch_maps: bool = False):
"""
Expand All @@ -30,6 +40,7 @@ def establish_league_connection(self, fetch_maps: bool = False):
map_fetch_thread = CustomThread(self.window, lambda: fetch_and_insert_maps(self))
map_fetch_thread.start()


def fetch_and_insert_maps(self):
"""
Retrieves maps from API and inserts them into the list.
Expand All @@ -38,17 +49,18 @@ def fetch_and_insert_maps(self):
if ladders is not None:
self.widgets.ladder_map.clear()
for ladder in ladders.results:
solo = '[Solo] ' if ladder.is_solo else ''
key = f'{solo}{ladder.metric} - {ladder.name} ({ladder.difficulty})'
solo = "[Solo] " if ladder.is_solo else ""
key = f"{solo}{ladder.metric} - {ladder.name} ({ladder.difficulty})"
self.league_api.ladder_dict[key] = ladder
self.widgets.ladder_map.addItem(key)


def update_ladder_index(self, selected_map):
"""Open Combat Log Dialog Box"""

if not selected_map in self.league_api.ladder_dict:
return

selected_ladder = self.league_api.ladder_dict[selected_map]
ladder_data = self.league_api.ladder_entries(selected_ladder.id)
table_index = list()
Expand All @@ -57,11 +69,23 @@ def update_ladder_index(self, selected_map):
for rank, entry in enumerate(ladder_data.results, 1):
table_index.append(rank)
row = entry.data
table_data.append((row['name'], row['handle'], row['DPS'], row['total_damage'], row['deaths'],
row['combat_time'], format_datetime_str(entry.var_date), row['max_one_hit'], row['debuff']))

model = LeagueTableModel(table_data, LADDER_HEADER, table_index, theme_font(self, 'table_header'),
theme_font(self, 'table'))
table_data.append(
(
row["name"],
row["handle"],
row["DPS"],
row["total_damage"],
row["deaths"],
row["combat_time"],
format_datetime_str(entry.var_date),
row["max_one_hit"],
row["debuff"],
)
)

model = LeagueTableModel(
table_data, LADDER_HEADER, table_index, theme_font(self, "table_header"), theme_font(self, "table")
)
sorting_proxy = SortingProxy()
sorting_proxy.setSourceModel(model)
table = self.widgets.ladder_table
Expand All @@ -85,17 +109,12 @@ def upload_callback(self):

establish_league_connection(self)

if (
self.parser1.active_combat is None
or self.parser1.active_combat.log_data is None
):
if self.parser1.active_combat is None or self.parser1.active_combat.log_data is None:
raise Exception("No data to upload")

with tempfile.NamedTemporaryFile(dir=self.app_dir, delete=False) as file:
data = gzip.compress(
"".join(
[logline_to_str(line) for line in self.parser1.active_combat.log_data]
).encode()
"".join([logline_to_str(line) for line in self.parser1.active_combat.log_data]).encode()
)
file.write(data)
file.flush()
Expand Down Expand Up @@ -167,7 +186,7 @@ def ladder_entries(self, id, page=1):
ladder=str(id),
page=page,
ordering="-data__DPS",
page_size=200,
page_size=50,
)
except OSCR_django_client.exceptions.ServiceException as e:
reply = QMessageBox()
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class Launcher():

version = '2024.03a041'
version = '2024.03a042'

# holds the style of the app
theme = {
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies = [
"pyqtgraph>=0.13.3",
"numpy>=1.26.1",
"STO-OSCR>=2024.3b40",
"OSCR-django-client>=2024.2b260",
"OSCR-django-client>=2024.3b40",
]
requires-python = ">=3.10"
authors = []
Expand Down

0 comments on commit 949a848

Please sign in to comment.