OSDN Git Service

rename database_ids & some variables in order to understand easily
[amulettoolsmh4/main.git] / model / db_accessor.py
index 97d77b5..50171e2 100644 (file)
@@ -8,7 +8,7 @@ import sys
 
 import db_supports
 from amuletskillsholder import AmuletSkillsHolder
-from randomseedsholder import RandomSeedsHolder
+from seedsholder import SeedsHolder
 from sufficientsholder import SufficientsHolder
 
 class DataBaseAccessor(object):
@@ -21,8 +21,8 @@ class DataBaseAccessor(object):
 
         self._skill_id2name_dict, self._skill_name2id_dict = self._get_skill_dict()
         (self._amulet_id2name_dict, self._amulet_name2id_dict, 
-            self._amulet_id2minmax_table_dict, self._amulet_id2second_table_dict,
-            self._amulet_id2suff_table_dict,
+            self._amulet_id2minmax_table_dict, self._amulet_id2skill2_table_dict,
+            self._amulet_id2sufficient_table_dict,
             self._amulet_id2skill1_id_dict, self._amulet_id2skill2_id_dict) = self._get_amulet_dict()
 
     def _print_dicts(self):
@@ -32,8 +32,8 @@ class DataBaseAccessor(object):
         print self._amulet_id2name_dict
         print self._amulet_name2id_dict
         print self._amulet_id2minmax_table_dict
-        print self._amulet_id2second_table_dict
-        print self._amulet_id2suff_table_dict
+        print self._amulet_id2skill2_table_dict
+        print self._amulet_id2sufficient_table_dict
         print self._amulet_id2skill1_id_dict
         print self._amulet_id2skill2_id_dict
 
@@ -76,13 +76,13 @@ class DataBaseAccessor(object):
         return skill_id2name_dict, skill_name2id_dict
 
     def _get_amulet_dict(self):
-        u""" create id2name, name2id, id2minmax_table, id2second_table, id2suff_table,
+        u""" create id2name, name2id, id2minmax_table, id2skill2_table, id2sufficient_table,
             id2skill1_ids, id2skill2_id dict of amulet 
         return (dict_id2name, dict_name2id, 
-            id2minmax_table, id2second_table, id2suff_table, id2skill1_ids, id2skill2_ids)
+            id2minmax_table, id2skill2_table, id2sufficient_table, id2skill1_ids, id2skill2_ids)
         """
         amulet_id2name_dict, amulet_name2id_dict = {}, {}
-        id2minmax_table, id2second_table, id2suff_table = {}, {}, {}
+        id2minmax_table, id2skill2_table, id2sufficient_table = {}, {}, {}
         id2skill1_ids, id2skill2_ids = {}, {}
         self._cursor.execute(db_supports.AMULET_TABLE_SELECT_ALL_SQL)
         for val in self._cursor.fetchall():
@@ -96,17 +96,17 @@ class DataBaseAccessor(object):
             amulet_id, table = val[0], val[1]
             id2minmax_table[amulet_id] = table
  
-        # id 2 second table name
-        self._cursor.execute(db_supports.SECOND_MASTER_TABLE_SELECT_ALL_SQL)
+        # id 2 skill2 table name
+        self._cursor.execute(db_supports.SEED2_SKILL2_MASTER_TABLE_SELECT_ALL_SQL)
         for val in self._cursor.fetchall():
             amulet_id, table = val[0], val[1]
-            id2second_table[amulet_id] = table
+            id2skill2_table[amulet_id] = table
 
         # id 2 sufficient table name
         self._cursor.execute(db_supports.SUFFICIENT_MASTER_TABLE_SELECT_ALL_SQL)
         for val in self._cursor.fetchall():
             amulet_id, table = val[0], val[1]
-            id2suff_table[amulet_id] = table
+            id2sufficient_table[amulet_id] = table
 
         # id 2 non zero skill1 ids
         # id 2 non zero skill2 ids
@@ -123,7 +123,7 @@ class DataBaseAccessor(object):
             id2skill2_ids[amu_id] = tuple(ls)
 
         return (amulet_id2name_dict, amulet_name2id_dict, 
-                id2minmax_table, id2second_table, id2suff_table,
+                id2minmax_table, id2skill2_table, id2sufficient_table,
                 id2skill1_ids, id2skill2_ids)
 
     def select_seeds(self, amu_id2skill_id_list_dict):
@@ -132,14 +132,14 @@ class DataBaseAccessor(object):
         """
         seed_set = None
         for key, val in amu_id2skill_id_list_dict.items():
-            if key in self._amulet_id2second_table_dict:
-                second_skill_table = self._amulet_id2second_table_dict[key]
+            if key in self._amulet_id2skill2_table_dict:
+                second_skill_table = self._amulet_id2skill2_table_dict[key]
                 amulet_skill = AmuletSkillsHolder(val)
 
                 if amulet_skill.is_empty():
                     continue
 
-                sql = db_supports.SECOND_TABLE_SELECT_SEED_SQL.format(table_name=second_skill_table) + amulet_skill.get_where_sql()
+                sql = db_supports.SEED2_SKILL2_TABLE_SELECT_SEED_SQL.format(table_name=second_skill_table) + amulet_skill.get_where_and_sql()
                 self._cursor.execute(sql)
 
                 if seed_set is None:
@@ -157,25 +157,25 @@ class DataBaseAccessor(object):
         is skill2_id is None, search all skills
         """
         if amu_id in self._amulet_id2name_dict.keys():
-            table = self._amulet_id2suff_table_dict[amu_id]
-            sql = db_supports.SUFFICIENT_TABLE_SELECT_THRESHOLDS_SQL.format(
+            table = self._amulet_id2sufficient_table_dict[amu_id]
+            sql = db_supports.SUFFICIENT_TABLE_SELECT_THRESHOLD1_SQL.format(
                     table_name=table, sufficient_val=sufficient_val)
             self._cursor.execute(sql)
             try:
-                threshold2 = self._cursor.fetchone()[slot_num-1]
+                threshold1 = self._cursor.fetchone()[slot_num-1]
             except TypeError, e:
-                threshold2 = None
+                threshold1 = None
 
-            if threshold2 is not None:
-                table = self._amulet_id2second_table_dict[amu_id]
+            if threshold1 is not None:
+                table = self._amulet_id2skill2_table_dict[amu_id]
                 if skill2_id is not None:
-                    sql = db_supports.SECOND_SLOT_TABLE_SELECT_SEEDS_FROM_THRESHOLD_AND_SKILL2_SQL.format(
-                        threshold=threshold2,
+                    sql = db_supports.SEED2_THRESHOLD1_TABLE_SELECT_SEEDS_FROM_THRESHOLD1_AND_SKILL2_SQL.format(
+                        threshold1=threshold1,
                         skill_table=table,
                         skill_id=skill2_id)
                 else:
-                    sql = db_supports.SECOND_SLOT_TABLE_SELECT_SEEDS_FROM_THRESHOLD_SQL.format(
-                        threshold=threshold2)
+                    sql = db_supports.SEED2_THRESHOLD1_TABLE_SELECT_SEEDS_FROM_THRESHOLD1_SQL.format(
+                        threshold1=threshold1)
                 self._cursor.execute(sql)
                 return set([x[0] for x in self._cursor.fetchall()])
             else:
@@ -198,11 +198,11 @@ class DataBaseAccessor(object):
                 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)})
+    def select_threshold1_from_sufficient(self, amulet_id, sufficient_vals):
+        u""" お守りのidと充足値のリストから、充足値とスロットごとの判定値1の辞書を得る
+            return dict({sufficient_val:(slot1_th1, slot2_th1, slot3_th1)})
         """
-        suff_table = self._amulet_id2suff_table_dict[amulet_id]
+        suff_table = self._amulet_idsufficient_table_dict[amulet_id]
         amulet_skill = SufficientsHolder(sufficient_vals)
         result_dict = {}
         if amulet_skill.is_empty() is False:
@@ -214,30 +214,30 @@ class DataBaseAccessor(object):
         return result_dict
 
     def select_skills_from_seeds(self, seed_set):
-        u""" get amulet id to (random_seed to skill ids dict) dict,
-        and random_seed to slot value dict
-        return: skill_dict, slot_dict
+        u""" get amulet id to (random_seed2 to skill ids dict) dict,
+        and random_seed2 to threshold1 dict
+        return: skill_dict, threshold1_dict
         """
-        skill_dict, slot_dict = {}, {}
+        skill_dict, threshold1_dict = {}, {}
 
         # skill dict
-        seeds = RandomSeedsHolder(seed_set)
-        for amu_id, table in self._amulet_id2second_table_dict.items():
-            sql = db_supports.SECOND_TABLE_SELECT_ALL_SQL.format(
-                    table_name=table) + seeds.get_where_sql()
+        seeds = SeedsHolder(seed_set)
+        for amu_id, table in self._amulet_id2skill2_table_dict.items():
+            sql = db_supports.SEED2_SKILL2_TABLE_SELECT_ALL_SQL.format(
+                    table_name=table) + seeds.get_where_in_sql()
             self._cursor.execute(sql)
             seed2skills_dic = {}
             for row in self._cursor.fetchall():
                 seed2skills_dic[row[0]] = [x for x in row[1:]]
             skill_dict[amu_id] = seed2skills_dic
 
-        # slot dict
-        sql = db_supports.SECOND_SLOT_TABLE_SELECT_ALL_SQL + seeds.get_where_sql()
+        # threshold1 dict
+        sql = db_supports.SEED2_THRESHOLD1_TABLE_SELECT_ALL_SQL + seeds.get_where_in_sql()
         self._cursor.execute(sql)
         for row in self._cursor.fetchall():
-            slot_dict[row[0]] = [x for x in row[1:]]
+            threshold1_dict[row[0]] = [x for x in row[1:]]
 
-        return skill_dict, slot_dict
+        return skill_dict, threshold1_dict
 
     def get_sufficient_value(self, amu_id, skill1_id, skill2_id, skill1_val, skill2_val):
         u""" 充足値を計算する。