OSDN Git Service

revise amulet search to consider of seed1 value,
[amulettoolsmh4/main.git] / model / db_accessor.py
index 1af496d..8770a78 100644 (file)
@@ -11,6 +11,7 @@ from amuletskillsholder import AmuletSkillsHolder
 from amuletidskillidholder import AmuletIdSkillIdHolder
 from seedsholder import SeedsHolder
 from sufficientsholder import SufficientsHolder
+from skillplaceholder import SkillPlaceHolder
 
 class DataBaseAccessor(object):
     u""" this is access class to database """
@@ -62,7 +63,6 @@ class DataBaseAccessor(object):
                     self._amulet_id2skill1_id_dict,
                     self._amulet_id2skill2_id_dict)
 
-
     def _get_skill_dict(self):
         u""" create id2name, name2id dict of skill 
             return (dict_id2name, dict_name2id)
@@ -153,6 +153,84 @@ class DataBaseAccessor(object):
         else:
             return seed_set
 
+    def select_skill2_place(self, amulet_id, seed2, skill2_id):
+        u""" Seed2、第2スキルid、お守りidから、指定されたSeed2において
+        Skill2_idが何枠目に属しているか判定し、判定された枠のタプルを返す
+        return (skill2's indexes)"""
+        second_skill_table = self._amulet_id2skill2_table_dict[amulet_id]
+        sql = db_supports.SEED2_SKILL2_TABLE_SELECT_ALL_FROM_SEED2_SQL.format(table_name=second_skill_table,seed2=seed2)
+        self._cursor.execute(sql)
+        row = self._cursor.fetchone() # seed2, skill_id1, ..., skill_id7
+        if row is not None and len(row) > 1:
+            return tuple([i for i, x in enumerate(row, 0) if x == skill2_id])
+        else:
+            return tuple()
+
+    def count_seed1s_from_skill_place(self, skill1_id, skill_places, amulet_id):
+        u""" お守りIdと、第1スキルの種類と出現枠を指定し、
+        それを満たすSeed1の個数を天運555と天運888に分けて返す"""
+        if skill_places is not None and len(skill_places) > 0:
+            # tenun 555
+            if 6 in skill_places:
+                places555 = list(skill_places).remove(6)
+                places555 = [] if places555 is None else place555
+            else:
+                places555 = list(skill_places)
+            place_holder = SkillPlaceHolder(places555, skill1_id)
+            if len(places555) > 0:
+                sql555 = (db_supports.SEED1_TENUN555_TABLE_COUNT_SEED1_SQL +
+                        place_holder.get_skill1_where_or_sql(amulet_id))
+            else:
+                sql555 = None
+            # tenun888
+            place_holder = SkillPlaceHolder(skill_places, skill1_id)
+            sql888 = (db_supports.SEED1_TENUN888_TABLE_COUNT_SEED1_SQL +
+                        place_holder.get_skill1_where_or_sql(amulet_id))
+        else:
+            return 0, 0
+
+        if sql555 is not None:
+            self._cursor.execute(sql555)
+            seeds_555 = self._cursor.fetchone()[0]
+        else:
+            seeds_555 = 0
+
+        self._cursor.execute(sql888)
+        seeds_888 = self._cursor.fetchone()[0]
+
+        return seeds_555, seeds_888
+
+    def select_seed1s_from_skill_place(self, skill1_id, skill_places, amulet_id):
+        u""" お守りIdと、第1スキルの種類と出現枠を指定し、
+        それを満たすSeed1のセットを天運555と天運888に分けて返す"""
+        if skill_places is not None and len(skill_places) > 0:
+            # tenun 555
+            if 6 in skill_places:
+                places555 = list(skill_places).remove(6)
+                places555 = [] if places555 is None else place555
+            else:
+                places555 = list(skill_places)
+            place_holder = SkillPlaceHolder(places555, skill1_id)
+            if len(places555) > 0:
+                sql555 = (db_supports.SEED1_TENUN555_TABLE_SELECT_SEED1_SQL +
+                        place_holder.get_skill1_where_or_sql(amulet_id))
+            else:
+                sql555 = None
+            # tenun888
+            place_holder = SkillPlaceHolder(skill_places, skill1_id)
+            sql888 = (db_supports.SEED1_TENUN888_TABLE_SELECT_SEED1_SQL +
+                        place_holder.get_skill1_where_or_sql(amulet_id))
+        else:
+            return set(), set()
+        seeds_555, seeds_888 = set(), set()
+        if sql555 is not None:
+            self._cursor.execute(sql555)
+            seeds_555 = set([x[0] for x in self._cursor.fetchall()])
+        self._cursor.execute(sql888)
+        seeds_888 = set([x[0] for x in self._cursor.fetchall()])
+
+        return seeds_555, seeds_888
+
     def select_seed1s_tenun(self, amu_id_skill1_id_list, key_tenun):
         u""" select seed1 from list of amulet_id and skill1_id,
         key_tenun must be KEY_TENUN555 or KEY_TENUN888