|
| 1 | +Mix.install([{:jason, "~> 1.4.0"}, {:csv, "~> 3.2"}]) |
| 2 | + |
| 3 | +signs = |
| 4 | + File.read!("priv/signs.json") |
| 5 | + |> Jason.decode!(keys: :atoms) |
| 6 | + |
| 7 | +Enum.map(signs, fn sign -> |
| 8 | + text = |
| 9 | + case sign do |
| 10 | + %{type: "realtime"} = sign -> |
| 11 | + List.wrap(sign.source_config) |
| 12 | + |> Enum.map_join(", ", fn config -> |
| 13 | + line = |
| 14 | + Enum.flat_map(config.sources, & &1.routes) |
| 15 | + |> Enum.uniq() |
| 16 | + |> case do |
| 17 | + ["Green-" <> branch] -> "Green #{branch}" |
| 18 | + [single] -> single |
| 19 | + routes -> "Green #{Enum.map_join(routes, "/", fn "Green-" <> b -> b end)}" |
| 20 | + end |
| 21 | + |
| 22 | + "#{line} to #{config.headway_direction_name}" |
| 23 | + end) |
| 24 | + |
| 25 | + %{id: "Silver_Line" <> _} = sign -> |
| 26 | + [sign[:configs], sign[:top_configs], sign[:bottom_configs]] |
| 27 | + |> Enum.filter(fn x -> x end) |
| 28 | + |> Enum.map_join(", ", fn configs -> |
| 29 | + if configs == [] do |
| 30 | + "" |
| 31 | + else |
| 32 | + line = |
| 33 | + for config <- configs, source <- config.sources, uniq: true do |
| 34 | + case source.route_id do |
| 35 | + "741" -> "SL1" |
| 36 | + "742" -> "SL2" |
| 37 | + "743" -> "SL3" |
| 38 | + "746" -> "SLW" |
| 39 | + end |
| 40 | + end |
| 41 | + |> Enum.join("/") |
| 42 | + |
| 43 | + "#{line} to #{hd(configs).headway_direction_name}" |
| 44 | + end |
| 45 | + end) |
| 46 | + |
| 47 | + sign -> |
| 48 | + for config <- sign[:configs], source <- config.sources, uniq: true do |
| 49 | + source.route_id |
| 50 | + end |
| 51 | + |> Enum.join(", ") |
| 52 | + end |
| 53 | + |
| 54 | + [sign.scu_id, "#{sign.pa_ess_loc}-#{sign.text_zone}", sign.id, text] |
| 55 | +end) |
| 56 | +|> Enum.sort() |
| 57 | +|> CSV.encode() |
| 58 | +|> Enum.join() |
| 59 | +|> IO.puts() |
0 commit comments