OSDN Git Service

implement in case skill2=0
authorkei9 <kei9@users.sourceforge.jp>
Sat, 7 Dec 2013 12:19:05 +0000 (21:19 +0900)
committerkei9 <kei9@users.sourceforge.jp>
Sat, 7 Dec 2013 12:19:05 +0000 (21:19 +0900)
amulettool.py
model/db_accessor.py
model/db_supports.py
view/constnumbers.py

index c94bcd2..565d39d 100644 (file)
@@ -139,7 +139,7 @@ class AmuletToolController(wx.App):
             skill_names = [self._skill_id2name_dict[x] for x in skill_ids]
             for combo in combo_dict[amu_key]:
                 combo.Clear()
             skill_names = [self._skill_id2name_dict[x] for x in skill_ids]
             for combo in combo_dict[amu_key]:
                 combo.Clear()
-                combo.Append(u"なし")
+                combo.Append(view.VAL_NO_SKILL)
                 for name in skill_names:
                     combo.Append(name)
                 combo.SetSelection(0)
                 for name in skill_names:
                     combo.Append(name)
                 combo.SetSelection(0)
@@ -158,11 +158,13 @@ class AmuletToolController(wx.App):
                 [self._amulet_id2skill1_id_dict, self._amulet_id2skill2_id_dict]
                 )):
             combo.Clear()
                 [self._amulet_id2skill1_id_dict, self._amulet_id2skill2_id_dict]
                 )):
             combo.Clear()
+            if i == 1:
+                combo.Append(view.VAL_NO_SKILL)
             skill_ids = skill_dict[amulet_id]
             for skill_id in skill_ids:
                 combo.Append(self._skill_id2name_dict[skill_id])
             skill_selected.append(skill_ids[i])
             skill_ids = skill_dict[amulet_id]
             for skill_id in skill_ids:
                 combo.Append(self._skill_id2name_dict[skill_id])
             skill_selected.append(skill_ids[i])
-            combo.SetSelection(i)
+            combo.SetSelection(0)   # combo1 = skill1, combo2 = No Skill
         self._set_spin_range(amulet_id, skill_selected[0], skill_selected[1])
 
     def _set_spin_views(self):
         self._set_spin_range(amulet_id, skill_selected[0], skill_selected[1])
 
     def _set_spin_views(self):
@@ -180,9 +182,14 @@ class AmuletToolController(wx.App):
 
     def _set_spin_range(self, amulet_id, skill1_id, skill2_id):
         u""" スキルに応じてSpinCtrlの最大最小をセットする """
 
     def _set_spin_range(self, amulet_id, skill1_id, skill2_id):
         u""" スキルに応じてSpinCtrlの最大最小をセットする """
-        minmax_dict = self.db_accessor.select_minmax_from_skill_ids(amulet_id, [skill1_id, skill2_id])
-        min1, max1 = minmax_dict[skill1_id][0], minmax_dict[skill1_id][1]
-        min2, max2 = minmax_dict[skill2_id][2], minmax_dict[skill2_id][3]
+        if skill2_id is None:
+            minmax_dict = self.db_accessor.select_minmax_from_skill_ids(amulet_id, [skill1_id])
+            min1, max1 = minmax_dict[skill1_id][0], minmax_dict[skill1_id][1]
+            min2, max2 = 0, 0
+        else:
+            minmax_dict = self.db_accessor.select_minmax_from_skill_ids(amulet_id, [skill1_id, skill2_id])
+            min1, max1 = minmax_dict[skill1_id][0], minmax_dict[skill1_id][1]
+            min2, max2 = minmax_dict[skill2_id][2], minmax_dict[skill2_id][3]
         self.frame_view.spin_ctrl_amulet_search_skill1_val.SetRange(min1, max1)
         self.frame_view.spin_ctrl_amulet_search_skill2_val.SetRange(min2, max2)
 
         self.frame_view.spin_ctrl_amulet_search_skill1_val.SetRange(min1, max1)
         self.frame_view.spin_ctrl_amulet_search_skill2_val.SetRange(min2, max2)
 
@@ -279,7 +286,10 @@ class AmuletToolController(wx.App):
         skill1_name = self.frame_view.combo_box_amulet_search_skill1.GetStringSelection()
         skill2_name = self.frame_view.combo_box_amulet_search_skill2.GetStringSelection()
         skill1_id = self._skill_name2id_dict[skill1_name]
         skill1_name = self.frame_view.combo_box_amulet_search_skill1.GetStringSelection()
         skill2_name = self.frame_view.combo_box_amulet_search_skill2.GetStringSelection()
         skill1_id = self._skill_name2id_dict[skill1_name]
-        skill2_id = self._skill_name2id_dict[skill2_name]
+        if skill2_name in self._skill_name2id_dict:
+            skill2_id = self._skill_name2id_dict[skill2_name]
+        else:
+            skill2_id = None
         if self.frame_view.amulet2radio_button_dict[view.NAME_AMULET1].GetValue():
             amu_id = self._amulet_name2id_dict[view.NAME_AMULET1]
         elif self.frame_view.amulet2radio_button_dict[view.NAME_AMULET2].GetValue():
         if self.frame_view.amulet2radio_button_dict[view.NAME_AMULET1].GetValue():
             amu_id = self._amulet_name2id_dict[view.NAME_AMULET1]
         elif self.frame_view.amulet2radio_button_dict[view.NAME_AMULET2].GetValue():
@@ -310,11 +320,14 @@ class AmuletToolController(wx.App):
         list_box = self.frame_view.list_box_amulet_search_seeds
         if skill1_name == skill2_name:
             self._show_message_dialog(message=u"異なるスキルを選択してください")
         list_box = self.frame_view.list_box_amulet_search_seeds
         if skill1_name == skill2_name:
             self._show_message_dialog(message=u"異なるスキルを選択してください")
-        elif skill1_val == 0 or skill2_val == 0:
-            self._show_message_dialog(message=u"スキルの値には0以外を指定してください")
+        elif skill1_val == 0:
+            self._show_message_dialog(message=u"第1スキルの値には0以外を指定してください")
         else:
             skill1_id = self._skill_name2id_dict[skill1_name]
         else:
             skill1_id = self._skill_name2id_dict[skill1_name]
-            skill2_id = self._skill_name2id_dict[skill2_name]
+            if skill2_name in self._skill_name2id_dict:
+                skill2_id = self._skill_name2id_dict[skill2_name]
+            else:
+                skill2_id = None # for skill2 is 0
             suff_dict = {}
             tup = self.db_accessor.get_sufficient_value(
                 amu_id, skill1_id, skill2_id, skill1_val, skill2_val)
             suff_dict = {}
             tup = self.db_accessor.get_sufficient_value(
                 amu_id, skill1_id, skill2_id, skill1_val, skill2_val)
index 42000b1..97d77b5 100644 (file)
@@ -154,6 +154,7 @@ class DataBaseAccessor(object):
 
     def select_seeds_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
 
     def select_seeds_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
+        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]
         """
         if amu_id in self._amulet_id2name_dict.keys():
             table = self._amulet_id2suff_table_dict[amu_id]
@@ -167,10 +168,14 @@ class DataBaseAccessor(object):
 
             if threshold2 is not None:
                 table = self._amulet_id2second_table_dict[amu_id]
 
             if threshold2 is not None:
                 table = self._amulet_id2second_table_dict[amu_id]
-                sql = db_supports.SECOND_SLOT_TABLE_SELECT_SEEDS_FROM_THRESHOLD_AND_SKILL2_SQL.format(
+                if skill2_id is not None:
+                    sql = db_supports.SECOND_SLOT_TABLE_SELECT_SEEDS_FROM_THRESHOLD_AND_SKILL2_SQL.format(
                         threshold=threshold2,
                         skill_table=table,
                         skill_id=skill2_id)
                         threshold=threshold2,
                         skill_table=table,
                         skill_id=skill2_id)
+                else:
+                    sql = db_supports.SECOND_SLOT_TABLE_SELECT_SEEDS_FROM_THRESHOLD_SQL.format(
+                        threshold=threshold2)
                 self._cursor.execute(sql)
                 return set([x[0] for x in self._cursor.fetchall()])
             else:
                 self._cursor.execute(sql)
                 return set([x[0] for x in self._cursor.fetchall()])
             else:
@@ -237,6 +242,7 @@ class DataBaseAccessor(object):
     def get_sufficient_value(self, amu_id, skill1_id, skill2_id, skill1_val, skill2_val):
         u""" 充足値を計算する。
         指定したスキルが見つからない場合はNoneを返す 
     def get_sufficient_value(self, amu_id, skill1_id, skill2_id, skill1_val, skill2_val):
         u""" 充足値を計算する。
         指定したスキルが見つからない場合はNoneを返す 
+        skill2_idがNoneのときはskill1のみから計算する
         return (sufficient_val, max1, max2)
         """
         
         return (sufficient_val, max1, max2)
         """
         
@@ -246,10 +252,13 @@ class DataBaseAccessor(object):
                     table_name=table,skill_id=skill1_id)
             self._cursor.execute(sql)
             max1 = self._cursor.fetchone()[0]
                     table_name=table,skill_id=skill1_id)
             self._cursor.execute(sql)
             max1 = self._cursor.fetchone()[0]
-            sql = db_supports.MIN_MAX_TABLE_SELECT_MAX2_OF_SKILL_SQL.format(
-                    table_name=table,skill_id=skill2_id)
-            self._cursor.execute(sql)
-            max2 = self._cursor.fetchone()[0]
+            if skill2_id is not None:
+                sql = db_supports.MIN_MAX_TABLE_SELECT_MAX2_OF_SKILL_SQL.format(
+                        table_name=table,skill_id=skill2_id)
+                self._cursor.execute(sql)
+                max2 = self._cursor.fetchone()[0]
+            else:
+                max2 = 1
 
             if max1 is None or max2 is None:
                 return None
 
             if max1 is None or max2 is None:
                 return None
@@ -257,7 +266,10 @@ class DataBaseAccessor(object):
             #print skill1_val, "/", max1 , skill2_val, "/", max2
             try:
                 skill1_val = max1 if skill1_val > max1 else skill1_val
             #print skill1_val, "/", max1 , skill2_val, "/", max2
             try:
                 skill1_val = max1 if skill1_val > max1 else skill1_val
-                skill2_val = max2 if skill2_val > max2 else skill2_val
+                if skill2_id is None:
+                    skill2_val = 0
+                else:
+                    skill2_val = max2 if skill2_val > max2 else skill2_val
                 val1 = (10 * skill1_val) // max1 if skill1_val >= 0 else 0
                 val2 = (10 * skill2_val) // max2 if skill2_val >= 0 else 0
             except TypeError, e:
                 val1 = (10 * skill1_val) // max1 if skill1_val >= 0 else 0
                 val2 = (10 * skill2_val) // max2 if skill2_val >= 0 else 0
             except TypeError, e:
index 0651fc3..ababf69 100644 (file)
@@ -280,6 +280,25 @@ SECOND_SLOT_TABLE_SELECT_SEEDS_FROM_THRESHOLD_AND_SKILL2_SQL = u"""
         slot5=SECOND_COL_SLOT5,
         slot6=SECOND_COL_SLOT6,
         slot7=SECOND_COL_SLOT7)
         slot5=SECOND_COL_SLOT5,
         slot6=SECOND_COL_SLOT6,
         slot7=SECOND_COL_SLOT7)
+SECOND_SLOT_TABLE_SELECT_SEEDS_FROM_THRESHOLD_SQL = u"""
+    select {seed} from {slot_table} 
+    where {slot1} >= {{threshold}} or 
+    {slot2} >= {{threshold}} or 
+    {slot3} >= {{threshold}} or 
+    {slot4} >= {{threshold}} or 
+    {slot5} >= {{threshold}} or 
+    {slot6} >= {{threshold}} or 
+    {slot7} >= {{threshold}}
+    """.format(
+        slot_table=SECOND_SLOT_TABLE_NAME,
+        seed=SECOND_COL_RANDOM_SEED,
+        slot1=SECOND_COL_SLOT1,
+        slot2=SECOND_COL_SLOT2,
+        slot3=SECOND_COL_SLOT3,
+        slot4=SECOND_COL_SLOT4,
+        slot5=SECOND_COL_SLOT5,
+        slot6=SECOND_COL_SLOT6,
+        slot7=SECOND_COL_SLOT7)
 
 # for sufficient value for slots
 SUFFICIENT_MASTER_TABLE_NAME = u"sufficient_master"
 
 # for sufficient value for slots
 SUFFICIENT_MASTER_TABLE_NAME = u"sufficient_master"
index 0aed117..4c91bf7 100644 (file)
@@ -12,6 +12,8 @@ KEY_AMULET2 = u"amulet2"
 KEY_AMULET3 = u"amulet3"
 KEY_THRESHOLD2 = u"threshold2"
 
 KEY_AMULET3 = u"amulet3"
 KEY_THRESHOLD2 = u"threshold2"
 
+VAL_NO_SKILL = u"なし"
+
 SKILL_SEARCH_PAGE = 1
 
 # skill vals
 SKILL_SEARCH_PAGE = 1
 
 # skill vals