def parse_spawn(self, elements): """ Either starts the parsing of ALL spawns found in the specified match or just one of them and displays the results in the other frames accordingly. """ self.clear_data_widgets() self.main_window.middle_frame.statistics_numbers_var.set("") self.main_window.ship_frame.ship_label_var.set("No match or spawn selected yet.") file_name, match_index, spawn_index = elements[0], int(elements[1]), int(elements[2]) lines = Parser.read_file(file_name) player_list = Parser.get_player_id_list(lines) player_name = Parser.get_player_name(lines) file_cube, match_timings, spawn_timings = Parser.split_combatlog(lines, player_list) match = file_cube[match_index] spawn = match[spawn_index] results = list(spawnstats.spawn_statistics( file_name, spawn, spawn_timings[match_index][spawn_index])) results[1] = Parser.parse_player_reaction_time(spawn, player_name) orig = len(results[1]) results[1] = ScreenParser.build_spawn_events( file_name, match_timings[::2][match_index], spawn_timings[match_index][spawn_index], spawn, player_name) print("[FileFrame] ScreenParser built {} events. Total: {}".format(len(results[1]) - orig, len(results[1]))) self.update_widgets_spawn(*results) arguments = (file_name, match_timings[::2][match_index], spawn_timings[match_index][spawn_index]) string = FileHandler.get_features_string(*arguments) self.main_window.middle_frame.screen_label_var.set(string) self.main_window.middle_frame.update_timeline( file_name, match_index, spawn_index, match_timings, spawn_timings, file_cube)
def parse_ship_descriptor(ship: Ship, line: dict, lines: list, event: tuple): """ Parse an event_descriptor of the SHIP type. Supports ability, component and crew type operations. :param ship: Ship instance for the spawn described by lines :param line: Trigger line dictionary :param lines: List of lines in this spawn :param event: Event descriptor tuple (PatternParser docstring) :return: The result of results this SHIP event descriptor """ if event[0] != Patterns.SHIP: raise InvalidDescriptor(event) event_type, args = event[1], event[2:] # "ability", "component", "crew" # Parse Component selected if event_type == "component": # Component must be selected on the Ship for this spawn component, = args return PatternParser.get_component_in_ship(lines, ship, component) # Parse Crew selected elif event_type == "crew": crew, = args return PatternParser.get_crew_in_ship(ship, crew) # Parse Ability Available elif event_type == "ability": return PatternParser.parse_ability_availability(line, lines, event, ship) # Parse ship type selected elif event_type == "type": # TODO: Optimize usage player = Parser.get_player_id_list(lines) abs_dict = Parser.get_abilities_dict(lines, player) ship_name = ship.name if ship is None else Parser.get_ship_for_dict(abs_dict) ship_type, = args return get_ship_category(ship_name) == ship_type raise InvalidDescriptor(event)
def get_component_in_ship(lines: list, ship: Ship, component: (str, Component)): """Return whether a component is found within a Ship instance""" if isinstance(component, Component): name, category = component.name, component.category else: # str name = component category = PatternParser.get_component_category(component) player = Parser.get_player_id_list(lines) abilities = Parser.get_abilities_dict(lines, player) if name in abilities: return True if ship is None: return False # Ship option not available at results time if category not in ship: return False # Configured improperly at results time categories = (category,) if "Weapon" in category: # Extend to double primaries/secondaries categories += (category[0] + "2",) # Loop over categories result = False for category in categories: if category not in ship: # Double primaries/secondaries continue component = ship[category] if not isinstance(component, Component): # Improper config print("[PatternParser] Improperly configured Ship instance:", ship, component) continue if component.name == name: result = True break continue return result
def get_ability_markers(spawn_list, ship_stats): """ Parse a spawn list of lines and take the Engine, Shield, Systems and CoPilot ability activations and create markers for them to be put in the TimeLine. """ # TODO: Use ship_statistics to create availability markers categories = ["engines", "shields", "copilot", "systems"] player_id_list = Parser.get_player_id_list(spawn_list) results = {key: [] for key in categories} # Activation markers for line in spawn_list: if not isinstance(line, dict): line = Parser.line_to_dictionary(line) ability = line["ability"] if (line["source"] != line["target"] or line["source"] not in player_id_list or "AbilityActivate" not in line["effect"]): continue if ability in abilities.copilots: category = "copilot" elif ability in abilities.shields: category = "shields" elif ability in abilities.systems: category = "systems" elif ability in abilities.engines: category = "engines" else: continue start = FileHandler.datetime_to_float(line["time"]) args = ("abilities", start, start + 1/60) kwargs = {"background": FileHandler.colors[category]} results[category].append((args, kwargs)) return results
def parse_spawn(self, file: str, match_i: int, spawn_i: int): """ Either starts the results of ALL spawns found in the specified match or just one of them and displays the results in the other frames accordingly. """ print("[FileFrame] Parsing '{}', match {}, spawn {}".format(file, match_i, spawn_i)) self.main_window.middle_frame.statistics_numbers_var.set("") self.main_window.ship_frame.ship_label_var.set("No match or spawn selected yet.") lines = Parser.read_file(file) player_list = Parser.get_player_id_list(lines) player_name = Parser.get_player_name(lines) file_cube, match_timings, spawn_timings = Parser.split_combatlog(lines, player_list) match = file_cube[match_i] spawn = match[spawn_i] results = list(spawnstats.spawn_statistics( file, spawn, spawn_timings[match_i][spawn_i])) results[1] = Parser.parse_player_reaction_time(spawn, player_name) orig = len(results[1]) results[1] = ScreenParser.build_spawn_events( file, match_timings[::2][match_i], spawn_timings[match_i][spawn_i], spawn, player_name) print("[FileFrame] ScreenParser built {} events. Total: {}".format(len(results[1]) - orig, len(results[1]))) self.update_widgets_spawn(*results) arguments = (file, match_timings[::2][match_i], spawn_timings[match_i][spawn_i]) string = FileHandler.get_features_string(*arguments) self.main_window.middle_frame.screen_label_var.set(string) self.main_window.middle_frame.update_timeline( file, match_i, spawn_i, match_timings, spawn_timings, file_cube) match_timing = datetime.combine(Parser.parse_filename(file).date(), match_timings[::2][match_i].time()) self.main_window.middle_frame.scoreboard.update_match(match_timing)
def _build_tracking_effects(events: list, screen_data: dict, ship: ShipStats): """Determine tracking penalty for each primary weapon event""" active_ids = Parser.get_player_id_list(events) distance = screen_data["distance"] primary = "PrimaryWeapon" for i, event in enumerate(events): if "custom" in event and event["custom"] is True: continue if "Primary Weapon Swap" in event["ability"] and event["self"] is True: primary = "PrimaryWeapon2" if primary == "PrimaryWeapon" else "PrimaryWeapon" continue ctg = Parser.get_event_category(event, active_ids) if ctg != "dmgd_pri": continue key = min(distance.keys(), key=lambda k: abs((k - event["time"]).total_seconds())) if abs((key - event["time"]).total_seconds()) > 0.5: continue if primary not in ship: continue tracking = ship[primary]["trackingAccuracyLoss"] * (distance[key] / 10) * 100 del events[i] event["effects"] = ( ("", "Tracking", "Penalty", "-{:.0f}%".format(tracking), "", "spvp_improvedfiringarctrackingbonus"), ) events.append(event) return events
def test_get_effects_ability_eligible(self): with open(self.FILE) as fi: lindex = fi.readlines() index = lindex.index(self.EFFECT) no_effect = lindex.index(self.LINE) lines = Parser.read_file(self.FILE) player = Parser.get_player_id_list(lines) line = Parser.line_to_dictionary(lines[index], player) effect = Parser.get_effects_ability(line, lines, "2963000049645") self.assertIsInstance(effect, dict) self.assertTrue(len(effect) > 0) # Tests get_effects_eligible self.assertFalse(Parser.get_effects_ability(lines[no_effect], lines, "2963000048240"))
def insert_spawn(self, spawn, player_name, active_ids: list = None): """Insert the events of a spawn into the Treeview""" self.delete_all() if len(spawn) == 0: raise ValueError("Invalid spawn passed.") spawn = spawn if isinstance(spawn[0], dict) else [Parser.line_to_dictionary(line) for line in spawn] start_time = spawn[0]["time"] active_ids = Parser.get_player_id_list(spawn) if active_ids is None else active_ids for line in spawn: if "custom" not in line or line["custom"] is False: line_event_dict = Parser.line_to_event_dictionary(line, active_ids, spawn) else: line_event_dict = line self.insert_event(line_event_dict, player_name, active_ids, start_time)
def spawn_statistics(file_name, spawn, spawn_timing, sharing_db=None): """Build strings to show in the StatsFrame""" # Retrieve required data lines = Parser.read_file(file_name, sharing_db) player_numbers = Parser.get_player_id_list(lines) (abilities_dict, dmg_t, dmg_d, healing, dmg_s, enemies, critcount, crit_luck, hitcount, ships_list, enemy_dmg_d, enemy_dmg_t) = \ Parser.parse_spawn(spawn, player_numbers) name = Parser.get_player_name(lines) # Build the statistics string stat_string = "{name}\n{enemies} enemies\n{dmg_d}\n{dmg_t}\n{dmg_r:.1f} : 1.0\n" \ "{dmg_s}\n{healing}\n{hitcount}\n{critcount}\n{crit_luck:.2f}\n" \ "{deaths}\n{minutes}:{seconds:.0f}\n{dps:.1f}" start = spawn_timing finish = Parser.line_to_dictionary(spawn[-1])["time"] delta = finish - start minutes, seconds = divmod(delta.total_seconds(), 60) killsassists = sum(True if enemy_dmg_t[enemy] > 0 else False for enemy in enemies if enemy in enemy_dmg_t) stat_string = stat_string.format( name=name, enemies=killsassists, dmg_d=dmg_d, dmg_t=dmg_t, dmg_r=dmg_d / dmg_t if dmg_t != 0 else 0, dmg_s=dmg_s, healing=healing, hitcount=hitcount, critcount=critcount, crit_luck=critcount / hitcount if hitcount != 0 else 0, deaths="-", minutes=minutes, seconds=seconds, dps=dmg_d / delta.total_seconds() if delta.total_seconds() != 0 else 0 ) # Build the components list components = {key: "" for key in abilities.component_types} for component in [ability for ability in abilities_dict.keys() if ability in abilities.components]: for type in components.keys(): if component not in getattr(abilities, type): continue # Dual primary/secondary weapons if components[type] != "": components[type] += " / {}".format(component) break components[type] = component break components = [components[category] for category in abilities.component_types] # Return return name, spawn, abilities_dict, stat_string, ships_list, components, enemies, enemy_dmg_d, enemy_dmg_t
def parse_file(self, file_name): """ Function either sets the file and calls add_matches to add the matches found in the file to the matches_listbox, or starts the parsing of all files found in the specified folder and displays the results in the other frames. """ self.clear_data_widgets() self.main_window.middle_frame.statistics_numbers_var.set("") self.main_window.ship_frame.ship_label_var.set("No match or spawn selected yet.") lines = Parser.read_file(file_name) player_list = Parser.get_player_id_list(lines) file_cube, _, _ = Parser.split_combatlog(lines, player_list) results = filestats.file_statistics(file_name) self.update_widgets(*results)
def get_spawn(self): """ Get the spawn from the selection in the file_tree :return: list of event strings, player_list, spawn timing and match timing """ selection = self.file_tree.selection()[0] elements = selection.split(" ") if len(elements) is not 3: tkinter.messagebox.showinfo("Requirement", "Please select a spawn to view the events of.") return lines = Parser.read_file(elements[0]) player_list = Parser.get_player_id_list(lines) file_cube, match_timings, spawn_timings = Parser.split_combatlog(lines, player_list) match_index, spawn_index = int(elements[1]), int(elements[2]) return (file_cube[match_index][spawn_index], player_list, spawn_timings[match_index][spawn_index], match_timings[match_index])
def file_statistics(file_name, sharing_db=None): """ Puts the statistics found in a file_cube from Parser.split_combatlog() into a format that is usable by the FileFrame to display them to the user """ lines = Parser.read_file(file_name) player_list = Parser.get_player_id_list(lines) file_cube, match_timings, spawn_timings = Parser.split_combatlog(lines, player_list) # Read sharing_db lines = Parser.read_file(file_name, sharing_db) name = Parser.get_player_name(lines) (abilities_dict, dmg_d, dmg_t, dmg_s, healing, hitcount, critcount, crit_luck, enemies, enemy_dmg_d, enemy_dmg_t, ships, uncounted) = \ Parser.parse_file(file_cube, player_list) total = 0 start = None for timing in match_timings: if start is not None: total += (timing - start).total_seconds() start = None continue start = timing minutes, seconds = divmod(total, 60) stat_string = "{name}\n{enemies} enemies\n{dmg_d}\n{dmg_t}\n{dmg_r:.1f} : 1.0\n" \ "{dmg_s}\n{healing}\n{hitcount}\n{critcount}\n{crit_luck:.2f}\n" \ "{deaths}\n{minutes}:{seconds:.0f}\n{dps:.1f}" stat_string = stat_string.format( name=name, enemies=len([enemy for enemy in enemies if enemy in enemy_dmg_t and enemy_dmg_t[enemy] > 0]), dmg_d=dmg_d, dmg_t=dmg_t, dmg_r=dmg_d / dmg_t if dmg_t != 0 else 0, dmg_s=dmg_s, healing=healing, hitcount=hitcount, critcount=critcount, crit_luck=critcount / hitcount if hitcount != 0 else 0, deaths=sum(len(match) for match in file_cube), minutes=minutes, seconds=seconds, dps=dmg_d / total, ) return abilities_dict, stat_string, ships, enemies, enemy_dmg_d, enemy_dmg_t, uncounted
def parse_match(self, file: str, match_i: int): """ Either adds sets the match and calls add_spawns to add the spawns found in the match or starts the results of all files found in the specified file and displays the results in the other frames. """ print("[FileFrame] Parsing file '{}', match {}".format(file, match_i)) self.main_window.middle_frame.statistics_numbers_var.set("") self.main_window.ship_frame.ship_label_var.set("No match or spawn selected yet.") lines = Parser.read_file(file) player_list = Parser.get_player_id_list(lines) file_cube, match_timings, _ = Parser.split_combatlog(lines, player_list) player_name = Parser.get_player_name(lines) match = file_cube[match_i] results = matchstats.match_statistics(file, match, match_timings[::2][match_i]) self.update_widgets(*results) match_list = Parser.build_spawn_from_match(match) self.main_window.middle_frame.time_view.insert_spawn(match_list, player_name) match_timing = datetime.combine(Parser.parse_filename(file).date(), match_timings[::2][match_i].time()) self.main_window.middle_frame.scoreboard.update_match(match_timing)
def parse_match(self, elements: list): """ Either adds sets the match and calls add_spawns to add the spawns found in the match or starts the parsing of all files found in the specified file and displays the results in the other frames. :param elements: specifies file and match """ self.clear_data_widgets() self.main_window.middle_frame.statistics_numbers_var.set("") self.main_window.ship_frame.ship_label_var.set("No match or spawn selected yet.") file_name, match_index = elements[0], int(elements[1]) lines = Parser.read_file(file_name) player_list = Parser.get_player_id_list(lines) file_cube, match_timings, _ = Parser.split_combatlog(lines, player_list) player_name = Parser.get_player_name(lines) match = file_cube[match_index] results = matchstats.match_statistics(file_name, match, match_timings[::2][match_index]) self.update_widgets(*results) match_list = Parser.build_spawn_from_match(match) self.main_window.middle_frame.time_view.insert_spawn(match_list, player_name)
def _process_new_file(self): """Backlog only the lines of a match that are match lines""" print("[LogStalker] Processing new file.") lines = self.read_file(self.path, 0) if len(lines) == 0: return player_list = Parser.get_player_id_list(lines) file_cube, _, _ = Parser.split_combatlog(lines, player_list) if len(file_cube) == 0: print("[LogStalker] No matches in this file") self._read_so_far = len(lines) return last_line = file_cube[-1][-1][-1] if last_line["time"] == lines[-1]["time"]: print("[LogStalker] Match still active") # Last line is still a match line match_len = sum(len(spawn) for spawn in file_cube[-1]) self._read_so_far = len(lines) - match_len return # Last line is no longer a match print("[LogStalker] Last line is not a match event") self._read_so_far = len(lines)
def _select_date(self, date: datetime): """Callback for Calendar widget selection command""" self.clear_data_widgets() self._tree.delete(*self._tree.get_children("")) if date not in self._dates: return self._files: List[str] = self._dates[date] for f, file in enumerate(sorted(self._files)): name = Parser.get_player_name_raw(file) cube, matches, spawns = Parser.split_combatlog_file(file) for m, match in enumerate(sorted(matches[::2])): match = datetime.strftime(match, "%H:%M, {}".format(name)) match_iid = "{},{}".format(f, m) self._tree.insert("", tk.END, text=match, iid=match_iid) for s, spawn in enumerate(sorted(spawns[m])): spawn = datetime.strftime(spawn, "%H:%M:%S") player_list: List[str] = Parser.get_player_id_list(cube[m][s]) abs_dict: Dict[str: int] = Parser.get_abilities_dict(cube[m][s], player_list) ships: List[str] = Parser.get_ship_for_dict(abs_dict) ship = self.format_ships_list(ships) spawn = "{}{}".format(spawn, ship) spawn_iid = "{},{},{}".format(f, m, s) self._tree.insert(match_iid, tk.END, text=spawn, iid=spawn_iid)
def update_timeline(self, file, match, spawn, match_timings, spawn_timings, file_cube): """ Update the TimeLine with the results of results the file and the screen results data """ # Get start and end times of the spawn start = FileHandler.datetime_to_float(Parser.line_to_dictionary(file_cube[match][spawn][0])["time"]) finish = FileHandler.datetime_to_float(Parser.line_to_dictionary(file_cube[match][spawn][-1])["time"])+1 self.time_line.delete_marker(tk.ALL) self.time_line.config(start=start, finish=finish) # Update the TimeLine screen_data = FileHandler.get_data_dictionary() screen_dict = FileHandler.get_spawn_dictionary( screen_data, file, match_timings[2 * match], spawn_timings[match][spawn] ) screen_dict = None if isinstance(screen_dict, str) or screen_dict is None else screen_dict spawn_list = file_cube[match][spawn] active_ids = Parser.get_player_id_list(spawn_list) markers = dict() if isinstance(screen_dict, dict): markers = FileHandler.get_markers(screen_dict, spawn_list, active_ids) markers["patterns"] = PatternParser.parse_patterns(spawn_list, screen_dict, Patterns.ALL_PATTERNS, active_ids) print("[TimeLine] Building {} markers.".format(sum(len(value) for value in markers.values()))) for category, data in markers.items(): for (args, kwargs) in data: try: self.time_line.create_marker(*args, **kwargs) except (ValueError, TypeError, tk.TclError) as e: print("[TimeLine] Marker creation failed: '{}', '{}', '{}', '{}': {}".format( args[0], args[1], args[2], kwargs["background"], repr(e)) ) if isinstance(e, ValueError): pass else: raise return
def test_get_abilities_dict(self): lines = Parser.read_file(self.FILE) player = Parser.get_player_id_list(lines) abilities = Parser.get_abilities_dict(lines, player) self.assertIsInstance(abilities, dict)
def filter(self, search=False): """ Go through all file filters and apply them to the list of files in the CombatLogs folder. Insert them into the file_frame file_tree widget when the file passed the filters. :param search: if search is True, the function will calculate the amount of files found and ask the user whether the results should be displayed first """ # logs, matches or spawns results = [] files = os.listdir(variables.settings["parsing"]["path"]) files_done = 0 splash = SplashScreen(self, len(files)) # Clear the widgets in the file frame self.window.file_select_frame.file_string_dict.clear() self.window.file_select_frame.clear_data_widgets() self.window.file_select_frame.file_tree.delete(*self.window.file_select_frame.file_tree.get_children()) # Start looping over the files in the CombatLogs folder for file_name in files: # Set passed to True. Will be set to False in some filter code passed = True # Update the SplashScreen progress bar files_done += 1 splash.update_max(files_done) # If the file does not end with .txt, it's not a CombatLog if not file_name.endswith(".txt") or not Parser.get_gsf_in_file(file_name): continue # Open the CombatLog lines = Parser.read_file(file_name) # Parse the CombatLog to get the data to filter against player_list = Parser.get_player_id_list(lines) file_cube, match_timings, spawn_timings = Parser.split_combatlog(lines, player_list) (abilities, damagedealt, damagetaken, selfdamage, healing, _, _, _, _, enemy_dmg_d, enemy_dmg_t, _, _) = Parser.parse_file(file_cube, player_list) matches = len(file_cube) damagedealt, damagetaken, selfdamage, healing = ( damagedealt / matches, damagetaken / matches, selfdamage / matches, healing / matches ) # If Ship filters are enabled, check file against ship filters if self.filter_type_vars["Ships"].get() is True: print("Ships filters are enabled") if not self.check_ships_file(self.ships_intvars, abilities): print("Continuing in file {0} because of Ships".format(file_name)) continue # If the Components filters are enabled, check against Components filters if self.filter_type_vars["Components"].get() is True: print("Components filters are enabled") for dictionary in self.comps_vars: if not self.check_components(dictionary, abilities): # Passed is applied here as "continue" will not work inside this for loop passed = False break if not passed: print("Continuing in file {0} because of Components".format(file_name)) continue if self.filter_type_vars["Date"].get() is True: print("Date filters are enabled") date = Parser.parse_filename(file_name) if not date: print("Continuing in file {0} because the filename could not be parsed".format(file_name)) continue if self.start_date_widget.selection > date: print("Continuing in file {0} because of the start date".format(file_name)) continue if self.end_date_widget.selection < date: print("Continuing in file {0} because of the end date".format(file_name)) continue enemies = sum(True if dmg > 0 else False for dmg in enemy_dmg_d.values()) killassists = sum(True if dmg > 0 else False for dmg in enemy_dmg_t.values()) if self.filter_type_vars["Statistics"].get() is True: for (scale_type, scale_max), (_, scale_min) in \ zip(self.statistics_scales_max.items(), self.statistics_scales_min.items()): value = locals()[scale_type] min, max = scale_min.value, scale_max.value condition = min <= value <= max if max > min else min <= value if condition is False: continue results.append(file_name) print("Amount of results: {0}".format(len(results))) print("Results: {0}".format(results)) splash.destroy() if search and len(results) is not 0: print("Search is enabled") if not tkinter.messagebox.askyesno("Search results", "With the filters you specified, %s results were found. Would you like " "to view them?" % len(results)): return if len(results) == 0: tkinter.messagebox.showinfo("Search results", "With the filters you specified, no results were found.") return for file_name in results: datetime_obj = Parser.parse_filename(file_name) string = datetime_obj.strftime("%Y-%m-%d %H:%M") if datetime_obj is not None else file_name print("Setting file string {0} to match file_name {1}".format(string, file_name)) self.window.file_select_frame.file_string_dict[string] = file_name self.window.file_select_frame.insert_file(string) self.destroy()
def test_get_player_id_list(self): lines = Parser.read_file(self.FILE) ids = Parser.get_player_id_list(lines) self.assertIsInstance(ids, list) self.assertGreater(len(ids), 0)
def get_weapon_markers(dictionary, spawn): """ Parse the given screen dictionary and spawn line list to generate markers for the TimeLine for the Primary Weapon and Secondary Weapon categories. The clicks are parsed into lightly coloured markers, while ability activations (hits) are parsed into bright markers. """ # Retrieve pre-requisite data player_list = Parser.get_player_id_list(spawn) # Create lists that will hold markers results = {"primaries": [], "secondaries": []} """ File Data """ # Loop over contents of spawn for line in spawn: if isinstance(line, str): line = Parser.line_to_dictionary(line) # Retrieve the ability of the line ability = line["ability"] # If the ability was self-targeted, then it is not a weapon # If the ability was not activated by self, then it is not damage dealt if line["self"] is True or line["target"] not in player_list: continue # Determine the category of this ability if ability in abilities.primaries: category = "primaries" elif ability in abilities.secondaries: category = "secondaries" else: # Ability is not a weapon continue # Generate the arguments for the marker creation start = FileHandler.datetime_to_float(line["time"]) args = (category, start, start + 1 / 60) # Save the marker results[category].append((args, {"background": FileHandler.colors[category]})) # If screen data does not contain mouse data, then return the # markers created so far if "clicks" not in dictionary or len(dictionary["clicks"]) == 0: return results """ Screen Data """ # This dictionary will hold when each button press was started buttons = {Button.left: None, Button.right: None} # This dictionary is for backwards compatibility, see loop buttons_press = {Button.left: False, Button.right: False} # Start looping over the data found in the screen dictionary for time, data in sorted(dictionary["clicks"].items()): # Backwards compatibility if isinstance(data, tuple): # The current interface for screen results button, press = data # Also for backwards-compatibility press = "press" in press if isinstance(press, str) else press else: # An older version of the interface saved only the button as value for the dictionary # This means that determining if the button was pressed has to be determined manually button = data # Does not support any other buttons than right and left if button not in (Button.left, Button.right): continue # Update if the button was pressed buttons_press[button] = not buttons_press[button] press = buttons_press[button] # Determine the category of the button press category = "primaries" if button == Button.left else ("secondaries" if button == Button.right else None) if category is None: continue # If the button was actually pressed, then save the time for use later if press is True: buttons[button] = time # If the button was already pressed, then a new marker can be created else: results[category].append( ((category, buttons[button], time), {"background": FileHandler.click_colors[category]}) ) return results