foot_stats_simulator 0.0.4 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -50,6 +50,7 @@ class SimulatorMatch < ActiveRecord::Base
50
50
  belongs_to :home_simulator_team, foreign_key: 'home_team_id', class_name: 'SimulatorTeam'
51
51
  belongs_to :visitor_simulator_team, foreign_key: 'visitor_team_id', class_name: 'SimulatorTeam'
52
52
 
53
+ before_create :populate_data
53
54
  after_create :update_by_timeline
54
55
 
55
56
  def home_team
@@ -66,9 +67,9 @@ class SimulatorMatch < ActiveRecord::Base
66
67
 
67
68
  def readable_status
68
69
  if status
69
- SimulatorMatch::STATUS_SEQUENCE[status.to_sym]
70
+ SimulatorMatch::STATUS_MAP[status.to_sym]
70
71
  else
71
- 0
72
+ SimulatorMatch::STATUS_MAP[:not_started]
72
73
  end
73
74
  end
74
75
 
@@ -133,14 +134,14 @@ class SimulatorMatch < ActiveRecord::Base
133
134
  {
134
135
  "@Id" => home_team.source_id.to_s,
135
136
  "@Nome" => home_team.full_name,
136
- "@Placar" => " ",
137
+ "@Placar" => timeline.home_score.to_s,
137
138
  "@PlacarPenaltis" => "",
138
139
  "@Tipo" => "Mandante"
139
140
  },
140
141
  {
141
142
  "@Id" => visitor_team.source_id.to_s,
142
143
  "@Nome" => visitor_team.full_name,
143
- "@Placar" => " ",
144
+ "@Placar" => timeline.visitor_score.to_s,
144
145
  "@PlacarPenaltis" => "",
145
146
  "@Tipo" => "Visitante"
146
147
  }
@@ -164,8 +165,19 @@ class SimulatorMatch < ActiveRecord::Base
164
165
  end
165
166
 
166
167
  protected
168
+ def populate_data
169
+ self.timeline_random_seed = Random.new_seed unless self.timeline_random_seed
170
+ self.source_id = self.class.dummy_source_id unless self.source_id
171
+ self.home_team_name = home_team.full_name unless self.home_team_name
172
+ self.home_score = 0 unless self.home_score
173
+ self.home_penalties_score = nil unless self.home_penalties_score
174
+ self.visitor_team_name = visitor_team.full_name unless self.visitor_team_name
175
+ self.visitor_score = 0 unless self.visitor_score
176
+ self.visitor_penalties_score = nil unless self.visitor_penalties_score
177
+ end
178
+
167
179
  def update_by_timeline
168
- return if readable_status >= SimulatorMatch::STATUS_SEQUENCE[:finished]
180
+ return if status.nil? || SimulatorMatch::STATUS_SEQUENCE[status.to_sym] >= SimulatorMatch::STATUS_SEQUENCE[:finished]
169
181
  timeline.update_match
170
182
  end
171
183
 
@@ -188,7 +200,6 @@ class SimulatorMatch < ActiveRecord::Base
188
200
  home_team_id: home_team.id,
189
201
  visitor_team_id: visitor_team.id,
190
202
  timeline_name: options[:timeline_name],
191
- source_id: dummy_source_id,
192
203
  date: dummy_date(options[:minutes_from_now]),
193
204
  referee: Faker::Name.name,
194
205
  stadium: "Estádio #{Faker::Name.name}",
@@ -202,21 +213,13 @@ class SimulatorMatch < ActiveRecord::Base
202
213
  cup: '',
203
214
  group: '',
204
215
  game_number: dummy_game_number(championship),
205
- live: options[:live],
206
- home_team_name: home_team.full_name,
207
- home_score: 0,
208
- home_penalties_score: nil,
209
- visitor_team_name: visitor_team.full_name,
210
- visitor_score: 0,
211
- visitor_penalties_score: nil,
212
- timeline_random_seed: Random.new_seed
216
+ live: options[:live]
213
217
  }
214
218
 
215
219
  match = self.create params
216
220
  match
217
221
  end
218
222
 
219
- protected
220
223
  def dummy_source_id
221
224
  source_id = rand(10000)
222
225
  if self.where(source_id: source_id).exists?
@@ -226,6 +229,7 @@ class SimulatorMatch < ActiveRecord::Base
226
229
  end
227
230
  end
228
231
 
232
+ protected
229
233
  def dummy_date(minutes_from_now)
230
234
  minutes_from_now.minutes.from_now
231
235
  end
@@ -19,7 +19,7 @@ class SimulatorPlayer < ActiveRecord::Base
19
19
  if count == 1
20
20
  self.first.to_foot_stats
21
21
  else
22
- { 'Equipe' => all.map(&:to_foot_stats) }
22
+ { 'Jogador' => all.map(&:to_foot_stats) }
23
23
  end
24
24
  end
25
25
  end
@@ -82,7 +82,7 @@ class SimulatorTimeline
82
82
  end
83
83
 
84
84
  def current_period_time
85
- SimulatorMatch::STATUS_SEQUENCE[current_period] || current_period.to_i
85
+ SimulatorMatch::STATUS_SEQUENCE[current_period.to_sym] || current_period.to_i
86
86
  end
87
87
 
88
88
  protected
@@ -1,4 +1,4 @@
1
- class FootStatsSimulator
1
+ module FootStatsSimulator
2
2
  class Engine < ::Rails::Engine
3
3
  isolate_namespace FootStatsSimulator
4
4
 
@@ -35,7 +35,7 @@ ActiveRecord::Migration.create_table :simulator_matches do |t|
35
35
  t.decimal :timeline_random_seed
36
36
 
37
37
  t.integer :source_id
38
- t.time :date
38
+ t.datetime :date
39
39
  t.string :status
40
40
  t.string :referee
41
41
  t.string :stadium
@@ -2,39 +2,45 @@ namespace :foot_stats do
2
2
  namespace :clone do
3
3
  desc "Clones FootStats championships to database"
4
4
  task championship: :environment do
5
- base_url = FootStats.base_url
6
- FootStats.base_url = "http://footstats.com.br/modyo.asmx/"
5
+ base_url = FootStats::Setup.base_url
6
+ FootStats::Setup.base_url = "http://footstats.com.br/modyo.asmx/"
7
7
  SimulatorChampionship.dump!
8
- FootStats.base_url = base_url
8
+ FootStats::Setup.base_url = base_url
9
9
  end
10
10
 
11
11
  desc "Clones FootStats championship teams to database"
12
12
  task team: :environment do
13
- base_url = FootStats.base_url
14
- FootStats.base_url = "http://footstats.com.br/modyo.asmx/"
13
+ base_url = FootStats::Setup.base_url
14
+ FootStats::Setup.base_url = "http://footstats.com.br/modyo.asmx/"
15
15
  SimulatorTeam.dump!
16
- FootStats.base_url = base_url
16
+ FootStats::Setup.base_url = base_url
17
17
  end
18
18
 
19
19
  desc "Clones FootStats players to database"
20
20
  task player: :environment do
21
- base_url = FootStats.base_url
22
- FootStats.base_url = "http://footstats.com.br/modyo.asmx/"
21
+ base_url = FootStats::Setup.base_url
22
+ FootStats::Setup.base_url = "http://footstats.com.br/modyo.asmx/"
23
23
  SimulatorPlayer.dump!
24
- FootStats.base_url = base_url
24
+ FootStats::Setup.base_url = base_url
25
25
  end
26
26
 
27
27
  desc "Clones all FootStats data to database"
28
28
  task data: :environment do
29
- base_url = FootStats.base_url
30
- FootStats.base_url = "http://footstats.com.br/modyo.asmx/"
29
+ base_url = FootStats::Setup.base_url
30
+ FootStats::Setup.base_url = "http://footstats.com.br/modyo.asmx/"
31
31
  SimulatorChampionship.dump!
32
32
  SimulatorTeam.dump!
33
33
  SimulatorPlayer.dump!
34
- FootStats.base_url = base_url
34
+ FootStats::Setup.base_url = base_url
35
35
  end
36
36
  end
37
37
 
38
+ desc "Setups all foot stats related content and create it's tables"
39
+ task bootstrap: :environment do
40
+ Rake::Task["foot_stats:migrate"].execute
41
+ Rake::Task["foot_stats:clone:data"].execute
42
+ end
43
+
38
44
  desc "Deletes all FootStats simulator data stored on database"
39
45
  task clean: :environment do
40
46
  SimulatorChampionship.delete_all
@@ -1,3 +1,3 @@
1
- class FootStatsSimulator
2
- VERSION = '0.0.4'
1
+ module FootStatsSimulator
2
+ VERSION = '1.0.0'
3
3
  end
@@ -3,14 +3,12 @@ require 'foot_stats'
3
3
 
4
4
  require 'faker'
5
5
 
6
- require 'singleton'
7
-
8
- class FootStatsSimulator
9
- attr_accessor :timelines_dir
10
-
11
- include Singleton
6
+ module FootStatsSimulator
7
+ def self.timelines_dir=(path)
8
+ @timelines_dir = path
9
+ end
12
10
 
13
- def self.method_missing(method_name, *args, &block)
14
- instance.send method_name, *args, &block
11
+ def self.timelines_dir
12
+ @timelines_dir
15
13
  end
16
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foot_stats_simulator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: