80 lines
2.6 KiB
Python
80 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
# -*- encoding: utf-8 -*-
|
|
|
|
import json
|
|
|
|
def readAllFile(loc):
|
|
with open(loc) as f:
|
|
return f.read()
|
|
|
|
def writeAllFile(loc,cnt):
|
|
with open(loc,'w') as f:
|
|
return f.write(cnt)
|
|
|
|
def formatFloat(num):
|
|
return '% 6.02f'%round(num,2)
|
|
|
|
locations = list(map(lambda a: a.split('\t'), readAllFile('locations.txt').strip().splitlines()))
|
|
|
|
def ct2label(data):
|
|
return {
|
|
'VerdadeiroPositivo' : data['true']['true'],
|
|
'FalsoPositivo' : data['false']['true'],
|
|
'VerdadeiroNegativo' : data['false']['false'],
|
|
'FalsoNegativo' : data['true']['false'],
|
|
}
|
|
|
|
def dict2matrix(dic, columnDir = 1):
|
|
emptyDict = dict()
|
|
columns = sorted(list(set().union(*list(map(set,map(dict.keys, dic.values()))))))[::columnDir]
|
|
lines = sorted(list(set(dic.keys())))
|
|
matrix = [[None for x in range(len(columns)+1)] for y in range(len(lines)+1)]
|
|
for ic, c in enumerate(columns):
|
|
matrix[0][ic+1] = c
|
|
for il, l in enumerate(lines):
|
|
matrix[il+1][0] = l
|
|
for ic, c in enumerate(columns):
|
|
for il, l in enumerate(lines):
|
|
matrix[il+1][ic+1] = dic.get(l,emptyDict).get(c,None)
|
|
return matrix
|
|
|
|
def matrix2tabular(mtx, percent=None):
|
|
s = r'\begin{tabular}{'+'|'.join(list('c'*len(mtx[0])))+'|}\n'
|
|
for line in mtx:
|
|
for xi, cell in enumerate(line):
|
|
if cell is not None:
|
|
if bool(percent) and (isinstance(cell, int) or isinstance(cell, float)):
|
|
tcell = cell
|
|
if percent == 100:
|
|
tcell*= 100
|
|
s+= formatFloat(tcell)
|
|
s+=r'\%'
|
|
else:
|
|
s+= str(cell)
|
|
if xi+1<len(mtx[0]):
|
|
s+= ' & '
|
|
s+=r' \\'
|
|
s+=r' \hline'
|
|
s+= '\n'
|
|
s+=r'\end{tabular}'+'\n'
|
|
return s
|
|
|
|
for (location, alias, needsconv) in locations:
|
|
needsconv = bool(int(needsconv))
|
|
qs_tr = json.loads(readAllFile(location+'/unitexable_train/quick_statistics.json'))
|
|
qs_te = json.loads(readAllFile(location+'/unitexable_test/quick_statistics.json'))
|
|
ct = json.loads(readAllFile(location+'/unitexable_test/confusion_matrix.json'))
|
|
st = json.loads(readAllFile(location+'/unitexable_test/confusion_matrix.stats.json'))
|
|
gp = json.loads(readAllFile(location+'/unitexable_test/equality.json'))
|
|
ct = dict(map(lambda a: [a[0],ct2label(a[1])],ct.items()))
|
|
m_ct = dict2matrix(ct, -1)
|
|
m_st = dict2matrix(st)
|
|
t_ct = matrix2tabular(m_ct)
|
|
t_st = matrix2tabular(m_st, 100)
|
|
writeAllFile(alias+'_ct.tex', t_ct)
|
|
writeAllFile(alias+'_st.tex', t_st)
|
|
|
|
|
|
|
|
|