bb_stats_crunch 0.0.10 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/bb_stats_crunch.rb +25 -23
- metadata +2 -2
data/lib/bb_stats_crunch.rb
CHANGED
@@ -1,20 +1,25 @@
|
|
1
|
-
class BbStatsCrunch
|
2
|
-
attr_accessor :team1, :team2, :score1, :score2
|
3
|
-
|
4
1
|
require 'csv'
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
class BbStatsCrunch
|
3
|
+
|
4
|
+
attr_accessor :team1, :team2, :score1, :score2, :viswins, :homewins
|
8
5
|
|
6
|
+
def initialize(team1, team2, score1, score2, viswins, homewins, totalscore)
|
7
|
+
@team1 = team1
|
8
|
+
@team2 = team2
|
9
|
+
@score1 = Float(score1)
|
10
|
+
@score2 = Float(score2)
|
11
|
+
@viswins = Float(viswins)
|
12
|
+
@homewins = Float(homewins)
|
13
|
+
@totalscore = Float(totalscore)
|
14
|
+
end
|
9
15
|
|
10
|
-
|
11
|
-
|
16
|
+
# puts "enter year (valid year between 1960 - 1969)"
|
17
|
+
# year = gets.chomp
|
12
18
|
|
13
|
-
|
14
|
-
|
15
|
-
teamwins = Hash.new("0")
|
16
|
-
puts year
|
19
|
+
year = 1960
|
20
|
+
homewins, viswins, totalscore = 0, 0, 0
|
17
21
|
|
22
|
+
File.open("files/GL#{year}.OUTPUT", 'w') do |content|
|
18
23
|
CSV.foreach("files/GL#{year}.TXT") do |row|
|
19
24
|
team1 = row[3]
|
20
25
|
score1 = row[9].to_i
|
@@ -22,18 +27,15 @@ puts year
|
|
22
27
|
score2 = row[10].to_i
|
23
28
|
totalscore = totalscore + score1 + score2
|
24
29
|
if score1 > score2
|
25
|
-
|
26
|
-
|
27
|
-
# teamwins["#{team1}"]
|
28
|
-
# teamwins["#{team1}"] += 1
|
29
|
-
# puts @teamwins["#{team1}"]
|
30
|
+
viswins += 1
|
31
|
+
content.puts "#{team1} beat #{team2} by a score of #{score1} to #{score2}"
|
30
32
|
else
|
31
|
-
|
33
|
+
homewins += 1
|
34
|
+
content.puts "#{team2} beat #{team1} by a score of #{score2} to #{score1}"
|
32
35
|
end
|
36
|
+
end
|
33
37
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
end
|
38
|
+
puts "The home team won #{homewins} times."
|
39
|
+
puts "The vistors won #{viswins} times."
|
40
|
+
puts "Total runs scored in #{year} was #{totalscore}."
|
39
41
|
end
|