Skip to content

Commit

Permalink
Fix negative leg break times.
Browse files Browse the repository at this point in the history
• The leg break times used to show negative when the shields were changed during the second pylon phase.
  • Loading branch information
Iterniam committed Apr 11, 2021
1 parent c6535cf commit 0171cae
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions pt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import colorama


VERSION = "v2.1"
VERSION = "v2.1.1"
follow_mode = False # False -> analyze mode

dt_dict = {
Expand Down Expand Up @@ -90,7 +90,7 @@ def __init__(self,
nickname: str,
pt_found: float,
phase_durations: dict[int, float],
shields: dict[int, list[tuple[str, float]]],
shields: dict[float, list[tuple[str, float]]],
legs: dict[int, list[float]],
body_dur: dict[int, float],
pylon_dur: dict[int, float]):
Expand Down Expand Up @@ -152,6 +152,10 @@ def pretty_print_phase(self, phase: int):

if phase in self.pylon_dur:
print(f'{fg.white} Pylons:\t{fg.li_green}{self.pylon_dur[phase]:7.3f}s')

if phase == 3 and self.shields[3.5]: # Print phase 3.5
print(f'{fg.white} Extra shields:\t\t {fg.li_yellow}'
f'{" | ".join((shield for shield, _ in self.shields[3.5]))}')
print('') # to print an enter

def pretty_print_sum_of_parts(self):
Expand Down Expand Up @@ -184,7 +188,7 @@ def __init__(self, run_nr: int):
self.nickname = ''
self.heist_start = 0.0
self.pt_found = 0.0
self.shields: dict[int, list[tuple[str, float]]] = defaultdict(list) # phase -> list((type, absolute time))
self.shields: dict[float, list[tuple[str, float]]] = defaultdict(list) # phase -> list((type, absolute time))
self.legs: dict[int, list[float]] = defaultdict(list) # phase -> list(absolute time)
self.body_vuln: dict[int, float] = {} # phase -> vuln-time
self.body_kill: dict[int, float] = {} # phase -> kill-time
Expand All @@ -194,6 +198,12 @@ def __init__(self, run_nr: int):
def __str__(self):
return '\n'.join((f'{key}: {val}' for key, val in vars(self).items()))

def post_process(self):
# Take the final shield from shield phase 3.5 and prepend it to phase 4.
self.shields[4] = [self.shields[3.5].pop()] + self.shields[4]
# Remove the extra shield from phase 4.
self.shields[4].pop()

def to_rel(self) -> RelRun:
pt_found = self.pt_found - self.heist_start
phase_durations = {}
Expand Down Expand Up @@ -225,6 +235,9 @@ def to_rel(self) -> RelRun:
# Set phase duration
phase_durations[phase] = previous_value - self.heist_start

# Set phase 3.5 shields
shields[3.5] = [(shield, nan) for shield, _ in self.shields[3.5]]

return RelRun(self.run_nr, self.nickname, pt_found, phase_durations, shields, legs, body_dur, pylon_dur)


Expand Down Expand Up @@ -262,7 +275,10 @@ def register_phase(log: Iterator[str], run: AbsRun, phase: int):
lambda line: Constants.HEIST_START in line, # Functions as abort as well
lambda line: Constants.HOST_MIGRATION in line])
if match == 0: # Shield switch
run.shields[phase].append(shield_from_line(line))
# Shield_phase '3.5' is for when shields swap during the pylon phase in phase 3.
shield_phase = 3.5 if phase == 3 and 3 in run.pylon_start else phase
run.shields[shield_phase].append(shield_from_line(line))

if follow_mode and len(run.shields[1]) == 1: # The first shield can help determine whether to abort.
print(f'{fg.white}First shield: {fg.li_cyan}{run.shields[phase][0][0]}')
elif match == 1: # Leg kill
Expand All @@ -272,7 +288,6 @@ def register_phase(log: Iterator[str], run: AbsRun, phase: int):
run.body_vuln[phase] = time_from_line(line)
kill_sequence += 1 # 3x BODY_VULNERABLE in one phase means PT dies.
if kill_sequence == 3: # PT dies.
run.shields[phase].pop() # We get a random extra shield we don't need.
run.body_kill[phase] = time_from_line(line)
return
elif match == 3: # Generic state change
Expand All @@ -288,8 +303,6 @@ def register_phase(log: Iterator[str], run: AbsRun, phase: int):
elif match == 6: # Phase endings (excludes phase 4)
if phase in [1, 3]: # Ignore phase 2 as it already matches body_kill.
run.pylon_end[phase] = time_from_line(line)
if phase == 3: # Put the final shield from phase 3 as the first of phase 4.
run.shields[phase + 1].append(run.shields[phase].pop())
return
elif match == 7: # Nickname
run.nickname = line.replace(',', '').split()[-2]
Expand Down Expand Up @@ -319,6 +332,7 @@ def read_run(log: Iterator[str], run_nr: int, require_heist_start=False) -> AbsR

for phase in [1, 2, 3, 4]:
register_phase(log, run, phase) # Adds information to run, including the start time
run.post_process() # Apply shield phase corrections

return run

Expand Down

0 comments on commit 0171cae

Please sign in to comment.