OSDN Git Service

add support functions to db accessor
[amulettoolsmh4/main.git] / model / db_accessor.py
index 93c8985..a44ffb9 100644 (file)
@@ -8,6 +8,7 @@ import sqlite3
 import db_supports
 from amuletskillsholder import AmuletSkillsHolder
 from randomseedsholder import RandomSeedsHolder
+from sufficientsholder import SufficientsHolder
 
 class DataBaseAccessor(object):
     u""" this is access class to database """
@@ -129,6 +130,36 @@ class DataBaseAccessor(object):
         else:
             return seed_set
 
+    def select_minmax_from_skill_ids(self, amulet_id, skill_ids):
+        u""" お守りのidとスキルidのリストから、スキルIDと取りうるスキルの最大最小値の辞書を得る
+            return dict{skill_id:(min1, max1, min2, max2)}
+        """
+        minmax_table = self._amulet_id2minmax_dict[amulet_id]
+        amulet_skill = AmuletSkillsHolder(skill_ids)
+        result_dict = {}
+        if amulet_skill.is_empty() is False:
+            sql = db_supports.MIN_MAX_TABLE_SELECT_ALL_SQL.format(table_name=minmax_table) + amulet_skill.get_where_in_sql()
+            self._cursor.execute(sql)
+
+            for row in self._cursor.fetchall():
+                result_dict[row[0]] = tuple(row[1])
+        return result_dict
+
+    def select_threshold_from_sufficient(self, amulet_id, sufficient_vals):
+        u""" お守りのidと充足値のリストから、充足値とスロットごとの判定値の辞書を得る
+            return dict({sufficient_val:(slot1_th, slot2_th, slot3_th)})
+        """
+        suff_table = self._amulet_id2suff_dict[amulet_id]
+        amulet_skill = SufficientsHolder(sufficient_vals)
+        result_dict = {}
+        if amulet_skill.is_empty() is False:
+            sql = db_supports.SUFFICIENT_TABLE_SELECT_ALL_SQL.format(table_name=suff_table) + amulet_skill.get_where_in_sql()
+            self._cursor.execute(sql)
+
+            for row in self._cursor.fetchall():
+                result_dict[row[0]] = tuple(row[1])
+        return result_dict
+
     def select_skills_from_seeds(self, seed_set):
         u""" get amulet id to (random_seed to skill ids dict) dict,
         and rendom_seed to slot value dict