Created
March 26, 2020 08:59
-
-
Save ibmua/a31de3c1c0830fb163e424aabe77a6e0 to your computer and use it in GitHub Desktop.
TopCoder Marathon Match 116 statistics visualizer for my solution
This file contains 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
# python3 vis.py or use a jupyter notebook | |
import os | |
import json | |
import random | |
import string | |
import time | |
import subprocess | |
from pathlib import Path | |
directory = '/home/i/C/marathon/116/outs/' | |
paths = sorted(Path(directory).iterdir(), key=os.path.getmtime, reverse=True) | |
def min_x_len(s,l): | |
s = str(s) | |
for i in range(l- len(s)): | |
s = " " + s | |
return s | |
def show_score(best, ours): | |
res = best/ours | |
res *= 10000 | |
res = int( round(res,0) ) | |
return min_x_len( res, 4 ) | |
mins = [111.]*200000 | |
min_tt = ['none']*200000 | |
print( str( len(os.listdir(directory)) ), "files") | |
print() | |
#for filename in os.listdir(directory): | |
for filename in paths: | |
#with open(directory + filename, 'r') as myfile: | |
with open(filename, 'r') as myfile: | |
data=myfile.read() | |
#print(data) | |
lines = [ tuple(float(n) for n in x.split(' ')) for x in data.strip().split('\n') ] | |
lines.sort() | |
#print(lines) | |
for l in lines: | |
tt = int(l[0]) | |
if l[1] < mins[ tt ]: | |
mins[ tt ] = l[1] | |
min_tt[tt] = str(filename)[ len(directory): ] | |
mins[ int(l[0]) ] = min( mins[ int(l[0]) ] , l[1] ) | |
bad_cutoff = 9000 | |
first_n_files = 300 | |
from_ = 0 | |
to_ = 1000 | |
min_count = 100 | |
show_first_n_fails = 10 | |
for filename in paths: | |
first_n_files -= 1 | |
if first_n_files == 0: | |
break | |
#with open(directory + filename, 'r') as myfile: | |
with open(filename, 'r') as myfile: | |
data=myfile.read() | |
lines = [ tuple(float(n) for n in x.split(' ')) for x in data.strip().split('\n') ] | |
score = 0. | |
count = 0 | |
poor = 0 | |
good_score = 0. | |
if len(lines) >= min_count: | |
for l in lines: | |
#print(score) | |
tt = int(l[0]) | |
if tt >=from_ and tt <=to_: | |
count+=1 | |
perf = mins[ tt ] / l[1] | |
score += perf | |
if perf < bad_cutoff/10000: | |
poor += 1 | |
if poor<=show_first_n_fails: | |
print( " ", min_x_len(tt, 3), show_score(mins[ tt ], l[1]) , round(l[1],4), round(mins[ tt ],4), min_tt[ tt ] ) | |
else: | |
good_score += perf | |
if count > min_count: | |
#print(score,count) | |
score /= count | |
#print(score,count) | |
tot_tests = min_x_len( len(lines), 5) | |
counted_tests = min_x_len( count, 5) | |
good_tests = min_x_len( count-poor, 5) | |
poor_tests = min_x_len( poor, 5) | |
good_test_post = "" | |
if count != poor: | |
good_score_str = min_x_len( int(round(good_score/(count-poor)*10000.-000, 0)), 6 ) | |
good_test_post = " | good " + str(good_tests) + good_score_str | |
#print(score) | |
print(min_x_len( str(filename)[ len(directory): ], 12), min_x_len(int(round(score*10000., 1)),5),'-', counted_tests, " |", poor_tests, " <", bad_cutoff/10000, " | total", tot_tests, good_test_post, str(int(round(1.- poor/count,2)*100))+"%") | |
else: | |
print('') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment