Exemple #1
0
def test4cell2pos():
    paar = xz.txt2tbl('benchbuch/xx_pruf4cell2pos.tsv')
    for cell, antwort in paar:
        x = cell2pos(cell)
        antwort = int(antwort)
        print(cell, '->', x, '==', antwort)
        assert x[0] == antwort
Exemple #2
0
def thislookup1v1(sache, dicfile):
    sache = sache2list(sache)
    assert len(sache) == len(uniq(sache))
    tbl = xz.txt2tbl(dicfile)
    dic = {lis[0]: "\t".join(lis[1:]) for lis in tbl}
    res = []
    for x in sache:
        if x in dic:
            res.append(dic[x])
        else:
            res.append(x)
    return res
Exemple #3
0
def replace(sache, listfile):
    sache = sache2list(sache)
    sache = "\n".join(sache)
    try:
        dic = xz.txt2dic(listfile)
    except:
        listfile = labomi + listfile
        dic = xz.obj2bin(listfile)
    tbl = xz.txt2tbl(listfile)
    for lis in tbl:
        vor = lis[0]
        nach = lis[1]
        sache = sache.replace(vor, nach)
    return sache
Exemple #4
0
def tbl4log(txt, dic, gettable=False):
    assert (isinstance(dic, dict))
    tbl = xz.txt2tbl(txt)
    header = xz.getheader(txt)
    #
    if not 'tag' in dic:
        dic['tag'] = xt.heute()
    #
    assert sorted(header) == sorted(list(dic.keys()))
    if tbl[-1][0] == str(dic['tag']):
        tbl.pop()
    res = [dic[k] for k in header]
    tbl.append(res)
    #
    xz.tbl2txt(tbl, txt)
    if gettable == True:
        return tbl
    else:
        tbl = xz.txt2ldic(txt)
        tbl = xz.bless(tbl)
        return tbl, header
Exemple #5
0
def sache2df(sache):
    xz.str2txt('X' + sache, EIGENDATEI)
    tbl = xz.txt2tbl(EIGENDATEI)
    idx = tbl[0][0]
    tbl = []
    return pd.read_csv(EIGENDATEI, sep="\t", index_col=idx)
Exemple #6
0
def show(var, header=[]):

    ### MODUL ###
    import japonais
    import pandas

    ### VARIABLE ###
    mode = ''
    zelle = {}

    ### MODE ###
    if isinstance(var, dict):
        mode = 'dic'
    elif isinstance(var, pandas.core.frame.DataFrame):
        mode = 'pds'
    elif isinstance(var, list):
        if var == []:
            print('* Achtung, Leer Liste!')
            print(var[0])  # ich mochte ein Felher passen
#		print( len(var[0]),type(var[0]),var[0] )
        if len(var) == 1:
            if isinstance(var[0], list):
                mode = 'tbl'
            elif isinstance(var[0], dict):
                mode = 'ldic'
        elif isinstance(var[1], list):
            mode = 'tbl'
            if isinstance(var[0], dict):  # 2017-10-15
                zelle = var.pop(0)
                assert (isinstance(var[-1], list))
        elif isinstance(var[0], dict):
            mode = 'ldic'
        else:
            assert not mode == '', 'Kein Mode'

    ### DICT ###
    if mode == 'dic':
        v1 = 0
        v2 = 0
        for x in var.keys():
            i = japonais.len(value4show(x))
            if v1 < i: v1 = i
        for x in var.values():
            i = japonais.len(value4show(x))
            if v2 < i: v2 = i

        fmt = '%s' + str(v1) + ' | %s' + str(v2)
        kys = var.keys()
        kys = list(kys)
        kys.sort()
        for k in kys:
            w = var[k]
            x = k.rjust(v1, ' ')
            x += ' | '
            x += str(w).rjust(v2, ' ')
            print(x)

    ### TABLE ###
    elif mode == 'tbl':
        lens = []
        xs = len(var)
        ys = len(var[0])
        for j in range(ys):
            lens.append(0)
            for i in range(xs):
                q = japonais.len(value4show(var[i][j]))
                if lens[j] < q: lens[j] = q
        showtable(var, lens)

    ### LIST-DICT ###
    elif mode == 'ldic':
        res = []
        lens = []
        for x in header:
            res.append(x)
        res = [res]
        #
        for dic in var:
            lis = []
            for x in header:
                lis.append(value4show(dic[x]))
            res.append(lis)
        #
        var = res
        xs = len(var)
        ys = len(var[0])
        for j in range(ys):
            lens.append(0)
            for i in range(xs):
                q = japonais.len(value4show(var[i][j]))
                if lens[j] < q: lens[j] = q
        #
        var.pop(0)
        showtable([header], lens)
        i = 0
        for x in lens:
            i += x
            i += 3
        i -= 1
        print('-' * i)
        showtable(var, lens)
        print('-' * i)
        showtable([header], lens)

    ### PANDAS ###
    elif mode == 'pds':
        for x in var.columns:
            typ = var[x].dtype
            if typ == 'float64':
                var[x] = var[x].astype('int64')
        tmp = labomi + 'x.tsv'
        var.to_csv(tmp, sep="\t")
        tbl = xz.txt2tbl(tmp)
        show(tbl)

    ## Gegenreaktion (contrecoup/backlash) ###
    if not zelle == {}:
        var.insert(0, zelle)
Exemple #7
0
    if opt.get('nurinhalt') == True:
        for tag in ['<table>', '<tbody>', '</table>', '</tbody>']:
            html = html.replace(tag, '')
    return html


#


########################
### LISTE zu OPTIONS ###
########################
def lis2opt(lis, gewahlt):
    res = ''
    for x in lis:
        w = '<option value="%s" selected>%s</option>' % (x, x)
        if x != gewahlt:
            w = w.replace(' selected', '')
        res += w
    return res


#

##### DIREKT ###############
if __name__ == '__main__':
    tbl = xz.txt2tbl(labomi + 'x.tsv')
    x = tbl2html(tbl, kopfer=True)
    print(x)
    kbench.enfin()
Exemple #8
0
def txt2xdic(txt):
    tbl = xz.txt2tbl(txt)
    tbl = tbl2xdic(tbl)
    return tbl
Exemple #9
0
			res[x][y] = w
	print( '*'*50 )
	print( res.xs )
	print( res.ys )
	print( '*'*50 )
	return res
"""

#

##### DIREKT ###############
if __name__ == '__main__':
    mode = 2
    if mode == 1:
        txt = 'a.tsv'
        tbl = xz.txt2tbl(txt)
        tbl = transpose(tbl)
        tbl = xz.bless(tbl)
        tbl = crosstable(tbl[0], tbl[1], tbl[2])
        #	tbl = crosstable(tbl[0],tbl[1],[])
        xz.show(tbl)
        xz.tbl2txt(tbl, 'b.tsv')
    #
    elif mode == 2:
        tbl = xz.txt2tbl('a.tsv')
        tbl = xz.bless(tbl)
        tbl = tbl2xdic(tbl)
        #
        sym = 'm2oq'
        sym = 'm2oj'
        tbl = tbl.aggrtyp(sym)