Skip to content

Commit

Permalink
added trim logfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinga13 committed Mar 30, 2024
1 parent a348918 commit a37da51
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 16 deletions.
15 changes: 14 additions & 1 deletion OSCRUI/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from PySide6.QtWidgets import QFileDialog, QLineEdit

from OSCR import LIVE_TABLE_HEADER, split_log_by_combat, split_log_by_lines
from OSCR import LIVE_TABLE_HEADER, OSCR, split_log_by_combat, split_log_by_lines
from .iofunctions import browse_path
from .textedit import format_path

Expand Down Expand Up @@ -261,3 +261,16 @@ def collapse_overview_table(self):
Hides the overview table
"""
self.widgets.overview_table_frame.hide()


def trim_logfile(self):
"""
Removes all combats but the most recent one from a logfile
"""
log_path = os.path.abspath(self.entry.text())
temp_parser = OSCR(log_path, self.parser_settings)
if os.path.getsize(log_path) > 125 * 1024 * 1024:
temp_parser.analyze_massive_log_file()
else:
temp_parser.analyze_log_file()
temp_parser.export_combat(0, log_path)
5 changes: 4 additions & 1 deletion OSCRUI/datafunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from OSCR import OSCR, HEAL_TREE_HEADER, TREE_HEADER
from PySide6.QtCore import Qt, QThread, Signal

from .callbacks import switch_main_tab, switch_overview_tab
from .callbacks import switch_main_tab, switch_overview_tab, trim_logfile
from .datamodels import DamageTreeModel, HealTreeModel, TreeSelectionModel
from .displayer import create_overview
from .subwindows import log_size_warning, show_warning, split_dialog
Expand Down Expand Up @@ -148,6 +148,9 @@ def get_data(self, combat: int | None = None, path: str | None = None):
if action == 'split dialog':
split_dialog(self)
return False
elif action == 'trim':
trim_logfile(self)
self.parser1.analyze_log_file()
elif action == 'continue':
self.parser1.analyze_massive_log_file()
else:
Expand Down
49 changes: 36 additions & 13 deletions OSCRUI/subwindows.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from PySide6.QtWidgets import QVBoxLayout

from OSCR import LiveParser, LIVE_TABLE_HEADER
from .callbacks import auto_split_callback, combat_split_callback, copy_live_data_callback
from .callbacks import (
auto_split_callback, combat_split_callback, copy_live_data_callback, trim_logfile)
from .displayer import create_live_graph, update_live_display, update_live_graph, update_live_table
from .datamodels import LiveParserTableModel
from .style import get_style, get_style_class, theme_font
Expand Down Expand Up @@ -54,12 +55,15 @@ def log_size_warning(self):
dialog.setWindowIcon(self.icons['oscr'])
dialog.addButton('Cancel', QMessageBox.ButtonRole.RejectRole)
default_button = dialog.addButton('Split Dialog', QMessageBox.ButtonRole.ActionRole)
dialog.addButton('Trim', QMessageBox.ButtonRole.ActionRole)
dialog.addButton('Continue', QMessageBox.ButtonRole.AcceptRole)
dialog.setDefaultButton(default_button)
clicked = dialog.exec()
if clicked == 1:
return 'split dialog'
elif clicked == 2:
return 'trim'
elif clicked == 3:
return 'continue'
else:
return 'cancel'
Expand Down Expand Up @@ -96,8 +100,27 @@ def split_dialog(self):
grid_layout.setVerticalSpacing(0)
grid_layout.setHorizontalSpacing(item_spacing)
vertical_layout.addLayout(grid_layout)

trim_heading = create_label(self, 'Trim Logfile:', 'label_heading')
grid_layout.addWidget(trim_heading, 0, 0, alignment=ALEFT)
label_text = (
'Removes all combats but the most recent one from the selected logfile. '
'All previous combats will be lost!')
trim_text = create_label(self, label_text, 'label')
trim_text.setWordWrap(True)
trim_text.setFixedWidth(self.sidebar_item_width)
grid_layout.addWidget(trim_text, 1, 0, alignment=ALEFT)
trim_button = create_button(self, 'Trim')
trim_button.clicked.connect(lambda: trim_logfile(self))
grid_layout.addWidget(trim_button, 1, 2, alignment=ARIGHT | ABOTTOM)
grid_layout.setRowMinimumHeight(2, item_spacing)
seperator_8 = create_frame(self, content_frame, 'hr', size_policy=SMINMIN)
seperator_8.setFixedHeight(self.theme['hr']['height'])
grid_layout.addWidget(seperator_8, 3, 0, 1, 3)
grid_layout.setRowMinimumHeight(4, item_spacing)

auto_split_heading = create_label(self, 'Split Log Automatically:', 'label_heading')
grid_layout.addWidget(auto_split_heading, 0, 0, alignment=ALEFT)
grid_layout.addWidget(auto_split_heading, 5, 0, alignment=ALEFT)
label_text = (
'Automatically splits the logfile at the next combat end after '
f'{self.settings.value("split_log_after", type=int):,} lines until the entire file has '
Expand All @@ -106,17 +129,17 @@ def split_dialog(self):
auto_split_text = create_label(self, label_text, 'label')
auto_split_text.setWordWrap(True)
auto_split_text.setFixedWidth(self.sidebar_item_width)
grid_layout.addWidget(auto_split_text, 1, 0, alignment=ALEFT)
grid_layout.addWidget(auto_split_text, 6, 0, alignment=ALEFT)
auto_split_button = create_button(self, 'Auto Split')
auto_split_button.clicked.connect(lambda: auto_split_callback(self, current_logpath))
grid_layout.addWidget(auto_split_button, 1, 2, alignment=ARIGHT | ABOTTOM)
grid_layout.setRowMinimumHeight(2, item_spacing)
seperator_3 = create_frame(self, content_frame, 'hr', size_policy=SMINMIN)
seperator_3.setFixedHeight(self.theme['hr']['height'])
grid_layout.addWidget(seperator_3, 3, 0, 1, 3)
grid_layout.setRowMinimumHeight(4, item_spacing)
grid_layout.addWidget(auto_split_button, 6, 2, alignment=ARIGHT | ABOTTOM)
grid_layout.setRowMinimumHeight(7, item_spacing)
seperator_8 = create_frame(self, content_frame, 'hr', size_policy=SMINMIN)
seperator_8.setFixedHeight(self.theme['hr']['height'])
grid_layout.addWidget(seperator_8, 8, 0, 1, 3)
grid_layout.setRowMinimumHeight(9, item_spacing)
range_split_heading = create_label(self, 'Export Range of Combats:', 'label_heading')
grid_layout.addWidget(range_split_heading, 5, 0, alignment=ALEFT)
grid_layout.addWidget(range_split_heading, 10, 0, alignment=ALEFT)
label_text = (
'Exports combats including and between lower and upper limit to selected file. '
'Both limits refer to the indexed list of all combats in the file starting with 1. '
Expand All @@ -125,7 +148,7 @@ def split_dialog(self):
range_split_text = create_label(self, label_text, 'label')
range_split_text.setWordWrap(True)
range_split_text.setFixedWidth(self.sidebar_item_width)
grid_layout.addWidget(range_split_text, 6, 0, alignment=ALEFT)
grid_layout.addWidget(range_split_text, 11, 0, alignment=ALEFT)
range_limit_layout = QGridLayout()
range_limit_layout.setContentsMargins(0, 0, 0, 0)
range_limit_layout.setSpacing(0)
Expand All @@ -152,12 +175,12 @@ def split_dialog(self):
get_style(self, 'entry', {'margin-top': 0, 'margin-left': '@csp'}))
upper_range_entry.setFixedWidth(self.sidebar_item_width // 7)
range_limit_layout.addWidget(upper_range_entry, 2, 1, alignment=AVCENTER)
grid_layout.addLayout(range_limit_layout, 6, 1)
grid_layout.addLayout(range_limit_layout, 11, 1)
range_split_button = create_button(self, 'Export Combats')
range_split_button.clicked.connect(
lambda le=lower_range_entry, ue=upper_range_entry:
combat_split_callback(self, current_logpath, le.text(), ue.text()))
grid_layout.addWidget(range_split_button, 6, 2, alignment=ARIGHT | ABOTTOM)
grid_layout.addWidget(range_split_button, 11, 2, alignment=ARIGHT | ABOTTOM)

content_frame.setLayout(vertical_layout)

Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class Launcher():

version = '2024.3b300'
version = '2024.3b301'
__version__ = '0.1'

# holds the style of the app
Expand Down

0 comments on commit a37da51

Please sign in to comment.