OSDN Git Service

revise amulet search to consider of seed1 value,
[amulettoolsmh4/main.git] / model / db_accessor.py
1 # -*- coding: utf-8 -*-
2
3 # database のアクセス用スクリプト
4 # 2013/12/04 written by kei9 
5
6 import sqlite3
7 import sys
8
9 import db_supports
10 from amuletskillsholder import AmuletSkillsHolder
11 from amuletidskillidholder import AmuletIdSkillIdHolder
12 from seedsholder import SeedsHolder
13 from sufficientsholder import SufficientsHolder
14 from skillplaceholder import SkillPlaceHolder
15
16 class DataBaseAccessor(object):
17     u""" this is access class to database """
18     def __init__(self, db_name):
19         u""" db_name is database name to access """
20         self._db_name = db_name
21         self._connect = sqlite3.connect(self._db_name)
22         self._cursor = self._connect.cursor()
23
24         self._skill_id2name_dict, self._skill_name2id_dict = self._get_skill_dict()
25         (self._amulet_id2name_dict, self._amulet_name2id_dict, 
26             self._amulet_id2minmax_table_dict, self._amulet_id2skill2_table_dict,
27             self._amulet_id2sufficient_table_dict,
28             self._amulet_id2skill1_id_dict, self._amulet_id2skill2_id_dict) = self._get_amulet_dict()
29
30     def _print_dicts(self):
31         u""" for debug """
32         print self._skill_id2name_dict
33         print self._skill_name2id_dict
34         print self._amulet_id2name_dict
35         print self._amulet_name2id_dict
36         print self._amulet_id2minmax_table_dict
37         print self._amulet_id2skill2_table_dict
38         print self._amulet_id2sufficient_table_dict
39         print self._amulet_id2skill1_id_dict
40         print self._amulet_id2skill2_id_dict
41
42     def get_dicts(self, clone_enable=False):
43         u""" get all dicts 
44             if clone_enable is True, return cloend dictionary,
45             otherwise return reference dictionary
46
47             returns (skill_id2name_dict, skill_name2id_dict, 
48                 amulet_id2name_dict, amulet_name2id_dict,
49                 amulet_id2skill_ids)
50         """
51         if clone_enable:
52             return (dict(self._skill_id2name_dict), 
53                     dict(self._skill_name2id_dict),
54                     dict(self._amulet_id2name_dict), 
55                     dict(self._amulet_name2id_dict),
56                     dict(self._amulet_id2skill1_id_dict),
57                     dict(self._amulet_id2skill2_id_dict))
58         else:
59             return (self._skill_id2name_dict, 
60                     self._skill_name2id_dict,
61                     self._amulet_id2name_dict, 
62                     self._amulet_name2id_dict,
63                     self._amulet_id2skill1_id_dict,
64                     self._amulet_id2skill2_id_dict)
65
66     def _get_skill_dict(self):
67         u""" create id2name, name2id dict of skill 
68             return (dict_id2name, dict_name2id)
69         """
70         skill_id2name_dict, skill_name2id_dict = {}, {}
71         self._cursor.execute(db_supports.SKILL_TABLE_SELECT_ALL_SQL)
72         for val in self._cursor.fetchall():
73             skill_id, name = val[0], val[1]
74             skill_id2name_dict[skill_id] = name
75             skill_name2id_dict[name] = skill_id
76
77         return skill_id2name_dict, skill_name2id_dict
78
79     def _get_amulet_dict(self):
80         u""" create id2name, name2id, id2minmax_table, id2skill2_table, id2sufficient_table,
81             id2skill1_ids, id2skill2_id dict of amulet 
82         return (dict_id2name, dict_name2id, 
83             id2minmax_table, id2skill2_table, id2sufficient_table, id2skill1_ids, id2skill2_ids)
84         """
85         amulet_id2name_dict, amulet_name2id_dict = {}, {}
86         id2minmax_table, id2skill2_table, id2sufficient_table = {}, {}, {}
87         id2skill1_ids, id2skill2_ids = {}, {}
88         self._cursor.execute(db_supports.AMULET_TABLE_SELECT_ALL_SQL)
89         for val in self._cursor.fetchall():
90             amulet_id, name = val[0], val[1]
91             amulet_id2name_dict[amulet_id] = name
92             amulet_name2id_dict[name] = amulet_id
93
94         # id 2 minmax table name
95         self._cursor.execute(db_supports.MIN_MAX_MASTER_TABLE_SELECT_ALL_SQL)
96         for val in self._cursor.fetchall():
97             amulet_id, table = val[0], val[1]
98             id2minmax_table[amulet_id] = table
99  
100         # id 2 skill2 table name
101         self._cursor.execute(db_supports.SEED2_SKILL2_MASTER_TABLE_SELECT_ALL_SQL)
102         for val in self._cursor.fetchall():
103             amulet_id, table = val[0], val[1]
104             id2skill2_table[amulet_id] = table
105
106         # id 2 sufficient table name
107         self._cursor.execute(db_supports.SUFFICIENT_MASTER_TABLE_SELECT_ALL_SQL)
108         for val in self._cursor.fetchall():
109             amulet_id, table = val[0], val[1]
110             id2sufficient_table[amulet_id] = table
111
112         # id 2 non zero skill1 ids
113         # id 2 non zero skill2 ids
114         for amu_id in amulet_id2name_dict.keys():
115             table = id2minmax_table[amu_id]
116             sql = db_supports.MIN_MAX_TABLE_SELECT_NON_ZERO_SKILL1_ID_SQL.format(table_name=table)
117             self._cursor.execute(sql)
118             ls = [x[0] for x in self._cursor.fetchall()]
119             id2skill1_ids[amu_id] = tuple(ls)
120
121             sql = db_supports.MIN_MAX_TABLE_SELECT_NON_ZERO_SKILL2_ID_SQL.format(table_name=table)
122             self._cursor.execute(sql)
123             ls = [x[0] for x in self._cursor.fetchall()]
124             id2skill2_ids[amu_id] = tuple(ls)
125
126         return (amulet_id2name_dict, amulet_name2id_dict, 
127                 id2minmax_table, id2skill2_table, id2sufficient_table,
128                 id2skill1_ids, id2skill2_ids)
129
130     def select_seed2s(self, amu_id2skill_id_list_dict):
131         u""" select seed2 from dict of amulet_id to skill2_id_list,
132         skill_id_list: list of skill_id, if skill_id is unknown, skill_id must be None
133         """
134         seed_set = None
135         for key, val in amu_id2skill_id_list_dict.items():
136             if key in self._amulet_id2skill2_table_dict:
137                 second_skill_table = self._amulet_id2skill2_table_dict[key]
138                 amulet_skill = AmuletSkillsHolder(val)
139
140                 if amulet_skill.is_empty():
141                     continue
142
143                 sql = db_supports.SEED2_SKILL2_TABLE_SELECT_SEED_SQL.format(table_name=second_skill_table) + amulet_skill.get_where_and_sql()
144                 self._cursor.execute(sql)
145
146                 if seed_set is None:
147                     seed_set = set([x[0] for x in self._cursor.fetchall()])
148                 else:
149                     seed_set = seed_set.intersection(set([x[0] for x in self._cursor.fetchall()]))
150
151         if seed_set is None:
152             return set()
153         else:
154             return seed_set
155
156     def select_skill2_place(self, amulet_id, seed2, skill2_id):
157         u""" Seed2、第2スキルid、お守りidから、指定されたSeed2において
158         Skill2_idが何枠目に属しているか判定し、判定された枠のタプルを返す
159         return (skill2's indexes)"""
160         second_skill_table = self._amulet_id2skill2_table_dict[amulet_id]
161         sql = db_supports.SEED2_SKILL2_TABLE_SELECT_ALL_FROM_SEED2_SQL.format(table_name=second_skill_table,seed2=seed2)
162         self._cursor.execute(sql)
163         row = self._cursor.fetchone() # seed2, skill_id1, ..., skill_id7
164         if row is not None and len(row) > 1:
165             return tuple([i for i, x in enumerate(row, 0) if x == skill2_id])
166         else:
167             return tuple()
168
169     def count_seed1s_from_skill_place(self, skill1_id, skill_places, amulet_id):
170         u""" お守りIdと、第1スキルの種類と出現枠を指定し、
171         それを満たすSeed1の個数を天運555と天運888に分けて返す"""
172         if skill_places is not None and len(skill_places) > 0:
173             # tenun 555
174             if 6 in skill_places:
175                 places555 = list(skill_places).remove(6)
176                 places555 = [] if places555 is None else place555
177             else:
178                 places555 = list(skill_places)
179             place_holder = SkillPlaceHolder(places555, skill1_id)
180             if len(places555) > 0:
181                 sql555 = (db_supports.SEED1_TENUN555_TABLE_COUNT_SEED1_SQL +
182                         place_holder.get_skill1_where_or_sql(amulet_id))
183             else:
184                 sql555 = None
185             # tenun888
186             place_holder = SkillPlaceHolder(skill_places, skill1_id)
187             sql888 = (db_supports.SEED1_TENUN888_TABLE_COUNT_SEED1_SQL +
188                         place_holder.get_skill1_where_or_sql(amulet_id))
189         else:
190             return 0, 0
191
192         if sql555 is not None:
193             self._cursor.execute(sql555)
194             seeds_555 = self._cursor.fetchone()[0]
195         else:
196             seeds_555 = 0
197
198         self._cursor.execute(sql888)
199         seeds_888 = self._cursor.fetchone()[0]
200
201         return seeds_555, seeds_888
202
203     def select_seed1s_from_skill_place(self, skill1_id, skill_places, amulet_id):
204         u""" お守りIdと、第1スキルの種類と出現枠を指定し、
205         それを満たすSeed1のセットを天運555と天運888に分けて返す"""
206         if skill_places is not None and len(skill_places) > 0:
207             # tenun 555
208             if 6 in skill_places:
209                 places555 = list(skill_places).remove(6)
210                 places555 = [] if places555 is None else place555
211             else:
212                 places555 = list(skill_places)
213             place_holder = SkillPlaceHolder(places555, skill1_id)
214             if len(places555) > 0:
215                 sql555 = (db_supports.SEED1_TENUN555_TABLE_SELECT_SEED1_SQL +
216                         place_holder.get_skill1_where_or_sql(amulet_id))
217             else:
218                 sql555 = None
219             # tenun888
220             place_holder = SkillPlaceHolder(skill_places, skill1_id)
221             sql888 = (db_supports.SEED1_TENUN888_TABLE_SELECT_SEED1_SQL +
222                         place_holder.get_skill1_where_or_sql(amulet_id))
223         else:
224             return set(), set()
225         seeds_555, seeds_888 = set(), set()
226         if sql555 is not None:
227             self._cursor.execute(sql555)
228             seeds_555 = set([x[0] for x in self._cursor.fetchall()])
229         self._cursor.execute(sql888)
230         seeds_888 = set([x[0] for x in self._cursor.fetchall()])
231
232         return seeds_555, seeds_888
233
234     def select_seed1s_tenun(self, amu_id_skill1_id_list, key_tenun):
235         u""" select seed1 from list of amulet_id and skill1_id,
236         key_tenun must be KEY_TENUN555 or KEY_TENUN888
237         result_num: result number of amulet
238         when either amu_id or skill1_id is None, this means that no. has no result
239         """
240         result_num = len(amu_id_skill1_id_list)
241         for amu_id, skill1_id in reversed(amu_id_skill1_id_list):
242             if amu_id is not None and skill1_id is not None:
243                 break
244             else:
245                 result_num -= 1
246         amulet_ids = [x[0] for x in amu_id_skill1_id_list[:result_num]]
247         skill1_ids = [x[1] for x in amu_id_skill1_id_list[:result_num]]
248         holder = AmuletIdSkillIdHolder(amulet_ids, skill1_ids)
249
250         if key_tenun == db_supports.KEY_TENUN555:
251             sql = db_supports.SEED1_TENUN555_TABLE_SELECT_SQL + holder.get_where_and_sql()
252         elif key_tenun == db_supports.KEY_TENUN888:
253             sql = db_supports.SEED1_TENUN888_TABLE_SELECT_SQL + holder.get_where_and_sql()
254         else:
255             raise NotImplementedError(u"Tenun must be 555 or 888")
256         self._cursor.execute(sql)
257         seed_set = set([x[0] for x in self._cursor.fetchall()])
258         return seed_set
259
260     def select_seed2s_from_sufficient_val(self, amu_id, sufficient_val, slot_num, skill2_id):
261         u""" get seeds set from slot number, skill2_id, amulet id, sufficient value
262         if skill2_id is None, search all skills
263         return (threshold, threshold1_seed2_set, threshold2_seed2_set, inishie_seed2_set)
264         """
265         th1_seeds_set = set()
266         th2_seeds_set = set()
267         ini_seeds_set = set()
268         if amu_id in self._amulet_id2name_dict.keys():
269             table = self._amulet_id2sufficient_table_dict[amu_id]
270             # threshold
271             sql = db_supports.SUFFICIENT_TABLE_SELECT_THRESHOLD_SQL.format(
272                     table_name=table, sufficient_val=sufficient_val)
273             self._cursor.execute(sql)
274             try:
275                 threshold = self._cursor.fetchone()[slot_num-1]
276             except TypeError, e:
277                 threshold = None
278
279             if threshold is not None:
280                 table = self._amulet_id2skill2_table_dict[amu_id]
281                 if skill2_id is not None:
282                     sql1 = db_supports.SEED2_THRESHOLD1_TABLE_SELECT_SEEDS_FROM_THRESHOLD1_AND_SKILL2_SQL.format(
283                         threshold1=threshold,
284                         skill_table=table,
285                         skill_id=skill2_id)
286                     sql2 = db_supports.SEED2_THRESHOLD2_TABLE_SELECT_SEEDS_FROM_THRESHOLD2_AND_SKILL2_SQL.format(
287                         threshold2=threshold,
288                         skill_table=table,
289                         skill_id=skill2_id)
290                     sql3 = db_supports.SEED2_INISHIE_TABLE_SELECT_SEED2_FROM_SKILL2_THRESHOLD_SQL.format(
291                         threshold=threshold,
292                         skill2_id=skill2_id)
293                 else:
294                     sql1 = db_supports.SEED2_THRESHOLD1_TABLE_SELECT_SEEDS_FROM_THRESHOLD1_SQL.format(
295                         threshold1=threshold)
296                     sql2 = db_supports.SEED2_THRESHOLD2_TABLE_SELECT_SEEDS_FROM_THRESHOLD2_SQL.format(
297                         threshold2=threshold)
298                     sql3 = db_supports.SEED2_INISHIE_TABLE_SELECT_SEED2_FROM_THRESHOLD_SQL.format(
299                         threshold=threshold)
300                 self._cursor.execute(sql1)
301                 th1_seeds_set = set([x[0] for x in self._cursor.fetchall()])
302                 self._cursor.execute(sql2)
303                 th2_seeds_set = set([x[0] for x in self._cursor.fetchall()])
304
305                 if amu_id == self._amulet_name2id_dict[db_supports.INISHIE_AMULET]:
306                     self._cursor.execute(sql3)
307                     ini_seeds_set = set([x[0] for x in self._cursor.fetchall()])
308
309         return (threshold, th1_seeds_set, th2_seeds_set, ini_seeds_set)
310
311     def select_minmax_from_skill_ids(self, amulet_id, skill_ids):
312         u""" お守りのidとスキルidのリストから、スキルIDと取りうるスキルの最大最小値の辞書を得る
313             return dict{skill_id:(min1, max1, min2, max2)}
314         """
315         minmax_table = self._amulet_id2minmax_table_dict[amulet_id]
316         amulet_skill = AmuletSkillsHolder(skill_ids)
317         result_dict = {}
318         if amulet_skill.is_empty() is False:
319             sql = db_supports.MIN_MAX_TABLE_SELECT_ALL_SQL.format(table_name=minmax_table) + amulet_skill.get_where_in_sql()
320             self._cursor.execute(sql)
321
322             for row in self._cursor.fetchall():
323                 result_dict[row[0]] = tuple(row[1:])
324         return result_dict
325
326     def select_threshold_from_sufficient(self, amulet_id, sufficient_vals):
327         u""" お守りのidと充足値のリストから、充足値とスロットごとの判定値の辞書を得る
328             return dict({sufficient_val:(slot1_th, slot2_th, slot3_th)})
329         """
330         suff_table = self._amulet_idsufficient_table_dict[amulet_id]
331         amulet_skill = SufficientsHolder(sufficient_vals)
332         result_dict = {}
333         if amulet_skill.is_empty() is False:
334             sql = db_supports.SUFFICIENT_TABLE_SELECT_ALL_SQL.format(table_name=suff_table) + amulet_skill.get_where_in_sql()
335             self._cursor.execute(sql)
336
337             for row in self._cursor.fetchall():
338                 result_dict[row[0]] = tuple(row[1])
339         return result_dict
340
341     def select_skill2s_from_seed2s(self, seed_set):
342         u""" get amulet id to (random_seed2 to skill ids dict) dict,
343         and random_seed2 to threshold1 dict
344         and random_seed2 to threshold2 dict
345         return: skill_dict, threshold1_dict, threshold2_dict
346         """
347         skill_dict, threshold1_dict, threshold2_dict = {}, {}, {}
348
349         # skill dict
350         seeds = SeedsHolder(seed_set)
351         for amu_id, table in self._amulet_id2skill2_table_dict.items():
352             sql = db_supports.SEED2_SKILL2_TABLE_SELECT_ALL_SQL.format(
353                     table_name=table) + seeds.get_where_in_sql()
354             self._cursor.execute(sql)
355             seed2skills_dic = {}
356             for row in self._cursor.fetchall():
357                 seed2skills_dic[row[0]] = [x for x in row[1:]]
358             skill_dict[amu_id] = seed2skills_dic
359
360         # threshold1 dict
361         sql = db_supports.SEED2_THRESHOLD1_TABLE_SELECT_ALL_SQL + seeds.get_where_in_sql()
362         self._cursor.execute(sql)
363         for row in self._cursor.fetchall():
364             threshold1_dict[row[0]] = [x for x in row[1:]]
365
366         # threshold2 dict
367         sql = db_supports.SEED2_THRESHOLD2_TABLE_SELECT_ALL_SQL + seeds.get_where_in_sql()
368         self._cursor.execute(sql)
369         for row in self._cursor.fetchall():
370             threshold2_dict[row[0]] = [x for x in row[1:]]
371
372         return skill_dict, threshold1_dict, threshold2_dict
373
374     def select_inishie_skill2_from_seed2(self, seed2_set):
375         u""" get inishie's dict of (skill2_id, threshold1, threshold2) from seed2 value """
376         result_dict = {}
377         for seed2 in seed2_set:
378             sql = db_supports.SEED2_INISHIE_TABLE_SELECT_FROM_SEED2_SQL.format(seed2=seed2)
379             self._cursor.execute(sql)
380             row = self._cursor.fetchone()
381             result_dict[seed2] = (row[0], row[1], row[2])
382         return result_dict
383
384     def select_table_nos_from_seed2(self, seed2_set):
385         u""" get dict of (table_no, no) from seed2 value """
386         result_dict = {}
387         for seed2 in seed2_set:
388             sql = db_supports.SEED2_TABLE_NO_TABLE_SELECT_FROM_SEED2_SQL.format(seed2=seed2)
389             self._cursor.execute(sql)
390             row = self._cursor.fetchone()
391             result_dict[seed2] = (row[0], row[1])
392         return result_dict
393
394     def select_table_nos_from_seed1(self, seed1_set, key_tenun):
395         u""" get dict of (table_no, no) from seed1 value based on key_tenun"""
396         result_dict = {}
397         if key_tenun == db_supports.KEY_TENUN555:
398             sql_format = db_supports.SEED1_TENUN555_TABLE_SELECT_TABLE_NOS_FROM_SEED1_SQL
399         elif key_tenun == db_supports.KEY_TENUN888:
400             sql_format = db_supports.SEED1_TENUN888_TABLE_SELECT_TABLE_NOS_FROM_SEED1_SQL
401         else:
402             raise NotImplementedError(u"Tenun must be 555 or 888")
403
404         for seed1 in seed1_set:
405             sql = sql_format.format(seed1=seed1)
406             self._cursor.execute(sql)
407             row = self._cursor.fetchone()
408             result_dict[seed1] = (row[0], row[1])
409         return result_dict
410
411     def select_near_seed1s_from_seed1(self, seed1, smaller_num, larger_num, key_tenun):
412         u""" get list of (no, seed1) near arg's seed1 
413         smaller_num means numbers to get smaller than arg's seed1
414         larger_num means numbers to get larger than arg's seed1"""
415         result_list = []
416         if key_tenun == db_supports.KEY_TENUN555:
417             sql_format = db_supports.SEED1_TENUN555_TABLE_SELECT_NEAR_SEED1S_FROM_NO_SQL
418         elif key_tenun == db_supports.KEY_TENUN888:
419             sql_format = db_supports.SEED1_TENUN888_TABLE_SELECT_NEAR_SEED1S_FROM_NO_SQL
420         else:
421             raise NotImplementedError(u"Tenun must be 555 or 888")
422         table_no, no = self.select_table_nos_from_seed1([seed1], key_tenun)[seed1]
423         sql = sql_format.format(table_no=table_no,min_no=(no-smaller_num),max_no=(no+larger_num))
424         self._cursor.execute(sql)
425         for row in self._cursor.fetchall():
426             result_list.append((row[0], row[1]))
427         return result_list
428
429     def select_all_from_seed1s(self, seed1_set, key_tenun):
430         u""" seed1に対応する(no, table_no, result_num, 
431         (amulet_id1, ..., amulet_id7), (skill1_id1, ..., skill1_id7))
432         の辞書を得る。存在しない場所はNoneで置き換えてある。
433         """
434         result_dict = {}
435         if key_tenun == db_supports.KEY_TENUN555:
436             sql_format = db_supports.SEED1_TENUN555_TABLE_SELECT_ALL_FROM_SEED1_SQL
437         elif key_tenun == db_supports.KEY_TENUN888:
438             sql_format = db_supports.SEED1_TENUN888_TABLE_SELECT_ALL_FROM_SEED1_SQL
439         else:
440             raise NotImplementedError(u"Tenun must be 555 or 888")
441
442         for seed1 in seed1_set:
443             sql = sql_format.format(seed1=seed1)
444             self._cursor.execute(sql)
445             row = self._cursor.fetchone()
446             if key_tenun == db_supports.KEY_TENUN555:
447                 amu_ids = [None if x == db_supports.NO_DATA else x for x in row[3:9]]
448                 skill_ids = [None if x == db_supports.NO_DATA else x for x in row[9:15]]
449             elif key_tenun == db_supports.KEY_TENUN888:
450                 amu_ids = [None if x == db_supports.NO_DATA else x for x in row[3:10]]
451                 skill_ids = [None if x == db_supports.NO_DATA else x for x in row[10:17]]
452             else:
453                 raise NotImplementedError(u"Tenun must be 555 or 888")
454             result_dict[seed1] = (row[0], row[1], row[2], amu_ids, skill_ids)
455         return result_dict
456
457     def get_sufficient_value(self, amu_id, skill1_id, skill2_id, skill1_val, skill2_val):
458         u""" 充足値を計算する。
459         指定したスキルが見つからない場合はNoneを返す 
460         skill2_idがNoneのときはskill1のみから計算する
461         return (sufficient_val, max1, max2)
462         """
463         if amu_id in self._amulet_id2minmax_table_dict:
464             table = self._amulet_id2minmax_table_dict[amu_id]
465             sql = db_supports.MIN_MAX_TABLE_SELECT_MAX1_OF_SKILL_SQL.format(
466                     table_name=table,skill_id=skill1_id)
467             self._cursor.execute(sql)
468             max1 = self._cursor.fetchone()[0]
469             if skill2_id is not None:
470                 sql = db_supports.MIN_MAX_TABLE_SELECT_MAX2_OF_SKILL_SQL.format(
471                         table_name=table,skill_id=skill2_id)
472                 self._cursor.execute(sql)
473                 max2 = self._cursor.fetchone()[0]
474             else:
475                 max2 = 1
476
477             if max1 is None or max2 is None:
478                 return None
479
480             #print skill1_val, "/", max1 , skill2_val, "/", max2
481             try:
482                 skill1_val = max1 if skill1_val > max1 else skill1_val
483                 if skill2_id is None:
484                     skill2_val = 0
485                 else:
486                     skill2_val = max2 if skill2_val > max2 else skill2_val
487                 val1 = (10 * skill1_val) // max1 if skill1_val >= 0 else 0
488                 val2 = (10 * skill2_val) // max2 if skill2_val >= 0 else 0
489             except TypeError, e:
490                 return None
491             except ZeroDivisionError, e:
492                 return None
493             else:
494                 return  (val1 + val2, max1, max2)
495
496         else:
497             return None
498
499     def get_skill_minmax(self):
500         u""" 全てのお守りのスキルにおいて、その最大値と最小値を返す 
501             return (min1, max1, min2, max2)
502         """
503         min1_ls, max1_ls, min2_ls, max2_ls = [],[],[],[]
504         # get min max of each amulet
505         for amu_id, table in self._amulet_id2minmax_table_dict.items():
506             sql = db_supports.MIN_MAX_TABLE_SELECT_MIN1_SQL.format(table_name=table)
507             self._cursor.execute(sql)
508             min1_ls.append(self._cursor.fetchone()[0])
509
510             sql = db_supports.MIN_MAX_TABLE_SELECT_MAX1_SQL.format(table_name=table)
511             self._cursor.execute(sql)
512             max1_ls.append(self._cursor.fetchone()[0])
513
514             sql = db_supports.MIN_MAX_TABLE_SELECT_MIN2_SQL.format(table_name=table)
515             self._cursor.execute(sql)
516             min2_ls.append(self._cursor.fetchone()[0])
517
518             sql = db_supports.MIN_MAX_TABLE_SELECT_MAX2_SQL.format(table_name=table)
519             self._cursor.execute(sql)
520             max2_ls.append(self._cursor.fetchone()[0])
521
522         return (min(min1_ls), max(max1_ls), min(min2_ls), max(max2_ls))
523
524     def get_skill_ids(self, amulet_id):
525         u""" 全てのお守りのスキルにおいて、その最大値と最小値を返す 
526             return (min1, max1, min2, max2)
527         """
528         min1_ls, max1_ls, min2_ls, max2_ls = [],[],[],[]
529         # get min max of each amulet
530         for amu_id, table in self._amulet_id2minmax_table_dict.items():
531             sql = db_supports.MIN_MAX_TABLE_SELECT_MIN1_SQL.format(table_name=table)
532             self._cursor.execute(sql)
533             min1_ls.append(self._cursor.fetchone()[0])
534
535             sql = db_supports.MIN_MAX_TABLE_SELECT_MAX1_SQL.format(table_name=table)
536             self._cursor.execute(sql)
537             max1_ls.append(self._cursor.fetchone()[0])
538
539             sql = db_supports.MIN_MAX_TABLE_SELECT_MIN2_SQL.format(table_name=table)
540             self._cursor.execute(sql)
541             min2_ls.append(self._cursor.fetchone()[0])
542
543             sql = db_supports.MIN_MAX_TABLE_SELECT_MAX2_SQL.format(table_name=table)
544             self._cursor.execute(sql)
545             max2_ls.append(self._cursor.fetchone()[0])
546
547         return (min(min1_ls), max(max1_ls), min(min2_ls), max(max2_ls))
548
549     def close(self):
550         u""" close database accessor """
551         self._cursor.close()
552         self._connect.close()
553
554 if __name__ == "__main__":
555     db = DataBaseAccessor("test.sqlite3")
556     #db._print_dicts()
557     hikari = [None, 57, None, None, None, None, None]
558     huru = [54, None, None, None, None, None, None]
559     #yuga = [None, None, 98, 75, None, None, None]
560     yuga = [None, None, 98, None, None, None, None]
561     dic = {2:hikari, 3:huru, 4:yuga}
562     #seeds = db.select_seeds(dic)
563     seeds = set([58241, 176])
564     skill_dic, slot_dic = db.select_skills_from_seeds(seeds)
565
566     print "seeds: ", seeds
567     print "amu_id to seed2skill dict: ", skill_dic
568     print "seed2slot dict", slot_dic
569     db.close()