wind, passing up units in weather, support stupid gtfs time, clean up unused inspects

61cfa79 · gmorell · 2022-08-09 04:53

18 files +34 -7

Files changed

modified apps/room_sanctum/lib/room_sanctum/condensers/basic_mqtt.ex
+4 −1
@@ -82,7 +82,10 @@ defmodule RoomSanctum.Condenser.BasicMQTT do
82 82 temp: f.main.temp,
83 83 feel: f.main.feels_like,
84 84 hum: f.main.humidity,
85 − pressure: f.main.pressure
85 + pressure: f.main.pressure,
86 + wind: f.wind,
87 + visibility: f.visibility,
88 + units: f.units
86 89 }
87 90 end)
88 91
modified apps/room_sanctum/lib/room_sanctum/storage.ex
+22 −2
@@ -553,8 +553,26 @@ defmodule RoomSanctum.Storage do
553 553 %Ecto.Changeset{data: %StopTime{}}
554 554
555 555 """
556 + defp convert_gtfs_time(time) do
557 + [hour, min, second] = time |> String.split(":")
558 + hour = hour |> String.to_integer()
559 +
560 + hour = cond do
561 + hour >= 24 -> hour - 24
562 + true -> hour
563 + end
564 + hourzf = hour |> Integer.to_string |> String.pad_leading(2, "0")
565 + "#{hourzf}:#{min}:#{second}"
566 + end
567 +
568 + defp convert_gtfs(attrs) do
569 + attrs
570 + |> Map.put("arrival_time", attrs["arrival_time"] |> convert_gtfs_time)
571 + |> Map.put("departure_time", attrs["departure_time"] |> convert_gtfs_time)
572 + end
573 +
556 574 def change_stop_time(%StopTime{} = stop_time, attrs \\ %{}) do
557 − StopTime.changeset(stop_time, attrs)
575 + StopTime.changeset(stop_time, attrs |> convert_gtfs)
558 576 end
559 577
560 578 alias RoomSanctum.Storage.GTFS.Stop
@@ -1836,8 +1854,10 @@ defmodule RoomSanctum.Storage do
1836 1854 foci = Configuration.get_foci!(query.foci_id)
1837 1855 {lat, lon} = foci.place.coordinates
1838 1856 tz = WhereTZ.lookup(lat, lon)
1839 − now = DateTime.new!(Date.utc_today, Time.new!(0,0,0), tz) # todo make this configurable from somewhere
1857 + # todo make this configurable from somewhere
1858 + now = DateTime.new!(Date.utc_today(), Time.new!(0, 0, 0), tz)
1840 1859 max = now |> DateTime.add(query.days * 24 * 60 * 60, :second)
1860 +
1841 1861 q =
1842 1862 from ic in ICalendar,
1843 1863 where: ic.source_id == ^source_id and ic.date_start >= ^now and ic.date_start <= ^max,
modified apps/room_sanctum/lib/room_sanctum_web/live/live_preview.ex
+5 −0
@@ -38,6 +38,10 @@ defmodule RoomSanctumWeb.LivePreview do
38 38 end
39 39 end
40 40
41 + defp to_l(direction) do
42 + direction
43 + end
44 +
41 45 def p_gtfs(assigns) do
42 46 ~H"""
43 47 <%= for e <- @entries.data do %>
@@ -101,6 +105,7 @@ defmodule RoomSanctumWeb.LivePreview do
101 105 <p><i class="fa-solid fa-fw fa-temperature-half"></i> <%= e.temp %>&deg;</p>
102 106 <p><i class="fa-solid fa-fw fa-droplet "></i> <%= e.hum %> &percnt; </p>
103 107 <p><i class="fa-solid fa-fw fa-gem "></i> <%= e.pressure %> mPa?</p>
108 + <p><i class="fa-solid fa-fw fa-wind "></i> <%= e.wind.speed %> <%= e.wind.deg |> to_l %>&deg;</p>
104 109 </div>
105 110 </div>
106 111 <% end %>
modified apps/room_tidal/lib/room_tidal/tidal_worker.ex
+1 −2
@@ -28,10 +28,9 @@ defmodule RoomTidal.Worker do
28 28 end
29 29
30 30 def handle_call({:query_tides, query}, _from, state) do
31 − IO.puts("xxx")
32 31 case HTTPoison.get(@root_url <> query.station_id, [], follow_redirect: true) do
33 32 {:ok, result} ->
34 − decoded = result.body |> Poison.decode!(keys: :atoms) |> IO.inspect
33 + decoded = result.body |> Poison.decode!(keys: :atoms)
35 34 {:reply, decoded.predictions, state}
36 35
37 36 {:error, reason} ->
modified apps/room_weather/lib/room_weather/weather_worker.ex
+2 −2
@@ -18,7 +18,7 @@ defmodule RoomWeather.Worker do
18 18
19 19 @decorate cacheable(cache: RoomZeus.Cache, opts: [ttl: @ttl])
20 20 def query_weather(name, query) do
21 − "weather#{name}" |> via_tuple() |> GenServer.call({:query_weather, query}) |> IO.inspect()
21 + "weather#{name}" |> via_tuple() |> GenServer.call({:query_weather, query})
22 22 end
23 23
24 24 def init(opts) do
@@ -40,7 +40,7 @@ defmodule RoomWeather.Worker do
40 40 }
41 41 ) do
42 42 {:ok, result} ->
43 − decoded = result.body |> Poison.decode!(keys: :atoms)
43 + decoded = result.body |> Poison.decode!(keys: :atoms) |> Map.put(:units, state.src.config.units)
44 44 {:reply, [decoded], state}
45 45
46 46 {:error, reason} ->

Parents: eef7589