-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathomar.rb
More file actions
42 lines (35 loc) · 1.33 KB
/
omar.rb
File metadata and controls
42 lines (35 loc) · 1.33 KB
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
require 'csv'
require 'hashie'
HEADER_TRANSLATIONS = {
'id' => :id,
'Línea' => :line,
'Nombre' => :name,
'IdaEntrada' => :forward_entrance,
'IdaCambio' => :forward_exchange,
'IdaSalida' => :forward_exit,
'VueltaEntrada' => :backward_entrance,
'VueltaCambio' => :backward_exchange,
'VueltaSalida' => :backward_exit,
'anterior' => :previous_station_distance,
'siguiente' => :next_station_distance
}.freeze
# Me genera el último hash creado con nil:nil, nil:nil
all_stations = []
CSV.foreach('stations.csv', headers: true) do |row|
headers = row.headers.map { |header| HEADER_TRANSLATIONS[header] }
all_stations << Hashie::Mash.new(headers.zip(row.map { |_, v| v }).to_h)
end
station_hash_by_id = Hashie::Mash.new
station_names_by_id = Hashie::Mash.new
combinations = Hashie::Mash.new
all_stations.each do |stn|
station_hash_by_id[stn.id] = stn
station_names_by_id[stn.id] = stn.name
end
group_by_station_name = all_stations.group_by { |e| e[:name] }
select_combination_station = group_by_station_name.select! { |_, v| v.count > 1 }
arr = select_combination_station.map { |k, value| [[k, value.map { |v| v[:id] }].flatten, value.map { |v| v[:line] }] }
arr.each { |element| element[0].each { |e| combinations[e] = element[1] } }
# 'lo valledor' -> 'parque almagro'
def search_before_and_after_combination_stations(initial)
end