+ 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
+ result_num: result number of amulet
+ when either amu_id or skill1_id is None, this means that no. has no result
+ """
+ result_num = len(amu_id_skill1_id_list)
+ for amu_id, skill1_id in reversed(amu_id_skill1_id_list):
+ if amu_id is not None and skill1_id is not None:
+ break
+ else:
+ result_num -= 1
+ amulet_ids = [x[0] for x in amu_id_skill1_id_list[:result_num]]
+ skill1_ids = [x[1] for x in amu_id_skill1_id_list[:result_num]]
+ holder = AmuletIdSkillIdHolder(amulet_ids, skill1_ids)
+
+ if key_tenun == db_supports.KEY_TENUN555:
+ sql = db_supports.SEED1_TENUN555_TABLE_SELECT_SQL + holder.get_where_and_sql()
+ elif key_tenun == db_supports.KEY_TENUN888:
+ sql = db_supports.SEED1_TENUN888_TABLE_SELECT_SQL + holder.get_where_and_sql()
+ else:
+ raise NotImplementedError(u"Tenun must be 555 or 888")
+ self._cursor.execute(sql)
+ seed_set = set([x[0] for x in self._cursor.fetchall()])
+ return seed_set
+
+ def select_seed2s_from_sufficient_val(self, amu_id, sufficient_val, slot_num, skill2_id):
+ u""" get seeds set from slot number, skill2_id, amulet id, sufficient value
+ if skill2_id is None, search all skills
+ return (threshold, threshold1_seed2_set, threshold2_seed2_set, inishie_seed2_set)
+ """
+ th1_seeds_set = set()
+ th2_seeds_set = set()
+ ini_seeds_set = set()
+ if amu_id in self._amulet_id2name_dict.keys():
+ table = self._amulet_id2sufficient_table_dict[amu_id]
+ # threshold
+ sql = db_supports.SUFFICIENT_TABLE_SELECT_THRESHOLD_SQL.format(
+ table_name=table, sufficient_val=sufficient_val)
+ self._cursor.execute(sql)
+ try:
+ threshold = self._cursor.fetchone()[slot_num-1]
+ except TypeError, e:
+ threshold = None
+
+ if threshold is not None:
+ table = self._amulet_id2skill2_table_dict[amu_id]
+ if skill2_id is not None:
+ sql1 = db_supports.SEED2_THRESHOLD1_TABLE_SELECT_SEEDS_FROM_THRESHOLD1_AND_SKILL2_SQL.format(
+ threshold1=threshold,
+ skill_table=table,
+ skill_id=skill2_id)
+ sql2 = db_supports.SEED2_THRESHOLD2_TABLE_SELECT_SEEDS_FROM_THRESHOLD2_AND_SKILL2_SQL.format(
+ threshold2=threshold,
+ skill_table=table,
+ skill_id=skill2_id)
+ sql3 = db_supports.SEED2_INISHIE_TABLE_SELECT_SEED2_FROM_SKILL2_THRESHOLD_SQL.format(
+ threshold=threshold,
+ skill2_id=skill2_id)
+ else:
+ sql1 = db_supports.SEED2_THRESHOLD1_TABLE_SELECT_SEEDS_FROM_THRESHOLD1_SQL.format(
+ threshold1=threshold)
+ sql2 = db_supports.SEED2_THRESHOLD2_TABLE_SELECT_SEEDS_FROM_THRESHOLD2_SQL.format(
+ threshold2=threshold)
+ sql3 = db_supports.SEED2_INISHIE_TABLE_SELECT_SEED2_FROM_THRESHOLD_SQL.format(
+ threshold=threshold)
+ self._cursor.execute(sql1)
+ th1_seeds_set = set([x[0] for x in self._cursor.fetchall()])
+ self._cursor.execute(sql2)
+ th2_seeds_set = set([x[0] for x in self._cursor.fetchall()])
+
+ if amu_id == self._amulet_name2id_dict[db_supports.INISHIE_AMULET]:
+ self._cursor.execute(sql3)
+ ini_seeds_set = set([x[0] for x in self._cursor.fetchall()])
+
+ return (threshold, th1_seeds_set, th2_seeds_set, ini_seeds_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_table_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)})