nature 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23b4e11e530f92323e9d996074b3cb5ebef6d456
4
- data.tar.gz: 87a042730ab16c8cfd5637abb2fadb6532d721c9
3
+ metadata.gz: 5666d866d9b3160c4c3a91451f5fcc36ac079474
4
+ data.tar.gz: 136a26866ec4bd6ea2c2a9c61a0e844a7a72e656
5
5
  SHA512:
6
- metadata.gz: 1d874388a685196b94477ebf87a1d02259e388ddd0e519c73d1be8bd7acf7323b0ffc1c4d0ba9230d00df4472ffb3451f1b74ef23eef3add99eec896c7757149
7
- data.tar.gz: fc4b267de3431e753f9a27e7131a93d3c3b040a18e004e75edf4c17718f878a261c15d01015c093928ac264e5cab781b2af4025f2392f9d989a6eca80f9d2556
6
+ metadata.gz: b5cc7f4df72d7688fca0fb757779e9a3ee5c5cca7d2924f3df5aa6daff3d3fb25b201c80566c4040412d67271f8e49ed38c5fcc706a1095b2db73fbfe2bbb0fa
7
+ data.tar.gz: feb6412f8391c679ea778bdb30aec896931213e5339380bced14a93830a3603bdb326da3ec7e8ba35467c8097d64cdf1d0a40e33eb5ea5735a278d88bc345a26
data/src/Fantasy.rb CHANGED
@@ -19,21 +19,34 @@ class Fantasy
19
19
  @avg_o["qb"] = 17.9
20
20
  @avg_o["te"] = 8.6
21
21
 
22
-
22
+ @bye_week = {}
23
+ Team.all.each do |t|
24
+ @bye_week[t.code] = t.bye_week
25
+ end
26
+
27
+ @settings_view = SettingsView.new(self)
28
+ @builder[:scrolledSettingsView].add @settings_view
23
29
  @show = true
24
30
  end
25
- def buttonFillRunPts__clicked(*a)
26
- @show = true
31
+
32
+ def buttonShowGames__clicked(*a)
27
33
  type = @builder[:type].active_text
28
- home_advantage = @builder[:entryHomeFieldPts].text.to_f
29
- o_factor = @builder[:entryOFactor].text.to_f
30
- d_factor = @builder[:entryDFactor].text.to_f
31
- count = 0
34
+ row = Setting.find_by_position(type)
35
+ fill_game_points(type, row.home_points, row.o_factor, row.d_factor)
36
+ end
37
+
38
+
39
+ def fill_game_points(type, home_advantage, o_factor, d_factor)
40
+ @show = false
32
41
  out "clear"
42
+ # home_advantage = @builder[:entryHomeFieldPts].text.to_f
43
+ # o_factor = @builder[:entryOFactor].text.to_f
44
+ # d_factor = @builder[:entryDFactor].text.to_f
45
+ count = 0
33
46
  Game.all.each do |g|
34
47
  home = Team.where(code: g.home).first
35
48
  away = Team.where(code: g.away).first
36
- home_o = home.read_attribute("#{type}_o")
49
+ home_o = home.read_attribute("#{type}_o")
37
50
  away_o = away.read_attribute("#{type}_o")
38
51
  home_d = home.read_attribute("#{type}_d")
39
52
  away_d = away.read_attribute("#{type}_d")
@@ -52,18 +65,19 @@ class Fantasy
52
65
 
53
66
 
54
67
  out "#{g.away} @ #{g.home}"
55
- out "#{g.home} #{type} offense = #{home_o}"
56
- out "#{g.away} #{type} defense = #{r2(away_d)} (factor=#{r2(away_d_factor)})"
57
- out "home total = #{r2(home_pts)}"
58
- out "#{g.away} #{type} offense = #{away_o}"
59
- out "#{g.home} #{type} defense = #{r2(home_d)} (factor=#{r2(home_d_factor)})"
60
- out "away total = #{r2(away_pts)}\n"
68
+ if @show
69
+ out "#{g.home} #{type} offense = #{home_o} + #{home_advantage} (home_points) = #{home_o + home_advantage}"
70
+ out "#{g.away} #{type} defense = #{r2(away_d)} (factor=#{r2(away_d_factor)})"
71
+ out "#{g.home} #{type} total = #{r2(home_pts)}"
72
+ out "#{g.away} #{type} offense = #{away_o}"
73
+ out "#{g.home} #{type} defense = #{r2(home_d)} (factor=#{r2(home_d_factor)})"
74
+ out "away total = #{r2(away_pts)}\n"
75
+ end
61
76
  count = count + 1
62
77
  g.save!
63
- # return if count > 5
64
78
  end
65
79
  out "Updated #{type} Points: Home = #{home_advantage.to_s} O Factor = #{o_factor.to_s} D Factor = #{d_factor}"
66
- # @builder[:window1].show_all
80
+
67
81
  end
68
82
 
69
83
 
@@ -71,20 +85,24 @@ class Fantasy
71
85
  def buttonComputeCombos__clicked(*a)
72
86
  out "clear"
73
87
  type = @builder[:type].active_text
74
- @teams = []
75
- Team.all.each do |team1|
76
- @teams << team1.code
77
- end
78
- @teams = @teams.sort
79
- for i in 0..31 do
80
- for j in (i+1)..31 do
81
- combo_pts(@teams[i], @teams[j], type)
82
- end
83
- end
88
+ Combo.all.each do |c|
89
+ combo_pts(c.team1, c.team2, type, false, c)
90
+ end
84
91
  out "Combos Updated"
85
92
  end
86
93
 
87
94
  def buttonShowCombos__clicked(*a)
95
+ @show = false
96
+ Setting.where(recalculate: "Y").each do |row|
97
+ out "clear"
98
+ fill_game_points(row.position, row.home_points, row.o_factor, row.d_factor)
99
+ Combo.all.each do |c|
100
+ combo_pts(c.team1, c.team2, row.position, false, c)
101
+ end
102
+ row.recalculate = ""
103
+ row.save!
104
+ @settings_view.reload
105
+ end
88
106
  Combos.new(self).show_glade
89
107
  end
90
108
 
@@ -99,7 +117,7 @@ class Fantasy
99
117
  combo_pts(team1, team2, type, true)
100
118
  end
101
119
 
102
- def combo_pts(team1,team2, type, show = false)
120
+ def combo_pts(team1,team2, type, show = false, row = nil)
103
121
  @show, @old_show = show, @show
104
122
  @opponents = []
105
123
  tot1 = 0
@@ -107,18 +125,17 @@ class Fantasy
107
125
  tot_best = 0
108
126
  tot_games = 0
109
127
  out "clear" if show
110
- out "#{type} Combos for #{team1} & #{team2}", true
128
+ out "#{type} Combos for #{team1} & #{team2}", true if show
111
129
  for week in 1..16 do
112
130
  best_pts = -99
113
131
  best_team = "Error"
114
132
  best_opponent = "Error"
115
- out "\nweek ##{week}"
116
- clear_events
133
+ out "\nweek ##{week}" if show
117
134
  Game.where("(home = '#{team1}' or away = '#{team1}' or home = '#{team2}' or away = '#{team2}') and week = #{week}").each do |g|
118
135
  home_pts = g.read_attribute("home_#{type}_pts")
119
136
  away_pts = g.read_attribute("away_#{type}_pts")
120
137
  if g.home == team1 or g.home == team2
121
- out " #{g.away} @ #{g.home} => #{g.home} = #{r2(home_pts)}"
138
+ out " #{g.away} @ #{g.home} => #{g.home} = #{r2(home_pts)}" if show
122
139
  if home_pts > best_pts
123
140
  best_pts = home_pts
124
141
  best_team = g.home
@@ -126,7 +143,7 @@ class Fantasy
126
143
  end
127
144
  end
128
145
  if g.away == team1 or g.away == team2
129
- out "#{g.away} @ #{g.home} => #{g.away} = #{r2(away_pts)}"
146
+ out "#{g.away} @ #{g.home} => #{g.away} = #{r2(away_pts)}" if show
130
147
  if away_pts > best_pts
131
148
  best_pts = away_pts
132
149
  best_team = g.away
@@ -134,19 +151,20 @@ class Fantasy
134
151
  end
135
152
  end
136
153
  end
154
+ worst_team = best_team == team1 ? team2 : team1
137
155
  if best_team != "Error"
138
- @opponents << best_opponent
139
- out "best = #{best_team} (#{r2(best_pts)})"
156
+ @opponents << "#{best_team} vs #{best_opponent}" + (@bye_week[worst_team] == week ? " (bye #{worst_team})" : "")
157
+ out "best = #{best_team} (#{r2(best_pts)})" if show
140
158
  tot_best = tot_best + best_pts
141
159
  tot_games = tot_games + 1
142
160
  end
143
161
  end
144
- out "\ntot games: #{tot_games} total: #{r2(tot_best)} avg: #{r2(tot_best/tot_games)}"
145
- out "\nOpponents: "
146
- @opponents.each { |o| out o }
147
- c = Combo.where("team1 = '#{team1}' and team2 = '#{team2}'").first
148
- c.send("avg_#{type}_pts=", tot_best/tot_games)
149
- c.save!
162
+ out "\ntot games: #{tot_games} total: #{r2(tot_best)} avg: #{r2(tot_best/tot_games)}" if show
163
+ out "\nOpponents: " if show
164
+ @opponents.each { |o| out o } if show
165
+ row ||= Combo.where("team1 = '#{team1}' and team2 = '#{team2}'").first
166
+ row.send("avg_#{type}_pts=", tot_best/tot_games)
167
+ row.save!
150
168
  @show = @old_show
151
169
  end
152
170
 
@@ -155,6 +173,8 @@ class Fantasy
155
173
  @builder[:out].buffer.text = ""
156
174
  elsif show
157
175
  @builder[:out].buffer.text += str + "\n"
176
+ else
177
+ @builder[:out].buffer.text = str
158
178
  end
159
179
  clear_events
160
180
  end
data/src/Setting.rb ADDED
@@ -0,0 +1,2 @@
1
+ class Setting < ActiveRecord::Base
2
+ end
@@ -0,0 +1,44 @@
1
+
2
+ class SettingsView < VR::ListView
3
+
4
+ def initialize(main)
5
+ @main = main
6
+ super(recalculate: String, position: String, home_points: VR::Col::SpinCol, o_factor: VR::Col::SpinCol, d_factor: VR::Col::SpinCol)
7
+ col_editable(home_points: true, o_factor: true, d_factor: true)
8
+ col_digits(home_points: 1, o_factor: 1, d_factor: 1)
9
+ col_width(110)
10
+
11
+ @update = Proc.new { |model_sym, row, view |
12
+ position = row[id(:position)]
13
+ rec = Setting.find_by_position(position)
14
+ if rec.home_points != row[id(:home_points)].value or rec.o_factor != row[id(:o_factor)].value or rec.d_factor != row[id(:d_factor)].value
15
+ rec.home_points = row[id(:home_points)].value
16
+ rec.o_factor = row[id(:o_factor)].value
17
+ rec.d_factor = row[id(:d_factor)].value
18
+ rec.recalculate = "Y"
19
+ rec.save!
20
+ @main.builder[:scrolledSettingsView].show_all
21
+ reload
22
+ end
23
+ }
24
+
25
+ @vr_renderer[:home_points].edited_callback = @update
26
+ @vr_renderer[:o_factor].edited_callback = @update
27
+ @vr_renderer[:d_factor].edited_callback = @update
28
+ reload
29
+ end
30
+
31
+ def reload()
32
+ self.model.clear
33
+ Setting.all.each do |s|
34
+ row = add_row()
35
+ row[:recalculate] = s.recalculate
36
+ row[:position] = s.position
37
+ row[:home_points] = VR::Col::SpinCol.new(s.home_points,0,5,0.1)
38
+ row[:o_factor] = VR::Col::SpinCol.new(s.o_factor,0,1,0.1)
39
+ row[:d_factor] = VR::Col::SpinCol.new(s.d_factor,0,1,0.1)
40
+ end
41
+ self.show
42
+ end
43
+
44
+ end
data/src/Wr.rb ADDED
@@ -0,0 +1,2 @@
1
+ class Wr < ActiveRecord::Base
2
+ end
@@ -3,9 +3,11 @@
3
3
  <interface>
4
4
  <requires lib="gtk+" version="3.0"/>
5
5
  <object class="GtkWindow" id="window1">
6
+ <property name="width_request">600</property>
6
7
  <property name="can_focus">False</property>
7
8
  <property name="title" translatable="yes">Nature Boy</property>
8
- <property name="gravity">east</property>
9
+ <property name="window_position">center</property>
10
+ <property name="gravity">center</property>
9
11
  <child>
10
12
  <object class="GtkBox" id="box1">
11
13
  <property name="visible">True</property>
@@ -33,14 +35,14 @@
33
35
  </child>
34
36
  <child>
35
37
  <object class="GtkScrolledWindow" id="scrolledwindow1">
36
- <property name="height_request">400</property>
38
+ <property name="height_request">300</property>
37
39
  <property name="visible">True</property>
38
40
  <property name="can_focus">True</property>
39
41
  <property name="vexpand">True</property>
40
42
  <property name="shadow_type">in</property>
41
43
  <child>
42
44
  <object class="GtkTextView" id="out">
43
- <property name="height_request">360</property>
45
+ <property name="height_request">200</property>
44
46
  <property name="visible">True</property>
45
47
  <property name="can_focus">True</property>
46
48
  <property name="hexpand">True</property>
@@ -56,167 +58,14 @@
56
58
  </packing>
57
59
  </child>
58
60
  <child>
59
- <object class="GtkGrid" id="grid2">
61
+ <object class="GtkScrolledWindow" id="scrolledSettingsView">
62
+ <property name="height_request">125</property>
60
63
  <property name="visible">True</property>
61
- <property name="can_focus">False</property>
62
- <child>
63
- <object class="GtkGrid" id="grid3">
64
- <property name="visible">True</property>
65
- <property name="can_focus">False</property>
66
- <property name="row_spacing">2</property>
67
- <property name="column_spacing">2</property>
68
- <child>
69
- <object class="GtkEntry" id="entryHomeFieldPts">
70
- <property name="visible">True</property>
71
- <property name="can_focus">True</property>
72
- <property name="text" translatable="yes">3</property>
73
- </object>
74
- <packing>
75
- <property name="left_attach">1</property>
76
- <property name="top_attach">0</property>
77
- <property name="width">1</property>
78
- <property name="height">1</property>
79
- </packing>
80
- </child>
81
- <child>
82
- <object class="GtkEntry" id="entryOFactor">
83
- <property name="visible">True</property>
84
- <property name="can_focus">True</property>
85
- <property name="text" translatable="yes">1</property>
86
- </object>
87
- <packing>
88
- <property name="left_attach">1</property>
89
- <property name="top_attach">1</property>
90
- <property name="width">1</property>
91
- <property name="height">1</property>
92
- </packing>
93
- </child>
94
- <child>
95
- <object class="GtkEntry" id="entryDFactor">
96
- <property name="visible">True</property>
97
- <property name="can_focus">True</property>
98
- <property name="text" translatable="yes">1</property>
99
- </object>
100
- <packing>
101
- <property name="left_attach">1</property>
102
- <property name="top_attach">2</property>
103
- <property name="width">1</property>
104
- <property name="height">1</property>
105
- </packing>
106
- </child>
107
- <child>
108
- <object class="GtkLabel" id="label2">
109
- <property name="visible">True</property>
110
- <property name="can_focus">False</property>
111
- <property name="label" translatable="yes">Home Field Pts:</property>
112
- </object>
113
- <packing>
114
- <property name="left_attach">0</property>
115
- <property name="top_attach">0</property>
116
- <property name="width">1</property>
117
- <property name="height">1</property>
118
- </packing>
119
- </child>
120
- <child>
121
- <object class="GtkLabel" id="label3">
122
- <property name="visible">True</property>
123
- <property name="can_focus">False</property>
124
- <property name="label" translatable="yes">Offense Factor:</property>
125
- </object>
126
- <packing>
127
- <property name="left_attach">0</property>
128
- <property name="top_attach">1</property>
129
- <property name="width">1</property>
130
- <property name="height">1</property>
131
- </packing>
132
- </child>
133
- <child>
134
- <object class="GtkLabel" id="label4">
135
- <property name="visible">True</property>
136
- <property name="can_focus">False</property>
137
- <property name="label" translatable="yes">Defense Factor:</property>
138
- </object>
139
- <packing>
140
- <property name="left_attach">0</property>
141
- <property name="top_attach">2</property>
142
- <property name="width">1</property>
143
- <property name="height">1</property>
144
- </packing>
145
- </child>
146
- </object>
147
- <packing>
148
- <property name="left_attach">0</property>
149
- <property name="top_attach">0</property>
150
- <property name="width">1</property>
151
- <property name="height">1</property>
152
- </packing>
153
- </child>
64
+ <property name="can_focus">True</property>
65
+ <property name="hexpand">True</property>
66
+ <property name="shadow_type">in</property>
154
67
  <child>
155
- <object class="GtkButtonBox" id="buttonbox1">
156
- <property name="visible">True</property>
157
- <property name="can_focus">False</property>
158
- <property name="orientation">vertical</property>
159
- <property name="spacing">2</property>
160
- <property name="layout_style">start</property>
161
- <child>
162
- <object class="GtkButton" id="buttonFillRunPts">
163
- <property name="label" translatable="yes">Fill Run Values</property>
164
- <property name="visible">True</property>
165
- <property name="can_focus">True</property>
166
- <property name="receives_default">True</property>
167
- </object>
168
- <packing>
169
- <property name="expand">False</property>
170
- <property name="fill">True</property>
171
- <property name="position">0</property>
172
- </packing>
173
- </child>
174
- <child>
175
- <object class="GtkButton" id="buttonComputeCombos">
176
- <property name="label" translatable="yes">Compute Combos</property>
177
- <property name="visible">True</property>
178
- <property name="can_focus">True</property>
179
- <property name="receives_default">True</property>
180
- </object>
181
- <packing>
182
- <property name="expand">False</property>
183
- <property name="fill">True</property>
184
- <property name="position">1</property>
185
- </packing>
186
- </child>
187
- <child>
188
- <object class="GtkButton" id="buttonShowCombos">
189
- <property name="label" translatable="yes">Show Combos</property>
190
- <property name="visible">True</property>
191
- <property name="can_focus">True</property>
192
- <property name="receives_default">True</property>
193
- </object>
194
- <packing>
195
- <property name="expand">False</property>
196
- <property name="fill">True</property>
197
- <property name="position">2</property>
198
- </packing>
199
- </child>
200
- <child>
201
- <object class="GtkButton" id="buttonBuildComboDB">
202
- <property name="label" translatable="yes">BuildComboDB</property>
203
- <property name="visible">True</property>
204
- <property name="can_focus">True</property>
205
- <property name="receives_default">True</property>
206
- </object>
207
- <packing>
208
- <property name="expand">False</property>
209
- <property name="fill">True</property>
210
- <property name="position">3</property>
211
- </packing>
212
- </child>
213
- </object>
214
- <packing>
215
- <property name="left_attach">1</property>
216
- <property name="top_attach">0</property>
217
- <property name="width">1</property>
218
- <property name="height">1</property>
219
- </packing>
68
+ <placeholder/>
220
69
  </child>
221
70
  </object>
222
71
  <packing>
@@ -226,67 +75,35 @@
226
75
  </packing>
227
76
  </child>
228
77
  <child>
229
- <object class="GtkGrid" id="grid1">
78
+ <object class="GtkButtonBox" id="buttonbox1">
230
79
  <property name="visible">True</property>
231
80
  <property name="can_focus">False</property>
81
+ <property name="spacing">5</property>
82
+ <property name="layout_style">end</property>
232
83
  <child>
233
- <object class="GtkButton" id="buttonRunCombo">
234
- <property name="label" translatable="yes">Run Combo</property>
84
+ <object class="GtkButton" id="buttonCancel">
85
+ <property name="label" translatable="yes">Cancel</property>
235
86
  <property name="visible">True</property>
236
87
  <property name="can_focus">True</property>
237
88
  <property name="receives_default">True</property>
238
89
  </object>
239
90
  <packing>
240
- <property name="left_attach">3</property>
241
- <property name="top_attach">0</property>
242
- <property name="width">1</property>
243
- <property name="height">1</property>
91
+ <property name="expand">False</property>
92
+ <property name="fill">True</property>
93
+ <property name="position">1</property>
244
94
  </packing>
245
95
  </child>
246
96
  <child>
247
- <object class="GtkEntry" id="entryTeam2">
97
+ <object class="GtkButton" id="buttonShowCombos">
98
+ <property name="label" translatable="yes">Show Combos</property>
248
99
  <property name="visible">True</property>
249
100
  <property name="can_focus">True</property>
250
- <property name="text" translatable="yes">BAL</property>
251
- </object>
252
- <packing>
253
- <property name="left_attach">2</property>
254
- <property name="top_attach">0</property>
255
- <property name="width">1</property>
256
- <property name="height">1</property>
257
- </packing>
258
- </child>
259
- <child>
260
- <object class="GtkEntry" id="entryTeam1">
261
- <property name="visible">True</property>
262
- <property name="can_focus">True</property>
263
- <property name="text" translatable="yes">ATL</property>
264
- </object>
265
- <packing>
266
- <property name="left_attach">1</property>
267
- <property name="top_attach">0</property>
268
- <property name="width">1</property>
269
- <property name="height">1</property>
270
- </packing>
271
- </child>
272
- <child>
273
- <object class="GtkComboBoxText" id="type">
274
- <property name="visible">True</property>
275
- <property name="can_focus">False</property>
276
- <property name="active">0</property>
277
- <property name="active_id">0</property>
278
- <items>
279
- <item id="&lt;Enter ID&gt;" translatable="yes">run</item>
280
- <item translatable="yes">wr</item>
281
- <item translatable="yes">te</item>
282
- <item translatable="yes">qb</item>
283
- </items>
101
+ <property name="receives_default">True</property>
284
102
  </object>
285
103
  <packing>
286
- <property name="left_attach">0</property>
287
- <property name="top_attach">0</property>
288
- <property name="width">1</property>
289
- <property name="height">1</property>
104
+ <property name="expand">False</property>
105
+ <property name="fill">True</property>
106
+ <property name="position">2</property>
290
107
  </packing>
291
108
  </child>
292
109
  </object>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nature
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Cunningham
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir:
10
10
  - "."
11
11
  cert_chain: []
12
- date: 2017-08-22 00:00:00.000000000 Z
12
+ date: 2017-08-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: visualruby
@@ -81,9 +81,12 @@ files:
81
81
  - src/Game.rb
82
82
  - src/MyClass.rb
83
83
  - src/ParseSchedule.rb
84
+ - src/Setting.rb
85
+ - src/SettingsView.rb
84
86
  - src/TallyGames.rb
85
87
  - src/Team.rb
86
88
  - src/Util.rb
89
+ - src/Wr.rb
87
90
  - src/glade/Combos.glade
88
91
  - src/glade/Fantasy.glade
89
92
  - src/glade/MyClass.glade