import re
import os
import pandas as pd
import numpy as np

top_dir = "./data/"
output_regex = re.compile(".*")
output_list = list(filter(lambda x: not os.path.isfile(os.path.join(top_dir,x)),filter(output_regex.match,os.listdir(top_dir))))
output_list.sort()
for i,out in enumerate(output_list):
    print("{}: {}".format(i,out))


data_tdir = output_list[int(input())]

data_regex = re.compile("data_*")
data_list = list(filter(data_regex.match,os.listdir(top_dir+data_tdir)))
data_list.sort()
head_lstps = []
for d in data_list:
    ds = d.split(".")[0].split("_")
    if ds[2] not in head_lstps:
        head_lstps.append(ds[2])

head_lstps.sort(key=int)
head_lstps = [str(x) for x in range(1,21)]

xsize = len(head_lstps)
data_table = np.zeros((xsize),dtype="object")
data_table[:] = "-"

for d in data_list:
    ds = d.split(".")[0].split("_")
    lstps = ds[2]
    df = pd.read_csv("./data/"+data_tdir+"/"+d)
    if df["conv_error"].iloc[0] == 0:
        data_table[head_lstps.index(lstps)] = str(df["iters"].iloc[0])
    if df["conv_error"].iloc[0] == 1:
        data_table[head_lstps.index(lstps)] = str("\\xmark")

print("h & {}\\\\".format(" & ".join([str(x) for x in head_lstps])))
for i,l in enumerate(head_lstps):
    print(" & \\SI{{{}}}{{\\noop}}".format(data_table[i]),end='')
#for x,r in enumerate(head_refine):
#    print("{:.3f} ".format(0.25/float(r)),end='')
#    for y,mp in enumerate(head_lstps):
#        print(" & {}".format(data_table[y,x]),end='')
#    print("\\\\")
