Exemple #1
0
def user_summary_for(rtype, storages, output_path: Path):
    ustats = {}

    def reg(user, query, stats):
        if user not in ustats:
            ustats[user] = {}
        ustats[user][query] = stats

    with ProcessPoolExecutor() as pp:
        digests = pp.map(get_digest, [s.path for s in storages])

    for s, digest in zip(storages, digests):
        everything = flatten([ch for ch in digest.changes.values()])
        for user, items in group_by_key(everything,
                                        key=lambda x: x.user).items():
            reg(user, s.name, len(items))

    now = datetime.now()
    doc = dominate.document(
        title=
        f'axol tags summary for {[s.name for s in storages]}, rendered at {fdate(now)}'
    )
    with doc.head:
        T.style(STYLE)
        raw_script(JS)  # TODO necessary?

        # TODO FIXME can't inline due to some utf shit
        sortable_js = Path(__file__).absolute().parent / 'js' / 'sorttable.js'
        T.script(src=str(sortable_js))

    ft = FormatTrait.for_(rtype)
    with doc.body:
        with T.table(cls='sortable'):
            emitted_head = False
            for user, stats in sorted(ustats.items(),
                                      key=lambda x: (-len(x[1]), x)):
                if not emitted_head:
                    with T.thead():
                        T.td('user')
                        for q, _ in stats.items():
                            T.td(q)
                    emitted_head = True

                with T.tr():
                    T.td(ft.user_link(user))
                    for q, st in stats.items():
                        with T.td(sorttable_customkey=str(st)):
                            # TODO I guess unclear which tag to choose though.
                            T.a(
                                q, href=f'summary/{q}.html'
                            )  # TODO link to source in index? or on pinboard maybe
                            # TODO also project onto user's tags straight away
                            T.sup(
                                str(st) if st < 5 else T.b(
                                    T.font(str(st), color='red')))  # TODO css

    output_path.write_text(str(doc))
    logger.info('Dumped user summary to %s', output_path)
Exemple #2
0
 def visitRepeat(self, ctx:TacticNotationsParser.RepeatContext):
     with tags.span(_class="repeat-wrapper"):
         with tags.span(_class="repeat"):
             self.visitChildren(ctx)
         repeat_marker = ctx.LGROUP().getText()[1]
         separator = ctx.ATOM()
         tags.sup(repeat_marker)
         if separator:
             tags.sub(separator.getText())
Exemple #3
0
 def visitRepeat(self, ctx: TacticNotationsParser.RepeatContext):
     with tags.span(_class="repeat-wrapper"):
         with tags.span(_class="repeat"):
             self.visitChildren(ctx)
         repeat_marker = ctx.LGROUP().getText()[1]
         separator = ctx.ATOM()
         tags.sup(repeat_marker)
         if separator:
             tags.sub(separator.getText())
Exemple #4
0
def dict_html(container, query, dict_, source, target):
    container.add(div(query, cls='word'))
    container.add(div(raw(
        f'{langs[source]} -> {langs[target[0]]}'), cls='lang'))
    for w in dict_:
        def_box = container.add(div()).add(ul())
        defin = dict_[w]
        def_box.add(li(f'{w} ({defin["word_type"]})'.lower(),
                    cls='definition'))
        synonyms = def_box.add(ol())
        for syn in defin['variants']:
            if not syn[1]:
                synonyms.add(li(syn[0], cls='synonyms'))
            else:
                syn_word = synonyms.add(li(f'{syn[0]} ',
                                        cls='synonyms has_example'))
                syn_word.add(sup(syn[1]))