Skip to content
This repository has been archived by the owner on Feb 18, 2020. It is now read-only.

Commit

Permalink
Merge develop into master. praper v0.3 release.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wegi committed Aug 29, 2016
2 parents ac50ee8 + db359c8 commit 612d504
Show file tree
Hide file tree
Showing 15 changed files with 207 additions and 38 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Changelog

## 0.4 [Upcoming]
## 1.0 [Upcoming]

## 0.3 [WIP]

## 0.3
* Show Pokemon thumbnails
* Don't allow sending away your favorite pokemon
* Add Candy Information
Expand All @@ -13,6 +14,7 @@
* Add button to show status of API connection
* Add reverse sort on click on table header
* Remove need for location. API works locationless now. no more spoofing!
* Add mass-renaming Pokemon according to our defined scheme. Send us a request / an issue to have your scheme added!

## 0.2
* Create automatic build on DockerHub
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ It is a work in progress, so please report all bugs to the issue page.
## Main Features
* **[Installation using pre-build image on DockerHub](https://github.com/Phaetec/pogo-cruncher/wiki/Installation:-Docker-version)**
* [Windows Installation using an Installer](https://github.com/Phaetec/pogo-cruncher/wiki/Installation-with-.exe-for-Windows)
* Mass send-away Pokemon
* Select all Pokemon except your favorites
* Select all Pokemon below a specified IV % Perfect threshold
* Select all Pokemon below a CP threshold
* Mass send-away / rename your Pokemon
* Evolve Pokemon
* Powerup Pokemon
* Mark Pokemon as favorite
Expand Down
17 changes: 17 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,23 @@ def favorite_pokemon():
'set_favorite': set_favorite})


@app.route('/api/pokemon/rename', methods=['POST'])
def rename_pokemon():
global pokemon_deletion_amount
global deleted_pokemon
rename_list = request.json
pokemon_deletion_amount = len(request.json)
deleted_pokemon = 0
for pokemon in rename_list:
req = pokeapi.create_request()
req.nickname_pokemon(pokemon_id=int(pokemon['id']), nickname=pokemon['name'])
req.call()
deleted_pokemon += 1
time.sleep(random.randint(200, 350)/100)

return jsonify({'status': 'ok'})


@app.route('/api/pokemon/upgrade', methods=['POST'])
def upgrade_pokemon():
pokemon_id = int(request.json['id'])
Expand Down
6 changes: 3 additions & 3 deletions example_dump.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"creation_time_ms": 1469380999758,
"height_m": 1.427628755569458,
"id": 4414520284995779213,
"individual_attack": 7,
"individual_defense": 9,
"individual_stamina": 10,
"individual_attack": 15,
"individual_defense": 15,
"individual_stamina": 15,
"move_1": 239,
"move_2": 45,
"pokeball": 1,
Expand Down
2 changes: 1 addition & 1 deletion frontend/project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject cruncher "0.2.11"
(defproject cruncher "0.3"
:description "FIXME: write this!"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/cruncher/communication/progress.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
[cruncher.utils.lib :as lib])
(:require-macros [cljs.core.async.macros :as m :refer [go]]))

(defn finished-progress-handler
"React on response after sending a new statement. Reset atom and call newly received url."
[response]
(lib/update-progress-status! {:status "finished", :to_delete 1, :deleted 1})
(com/route :get-all-pokemon))

(defn update-progress-handler
"Set new app state with the progress information from the API."
[response]
Expand Down
1 change: 1 addition & 0 deletions frontend/src/cruncher/config.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
:get-all-pokemon "api/pokemon"
:toggle-favorite "api/pokemon/favorite"
:crunch-selected-pokemon "api/pokemon/delete"
:rename-selected-pokemon "api/pokemon/rename"
:status-delete "api/status/delete"
:get-player "api/player"
:evolve-pokemon "api/pokemon/evolve"
Expand Down
84 changes: 84 additions & 0 deletions frontend/src/cruncher/rename.cljs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
(ns cruncher.rename
(:require [om.next :as om :refer-macros [defui]]
[om.dom :as dom :include-macros true]
[ajax.core :refer [POST]]
[goog.dom :as gdom]
[cruncher.utils.views :as vlib]
[cruncher.utils.lib :as lib]
[cruncher.config :as config]
[cruncher.communication.progress :as progress]
[cruncher.communication.utils :as clib]
[cruncher.communication.main :as com]))

(defn- dispatch-scheme
"Gets a string containing the user's selection. Construct the new nickname from it."
[scheme iv at df st t1 t2]
(let [iv-int (lib/str->int iv)]
(cond
(and (= "rename-scheme-1" scheme) (= iv-int 100)) (str iv-int "%")
(= "rename-scheme-1" scheme) (str iv-int "% " at "/" df "/" st)
(= "rename-scheme-2" scheme) (str at "/" df "/" st)
(= "rename-scheme-3" scheme) (str iv-int "%")
(= "rename-scheme-4" scheme) (str iv-int "% " t1 "/" t2))))

(defn- create-list-of-new-names
"Returns list of maps like this one: {:id 42, :name 33% 15/0/0}, while :name is also
a string."
[scheme]
(let [rows (gdom/getElementsByClass "poketable-row")]
(doall (remove nil? (map (fn [row]
(let [id (.getAttribute row "data-id")
iv (.getAttribute row "data-iv-perfect")
at (.getAttribute row "data-at")
df (.getAttribute row "data-df")
st (.getAttribute row "data-st")
t1 (.getAttribute row "data-type-1")
t2 (.getAttribute row "data-type-2")
checkbox (gdom/getElement (str "poketable-checkbox-" id))]
(when (.-checked checkbox)
{:id id
:name (dispatch-scheme scheme iv at df st t1 t2)})))
rows)))))

(defn- do-the-rename-dance!
"Rename all selected pokemon according to the selected scheme. Not reversible!"
[this scheme]
(let [url (:rename-selected-pokemon config/api)
new-nicknames (create-list-of-new-names scheme)]
(when (pos? (count new-nicknames))
(lib/loading!)
(lib/update-progress-status! {:status "ok", :to_delete (count new-nicknames), :deleted 0})
(progress/query-status this)
(POST (clib/make-url url)
{:body (clib/clj->json new-nicknames)
:handler progress/finished-progress-handler
:error-handler com/error-handler
:response-format :json
:headers {"Content-Type" "application/json"}
:keywords? true}))))

(defui SelectSchemes
Object
(render [this]
(let [scheme (or (om/get-state this :scheme) "rename-scheme-1")]
(dom/div nil
(dom/div #js {:className "input-group"}
(dom/select #js {:className "form-control"
:onChange #(vlib/commit-component-state this :scheme %)
:value scheme}
(dom/option #js {:value "rename-scheme-1"} "IV% AT/DF/ST")
(dom/option #js {:value "rename-scheme-2"} "AT/DF/ST")
(dom/option #js {:value "rename-scheme-3"} "IV%")
(dom/option #js {:value "rename-scheme-4"} "IV% Type1/Type2"))
(dom/div #js {:className "input-group-btn"}
(vlib/button-primary #(do-the-rename-dance! this scheme) "Rename")))))))
(def select-schemes (om/factory SelectSchemes {}))

(defui RenamingControls
Object
(render [this]
(dom/div nil
(dom/p #js {:className "lead"} "Renaming " (dom/span #js {:className "badge"} "new"))
(dom/label #js {:className "control-label"} "Renames selected Pokemon. Not reversible")
(select-schemes (om/props this)))))
(def controls (om/factory RenamingControls))
10 changes: 10 additions & 0 deletions frontend/src/cruncher/selections.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@
(when favorite (set! (.. checkbox -checked) false))))
rows))))

(defn select-all
"Select all pokemon."
[]
(let [rows (gdom/getElementsByClass "poketable-row")]
(doall (map #(let [id (.getAttribute % "data-id")
checkbox (gdom/getElement (str "poketable-checkbox-" id))]
(set! (.. checkbox -checked) true))
rows))))

(defn unselect-all
"Unselect all pokemon."
[]
Expand Down Expand Up @@ -97,6 +106,7 @@
(dom/div #js {:className "col-md-6"}
(dom/label #js {:className "control-label"} "Clicking a button always overrides manual selections")
(dom/br nil)
(vlib/button-default select-all "All")
(vlib/button-default unselect-all "Unselect")
(vlib/button-default unselect-favorites "Unselect Favorites")
(vlib/button-default select-all-but-favorite "Select all but Favorites"))
Expand Down
16 changes: 6 additions & 10 deletions frontend/src/cruncher/shredder/main.cljs
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
(ns cruncher.shredder.main
(:require [ajax.core :refer [GET POST]]
(:require [ajax.core :refer [POST]]
[goog.dom :as gdom]
[cruncher.utils.lib :as lib]
[cruncher.config :as config]
[cruncher.communication.utils :as clib]
[cruncher.communication.main :as com]
[cruncher.communication.progress :as progress]
[cruncher.selections :as selections]))
[cruncher.selections :as selections]
[cruncher.utils.views :as vlib]))

(defn success-handler
"React on response after sending a new statement. Reset atom and call newly received url."
[response]
(lib/update-progress-status! {:status "finished", :to_delete 1, :deleted 1})
(com/route :get-all-pokemon))

(defn power-on
"Crunch 'em all!"
[this]
(selections/unselect-favorites)
(let [url (:crunch-selected-pokemon config/api)
selected-pokemon (vec (map #(.. % -value) (filter #(.. % -checked) (gdom/getElementsByClass "poketable-checkbox"))))]
(when (pos? (count selected-pokemon))
selected-pokemon (vlib/get-selected-pokemon)]
(when (vlib/selected-pokemon?)
(when (js/confirm "Do you really want to send away the selected Pokemon?\nYou won't get them back!\n\nConsider your decision.")
(lib/loading!)
(lib/update-progress-status! {:status "ok", :to_delete (count selected-pokemon), :deleted 0})
(progress/query-status this)
(POST (clib/make-url url)
{:body (clib/clj->json {:ids selected-pokemon
:safe 1})
:handler success-handler
:handler progress/finished-progress-handler
:error-handler com/error-handler
:response-format :json
:headers {"Content-Type" "application/json"}
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/cruncher/utils/lib.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@


;;;; Helpers
(defn log
"Use JS's console log. Produces beautiful output in combination with cljs.devtools, which should
automatically load when starting the app."
[& strs]
(.log js/console strs))

(defn pokemon-evolution
[pokemon]
(if (= (:name pokemon) "Eevee")
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/cruncher/utils/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,18 @@
(dom/span #js {:dangerouslySetInnerHTML #js {:__html string}}))


;;;; Selections
(defn get-selected-pokemon
"Returns all selected Pokemon."
[]
(vec (map #(.. % -value) (filter #(.. % -checked) (gdom/getElementsByClass "poketable-checkbox")))))

(defn selected-pokemon?
"Returns true if some Pokemon were selected in the DOM."
[]
(pos? (count (get-selected-pokemon))))


;;;; UIs
(defui Loader
; "Spinning icon to indicate if there is data being transferred."
Expand Down
41 changes: 24 additions & 17 deletions frontend/src/cruncher/views.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[cruncher.moves.main :as moves]
[cruncher.selections :as selections]
[cruncher.utils.status :as status]
[cruncher.rename :as rename]
[cruncher.shredder.main :as shredder]
[cruncher.utils.extensions]
[cruncher.utils.lib :as lib]
Expand All @@ -29,14 +30,18 @@
(dom/div #js {:className "row"}
(dom/div #js {:className "col-md-6"}
(dom/p #js {:className "lead"} "Controls")
(dom/label #js {:className "control-label"} "Reload your Pokemon or mass-send them away")
(dom/br nil)
(vlib/button-primary #(com/route :get-all-pokemon) "Load your Pokemon")
(vlib/button-primary #(shredder/power-on this) (dom/span nil (vlib/fa-icon "fa-eraser") " Crunch selected Pokemon")))
(dom/div #js {:className "col-md-6"}
(dom/div #js {:className "col-md-3"}
(dom/div nil (rename/controls (om/props this))))
(dom/div #js {:className "col-md-3"}
(dom/p #js {:className "lead"} "Information")
(dom/div nil (:evolution-number (om/props this)) " Evolutions available")))
(dom/br nil) (dom/br nil)
(selections/controls (om/props this))
(dom/br nil) (dom/br nil)
(dom/br nil)
(dom/div nil (selections/controls (om/props this)))
(dom/br nil)
(dom/div nil (progress/progress-bar (om/props this))))))
(def controls (om/factory Controls))

Expand Down Expand Up @@ -138,7 +143,12 @@
:data-favorite (:favorite pokemon)
:data-id (:id pokemon)
:data-iv-perfect (:individual_percentage pokemon)
:data-cp (:cp pokemon)}
:data-cp (:cp pokemon)
:data-at (:individual_attack pokemon)
:data-df (:individual_defense pokemon)
:data-st (:individual_stamina pokemon)
:data-type-1 (subs (:type move-1) 0 2)
:data-type-2 (subs (:type move-2) 0 2)}
(dom/td nil
(dom/div #js {:className "checkbox"})
(dom/label nil
Expand Down Expand Up @@ -218,8 +228,9 @@
(dom/li nil "Click on the table headers to sort the data")
(dom/li nil "Crunching Pokemon really means you're sending them away -- "
(dom/strong nil "there is no possibility to get them back!!!"))
(dom/li nil "Automated Pokemon crunching takes between 2 and 3 seconds per pokemon to prevent robotic behaviour.")
(dom/li nil "Your selected favorite Pokemon cannot be sent away and are automatically unselected when start sending them away."))
(dom/li nil "Automated Pokemon crunching / renaming takes between 2 and 3 seconds per Pokemon to prevent robotic behaviour.")
(dom/li nil "Your selected favorite Pokemon cannot be sent away and are automatically unselected when start sending them away.")
(dom/li #js {:className "text-info"} "The nicknames of your renamed Pokemon might first be visible after you restart the game on your phone."))
(dom/hr nil))))
(def header (om/factory Header))

Expand All @@ -239,11 +250,10 @@

(defn validate-login-button
"Show Login button and disable it when one of these fields is empty."
[email password location service]
(let [not-empty? (and
(pos? (count email))
(pos? (count password))
(pos? (count service)))]
[email password service]
(let [not-empty? (and (pos? (count email))
(pos? (count password))
(pos? (count service)))]
(vlib/button-primary #(auth/ajax-login email password service) not-empty? "Login")))

(defui Login
Expand All @@ -252,7 +262,6 @@
;; TODO return empty string if om/get-state is empty
(let [email (or (om/get-state this :email) "")
password (or (om/get-state this :password) "")
location (or (om/get-state this :location) "")
service (or (om/get-state this :service) "")]
(dom/div #js {:className "row"}
(dom/div #js {:className "col-md-6 col-md-offset-3"}
Expand All @@ -275,7 +284,7 @@
:type "password"
:placeholder "password"}))
(google-ptc-switch this)
(validate-login-button email password location service))))))))
(validate-login-button email password service))))))))
(def login (om/factory Login))

(defn view-dispatcher
Expand All @@ -297,8 +306,6 @@
(view-dispatcher this)
(dom/div nil (vlib/back-to-top))
(dom/hr nil)
(dom/div nil (status/api-test (om/props this)))
#_(dom/div nil (poketable (om/props this)))
#_(dom/div nil (login)))))
(dom/div nil (status/api-test (om/props this))))))


Binary file modified screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 612d504

Please sign in to comment.