all of the "basic" collectors and a fixed config + repo

2867358 · gmorell · 2022-07-19 05:37

12 files +43 -5

Files changed

added apps/room_hermes/lib/room_hermes/repo.ex
+5 −0
@@ -0,0 +1,5 @@
1 +defmodule RoomHermes.Repo do
2 + use Ecto.Repo,
3 + otp_app: :room_hermes,
4 + adapter: Ecto.Adapters.Postgres
5 +end
modified apps/room_sanctum/lib/room_sanctum/condensers/basic_mqtt.ex
+29 −5
@@ -3,14 +3,22 @@ defmodule RoomSanctum.Condenser.BasicMQTT do
3 3 import MapMerge
4 4
5 5 def condense({id, type}, data) do
6 − IO.inspect({id, type, data})
6 + if type == :tidal do
7 + IO.inspect({id, type, data})
8 + end
7 9
8 10 case type do
9 11 :gtfs ->
10 12 data
11 13 |> Enum.map(fn f ->
12 − %{time: f.arrival_time, destination: f.trip.trip_headsign, direction: f.trip.direction.direction, route: f.trip.route_id}
14 + %{
15 + time: f.arrival_time,
16 + destination: f.trip.trip_headsign,
17 + direction: f.trip.direction.direction,
18 + route: f.trip.route_id
19 + }
13 20 end)
21 +
14 22 :gbfs ->
15 23 data
16 24 |> Enum.map(fn f ->
@@ -18,7 +26,17 @@ defmodule RoomSanctum.Condenser.BasicMQTT do
18 26 end)
19 27
20 28 :tidal ->
21 − :ok
29 + data
30 + |> Enum.group_by(fn x -> x.type end)
31 + |> Enum.map(fn {extreme, data} ->
32 + [first, second] = data
33 + k1 = "first_#{extreme |> String.downcase()}" |> String.to_atom()
34 + k2 = "second_#{extreme |> String.downcase()}" |> String.to_atom()
35 + kv1 = "first_v#{extreme |> String.downcase()}" |> String.to_atom()
36 + kv2 = "second_v#{extreme |> String.downcase()}" |> String.to_atom()
37 + %{k1 => first.t, k2 => second.t, kv1 => first.v, kv2 => second.v}
38 + end)
39 + |> Enum.reduce(&Map.merge/2)
22 40
23 41 :weather ->
24 42 data
@@ -41,10 +59,16 @@ defmodule RoomSanctum.Condenser.BasicMQTT do
41 59 end)
42 60
43 61 :ephem ->
44 − :ok
62 + data |> Enum.map(fn f -> {f.period, f.result} end) |> Enum.into(%{})
45 63
46 64 :calendar ->
47 − :ok
65 + data
66 + |> Enum.map(fn f ->
67 + %{
68 + date_start: f.date_start |> DateTime.to_date(),
69 + description: f.blob["description"]
70 + }
71 + end)
48 72 end
49 73 end
50 74 end
modified config/dev.exs
+9 −0
@@ -1,5 +1,14 @@
1 1 import Config
2 2
3 +# Configure your database
4 +config :room_hermes,
5 + RoomHermes.Repo,
6 + username: "postgres",
7 + password: "postgres",
8 + hostname: "localhost",
9 + database: "room_sanctum_dev",
10 + show_sensitive_data_on_connection_error: true,
11 + pool_size: 10
3 12 # For development, we disable any cache and enable
4 13 # debugging and code reloading.
5 14 #

Parents: 45b281d