Пример #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
Пример #2
0
def main():
    items = [
            {'time': date(2016, 11, 1), 'episode': 1,
                'text': 'SQuAD 1.1'},
            {'time': date(2015, 12, 7), 'episode': 1,
                'text': 'CNN/Daily Mail'},
            {'time': date(2016, 5, 2), 'episode': 1,
                'text': 'Children Book Test'},
            {'time': date(2017, 7, 30), 'episode': 1,
                'text': 'TriviaQA'},
            {'time': date(2017, 9, 1), 'episode': 1,
                'text': 'RACE'},
            {'time': date(2018, 5, 1), 'episode': 1,
                'text': 'NarrativeQA'},
            {'time': date(2018, 7, 15), 'episode': 1,
                'text': 'SQuAD 2.0'},
            {'time': date(2018, 11, 2), 'episode': 1,
                'text': 'HotpotQA'},
            {'time': date(2015, 12, 7), 'episode': 2,
                'text': 'Attentive Reader'},
            {'time': date(2016, 8, 7), 'episode': 2,
                'text': 'Stanford Attentive Reader'},
            {'time': date(2017, 4, 24), 'episode': 2,
                'text': 'Match-LSTM'},
            {'time': date(2017, 4, 24), 'episode': 2,
                'text': 'BiDAF'},
            {'time': date(2017, 7, 30), 'episode': 2,
                'text': 'R-Net'},
            {'time': date(2018, 4, 30), 'episode': 2,
                'text': 'QANet'},
            {'time': date(2018, 6, 1), 'episode': 2,
                'text': 'BiDAF+self-att.+ELMo'},
            {'time': date(2018, 10, 11), 'episode': 2,
                'text': 'BERT'},
            ]

    options = {
        'initialWidth': 400,
        'initialHeight': 400,
        'direction': 'right',
        'dotColor': color,
        'labelBgColor': color,
        'linkColor': color,
        'textFn': lambda d: d['text'],
        'margin': {'left': 0, 'right': 0, 'top': 0, 'bottom': 0},
        'layerGap': 20,
        'labella': {
            'maxPos': 1200,
            'algorithm': 'simple'
            }
        }

    tl = TimelineSVG(items, options=options)
    tl.export('timeline.svg')

    tl = TimelineTex(items, options=options)
    tl.export('timeline.tex')
Пример #3
0
def main():
    items = [
        {"time": date(1977, 4, 25), "episode": 4, "text": "A New Hope"},
        {
            "time": date(1980, 4, 17),
            "episode": 5,
            "text": "The Empire Strikes Back",
        },
        {
            "time": date(1984, 4, 25),
            "episode": 6,
            "text": "Return of the Jedi",
        },
        {
            "time": date(1999, 4, 19),
            "episode": 1,
            "text": "The Phantom Menace",
        },
        {
            "time": date(2002, 4, 16),
            "episode": 2,
            "text": "Attack of the Clones",
        },
        {
            "time": date(2005, 4, 19),
            "episode": 3,
            "text": "Revenge of the Sith",
        },
        {
            "time": date(2015, 11, 18),
            "episode": 7,
            "text": "The Force Awakens",
        },
    ]

    options = {
        "initialWidth": 804,
        "initialHeight": 160,
        "direction": "down",
        "dotColor": COLOR_10,
        "labelBgColor": COLOR_10,
        "linkColor": COLOR_10,
        "textFn": None,
        "labelPadding": {"left": 0, "right": 0, "top": 1, "bottom": 1},
        "margin": {"left": 20, "right": 20, "top": 30, "bottom": 20},
        "layerGap": 40,
        "labella": {
            "maxPos": 800,
        },
        "latex": {"reproducible": True},
    }

    tl = TimelineSVG(items, options=options)
    tl.export("timeline_kit_3.svg")

    tl = TimelineTex(items, options=options)
    tl.export("timeline_kit_3.tex")
Пример #4
0
def main():
    items = [
            {'time': 1, 'width': 50},
            {'time': 2, 'width': 50},
            {'time': 3, 'width': 50},
            {'time': 3, 'width': 50},
            {'time': 3, 'width': 50},
            {'time': 304, 'width': 50},
            {'time': 454, 'width': 50},
            {'time': 454, 'width': 50},
            {'time': 454, 'width': 50},
            {'time': 804, 'width': 50},
            {'time': 804, 'width': 70},
            {'time': 804, 'width': 50},
            {'time': 804, 'width': 50},
            {'time': 854, 'width': 50},
            {'time': 854, 'width': 50}]

    options = {
        'initialWidth': 1000,
        'initialHeight': 112,
        'scale': LinearScale(),
        'direction': 'up',
        'dotColor': '#000000',
        'labelBgColor': COLOR_10,
        'linkColor': COLOR_10,
        'labelPadding': {'left': 0, 'right': 0, 'top': 0, 'bottom': 0},
        'labella': {
            'minPos': 0,
            'maxPos': 960,
            'nodeHeight': 12
            },
        'showTicks': False
        }

    tl = TimelineSVG(items, options=options)
    tl.export('timeline_up.svg')

    tl = TimelineTex(items, options=options)
    tl.export('timeline_up.tex', build_pdf=True)
Пример #5
0
def main():
    items = [
            {'time': date(1977, 4,25), 'episode': 4,
                'text': 'A New Hope'},
            {'time': date(1980, 4,17), 'episode': 5,
                'text': 'The Empire Strikes Back'},
            {'time': date(1984, 4,25), 'episode': 6,
                'text': 'Return of the Jedi'},
            {'time': date(1999, 4,19), 'episode': 1,
                'text': 'The Phantom Menace'},
            {'time': date(2002, 4,16), 'episode': 2,
                'text': 'Attack of the Clones'},
            {'time': date(2005, 4,19), 'episode': 3,
                'text': 'Revenge of the Sith'},
            {'time': date(2015,11,18), 'episode': 7,
                'text': 'The Force Awakens'},
            ]

    options = {
        'initialWidth': 804,
        'initialHeight': 160,
        'direction': 'up',
        'dotColor': color_4,
        'labelBgColor': color_4,
        'linkColor': color_4,
        'textFn': lambda d : d['text'],
        'margin': {'left': 20, 'right': 20, 'top': 20, 'bottom': 30},
        'layerGap': 40,
        'labella': {
            'maxPos': 800,
            'algorithm': 'simple'
            }
        }

    tl = TimelineSVG(items, options=options)
    tl.export('timeline_kit_4.svg')

    tl = TimelineTex(items, options=options)
    tl.export('timeline_kit_4.tex')
Пример #6
0
def main():
    data = [
        {"time": 1, "name": "Müller", "team": "GER"},
        {"time": 23, "name": "Klose", "team": "GER"},
        {"time": 24, "name": "Kroos", "team": "GER"},
        {"time": 26, "name": "Kroos", "team": "GER"},
        {"time": 29, "name": "Khedira", "team": "GER"},
        {"time": 69, "name": "Schürrle", "team": "GER"},
        {"time": 79, "name": "Schürrle", "team": "GER"},
        {"time": 90, "name": "Oscar", "team": "BRA"},
    ]

    options = {
        "direction": "up",
        "initialWidth": 804,
        "initialHeight": 120,
        "scale": LinearScale(),
        "domain": [0, 90],
        "margin": {"left": 20, "right": 20, "top": 30, "bottom": 20},
        "textFn": lambda d: d["name"],
        "layerGap": 40,
        "dotColor": color5,
        "labelBgColor": color5,
        "linkColor": color5,
        "labella": {
            "maxPos": 764,
            "algorithm": "simple",
        },
        "labelPadding": {"left": 0, "right": 2, "top": 0, "bottom": 0},
        "latex": {"reproducible": True},
    }

    tl = TimelineSVG(data, options=options)
    tl.export("timeline_kit_5.svg")

    tl = TimelineTex(data, options=options)
    tl.export("timeline_kit_5.tex")
Пример #7
0
def main():
    items = [
        {
            "time": 1,
            "width": 50
        },
        {
            "time": 2,
            "width": 50
        },
        {
            "time": 3,
            "width": 50
        },
        {
            "time": 3,
            "width": 50
        },
        {
            "time": 3,
            "width": 50
        },
        {
            "time": 304,
            "width": 50
        },
        {
            "time": 454,
            "width": 50
        },
        {
            "time": 454,
            "width": 50
        },
        {
            "time": 454,
            "width": 50
        },
        {
            "time": 804,
            "width": 50
        },
        {
            "time": 804,
            "width": 70
        },
        {
            "time": 804,
            "width": 50
        },
        {
            "time": 804,
            "width": 50
        },
        {
            "time": 854,
            "width": 50
        },
        {
            "time": 854,
            "width": 50
        },
    ]

    options = {
        "initialWidth": 1000,
        "initialHeight": 112,
        "scale": LinearScale(),
        "direction": "up",
        "dotColor": "#000000",
        "labelBgColor": COLOR_10,
        "linkColor": COLOR_10,
        "labelPadding": {
            "left": 0,
            "right": 0,
            "top": 0,
            "bottom": 0
        },
        "labella": {
            "minPos": 0,
            "maxPos": 960,
            "nodeHeight": 12
        },
        "showTicks": False,
        "latex": {
            "reproducible": True
        },
    }

    tl = TimelineSVG(items, options=options)
    tl.export("timeline_up.svg")

    tl = TimelineTex(items, options=options)
    tl.export("timeline_up.tex", build_pdf=True)
Пример #8
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))
Пример #9
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')
Пример #10
0
def main():
    items = [
        {
            'time': date(1977, 4, 25),
            'episode': 4,
            'text': 'A New Hope'
        },
        {
            'time': date(1980, 4, 17),
            'episode': 5,
            'text': 'The Empire Strikes Back'
        },
        {
            'time': date(1984, 4, 25),
            'episode': 6,
            'text': 'Return of the Jedi'
        },
        {
            'time': date(1999, 4, 19),
            'episode': 1,
            'text': 'The Phantom Menace'
        },
        {
            'time': date(2002, 4, 16),
            'episode': 2,
            'text': 'Attack of the Clones'
        },
        {
            'time': date(2005, 4, 19),
            'episode': 3,
            'text': 'Revenge of the Sith'
        },
        {
            'time': date(2015, 11, 18),
            'episode': 7,
            'text': 'The Force Awakens'
        },
    ]

    options = {
        'initialWidth': 400,
        'initialHeight': 250,
        'direction': 'left',
        'dotColor': '#000000',
        'labelBgColor': '#777',
        'linkColor': '#777',
        'textFn': lambda x: x['text'] + ' - ' + str(x['time'].year),
        'labelPadding': {
            'left': 0,
            'right': 0,
            'top': 0,
            'bottom': 0
        },
        'margin': {
            'left': 20,
            'right': 20,
            'top': 20,
            'bottom': 20
        },
        'labella': {
            'nodeHeight': 12,
        },
        'showTicks': False
    }

    tl = TimelineSVG(items, options=options)
    tl.export('timeline_kit_2.svg')

    tl = TimelineTex(items, options=options)
    tl.export('timeline_kit_2.tex')
Пример #11
0
def main():
    items = [
        {
            "time": date(1977, 4, 25),
            "episode": 4,
            "text": "A New Hope"
        },
        {
            "time": date(1980, 4, 17),
            "episode": 5,
            "text": "The Empire Strikes Back",
        },
        {
            "time": date(1984, 4, 25),
            "episode": 6,
            "text": "Return of the Jedi",
        },
        {
            "time": date(1999, 4, 19),
            "episode": 1,
            "text": "The Phantom Menace",
        },
        {
            "time": date(2002, 4, 16),
            "episode": 2,
            "text": "Attack of the Clones",
        },
        {
            "time": date(2005, 4, 19),
            "episode": 3,
            "text": "Revenge of the Sith",
        },
        {
            "time": date(2015, 11, 18),
            "episode": 7,
            "text": "The Force Awakens",
        },
    ]

    options = {
        "margin": {
            "left": 40.5,
            "right": 20,
            "top": 20,
            "bottom": 20
        },
        "initialWidth": 400,
        "initialHeight": 250,
        "direction": "right",
        "dotColor": "#000000",
        "labelBgColor": "#000000",
        "linkColor": "#000000",
        "textFn": lambda x: str(x["time"].year) + " - " + x["text"],
        "labelPadding": {
            "left": 2,
            "right": 0,
            "top": 0,
            "bottom": 0
        },
        "labella": {
            "nodeHeight": 12,
        },
        "latex": {
            "fontsize": "12pt",
            "reproducible": True
        },
    }

    tl = TimelineSVG(items, options=options)
    tl.export("timeline_kit_1.svg")

    tl = TimelineTex(items, options=options)
    tl.export("timeline_kit_1.tex")
Пример #12
0
def main():
    data = [
        {
            'time': 1,
            'name': 'Müller',
            'team': 'GER'
        },
        {
            'time': 23,
            'name': 'Klose',
            'team': 'GER'
        },
        {
            'time': 24,
            'name': 'Kroos',
            'team': 'GER'
        },
        {
            'time': 26,
            'name': 'Kroos',
            'team': 'GER'
        },
        {
            'time': 29,
            'name': 'Khedira',
            'team': 'GER'
        },
        {
            'time': 69,
            'name': 'Schürrle',
            'team': 'GER'
        },
        {
            'time': 79,
            'name': 'Schürrle',
            'team': 'GER'
        },
        {
            'time': 90,
            'name': 'Oscar',
            'team': 'BRA'
        },
    ]

    options = {
        'direction': 'up',
        'initialWidth': 804,
        'initialHeight': 120,
        'scale': LinearScale(),
        'domain': [0, 90],
        'margin': {
            'left': 20,
            'right': 20,
            'top': 30,
            'bottom': 20
        },
        'textFn': lambda d: d['name'],
        'layerGap': 40,
        'dotColor': color5,
        'labelBgColor': color5,
        'linkColor': color5,
        'labella': {
            'maxPos': 764,
            'algorithm': 'simple',
        },
        'labelPadding': {
            'left': 0,
            'right': 2,
            'top': 0,
            'bottom': 0
        },
    }

    tl = TimelineSVG(data, options=options)
    tl.export('timeline_kit_5.svg')

    tl = TimelineTex(data, options=options)
    tl.export('timeline_kit_5.tex')
Пример #13
0
def test_labella(struct, name):
  #tl = TimelineTex(struct, options={'scale': LinearScale()})
  tl = TimelineTex(struct, options={'scale': TimeScale()})
  tl.export(f"{name}.tex")