Exemplo n.º 1
0
 def get_top_members_per_num_characters(self, top_n=20):
     query = Member.select(Member, fn.SUM(fn.LENGTH(Message.content)).alias('length')) \
                   .join(Message, JOIN.RIGHT_OUTER) \
                   .group_by(Member) \
                   .order_by(SQL('length').desc()) \
                   .limit(top_n)
     return list(query)
Exemplo n.º 2
0
def print_points(upgrade_discipline, output_format):
    """
    Print out points tally for each Person
    """
    if output_format == 'null':
        return

    cur_year = date.today().year
    start_date = date(cur_year - 1, 1, 1)

    upgrades_needed = (
        Points.select(Points, Result.place, Event.discipline, Person.id,
                      Person.first_name, Person.last_name,
                      fn.MAX(Race.date).alias('last_date')).join(
                          Result, src=Points).join(Person, src=Result).join(
                              Race, src=Result).join(
                                  Event,
                                  src=Race).where(Race.date >= start_date).
        where(Event.discipline << DISCIPLINE_MAP[upgrade_discipline]).group_by(
            Person.id).having(Points.needs_upgrade == True).order_by(
                Points.sum_categories.asc(), Points.sum_value.desc(),
                Person.last_name.collate('NOCASE').asc(),
                Person.first_name.collate('NOCASE').asc()))

    points = (Points.select(
        Points, Result, Person, Race.id, Race.name, Race.date, Race.starters,
        Race.categories, Event.id, Event.name,
        Event.discipline).join(Result, src=Points).join(
            Person,
            src=Result).join(Race, src=Result).join(Event, src=Race).where(
                Event.discipline << DISCIPLINE_MAP[upgrade_discipline]).where(
                    fn.LENGTH(Person.last_name) > 1).order_by(
                        Person.last_name.collate('NOCASE').asc(),
                        Person.first_name.collate('NOCASE').asc(),
                        Race.date.asc()))

    person = None
    with get_writer(output_format, upgrade_discipline) as writer:
        writer.start_upgrades()
        for point in upgrades_needed.execute():
            # Confirm that they haven't already been upgraded on the site
            obra = get_obra_data(point.result.person, point.result.race.date)
            discipline = point.result.race.event.discipline
            if obra.category_for_discipline(discipline) >= min(
                    point.sum_categories):
                writer.upgrade(point)
        writer.end_upgrades()

        for point in points.execute():
            if person != point.result.person:
                if person:
                    writer.end_person(person)
                person = point.result.person
                writer.start_person(person)
            writer.point(point)
        else:
            writer.end_person(person, True)
Exemplo n.º 3
0
    def get_top_members_per_num_characters(self, top_n=20):
        """Gets the most active members sorted by the sum of the number of
        characters in the messages they posted.

        Args:
            top_n: The maximum number of members to return.

        Returns:
            A list of the top n most active members.
        """
        query = Member.select(Member, fn.SUM(fn.LENGTH(Message.content)).alias('length')) \
                      .join(Message, JOIN.RIGHT_OUTER) \
                      .group_by(Member) \
                      .order_by(SQL('length').desc()) \
                      .limit(top_n)
        return list(query)
Exemplo n.º 4
0
    def get_user_unique_random(
        cls,
        user_id: Union[int, User],
        years: List[int] = None,
        limit=QUOTES_LIMIT,
        filter_quote_by_max_length_text: int = None,
    ) -> List['Quote']:
        sub_query = Request.get_all_quote_id_by_user(user_id).distinct()

        where = cls.id.not_in(sub_query)
        if years:
            fn_year = fn.strftime('%Y', cls.date).cast('INTEGER')
            where = where & fn_year.in_(years)

        if filter_quote_by_max_length_text:
            where = where & (fn.LENGTH(cls.text) <=
                             filter_quote_by_max_length_text)

        query = (cls.select().where(where).order_by(fn.Random()).limit(limit))
        return list(query)
        fout.write(f"---config@码表别名=系统单字\n")
        pipe(
            CharPhoneTable.select().order_by(CharPhoneTable.priority.desc()),
            filter(lambda e: e.char in char_to_shape),
            map(lambda e: f"{e.char}\t{e.zrm+char_to_shape[e.char]}#序40000"),
            for_each(lambda e: fout.write(e + '\n')),
        )

    del_words = pipe(DelWordTable.select(), map(lambda e: e.word), set)
    sys_word_data = f"{output_dir}/sys_word_data.txt"
    with open(sys_word_data, 'w', encoding='utf8') as fout:
        fout.write("---config@码表分类=主码-2\n")
        fout.write("---config@允许编辑=否\n")
        fout.write(f"---config@码表别名=系统词组\n")
        pipe(
            WordPhoneTable.select().order_by(fn.LENGTH(WordPhoneTable.word),
                                             WordPhoneTable.priority.desc()),
            filter(lambda e: e.word not in del_words),
            map(lambda e: (f'{e.word}\t{e.zrm}', e.word[0], e.word[-1])),
            filter(lambda e: e[1] in char_to_shape and e[2] in char_to_shape),
            map(lambda e:
                f'{e[0]}{char_to_shape[e[1]][0]}{char_to_shape[e[2]][-1]}#序20000'
                ), for_each(lambda e: fout.write(e + '\n')))

    with open(f'{output_dir}/sys_eng_data.txt', 'w', encoding='utf8') as fout:
        fout.write("---config@码表分类=主码-3\n")
        fout.write("---config@允许编辑=否\n")
        fout.write(f"---config@码表别名=系统英文\n")
        pipe(
            EngWordTable.select().where(EngWordTable.priority > 100).order_by(
                fn.LENGTH(EngWordTable.word), EngWordTable.priority),
def facal_nas_fhaide():
    return Facal.select().order_by(fn.LENGTH(Facal.litrichean).desc()).first()
Exemplo n.º 7
0
                lambda e: f"{e.char}\t{e.zrm+char_to_shape[e.char]}#序40000"),
            for_each(lambda e: fout.write(e+'\n')),
        )

    del_words = pipe(
        DelWordTable.select(),
        map(lambda e: e.word),
        set
    )
    sys_word_data = f"{output_dir}/sys_word_data.txt"
    with open(sys_word_data, 'w', encoding='utf8') as fout:
        fout.write("---config@码表分类=主码-2\n")
        fout.write("---config@允许编辑=否\n")
        fout.write(f"---config@码表别名=系统词组\n")
        pipe(
            WordPhoneTable.select().order_by(fn.LENGTH(WordPhoneTable.word),
                                             WordPhoneTable.priority.desc()),
            filter(lambda e: e.word not in del_words),
            map(lambda e: (f'{e.word}\t{e.zrm}', e.word[0], e.word[-1])),
            filter(lambda e: e[1] in char_to_shape and e[2] in char_to_shape),
            map(lambda e: f'{e[0]}{char_to_shape[e[1]][0]}{char_to_shape[e[2]][-1]}#序20000'),
            for_each(lambda e: fout.write(e+'\n'))
        )

    with open(f'{output_dir}/sys_eng_data.txt', 'w', encoding='utf8') as fout:
        fout.write("---config@码表分类=主码-3\n")
        fout.write("---config@允许编辑=否\n")
        fout.write(f"---config@码表别名=系统英文\n")
        pipe(EngWordTable.select().where(EngWordTable.priority > 100).order_by(fn.LENGTH(EngWordTable.word), EngWordTable.priority),
             filter(lambda e: is_all_alpha(e.word)),
             map(lambda e: e.word+'\t'+e.word+"#序10000"),