summaryrefslogtreecommitdiff
path: root/analysis0510.py
diff options
context:
space:
mode:
authorKunoiSayami <[email protected]>2023-05-15 22:34:12 +0800
committerKunoiSayami <[email protected]>2023-05-15 22:34:12 +0800
commitadc1180f40a904c2773523569033639406da4812 (patch)
treea91563e03f757a5d39c8ee86329709803299205a /analysis0510.py
parent4afec90b7e4c45e8878c677ec77d4f8b1d522df9 (diff)
feat(exp): Enchant analysis script
Signed-off-by: KunoiSayami <[email protected]>
Diffstat (limited to 'analysis0510.py')
-rwxr-xr-xanalysis0510.py49
1 files changed, 42 insertions, 7 deletions
diff --git a/analysis0510.py b/analysis0510.py
index b51fc8c..c1464ce 100755
--- a/analysis0510.py
+++ b/analysis0510.py
@@ -5,25 +5,60 @@ import argparse
def read_from_line(line: str) -> dict[str, int | float]:
ret = {}
if 'skip:' in line:
- ret.update({'skip': int(line.split('skip:', 2)[1].split(',')[0])})
- ret.update({'sample': int(line.split('length:', 2)[1].split('|', 2)[0])})
- ret.update({'custom': float(line.split('custom time: ', 2)[1].split('time')[0])})
- ret.update({'normal': float(line.rsplit('time:', 2)[1])})
+ ret.update({'skip': int(line.split('skip:', 1)[1].split(',')[0])})
+ ret.update({'sample': int(line.split('length:', 1)[1].split('|', 1)[0])})
+ ret.update({'custom': float(line.split('custom time: ', 1)[1].split('time')[0])})
+ ret.update({'normal': float(line.rsplit('time:', 1)[1])})
return ret
-def read(file: str) -> None:
+def calc_avg(sz: list[float]) -> float:
+ return sum(sz) / len(sz)
+
+
+def calc_middle_number(sz: list[float]) -> float:
+ if (length := len(sz)) & 1 == 0:
+ length = length // 2
+ return (sz[length] + sz[length - 1]) / 2
+ return sz[length // 2]
+
+
+def get_array_summary(sz: list[float]) -> tuple[str, str]:
+ sz.sort()
+ middle = calc_middle_number(sz)
+ avg = calc_avg(sz)
+ return f'{middle:.6f}', f'{avg:.6f}'
+
+
+def read(file: str, need_calc: bool = False) -> None:
items = {}
with open(file) as fin:
while s := fin.readline():
- element = read_from_line(s)
+ element = read_from_line(s.strip())
if (sample := element['sample']) not in items:
items.update({sample: []})
items[sample].append(element)
+ if need_calc:
+ keys = ['custom', 'normal']
+ new_result = {}
+ for key, value in items.items():
+ if key not in new_result:
+ new_result.update({key: {x: [] for x in keys}})
+ for element in value:
+ # print(element)
+ for x in keys:
+ new_result[key][x].append(element[x])
+ print(*keys)
+ for key, value in new_result.items():
+ print(key, *list(get_array_summary(value[x]) for x in keys))
+ return
print(items)
if __name__ == '__main__':
arg_ = argparse.ArgumentParser()
arg_.add_argument("file")
- read(arg_.parse_args().file)
+ sub_ = arg_.add_subparsers(title="sub", dest='sub')
+ sub_.add_parser('calc')
+ parser_ = arg_.parse_args()
+ read(parser_.file, parser_.sub == 'calc')