about summary refs log tree commit diff stats
path: root/app/jobs
diff options
context:
space:
mode:
authorKelly Rauchenberger <fefferburbia@gmail.com>2017-09-23 10:33:18 -0400
committerKelly Rauchenberger <fefferburbia@gmail.com>2017-09-23 10:33:18 -0400
commite21e91ab9eefd9db5e73a67afca5087e4dd293fd (patch)
tree6e13aa2552721323557cb5a517e1f241ec1dc5b9 /app/jobs
parentf6cdc2fd2f50224fb7dd31d3ccb374cf4ffe7b6d (diff)
downloadpokeviewer-e21e91ab9eefd9db5e73a67afca5087e4dd293fd.tar.gz
pokeviewer-e21e91ab9eefd9db5e73a67afca5087e4dd293fd.tar.bz2
pokeviewer-e21e91ab9eefd9db5e73a67afca5087e4dd293fd.zip
Started writing extractor
Diffstat (limited to 'app/jobs')
-rw-r--r--app/jobs/pokeviewer/extract_save_data_job.rb88
1 files changed, 88 insertions, 0 deletions
diff --git a/app/jobs/pokeviewer/extract_save_data_job.rb b/app/jobs/pokeviewer/extract_save_data_job.rb new file mode 100644 index 0000000..193bd73 --- /dev/null +++ b/app/jobs/pokeviewer/extract_save_data_job.rb
@@ -0,0 +1,88 @@
1module Pokeviewer
2 class ExtractSaveDataJob < ApplicationJob
3 queue_as :default
4
5 def perform(args)
6 game = Trainer.find_or_create_by!(
7 name: args["playerName"],
8 number: args["playerId"]) do |r|
9 case args["gameId"].to_i
10 when 1
11 r.game = :ruby
12 when 2
13 r.game = :sapphire
14 when 3
15 r.game = :firered
16 when 4
17 r.game = :leafgreen
18 when 5
19 r.game = :emerald
20 else
21 # Invalid, so just leave the field nil
22 end
23 end
24
25 pokemons = args["pokemon"].map do |param|
26 pk = Pokemon.find_or_create_by!(key: param["key"]) do |r|
27 r.species_id = param["species"]
28 r.ot_name = param["otName"]
29 r.ot_number = param["otId"]
30 r.met_type = :normal
31 r.met_level = param["metLevel"]
32 r.shiny = param["shiny"]
33 r.nature = Pokemon.nature.values[param["nature"]]
34 r.gender = param["gender"]
35 r.second_ability = param["secondAbility"]
36
37 # Handle Unown form
38 if r.species_id == 201
39 r.unown_letter = Pokemon.unown_letter.values[param["unownLetter"]]
40 end
41 end
42
43 rev = Revision.new(pokemon: pk)
44 rev.nickname = param["nickname"]
45 rev.experience = param["experience"]
46 rev.level = param["level"]
47 rev.hp = param["hp"]
48 rev.attack = param["attack"]
49 rev.defense = param["defense"]
50 rev.special_attack = param["spAttack"]
51 rev.special_defense = param["spDefense"]
52 rev.speed = param["speed"]
53 rev.coolness = param["coolness"]
54 rev.beauty = param["beauty"]
55 rev.cuteness = param["cuteness"]
56 rev.smartness = param["smartness"]
57 rev.toughness = param["toughness"]
58 rev.sheen = param["sheen"]
59 rev.hold_item = param["heldItem"]
60 rev.move_1_id = param["moves"][0]["id"]
61 rev.move_1_pp_bonuses = param["moves"][0]["ppBonuses"]
62
63 if param["moves"].length >= 2
64 rev.move_2_id = param["moves"][1]["id"]
65 rev.move_2_pp_bonuses = param["moves"][1]["ppBonuses"]
66 end
67
68 if param["moves"].length >= 3
69 rev.move_3_id = param["moves"][2]["id"]
70 rev.move_3_pp_bonuses = param["moves"][2]["ppBonuses"]
71 end
72
73 if param["moves"].length == 4
74 rev.move_4_id = param["moves"][3]["id"]
75 rev.move_4_pp_bonuses = param["moves"][3]["ppBonuses"]
76 end
77
78 if pk.revisions.empty? or rev.diff?(pk.revisions.last)
79 rev.save!
80 end
81
82 pk
83 end
84
85 game.pokemon = pokemons
86 end
87 end
88end