-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_data2.rb
88 lines (62 loc) · 1.6 KB
/
get_data2.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
require 'csv'
def get_all_players_on_a_team(team_name, data_total)
players_on_team = []
data_total.each do |player|
if player["team"] == team_name
players_on_team << player
end
end
players_on_team
end
def get_all_players_by_position(position, data_total)
players_per_position = []
data_total.each do |player|
if player["position"] == position
players_per_position << player
end
end
players_per_position
end
def return_team_array(team_name,data_sep_by_team)
data_sep_by_team.each do |team_array|
if team_array.to_s.include?(team_name.to_s)
return team_array
end
end
end
def return_position_array(position, players_per_position)
players_per_position.each do |position_array|
if position_array.to_s.include?(position.to_s)
return position_array
end
end
end
data_total = []
CSV.foreach('lackp_starting_rosters.csv', headers:true) do |row|
data_total << row
end
teams = []
data_total.each do |row|
teams << row["team"]
end
teams.uniq!
data_sep_by_team = []
teams.each do |team|
data_sep_by_team << get_all_players_on_a_team(team, data_total)
end
positions = []
data_total.each do |row|
positions << row["position"]
end
positions.uniq!
players_in_each_position = []
positions.each do |position|
players_in_each_position << get_all_players_by_position(position, data_total)
end
teams_hash = {}
teams.each do |team_name|
teams_hash[team_name] = return_team_array(team_name,data_sep_by_team)
end
positions_hash = {}
positions.each do |position|
positions_hash[position] = return_position_array(position, players_per_position)