Explorar o código

Query optimization. Skillup report improved. Imperfect monsters handled.

Iñigo Valentin %!s(int64=7) %!d(string=hai) anos
pai
achega
930311e5fa

+ 2 - 3
application/entity/K_Fusion.php

@@ -26,7 +26,7 @@
          */
         public function __construct($db, $id){
             global $path;
-            parent::__construct($db, $id);
+            parent::__construct($db, $id, false);
             $s =
               "SELECT monster.id AS id " .
               "FROM " . 
@@ -39,10 +39,9 @@
               "    k_monster.awakens_from = $id OR " .
               "    k_monster.awakens_to = $id " .
               "  ); ";
-            //error_log($s);
             $q = $this->db->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                array_push($this->owned, new Monster($this->db, $r["id"]));
+                array_push($this->owned, new Monster($this->db, $r["id"], false));
             }
         }
     }

+ 48 - 45
application/entity/K_Monster.php

@@ -52,7 +52,7 @@
          * Default star level.
          */
         public $natural_stars;
-        
+
         /**
          * Indicates if the monster is obtainable.
          */
@@ -201,8 +201,9 @@
          *
          * @param SQLite3 $db Connection to the database.
          * @param int $id Monster identifier.
+         * @param complete If false, query only k_monster.
          */
-        public function __construct($db, $id){
+        public function __construct($db, $id, $complete = true){
             global $path;
             parent::__construct($db);
             $s =
@@ -256,7 +257,7 @@
                 $this->can_awaken = $r["can_awaken"];
                 $this->awaken_bonus = $r["awaken_bonus"];
                 $this->skill_ups_to_max = $r["skill_ups_to_max"];
-                if ($r["leader_skill"]){
+                if ($complete && $r["leader_skill"]){
                     $this->leader_skill = new K_Leader_Skill($this->db, $r["leader_skill"]);
                 }
                 $this->base_hp = $r["base_hp"];
@@ -279,48 +280,50 @@
                 $this->homunculus = $r["homunculus"];
                 $this->craft_cost = $r["craft_cost"];
             }
-            $s =
-              "SELECT " .
-              "  skill " .
-              "FROM " .
-              "  k_skill, " .
-              "  k_monster_skill " .
-              "WHERE " .
-              "  id = skill AND " .
-              "  monster = $id " .
-              "ORDER BY slot; ";
-            $q = $this->db->query($s);
-            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                array_push($this->skill, new K_Skill($this->db, $r["skill"]));
-            }
-            $s =
-              "SELECT " .
-              "  element, " .
-              "  grade, " .
-              "  amount " .
-              "FROM k_monster_essence " .
-              "WHERE " .
-              "  monster = $id " .
-              "ORDER BY " .
-              "  element <> 'Magic', " .
-              "  grade <> 'Low', " .
-              "  grade <> 'Mid'; ";
-            $q = $this->db->query($s);
-            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                $e = [
-                    "element" => $r["element"],
-                    "grade" => $r["grade"],
-                    "amount" => $r["amount"]
-                ];
-                array_push($this->essences, $e);
-            }
-             $s =
-              "SELECT source " .
-              "FROM k_monster_source " .
-              "WHERE monster = $id; ";
-            $q = $this->db->query($s);
-            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                array_push($this->sources, new K_Source($this->db, $r["source"]));
+            if ($complete){
+                $s =
+                "SELECT " .
+                "  skill " .
+                "FROM " .
+                "  k_skill, " .
+                "  k_monster_skill " .
+                "WHERE " .
+                "  id = skill AND " .
+                "  monster = $id " .
+                "ORDER BY slot; ";
+                $q = $this->db->query($s);
+                while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+                    array_push($this->skill, new K_Skill($this->db, $r["skill"]));
+                }
+                $s =
+                "SELECT " .
+                "  element, " .
+                "  grade, " .
+                "  amount " .
+                "FROM k_monster_essence " .
+                "WHERE " .
+                "  monster = $id " .
+                "ORDER BY " .
+                "  element <> 'Magic', " .
+                "  grade <> 'Low', " .
+                "  grade <> 'Mid'; ";
+                $q = $this->db->query($s);
+                while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+                    $e = [
+                        "element" => $r["element"],
+                        "grade" => $r["grade"],
+                        "amount" => $r["amount"]
+                    ];
+                    array_push($this->essences, $e);
+                }
+                $s =
+                "SELECT source " .
+                "FROM k_monster_source " .
+                "WHERE monster = $id; ";
+                $q = $this->db->query($s);
+                while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+                    array_push($this->sources, new K_Source($this->db, $r["source"]));
+                }
             }
         }
 

+ 12 - 92
application/entity/Monster.php

@@ -181,8 +181,9 @@
          *
          * @param SQLite3 $db Connection to the database.
          * @param int $id Monster identifier.
+         * @param complete If false, query only monster and k_monster.
          */
-        public function __construct($db, $id){
+        public function __construct($db, $id, $complete = true){
             global $path;
             parent::__construct($db);
             $s =
@@ -225,7 +226,7 @@
             $this->id = $r["id"];
             $this->com2us_id = $r["com2us_id"];
             if (strlen($r["monster"]) > 0){
-                $this->monster = new K_Monster($this->db, $r["monster"]);
+                $this->monster = new K_Monster($this->db, $r["monster"], $complete);
             }
             $this->stars = $r["stars"];
             $this->level = $r["level"];
@@ -255,97 +256,16 @@
             $this->ignore_for_fusion = $r["ignore_for_fusion"];
             $this->priority = $r["priority"];
             $this->notes = $r["notes"];
-            $s =
-              "SELECT rune " .
-              "FROM monster_rune " .
-              "WHERE monster = '$this->id'; ";
-            $q = $this->db->query($s);
-            while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                array_push($this->rune, new Rune($this->db, $r["rune"]));
+            if ($complete){
+                $s =
+                "SELECT rune " .
+                "FROM monster_rune " .
+                "WHERE monster = '$this->id'; ";
+                $q = $this->db->query($s);
+                while ($r = $q->fetchArray(SQLITE3_ASSOC)){
+                    array_push($this->rune, new Rune($this->db, $r["rune"]));
+                }
             }
         }
-
-        /**
-         * TODO: UNUSED
-         * Gets a stat increase from rune monsters.
-         * 
-         * @param $stat Stat name ("ATK", "DEF", "HP", "SPD", "CRR", "CRD", "RES", "ACC").
-         * @return Value of the base stat (floored integer), -1 if wrong stat.
-         */
-        public function get_rune_stat($stat){
-            switch ($stat){
-                case "ATK":
-                    $base = $this->atk;
-                    $name_flat = 'ATK flat';
-                    $name_perc = 'ATK%';
-                    break;
-                case "DEF":
-                    $base = $this->def;
-                    $name_flat = 'DEF flat';
-                    $name_perc = 'DEF%';
-                    break;
-                case "HP":
-                    $base = $this->hp;
-                    $name_flat = 'HP flat';
-                    $name_perc = 'HP%';
-                    break;
-                case "SPD":
-                    $base = $this->hp;
-                    $name_flat = 'SPD';
-                    $name_perc = '-';
-                    break;
-                case "CRR":
-                    $base = $this->crr;
-                    $name_flat = 'CRate';
-                    $name_perc = '-';
-                    break;
-                case "CRD":
-                    $base = $this->crd;
-                    $name_flat = 'CDmg';
-                    $name_perc = '-';
-                    break;
-                case "RES":
-                    $base = $this->res;
-                    $name_flat = 'RES';
-                    $name_perc = '-';
-                    break;
-                case "ACC":
-                    $base = $this->acc;
-                    $name_flat = 'ACC';
-                    $name_perc = '-';
-                    break;
-                default:
-                    return -1;
-            }
-            $s =
-              "SELECT sum(value) AS v FROM ( " .
-              "  SELECT m_v AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND m_t = '" . $name_flat . "' " .
-              "  UNION " .
-              "  SELECT cast(m_v * " . $base . " / 100 AS int) AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND m_t = '" . $name_perc . "' " .
-              "  UNION " .
-              "  SELECT i_v AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND i_t = '" . $name_flat . "' " .
-              "  UNION " .
-              "  SELECT cast(i_v * " . $base . " / 100 AS int) AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND i_t = '" . $name_perc . "' " .
-              "  UNION " .
-              "  SELECT s1_v AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND s1_t = '" . $name_flat . "' " .
-              "  UNION " .
-              "  SELECT cast(s1_v * " . $base . " / 100 AS int) AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND s1_t = '" . $name_perc . "' " .
-              "  UNION " .
-              "  SELECT s2_v AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND s2_t = '" . $name_flat . "' " .
-              "  UNION " .
-              "  SELECT cast(s2_v * " . $base . " / 100 AS int) AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND s2_t = '" . $name_perc . "' " .
-              "  UNION " .
-              "  SELECT s3_v AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND s3_t = '" . $name_flat . "' " .
-              "  UNION " .
-              "  SELECT cast(s3_v * " . $base . " / 100 AS int) AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND s3_t = '" . $name_perc . "' " .
-              "  UNION " .
-              "  SELECT s4_v AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND s4_t = '" . $name_flat . "' " .
-              "  UNION " .
-              "  SELECT cast(s4_v * " . $base . " / 100 AS int) AS value FROM rune, monster_rune WHERE rune = id AND monster = " . $this->id . " AND s4_t = '" . $name_perc . "' " .
-              ");";
-            $q = $this->db->query($s);
-            $r = $q->fetchArray(SQLITE3_ASSOC);
-            return $r["v"];
-        }
     }
 ?>

+ 1 - 1
application/page/Catalog_Page.php

@@ -40,7 +40,7 @@
             $s_mon = $this->build_query();
             $q_mon = $this->db->query($s_mon);
             while ($r_mon = $q_mon->fetchArray(SQLITE3_ASSOC)){
-                array_push($this->monsters, new K_Monster($db, $r_mon["id"]));
+                array_push($this->monsters, new K_Monster($db, $r_mon["id"], false));
             }
             $this->title = "Catalog - SWDB";
             $this->description = "Catalog of all monsters";

+ 1 - 1
application/page/Fusion_Page.php

@@ -47,7 +47,7 @@
               "ORDER BY stars DESC; ";
             $q = $this->db->query($s);
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
-                array_push($this->products, new K_Monster($this->db, $r["product"]));
+                array_push($this->products, new K_Monster($this->db, $r["product"], false));
             }
             $s = $this->build_query();
             $q = $this->db->query($s);

+ 13 - 2
application/page/Monster_Info_Page.php

@@ -32,7 +32,11 @@
             $this->view = $path["view"] . "monster_info.php";
             $title = "";
             $monster = new K_Monster($db, $id);
+            error_log("ID  : " . $monster->id);
+            error_log("FROM: " . $monster->awakens_from);
+            error_log("TO  : " . $monster->awakens_to);
             if ($monster->can_awaken == 0){
+                error_log("CAN_AWAKEN 0 -> SILVER");
                 // Silver star monster.
                 $this->monster[0] = $monster;
                 $this->monster[1] = null;
@@ -40,31 +44,38 @@
                 $title = $this->monster[0]->element . " " . $this->monster[0]->name;
             }
             elseif ($monster->can_awaken == 1 && $monster->awakens_to == "" && $monster->awakens_from == ""){
+                error_log(" -> DEGFAULT PURPLE");
                 // Default purple (Rainbowmon or King Angelmon)
                 $this->monster[0] = null;
                 $this->monster[1] = $monster;
                 $this->monster[2] = null;
                 $title = $this->monster[1]->name;
             }
-            elseif ($monster->can_awaken == 1 && $monster->awakens_to == "" && $monster->awakens_from =! ""){
+            elseif ($monster->can_awaken == 1 && $monster->awakens_to == "" && strlen($monster->awakens_from) > 0){
+                error_log("NORMAL MONSTER AWAKEN, no 2a. FROM: " . $monster->awakens_from);
                 // Normal monster, already awakened, no 2a.
                 $this->monster[0] = new K_Monster($db, $monster->awakens_from);
                 $this->monster[1] = $monster;
                 $this->monster[2] = null;
                 $title = $this->monster[1]->name . " - " .$this->monster[0]->element . " " . $this->monster[0]->name;
             }
-            elseif ($monster->can_awaken == 1 && $monster->awakens_to != "" && $monster->awakens_from == ""){
+            elseif ($monster->can_awaken == 1 && strlen($monster->awakens_to) > 0 && $monster->awakens_from == ""){
                 // Normal monster, not awakened, may have 2a.
                 $this->monster[0] = $monster;
                 $this->monster[1] = new K_Monster($db, $this->monster[0]->awakens_to);
                 if ($this->monster[1]->awakens_to == ""){
+                    error_log("NORMAL MONSTER, GOLD, NO 2a");
                     $this->monster[2] = null;
                 }
                 else{
+                    error_log("NORMAL MONSTER, GOLD, WITH 2a");
                     $this->monster[2] = new K_Monster($db, $this->monster[1]->awakens_to);
                 }
                 $title = $this->monster[1]->name . " - " .$this->monster[0]->element . " " . $this->monster[0]->name;
             }
+            else{
+                error_log("UNKNOWN");
+            }
 
             $this->title = $title ." - SWDB";
             $this->description = $title . " info - SWDB";

+ 9 - 4
application/page/Report_Runeupgrade_Page.php

@@ -102,7 +102,12 @@
                         "alternative" => [],
                     ];
                 }
-                array_push($rupgrade["alternative"], new Rune($this->db, $r["alternative"]));
+                $rune_alt = new Rune($this->db, $r["alternative"]);
+                // If the alternative rune isassigned
+                if ($this->filters["alternative_source"] > 0 && strlen($rune_alt->assigned_to) > 0){
+                    $rune_alt->assigned_to = new Monster($this->db, $rune_alt->assigned_to);
+                }
+                array_push($rupgrade["alternative"], $rune_alt);
             }
             // Last entries
             array_push($upgrade["upgrade"], $rupgrade);
@@ -135,7 +140,7 @@
                 $this->filters["monster_name"] = SQLite3::escapeString($_GET["monster_name"]);
             }
             // Runes
-            if (isset($_GET["rune_min_stars"]) && intval($_GET["rune_min_stars"]) > 0 && intval($_GET["mnster_min_stars"]) < 7){
+            if (isset($_GET["rune_min_stars"]) && intval($_GET["rune_min_stars"]) > 0 && intval($_GET["rune_min_stars"]) < 7){
                 $this->filters["rune_min_stars"] = $_GET["rune_min_stars"];
             }
             if (isset($_GET["rune_max_stars"]) && intval($_GET["max_stars"]) > 0 && intval($_GET["rune_max_stars"]) < 7){
@@ -239,11 +244,11 @@
                 case 0: // Unassigned
                     $s = $s . " rune_alt.assigned_to IS NULL AND ";
                     break;
-                case 1: // Unassigned or assigneed to lower star monsters
+                case 1: // Unassigned or assigned to lower star monsters
                     $s = $s . 
                       " ( " .
                       " rune_alt.assigned_to IS NULL OR " .
-                      " rune_alt assigned_to IN (SELECT id FROM monster m WHERE m.stars < monster.stars) " .
+                      " rune_alt.assigned_to IN (SELECT id FROM monster m WHERE m.stars < monster.stars) " .
                       " ) AND ";
                     break;
                 // Case 2: Assigned or unassigned.

+ 6 - 6
application/page/Report_Skillup_Page.php

@@ -21,8 +21,8 @@
             "max_stars" => 6,
             "min_natural_stars" => 5,
             "max_natural_stars" => 5,
-            "in_storage" => true,
-            "without_runes" => true,
+            "in_storage" => false,
+            "without_runes" => false,
             "family" => false,
             "maxed" => false,
             "2a" => false
@@ -69,11 +69,11 @@
             if (isset($_GET["max_natural_stars"]) && intval($_GET["max_natural_stars"]) > 0 && intval($_GET["max_natural_stars"]) < 6){
                 $this->filters["max_natural_stars"] = $_GET["max_natural_stars"];
             }
-            if (isset($_GET["in_storage"]) && $_GET["in_storage"] != "on"){
-                $this->filters["in_storage"] = false;
+            if (isset($_GET["in_storage"]) && $_GET["in_storage"] == "on"){
+                $this->filters["in_storage"] = true;
             }
-            if (isset($_GET["without_runes"]) && $_GET["without_runes"] != "on"){
-                $this->filters["without_runes"] = false;
+            if (isset($_GET["without_runes"]) && $_GET["without_runes"] == "on"){
+                $this->filters["without_runes"] = true;
             }
             if (isset($_GET["family"]) && $_GET["family"] == "on"){
                 $this->filters["family"] = true;

+ 3 - 3
application/page/Runes_Page.php

@@ -28,7 +28,7 @@
             "max_quality" => 4,
             "min_original_quality" => 0,
             "max_original_quality" => 4,
-            "min_stars" => 1,
+            "min_stars" => 6,
             "max_stars" => 6,
             "min_level" => 0,
             "max_level" => 15,
@@ -36,7 +36,7 @@
             "max_efficiency" => 100,
             "min_max_efficiency" => 0,
             "max_max_efficiency" => 100,
-            "assigned" => 0,
+            "assigned" => 1,
             "group" => "SLOT"
         ];
 
@@ -58,7 +58,7 @@
             while ($r = $q->fetchArray(SQLITE3_ASSOC)){
                 $rune = new Rune($db, $r["id"]);
                 if (strlen($rune->assigned_to) > 0){
-                    $rune->assigned_to = new Monster($this->db, $rune->assigned_to);
+                    $rune->assigned_to = new Monster($this->db, $rune->assigned_to, false);
                 }
                 array_push($this->runes, $rune);
         }

+ 0 - 24
application/view/catalog.php

@@ -88,30 +88,6 @@
                             <input type='text' name='name' id='filter_name' value='<?=$page->filters["name"]?>'/>
                         </td>
                     </tr>
-                    <tr>
-                        <td class='filter' colspan='2'>
-<?php
-                            $checked = "";
-                            if ($page->filters["in_storage"]){
-                                $checked = "checked";
-                            }
-?>
-                            <input type='checkbox' name='in_storage' <?=$checked?>/>
-                            Show monsters in storage
-                        </td>
-                    </tr>
-                    <tr>
-                        <td class='filter' colspan='2'>
-<?php
-                            $checked = "";
-                            if ($page->filters["without_runes"]){
-                                $checked = "checked";
-                            }
-?>
-                            <input type='checkbox' name='without_runes' <?=$checked?>/>
-                            Show monsters without runes
-                        </td>
-                    </tr>
                 </table>
                 <div id='filter_apply'>
                     <input type='submit' value='Apply'/>

+ 5 - 5
application/view/home.php

@@ -41,7 +41,7 @@
             </h2>
             <article>
                 <h3>
-                    <a href='<?=$root?>catalog'>
+                    <a href='/catalog'>
                         Catalog
                     </a>
                 </h3>
@@ -53,7 +53,7 @@
             </article>
             <article>
                 <h3>
-                    <a href='<?=$root?>monsters'>
+                    <a href='/monsters'>
                         Monsters
                     </a>
                 </h3>
@@ -65,7 +65,7 @@
             </article>
             <article>
                 <h3>
-                    <a href='<?=$root?>runes'>
+                    <a href='/runes'>
                         Runes
                     </a>
                 </h3>
@@ -77,7 +77,7 @@
             </article>
             <article>
                 <h3>
-                    <a href='<?=$root?>fusion'>
+                    <a href='/fusion'>
                         Fusion
                     </a>
                 </h3>
@@ -89,7 +89,7 @@
             </article>
             <article>
                 <h3>
-                    <a href='<?=$root?>report'>
+                    <a href='/report'>
                         Reports
                     </a>
                 </h3>

+ 2 - 2
application/view/monster_info.php

@@ -34,12 +34,12 @@
         include __DIR__ . "/inc/header.php";
         for ($i = 0; $i < 3; $i ++){
             if ($page->monster[$i] != null){
-                if ($i == 0 && monster[1] == null){
+                if ($i == 0 && $page->monster[1] == null){
                     // Silver monster.
                         $star_class ="star_silver";
                     $mon_title = $page->monster[$i]->element . " " . $page->monster[$i]->name;
                 }
-                elseif ($i == 0 && monster[1] != null){
+                elseif ($i == 0 && $page->monster[1] != null){
                     // Gold monster.
                     $star_class ="star_gold";
                     $mon_title = $page->monster[$i]->element . " " . $page->monster[$i]->name;

+ 1 - 1
application/view/report.php

@@ -86,7 +86,7 @@
                             </tr>
                             <tr>
                             <td class='filter' colspan='2'>
-                                <input type='checkbox' name='maxed' <?=$checked?>/>
+                                <input type='checkbox' name='maxed'/>
                                 Show fully skilled-up monster
                             </td>
                             </tr>

+ 11 - 0
application/view/report_runeupgrade.php

@@ -773,6 +773,17 @@
                                                     <?=$alternative->level?>
                                                 </span>
                                             </div> <!-- .rune_panel -->
+<?php
+                                            if ($page->filters["alternative_source"] > 0 && null != $alternative->assigned_to){
+?>
+                                                <div class='assigned'>
+                                                    <a target='blank' href='/monsters/<?=$alternative->assigned_to->id?>'>
+                                                        <img title='<?=$alternative->assigned_to->monster->name?>' class='monster_image border_<?=$alternative->assigned_to->monster->element?>' src='<?=$alternative->assigned_to->monster->get_image()?>'/>
+                                                    </a>
+                                                </div>
+<?php
+                                            }
+?>
                                         </td>
                                         <td class='stats'>
                                             <table>

+ 8 - 8
application/view/runes.php

@@ -774,7 +774,7 @@
                         <tr>
                             <td class='icon'>
                                 <div class='rune_panel rune_slot_<?=$rune->slot?> rune_level_<?=$rune->level?> rune_quality_<?=$rune->quality?> rune_original_quality_<?=$rune->original_quality?>'>
-                                    <img class='rune_base' src=<?=$path["img"]["layout"]?>rune/base.png/>
+                                    <img class='rune_base' src='<?=$path["img"]["layout"]?>rune/base.png'/>
                                     <img class='rune_icon' src='<?=$path["img"]["layout"]?>rune/<?=$rune->type?>.png'/>
                                     <span class='rune_stars'>
 <?php
@@ -790,15 +790,15 @@
                                     </span>
                                 </div>
 <?php
-                                    if ($rune->assigned_to != null){
+                                if ($rune->assigned_to != null){
 ?>
-                                        <div class='assigned'>
-                                            <a target='blank' href='/monsters/<?=$rune->assigned_to->id?>'>
-                                                <img title='<?=$rune->assigned_to->monster->name?>' class='monster_image border_<?=$rune->assigned_to->monster->element?>' src='<?=$rune->assigned_to->monster->get_image()?>'/>
-                                            </a>
-                                        </div>
+                                    <div class='assigned'>
+                                        <a target='blank' href='/monsters/<?=$rune->assigned_to->id?>'>
+                                            <img title='<?=$rune->assigned_to->monster->name?>' class='monster_image border_<?=$rune->assigned_to->monster->element?>' src='<?=$rune->assigned_to->monster->get_image()?>'/>
+                                        </a>
+                                    </div>
 <?php
-                                    }
+                                }
 ?>
                             </td>
                             <td class='stats'>

+ 79 - 3
install_base.py

@@ -283,6 +283,18 @@ def insert(db, table, values):
         raise
     cursor.close;
 
+"""
+Dowwnloads a file.
+
+If OPT_DOWNLOAD is set to false, it will do nothing (but it will still return
+true).
+If OPT_DOWNLOAD_OVERWRITE it will only download the file if the target doesn't
+exist (but it will still return true if it does).
+
+:param url: File url.
+:param target: Full or relative path (whit filename to save the url).
+:returns: True on success, false on error.
+"""
 def download(url, target):
     if OPT_DOWNLOAD == False:
         return True
@@ -294,6 +306,12 @@ def download(url, target):
     except:
         return False
 
+"""
+Parses building date (tables k_building, k_building_level).
+
+:param db: Sqlite database connection.
+:param url: Swarfarm APIv2, buildings.
+"""
 def parseBuildings(db, url):
     print("Parsing buildings...")
     http = urllib3.PoolManager()
@@ -322,6 +340,12 @@ def parseBuildings(db, url):
         else:
             break
 
+"""
+Parses skill data (tables k_skill, k_skill_level, k_skill_effect).
+
+:param db: Sqlite database connection.
+:param url: Swarfarm APIv2, skills.
+"""
 def parseSkills(db, url):
     print("Parsing skills...")
     http = urllib3.PoolManager()
@@ -360,6 +384,12 @@ def parseSkills(db, url):
         else:
             break
 
+"""
+Parses leader skills (table k_leader_skill).
+
+:param db: Sqlite database connection.
+:param url: Swarfarm APIv2, leader-skills.
+"""
 def parseLeaderSkills(db, url):
     print("Parsing leader skills...")
     http = urllib3.PoolManager()
@@ -382,6 +412,12 @@ def parseLeaderSkills(db, url):
         else:
             break
 
+"""
+Parses skill effects (table k_effect).
+
+:param db: Sqlite database connection.
+:param url: Swarfarm APIv2, skill-efects.
+"""
 def parseEffects(db, url):
     print("Parsing skill effects...")
     http = urllib3.PoolManager()
@@ -403,6 +439,12 @@ def parseEffects(db, url):
         else:
             break
 
+"""
+Parses monster sources (table k_source).
+
+:param db: Sqlite database connection.
+:param url: Swarfarm APIv2, craft-materials.
+"""
 def parseSources(db, url):
     print("Parsing sources...")
     http = urllib3.PoolManager()
@@ -424,7 +466,13 @@ def parseSources(db, url):
         else:
             break
 
+"""
+Parses monster data (tables k_monster, k_monster_essence, k_monster_source,
+k_monsster_skill).
 
+:param db: Sqlite database connection.
+:param url: Swarfarm APIv2, monsters.
+"""
 def parseMonsters(db, url):
     print("Parsing monsters...")
     http = urllib3.PoolManager()
@@ -532,9 +580,7 @@ def parseMonsters(db, url):
                 insert(db, "k_monster_source", (id, source["id"]))
             # TODO: craft_materials
             image = "https://swarfarm.com/static/herders/images/monsters/" + mon["image_filename"]
-            #download(image, 'public/img/content/monster/' + str(id).zfill(4) + '.png')
-            if id > 1215:
-                download(image, 'public/img/content/monster/' + str(id).zfill(4) + '.png')
+            download(image, 'public/img/content/monster/' + str(id).zfill(4) + '.png')
 
         # Next page
         db.commit()
@@ -544,6 +590,12 @@ def parseMonsters(db, url):
         else:
             break
 
+"""
+Parses fusion data (table k_fusion).
+
+:param db: Sqlite database connection.
+:param url: Swarfarm APIv2, fusions.
+"""
 def parseFusions(db, url):
     print("Parsing fusions...")
     http = urllib3.PoolManager()
@@ -566,6 +618,12 @@ def parseFusions(db, url):
         else:
             break
 
+"""
+Parses crafting materials (table k_craft).
+
+:param db: Sqlite database connection.
+:param url: Swarfarm APIv2, craft-materials.
+"""
 def parseCraft(db, url):
     print("Parsing crafting materials...")
     http = urllib3.PoolManager()
@@ -586,8 +644,25 @@ def parseCraft(db, url):
         else:
             break
 
+"""
+Removes references to imperfect monsters.
 
+Imperfect monsters are only available in Japanese servers due to legal reasons,
+they are not needed for this app. They wont be deleted, but awakening chains
+wil be cut.
 
+:param db: Sqlite database connection.
+"""
+def removeImperfect():
+    SELECT id, element, name FROM k_monster WHERE awakens_from IN (SELECT id FROM k_monster WHERE name LIKE 'Imperfect %');
+    cursor = db.cursor()
+    cursor.execute('''
+        UPDATE k_monster
+        SET awakens_from = null
+        WHERE awakens_from IN (SELECT id FROM k_monster WHERE name LIKE 'Imperfect %')
+    ''');
+    db.commit()
+    cursor.close()
 
 
 
@@ -603,3 +678,4 @@ parseSources(db, 'https://swarfarm.com/api/v2/monster-sources/')
 parseMonsters(db, 'https://swarfarm.com/api/v2/monsters/')
 parseFusions(db, 'https://swarfarm.com/api/v2/fusions/')
 parseCraft(db, 'https://swarfarm.com/api/v2/craft-materials/')
+removeImperfect(db)

+ 24 - 5
install_user.py

@@ -9,10 +9,10 @@ import sqlite3
 import wget
 import json
 
-user = "ivv0"
+USER = "ivv0"
 
 """
-Opens the database file.
+Opens the database file and deletes from the user tables
 
 :param name: The path to the sqlite database.
 :returns: Connection to the database.
@@ -63,6 +63,12 @@ def insert(db, table, values):
         raise
     cursor.close;
 
+"""
+Parses building data (table building).
+
+:param db: Sqlite database connection.
+:param url: Swarfarm APIv2, building-instances.
+"""
 def parseBuildings(db, url):
     print("Parsing buildings...")
     http = urllib3.PoolManager()
@@ -82,6 +88,12 @@ def parseBuildings(db, url):
         else:
             break
 
+"""
+Parses rune data (table rune).
+
+:param db: Sqlite database connection.
+:param url: Swarfarm APIv2, rune-instances.
+"""
 def parseRunes(db, url):
     print("Parsing runes...")
     http = urllib3.PoolManager()
@@ -316,6 +328,12 @@ def parseRunes(db, url):
         else:
             break
 
+"""
+Parses monster data (tables monster, monster_rune).
+
+:param db: Sqlite database connection.
+:param url: Swarfarm APIv2, monster-instances.
+"""
 def parseMonsters(db, url):
     print("Parsing monsters...")
     http = urllib3.PoolManager()
@@ -368,12 +386,13 @@ def parseMonsters(db, url):
 
 
 
+
 """
 Begin script
 """
 db = openDatabase('application/sw.sqlite')
-parseBuildings(db, 'https://swarfarm.com/api/v2/profiles/' + user +  '/buildings/')
-parseRunes(db, 'https://swarfarm.com/api/v2/profiles/' + user +  '/runes/')
-parseMonsters(db, 'https://swarfarm.com/api/v2/profiles/' + user +  '/monsters/')
+parseBuildings(db, 'https://swarfarm.com/api/v2/profiles/' + USER +  '/buildings/')
+parseRunes(db, 'https://swarfarm.com/api/v2/profiles/' + USER +  '/runes/')
+parseMonsters(db, 'https://swarfarm.com/api/v2/profiles/' + USER +  '/monsters/')
 db.commit()