コード例 #1
0
def order_topics_by_insertions(q: Queryable):
    """
    Number of insertions.
    """
    return apply(
        [where(a_('is_topic')),
         order_by(a_('inserted_diffs').count())], q)
コード例 #2
0
    def get_filtered_clan_list(self):
        schools = self.get_filtered_school_list()
        clanids = query(schools) \
            .distinct(a_('clanid')) \
            .select(a_('clanid')) \
            .to_list()

        return [api.data.clans.get(x) for x in clanids]
コード例 #3
0
    def get_filtered_clan_list(self):
        schools = self.get_filtered_school_list()
        clanids = query(schools) \
            .distinct(a_('clanid')) \
            .select(a_('clanid')) \
            .to_list()

        return [api.data.clans.get(x) for x in clanids]
コード例 #4
0
def order_topics_by_insertion_length(q: Queryable):
    """
    Text Length.
    """
    return apply([
        where(a_('is_topic')),
        order_by(query(a_('inserted_diffs')).sum(lambda x: len(x[1])))
    ])
コード例 #5
0
def get_school_rank(sid):
    """return the school rank"""

    if api.data.schools.is_path(sid):
        return query(api.data.schools.get(sid).techs).select(a_('rank')).first_or_default(1)
    return query(api.character.rankadv.get_all()).where(
            lambda x: x.school == sid or x.replaced == sid).count()
コード例 #6
0
def get_references():
    """return a list of data-packs that are referenced by the character"""

    refs_ = []
    # get references from families
    family_ = api.data.families.get(api.character.get_family())
    if family_:
        refs_.append(family_.pack)

    # get references from schools
    for s in [
            api.data.schools.get(x) for x in api.character.schools.get_all()
            if api.data.schools.get(x) is not None
    ]:
        refs_.append(s.pack)

    # get references from skills
    for s in [
            api.data.skills.get(x) for x in api.character.skills.get_all()
            if api.data.skills.get(x) is not None
    ]:
        refs_.append(s.pack)

    # get references from spells
    for s in [
            api.data.spells.get(x) for x in api.character.spells.get_all()
            if api.data.spells.get(x) is not None
    ]:
        refs_.append(s.pack)

    return query(refs_).where(lambda y: y is not None).distinct(
        a_('id')).to_list()
コード例 #7
0
def get_school_rank(sid):
    """return the school rank"""

    if api.data.schools.is_path(sid):
        return query(api.data.schools.get(sid).techs).select(a_('rank')).first_or_default(1)
    return query(api.character.rankadv.get_all()).where(
            lambda x: x.school == sid or x.replaced == sid).count()
コード例 #8
0
def get_paths_with_rank(rank):
    """returns alternate schools list with rank equal to `rank`"""

    return query(__api.ds.schools) \
        .where(lambda x: 'alternate' in x.tags) \
        .where(lambda x: query(x.techs).select(a_('rank')).first_or_default(0) == rank) \
        .to_list()
コード例 #9
0
def get_requirements(sid):
    """returns the requirements to join the given school"""
    school_ = get(sid)
    if not school_:
        log.api.error(u"school not found: %s", sid)
        return []

    requirements_by_data_ = school_.require

    # fixme. since i can't rewrite all alternate path
    # I decided to patch these requirement by code

    import l5r.api.character.schools
    from l5rdal.requirements import Requirement
    coded_requirements_ = []

    if is_path(sid):
        # An alternate path can only be joined
        # on the same school rank that its technique replaces

        path_rank_ = query(school_.techs).select(a_('rank')).first_or_default(0)

        if path_rank_ > 0:

            r = Requirement()
            r.field = api.character.schools.get_current()
            r.type = 'school'
            r.min = path_rank_ - 1
            r.max = path_rank_ - 1
            r.trg = None
            r.text = __api.tr("Replaces School Rank: {0}").format(path_rank_)

            coded_requirements_.append(r)

    return requirements_by_data_ + coded_requirements_
コード例 #10
0
def get_paths_with_rank(rank):
    """returns alternate schools list with rank equal to `rank`"""

    return query(__api.ds.schools) \
        .where(lambda x: 'alternate' in x.tags) \
        .where(lambda x: query(x.techs).select(a_('rank')).first_or_default(0) == rank) \
        .to_list()
コード例 #11
0
def get_tech_by_rank(rank):
    """returns the technique learned at the given insight rank, or None"""

    # get the school rank at that insight rank
    rank_ = query(api.character.rankadv.get_all()).where(
        lambda x: x.rank == rank).to_list()

    if not rank_:
        #log.api.error(u"get_tech_by_rank. rank advancement not found: %d", rank)
        return None

    school_id = rank_[0].school
    if len(rank_) > 1:
        # find a replacement
        replacement_ = query(rank_).where(
            lambda x: x.replaced == school_id).first_or_default(None)
        if replacement_:
            school_id = replacement_.school

    school_ = api.data.schools.get(school_id)

    if not school_:
        return None

    return query(school_.techs).where(lambda x: x.rank == rank).select(
        a_('id')).first_or_default(None)
コード例 #12
0
def get_tech_by_rank(rank):
    """returns the technique learned at the given insight rank, or None"""

    # get the school rank at that insight rank
    rank_ = query(api.character.rankadv.get_all()).where(
        lambda x: x.rank == rank).to_list()

    if not rank_:
        #log.api.error(u"get_tech_by_rank. rank advancement not found: %d", rank)
        return None


    school_id = rank_[0].school
    if len(rank_) > 1:        
        # find a replacement
        replacement_ = query(rank_).where(lambda x: x.replaced == school_id).first_or_default(None)
        if replacement_:
            school_id = replacement_.school

    school_ = api.data.schools.get(school_id)

    if not school_:
        return None

    return query(school_.techs).where(lambda x: x.rank == rank).select(a_('id')).first_or_default(None)
コード例 #13
0
def get_tech_by_rank(rank):
    """returns the technique learned at the given insight rank, or None"""

    # get the school rank at that insight rank
    rank_ = query(api.character.rankadv.get_all()).where(
        lambda x: x.rank == rank).first_or_default(None)

    if not rank_:
        log.api.error(u"get_tech_by_rank. rank advancement not found: %d",
                      rank)
        return None

    school_id = rank_.school
    school_rank = query(api.character.rankadv.get_all()).where(
        lambda x: (x.school == school_id or x.replaced == school_id
                   ) and x.rank <= rank).count()

    school_ = api.data.schools.get(school_id)

    if not school_:
        return None

    # for path use the school rank as a tech index
    if api.data.schools.is_path(school_.id):
        try:
            return school_.techs[school_rank - 1].id
        except:
            return None

    return query(school_.techs).where(lambda x: x.rank == school_rank).select(
        a_('id')).first_or_default(None)
コード例 #14
0
def get_bottom_category(q: Queryable) -> Queryable:
    return apply([
        group_by_category,
        order_grouping_by(a_('duration'), Order.Asc),
        fst,
        as_category
    ], q)
コード例 #15
0
def get_techs_by_school(sid):
    """returns all the techniques learned in the given school"""

    school_ = api.data.schools.get(sid)
    if not school_:
        return []

    return query(school_.techs).where(lambda x: api.character.has_rule(x.id)).select(a_('id')).to_list()
コード例 #16
0
    def load_families(self, clanid=None):
        self.cb_family.blockSignals(True)
        self.cb_family.clear()

        if clanid:
            family_list = query(api.data.families.get_all()).where(
                lambda x: x.clanid == clanid).order_by(a_('name'))
        else:
            family_list = query(api.data.families.get_all()).order_by(
                a_('name'))

        for f in family_list:
            self.cb_family.addItem(f.name, f.id)
        self.cb_family.blockSignals(False)

        # select first family
        self.on_family_changed(0)
コード例 #17
0
def get_techs_by_school(sid):
    """returns all the techniques learned in the given school"""

    school_ = api.data.schools.get(sid)
    if not school_:
        return []

    return query(school_.techs).where(lambda x: api.character.has_rule(x.id)).select(a_('id')).to_list()
コード例 #18
0
    def load_clans(self):
        self.cb_clan.blockSignals(True)
        self.cb_clan.clear()
        self.cb_clan.addItem(self.tr("No Clan"), None)

        for c in query(api.data.clans.all()).order_by(a_('name')):
            self.cb_clan.addItem(c.name, c.id)
        self.cb_clan.blockSignals(False)

        # select first clan
        self.on_clan_changed(0)
コード例 #19
0
    def load_clans(self):
        self.cb_clan.blockSignals(True)
        self.cb_clan.clear()
        self.cb_clan.addItem(self.tr("No Clan"), None)

        for c in query(api.data.clans.all()).order_by(a_('name')):
            self.cb_clan.addItem(c.name, c.id)
        self.cb_clan.blockSignals(False)

        # select first clan
        self.on_clan_changed(0)
コード例 #20
0
def get_skill_emphases(skill_id):
    """return the emphases for a skill"""
    sk_emph_list = []
    for r in api.character.rankadv.get_all():
        if skill_id not in r.emphases:
            continue
        sk_emph_list += r.emphases[skill_id]

    sk_emph_list += query(__api.pc.advans).where(
        lambda x: x.type == 'emph' and x.skill == skill_id).select(a_('text')).to_list()

    return sk_emph_list
コード例 #21
0
def get_skill_emphases(skill_id):
    """return the emphases for a skill"""
    sk_emph_list = []
    for r in api.character.rankadv.get_all():
        if skill_id not in r.emphases:
            continue
        sk_emph_list += r.emphases[skill_id]

    sk_emph_list += query(__api.pc.advans).where(
        lambda x: x.type == 'emph' and x.skill == skill_id).select(a_('text')).to_list()

    return sk_emph_list
コード例 #22
0
    def load_families(self, clanid=None):
        self.cb_family.blockSignals(True)
        self.cb_family.clear()

        if clanid:
            family_list = query(api.data.families.get_all()).where(lambda x: x.clanid == clanid).order_by(a_('name'))
        else:
            family_list = query(api.data.families.get_all()).order_by(a_('name'))

        for f in family_list:
            self.cb_family.addItem(f.name, f.id)
        self.cb_family.blockSignals(False)

        # select first family
        self.on_family_changed(0)
コード例 #23
0
def get_references():
    """return a list of data-packs that are referenced by the character"""

    refs_ = []
    # get references from families
    family_ = api.data.families.get(api.character.get_family())
    if family_:
        refs_.append(family_.pack)

    # get references from schools
    for s in [api.data.schools.get(x) for x in api.character.schools.get_all() if api.data.schools.get(x) is not None]:
        refs_.append(s.pack)

    # get references from skills
    for s in [api.data.skills.get(x) for x in api.character.skills.get_all() if api.data.skills.get(x) is not None]:
        refs_.append(s.pack)

    # get references from spells
    for s in [api.data.spells.get(x) for x in api.character.spells.get_all() if api.data.spells.get(x) is not None]:
        refs_.append(s.pack)

    return query(refs_).where(lambda y: y is not None).distinct(a_('id')).to_list()
コード例 #24
0
def leave_path():
    """the character resume its former path"""

    # this function assumes that the character is
    # currently following an alternate path

    former_school_ = query(get_all()).where(
        lambda x: not api.data.schools.is_path(x)).order_by(a_('rank')).first_or_default(None)

    if not former_school_:
        log.api.error(u"former school not found. could not resume old path")
        return False


    from models.advancements.rank import Rank
    adv = Rank()
    # the insight rank
    adv.rank = api.character.insight_rank()
    # this is the current school for this rank
    adv.school = former_school_.school
    # no cost advancing in the same rank
    adv.cost = 0
    # description
    adv.desc = api.tr("Insight Rank {0}. School: {1} rank {2} ").format(
        adv.rank,
        api.data.schools.get(adv.school).name,
        api.character.schools.get_school_rank(adv.school) + 1
    )

    # get 3 spells each rank other than the first
    if api.data.schools.is_shugenja(adv.school) and adv.rank > 1:
        adv.gained_spells_count = __api.pc.get_spells_per_rank()

    # get 2 kiho each rank
    if api.data.schools.is_brotherhood_monk(adv.school) and adv.rank > 1:
        adv.gained_kiho_count = 2

    return api.character.append_advancement(adv)
コード例 #25
0
def leave_path():
    """the character resume its former path"""

    # this function assumes that the character is
    # currently following an alternate path

    former_school_ = query(
        get_all()).where(lambda x: not api.data.schools.is_path(x)).order_by(
            a_('rank')).first_or_default(None)

    if not former_school_:
        log.api.error(u"former school not found. could not resume old path")
        return False

    from l5r.models.advancements.rank import Rank
    adv = Rank()
    # the insight rank
    adv.rank = api.character.insight_rank()
    # this is the current school for this rank
    adv.school = former_school_.school
    # no cost advancing in the same rank
    adv.cost = 0
    # description
    adv.desc = api.tr("Insight Rank {0}. School: {1} rank {2} ").format(
        adv.rank,
        api.data.schools.get(adv.school).name,
        api.character.schools.get_school_rank(adv.school) + 1)

    # get 3 spells each rank other than the first
    if api.data.schools.is_shugenja(adv.school) and adv.rank > 1:
        adv.gained_spells_count = __api.pc.get_spells_per_rank()

    # get 2 kiho each rank
    if api.data.schools.is_brotherhood_monk(adv.school) and adv.rank > 1:
        adv.gained_kiho_count = 2

    return api.character.append_advancement(adv)
コード例 #26
0
def items_edited_during_standard(q: Queryable):
    return apply([
        where(And(a_('is_item'), a_('edited'), a_('during_standard'))),
    ], q)
コード例 #27
0
def get_learned_spells():
    """return the spells not bounded to a rank advancement"""
    return query(__api.pc.advans).where(lambda x: x.type == 'spell').select(
        a_('spell')).distinct().to_list()
コード例 #28
0
    return x.first()


def count(x):
    return lambda x: x.count()


def order_grouping_by(selector: Callable, type: Order = Order.Asc):
    """
    subselect the group items within each grouping.
    """
    asc = lambda x: x.order_by(lambda y: query(y).select(selector).sum())
    desc = lambda x: x.order_by_descending(lambda y: query(y).select(selector).
                                           sum())
    return asc if type == Order.Asc else desc


order_by_duration = order_by(get_sum(a_('duration')))
group_by_category = group_by(a_('parent_category'))
group_by_concept = group_by(a_('data.concept_name'))
group_by_collection = group_by(a_('data.collection_name'))
group_by_date = group_by(m_('date'))
group_by_learning_mode = group_by(a_('data.learning_mode'))
group_by_element_type = group_by(a_('data.element_type'))
group_by_edited = group_by(m_('was_edited'))

#order_by_deletion_number = order_by(lambda x: text_deletions(x.data.element_content).count())
#order_by_insertion_number = order_by(lambda x: text_insertions(x.data.element_content).count())
#order_by_deletion_length = order_by(lambda x: text_insertions(x.data.element_content).sum())
#order_by_insertion_length = order_by(lambda x: sum(len(tup[1]) for tup in text_insertions(x.data.element_content)))
コード例 #29
0
 def test_a_negative(self):
     c = TestAttributeSelector.HasAttributes()
     foo_selector = a_('foo')
     self.assertRaises(AttributeError, lambda: foo_selector(c))
コード例 #30
0
def order_categories_by_time(q: Queryable) -> Queryable:
    return apply([
        group_by_category,
        order_grouping_by(a_('duration'), Order.Desc),
        select(lambda x: Category(name=x.key, time=x.sum(a_('duration'))))
    ], q)
コード例 #31
0
 def test_a_result_is_callable(self):
     foo_selector = a_('foo')
     self.assertTrue(is_callable(foo_selector))
コード例 #32
0
def get_all_kata():
    """returns all character kata"""
    return query(__api.pc.advans).where(lambda x: x.type == 'kata').select(a_('kata')).to_list()
コード例 #33
0
ファイル: selectmark.py プロジェクト: Dror-LightCyber/asq
def bench():
    results = query(items).select(a_("value")).to_list()
コード例 #34
0
ファイル: selectmark.py プロジェクト: scls19fr/asq
def bench():
    results = query(items).select(a_("value")).to_list()
コード例 #35
0
def get_all_kata():
    """returns all character kata"""
    return query(__api.pc.advans).where(lambda x: x.type == 'kata').select(
        a_('kata')).to_list()
コード例 #36
0
def get_memorized_spells():
    """return the memorized spels"""
    return query(__api.pc.advans).where(
        lambda x: x.type == 'memo_spell').select(a_('spell')).distinct().to_list()
コード例 #37
0
ファイル: test_selectors.py プロジェクト: pombredanne/asq
 def test_a_positive(self):
     c = TestAttributeSelector.HasAttributes()
     jim_selector = a_('jim')
     self.assertEqual(jim_selector(c), 23)
コード例 #38
0
ファイル: test_selectors.py プロジェクト: pombredanne/asq
 def test_a_negative(self):
     c = TestAttributeSelector.HasAttributes()
     foo_selector = a_('foo')
     self.assertRaises(AttributeError, lambda: foo_selector(c))
コード例 #39
0
def get_all():
    """return all the character schools"""
    return query(api.character.rankadv.get_all()).select(
        a_('school')).distinct().to_list()
コード例 #40
0
ファイル: test_selectors.py プロジェクト: pombredanne/asq
 def test_a_result_is_callable(self):
     foo_selector = a_('foo')
     self.assertTrue(is_callable(foo_selector))
コード例 #41
0
def get_former_school():
    """returns the first available school to return after an alternate path"""
    return query(
        get_all()).where(lambda x: not api.data.schools.is_path(x)).order_by(
            a_('rank')).first_or_default(None)
コード例 #42
0
def get_memorized_spells():
    """return the memorized spels"""
    return query(
        __api.pc.advans).where(lambda x: x.type == 'memo_spell').select(
            a_('spell')).distinct().to_list()
コード例 #43
0
def get_all():
    """return all the character schools"""
    return query(api.character.rankadv.get_all()).select(a_('school')).distinct().to_list()
コード例 #44
0
def get_top_collection(q: Queryable) -> Queryable:
    return apply([
        group_by_collection,
        order_grouping_by(a_('duration'), Order.Desc), fst, as_collection
    ], q)
コード例 #45
0
 def test_a_positive(self):
     c = TestAttributeSelector.HasAttributes()
     jim_selector = a_('jim')
     self.assertEqual(jim_selector(c), 23)
コード例 #46
0
def get_collection_times(q: Queryable) -> Queryable:
    return apply([
        group_by_collection,
        order_grouping_by(a_('duration'), Order.Desc),
        select(lambda x: as_collection(x))
    ], q)
コード例 #47
0
def get_learned_spells():
    """return the spells not bounded to a rank advancement"""
    return query(__api.pc.advans).where(
        lambda x: x.type == 'spell').select(a_('spell')).distinct().to_list()
コード例 #48
0
def order_by_child_delta(q: Queryable):
    return apply([order_by(a_('data.children_delta'))], q)