Last active
June 1, 2022 23:30
-
-
Save xorus/32535e7befcba943204b3d14ea5dfe49 to your computer and use it in GitHub Desktop.
tea logs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import datetime | |
import os | |
from turtle import color | |
from venv import create | |
from sortedcontainers import SortedDict | |
import matplotlib.pyplot as plt | |
import matplotlib.patches as mpatches | |
import matplotlib.transforms as transforms | |
import imageio | |
import pandas | |
logFolder = "logs" | |
# TEA | |
fightID = "80037586" | |
phaseColors = ['b', 'c', 'r', 'y', 'g'] | |
phases = [2.20, 2.6, 5.5, 11.6, 18.83] | |
phaseNames = ["LL", "Limit Cut", "BJCC", "Alex Prime", "Perfect"] | |
wipeRegExp = re.compile( | |
r"33\|([0-9]*)-([0-9]*)-([0-9]*)T([0-9]*):([0-9]*):([0-9]*).*\|"+fightID+"\|40000005.*") | |
clearRegExp = re.compile( | |
r"33\|([0-9]*)-([0-9]*)-([0-9]*)T([0-9]*):([0-9]*):([0-9]*).*\|"+fightID+"\|40000003.*") | |
startRegExp = re.compile( | |
r"00\|([0-9]*)-([0-9]*)-([0-9]*)T([0-9]*):([0-9]*):([0-9]*).*\|0039\|\|Engage!\|.*") | |
minFrameDuration = 0.02 | |
rampUpTime = 5 | |
rampDownTime = 2 | |
gifTime = 15 | |
def parseLog(logFile, dict): | |
with open(logFile, 'r', encoding="utf8") as logSource: | |
startTime = datetime.datetime(9999, 12, 31) | |
endTime = datetime.datetime(1, 1, 1) | |
clear = False | |
for i, line in enumerate(logSource): | |
startMatch = startRegExp.match(line) | |
if startMatch: | |
startTime = datetime.datetime(int(startMatch.group(1)), int(startMatch.group(2)), int( | |
startMatch.group(3)), int(startMatch.group(4)), int(startMatch.group(5)), int(startMatch.group(6))) | |
else: | |
wipeMatch = wipeRegExp.match(line) | |
if wipeMatch: | |
endTime = datetime.datetime(int(wipeMatch.group(1)), int(wipeMatch.group(2)), int( | |
wipeMatch.group(3)), int(wipeMatch.group(4)), int(wipeMatch.group(5)), int(wipeMatch.group(6))) | |
clear = False | |
else: | |
clearMatch = clearRegExp.match(line) | |
if clearMatch: | |
endTime = datetime.datetime(int(clearMatch.group(1)), int(clearMatch.group(2)), int( | |
clearMatch.group(3)), int(clearMatch.group(4)), int(clearMatch.group(5)), int(clearMatch.group(6))) | |
clear = True | |
if endTime > startTime: | |
duration = (endTime-startTime).total_seconds()/60 | |
dict[startTime] = (duration, clear) | |
startTime = datetime.datetime(9999, 12, 31) | |
endTime = datetime.datetime(1, 1, 1) | |
def createCSV(dict): | |
csv = open("pulls.csv", "w") | |
csv_sep = "," | |
previousDate = datetime.datetime(1, 1, 1) | |
day = 0 | |
pull = 1 | |
csv.write("pull,day,duration\n") | |
# dict is supposedly sorted | |
for i in range(len(dict)): | |
entry = dict.peekitem(i) | |
date = entry[0] | |
duration = entry[1][0] * 60 | |
delta = date - previousDate | |
if delta.seconds > 10800: | |
day += 1 | |
previousDate = date | |
csv.write(f"{pull}{csv_sep}{day}{csv_sep}{duration}\n") | |
pull += 1 | |
csv.close() | |
def processDays(dict): | |
day = 0 | |
previousDate = datetime.datetime(1, 1, 1) | |
days = [] | |
for j in range(len(dict)): | |
date = dict.peekitem(j)[0] | |
delta = date - previousDate | |
if delta.seconds > 10800: | |
day += 1 | |
days.append(j) | |
plt.axvline(x=j, color='tab:gray', linestyle=':', linewidth=1.0, alpha=0.5, label=f"day {day}") | |
# plt.text(j, (phases[-2:][0]), f"day {day}", rotation=90, verticalalignment='top', fontname="Trebuchet MS", color='tab:gray') | |
plt.text(j, -0.5, f"day {day}", rotation=45, verticalalignment='top', horizontalalignment='right', fontname="Trebuchet MS", color='tab:gray', fontsize=8) | |
# plt.text(j, -0.5, f"day {day}", rotation=45, verticalalignment='top', horizontalalignment='center', fontname="Trebuchet MS", color='tab:gray', fontsize=8) | |
plt.annotate(xy=(j, -0.5), text=f"day {day}") | |
previousDate = date | |
def parseFolder(): | |
dict = SortedDict() | |
i = 1 | |
totalFiles = len(os.listdir(logFolder)) | |
plt.figure(figsize=(16, 9)) | |
plt.ylim([0, 18.83]) | |
for filename in os.listdir(logFolder): | |
print(f"File {i} of {totalFiles}") | |
i += 1 | |
parseLog(logFolder+"\\"+filename, dict) | |
# plt.axvline(x=len(dict)) | |
createCSV(dict) | |
adjustedPhases = [0] + phases | |
for iPhase in range(len(phases)): | |
plt.axhspan(adjustedPhases[iPhase], adjustedPhases[iPhase+1], | |
facecolor=phaseColors[iPhase], alpha=0.1) | |
filenames = [] | |
t = datetime.timedelta() | |
wipecount = [] | |
wipecount = [0 for i in range(5)] | |
rampUpIdx = len(dict) | |
rampDownIdx = 0 | |
frameDuration = gifTime/len(dict) | |
frameStep = 1 | |
if frameDuration < minFrameDuration: | |
frameDuration = minFrameDuration | |
rampUpIdx = rampUpTime/frameDuration | |
rampDownIdx = rampDownTime/frameDuration | |
frameStep = (len(dict) - rampUpIdx - rampDownIdx) / \ | |
((gifTime - rampUpTime - rampDownTime) / frameDuration) | |
print(f"up {rampUpIdx}\ndown {rampDownIdx}\nstep {frameStep}") | |
# Dolls line | |
dollsLine = plt.axhline( | |
y=1, color='b', linestyle='--', alpha=0.5, label="Dolls") | |
# WH line | |
wormholeLine = plt.axhline( | |
y=9, color='y', linestyle='--', alpha=0.5, label="Wormhole") | |
lines = [dollsLine, wormholeLine] | |
legendLines = plt.legend(handles=lines, loc="upper right") | |
processDays(dict) | |
for j in range(len(dict)): | |
# Dots, trop la flemme | |
if dict.peekitem(j)[1][1]: | |
plt.plot(j, dict.peekitem(j)[ | |
1][0], color='yellow', marker='*', markeredgecolor='gray', markersize=10) | |
else: | |
if (dict.peekitem(j)[1][0] > 0 and dict.peekitem(j)[1][0] < phases[0]): | |
plt.plot(j, dict.peekitem(j)[ | |
1][0], color=phaseColors[0], marker='o', markersize=5) | |
if (dict.peekitem(j)[1][0] > phases[0] and dict.peekitem(j)[1][0] < phases[1]): | |
plt.plot(j, dict.peekitem(j)[ | |
1][0], color=phaseColors[1], marker='o', markersize=5) | |
if (dict.peekitem(j)[1][0] > phases[1] and dict.peekitem(j)[1][0] < phases[2]): | |
plt.plot(j, dict.peekitem(j)[ | |
1][0], color=phaseColors[2], marker='o', markersize=5) | |
if (dict.peekitem(j)[1][0] > phases[2] and dict.peekitem(j)[1][0] < phases[3]): | |
plt.plot(j, dict.peekitem(j)[ | |
1][0], color=phaseColors[3], marker='o', markersize=5) | |
if (dict.peekitem(j)[1][0] > phases[3] and dict.peekitem(j)[1][0] < phases[4]): | |
plt.plot(j, dict.peekitem(j)[ | |
1][0], color=phaseColors[4], marker='o', markersize=5) | |
t += datetime.timedelta(seconds=int(dict.peekitem(j)[1][0]*60)) | |
plt.title(f"TEA prog : {j+1} pulls ({t} combat time)", | |
fontname="Trebuchet MS", fontsize=18, weight="bold") | |
# Legend | |
patches = [] | |
counted = False | |
for iPatch in range(len(phases)): | |
if (not counted and dict.peekitem(j)[1][0] < phases[iPatch]): | |
counted = True | |
wipecount[iPatch] += 1 | |
patches += [mpatches.Patch(color=phaseColors[iPatch], | |
label=(phaseNames[iPatch]) + f": {wipecount[iPatch]}")] | |
plt.legend(handles=patches, loc="upper left") | |
# Weird shit for double legend, whatever | |
plt.gca().add_artist(legendLines) | |
plt.xlabel("Pull #", fontname="Trebuchet MS", | |
fontsize=12, weight="bold") | |
plt.ylabel("Duration (min)", fontname="Trebuchet MS", | |
fontsize=12, weight="bold") | |
# Create file name and append it to a list (Used for the gif) | |
# if j < rampUpIdx or j > (len(dict) - rampDownIdx) or (j - rampUpIdx)%int(frameStep) == 0: | |
# filename = f'{j}.png' | |
# filenames.append(filename) | |
# # Save frame | |
# plt.savefig(filename) | |
# Build gif | |
# with imageio.get_writer('TEAProg.gif', format='GIF-PIL', mode='I', loop = 1, duration=frameDuration, subrectangles=True) as writer: | |
# for filename in filenames: | |
# image = imageio.imread(filename) | |
# writer.append_data(image) | |
# for filename in set(filenames): | |
# os.remove(filename) | |
plt.show() | |
parseFolder() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment