Example #1
0
def get_timeline(assignment_id, current_date, name = 'timeline'):
    mask_1 = df['Assignment'] == assignment_id
    mask_2 = df['Entry Date'] <= current_date
    max_date = df.loc[mask_1, 'Entry Date'].max()
    mask = mask_1 & mask_2
    df_small = df.loc[mask, ['Transaction', 'status_date']]

    tmp = df_small.groupby(['status_date'], as_index=True).apply(aggregator).reset_index()
    # tmp['status_date'] = tmp['status_date'].astype(str)

    tmp = tmp.rename(
        columns={
            0: 'status'
        }
    )

    # mask = df['Assignment'] == assignment_id
    # df_small = df.loc[mask, ['Transaction', 'status_date']]
    #
    # ([rec for rec in df_small.iterrows()][0][1]['status_date'])

    items = [
        {'time': rec[1]['status_date'], 'text': rec[1]['status']} for rec in tmp.iterrows()
    ]

    # print(f'max_date is {max_date}, current_date is {current_date}')
    if current_date < max_date:
        # print('True')
        today_dict = {
            'time': datetime.strptime(current_date, DATE_FORMAT),
            'text': 'Today',
        }
        items.append(today_dict)

    if len(items) <= 1:
        print('Only one sample')
        return None
        # return tmp.loc[0, 'status_date'], tmp.loc[0, 'status']


    #     return items

    try:
        tl = TimelineTex(items, options=options)
        tl.export(f'{name}.tex')
        # tl.export(f'timeline_{assignment_id}.tex')
        # else:
        #     tl.export(f'{folder}/timeline_{assignment_id}.tex')
        pdf_filename = f'{name}.pdf'
        command = 'convert -verbose -density 500 "{}" -quality 100 "{}"'.format(pdf_filename,
                                                                                pdf_filename.replace('.pdf',
                                                                                                     '.png'))
        p = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True)
        (out, err) = p.communicate()
    except:
        pass
Example #2
0
def make_rank_plot(
    results,
    output_file,
    keep_methods=None,
    higher_better=True,
    return_ranks=False,
):
    methods = keep_methods[:]
    avg_ranks, all_ranks = compute_ranks(results,
                                         keep_methods=keep_methods,
                                         higher_better=higher_better)
    plot_data = [{
        "time": rank,
        "text": method_name(method)
    } for method, rank in avg_ranks.items()]

    color = "#000"

    options = {
        "scale": LinearScale(),
        "direction": "up",
        "domain": [1, len(methods)],
        "layerGap": 20,
        "borderColor": "#000",
        "showBorder": False,
        "labelBgColor": "#fff",
        "linkColor": color,
        "labelTextColor": color,
        "dotColor": color,
        "initialWidth": 600,
        "initialHeight": 75,
        "latex": {
            "linkThickness": "thin",
            "reproducible": True
        },
        "dotRadius": 2,
        "margin": {
            "left": 0,
            "bottom": 0,
            "right": 0,
            "top": 0
        },
    }

    tl = TimelineTex(plot_data, options=options)
    texlines = tl.export()

    n_datasets = len(all_ranks)

    ref_method, CD, _ = reference_difference(avg_ranks, n_datasets)

    # we're going to insert the critical difference line after the dots
    # scope,·so we first have to figure out where that is.
    lines = texlines.split("\n")
    idx = None
    find_scope = False
    for i, line in enumerate(lines):
        if line.strip() == "% dots":
            find_scope = True
        if find_scope and "\\end{scope}" in line:
            idx = i + 1
            break

    before = lines[:idx]
    after = lines[idx:]

    nodes, _ = tl.compute()
    bestnode = next(
        (n for n in nodes if n.data.text == method_name(ref_method)), None)
    # idealPos is the position on the axis
    posBest = bestnode.getRoot().idealPos
    posCD = tl.options["scale"](bestnode.data.time + CD)

    CDlines = [
        "% Critical difference",
        "\\def\\posBest{%.16f}" % posBest,
        "\\def\\posCD{%.16f}" % posCD,
        "\\begin{scope}",
        "\\draw (\\posBest, 30) -- (\\posBest, 20);",
        "\\draw (\\posBest, 25) --node[below] {CD} (\\posCD, 25);",
        "\\draw (\\posCD, 30) -- (\\posCD, 20);",
        "\\end{scope}",
    ]

    all_lines = before + [""] + CDlines + after

    with open(output_file, "w") as fp:
        fp.write("\n".join(all_lines))
Example #3
0
# werkervaring.py
import pandas as pd
from labella.scale import LinearScale
from labella.timeline import TimelineTex


def makeInput(_df):
    length = len(_df.year_start)
    out = []
    print(_df)
    for i in range(length):
        _dict = {}
        _dict['time'] = _df.year_start[i]
        #dict['year_end'] = _df.year_end[i]
        _dict['text'] = _df.employer[i]
        #dict['job_title'] = _df.job_title[i]
        out = out + [_dict]
    return out


header_list = ['year_start', 'year_end', 'employer', 'job_title']
df = pd.read_csv('werkervaring.csv', names=header_list)
xtimeline = makeInput(df)
ttimeline = TimelineTex(xtimeline, options={'scale': LinearScale()})

ttimeline.export('werkervaring.tex')
Example #4
0
def test_labella(struct, name):
  #tl = TimelineTex(struct, options={'scale': LinearScale()})
  tl = TimelineTex(struct, options={'scale': TimeScale()})
  tl.export(f"{name}.tex")