neiam
/apollos_crib
It's Apollo's Crib
public · Issues · Pulls 1 · Labels · Forks · Compare · Actions failure · Badges · Packages
⭐
Log in to mark this repository.
cleanup aqi warnings
ae73786 · gmorell · 2022-08-20 15:49
Files changed
modified
apps/room_air_quality/lib/room_air_quality/aqi_worker.ex
+16
−44
@@ -9,7 +9,7 @@ defmodule RoomAirQuality.Worker do
| 9 | 9 | alias RoomSanctum.Repo |
| 10 | 10 | |
| 11 | 11 | @registry :zeus |
| 12 | − @monitoring_site_url "https://s3-us-west-1.amazonaws.com//files.airnowtech.org/airnow/today/Monitoring_Site_Locations_V2.dat" | |
| 12 | + # @monitoring_site_url "https://s3-us-west-1.amazonaws.com//files.airnowtech.org/airnow/today/Monitoring_Site_Locations_V2.dat" | |
| 13 | 13 | |
| 14 | 14 | def start_link(opts) do |
| 15 | 15 | GenServer.start_link(__MODULE__, opts, name: via_tuple("aqi" <> opts[:name])) |
@@ -46,46 +46,16 @@ defmodule RoomAirQuality.Worker do
| 46 | 46 | {:reply, :ok, state} |
| 47 | 47 | end |
| 48 | 48 | |
| 49 | − def handle_cast(:refresh_db_cfg, state) do | |
| 50 | − IO.puts("rerere") | |
| 51 | − {:noreply, state} | |
| 52 | − end | |
| 53 | − | |
| 54 | 49 | defp bcast(id, file, complete, total) do |
| 55 | 50 | Phoenix.PubSub.broadcast(RoomSanctum.PubSub, "aqi", {:aqi, id, file, complete, total}) |
| 56 | 51 | end |
| 57 | 52 | |
| 58 | − defp bcast(id, file, message) do | |
| 59 | − Phoenix.PubSub.broadcast(RoomSanctum.PubSub, "aqi", {:aqi, id, file, message}) | |
| 60 | − end | |
| 61 | − | |
| 62 | − defp intify(val) when is_binary(val) do | |
| 63 | − val | |
| 64 | − |> String.to_integer() | |
| 65 | − end | |
| 66 | − | |
| 67 | − defp intify(val) do | |
| 68 | − val | |
| 69 | − end | |
| 70 | − | |
| 71 | − defp inj_iddt(map, id, dt) do | |
| 72 | − map | |
| 73 | − |> Map.put( | |
| 74 | − :source_id, | |
| 75 | − id | |
| 76 | − |> intify | |
| 77 | − ) | |
| 78 | − |> Map.put(:inserted_at, dt) | |
| 79 | − |> Map.put(:updated_at, dt) | |
| 80 | − end | |
| 81 | − | |
| 82 | 53 | defp write_data(result, type, id) do |
| 83 | 54 | datetime = NaiveDateTime.local_now() |
| 84 | 55 | Logger.info("AQI::#{id} writing bundle") |
| 85 | 56 | |
| 86 | 57 | case type do |
| 87 | 58 | :hourly -> |
| 88 | − as_csv = | |
| 89 | 59 | result.body |
| 90 | 60 | |> String.split("\r\n") |
| 91 | 61 | |> Enum.filter(fn x -> x != "" end) |
@@ -123,7 +93,6 @@ defmodule RoomAirQuality.Worker do
| 123 | 93 | |> Enum.to_list() |
| 124 | 94 | |
| 125 | 95 | :sites -> |
| 126 | − as_csv = | |
| 127 | 96 | result.body |
| 128 | 97 | |> String.split("\r\n") |
| 129 | 98 | |> List.delete_at(0) |
@@ -158,7 +127,7 @@ defmodule RoomAirQuality.Worker do
| 158 | 127 | |> Enum.to_list() |
| 159 | 128 | |> Enum.map(fn {:ok, x} -> x end) |
| 160 | 129 | |> Enum.group_by(fn x -> x.aqsid end) |
| 161 | − |> Enum.map(fn {k, v} -> | |
| 130 | + |> Enum.map(fn {_k, v} -> | |
| 162 | 131 | p = v |> Enum.map(fn q -> q.parameter end) |
| 163 | 132 | f = v |> List.first() |
| 164 | 133 | f |> Map.put(:parameters, p) |
@@ -189,7 +158,6 @@ defmodule RoomAirQuality.Worker do
| 189 | 158 | end) |
| 190 | 159 | |
| 191 | 160 | :hourly_obs -> |
| 192 | − as_csv = | |
| 193 | 161 | result.body |
| 194 | 162 | |> String.split("\r\n") |
| 195 | 163 | |> List.delete_at(0) |
@@ -274,15 +242,15 @@ defmodule RoomAirQuality.Worker do
| 274 | 242 | end |
| 275 | 243 | end |
| 276 | 244 | |
| 277 | − defp build_todays_url(ts \\ DateTime.utc_now()) do | |
| 278 | − sh = | |
| 279 | − ts | |
| 280 | − |> DateTime.add(-1 * 60 * 60, :second) | |
| 281 | − | |
| 282 | − file_str = sh |> Timex.format!("%Y%m%d%H", :strftime) | |
| 283 | − | |
| 284 | − "https://s3-us-west-1.amazonaws.com//files.airnowtech.org/airnow/today/HourlyData_#{file_str}.dat" | |
| 285 | − end | |
| 245 | +# defp build_todays_url(ts \\ DateTime.utc_now()) do | |
| 246 | +# sh = | |
| 247 | +# ts | |
| 248 | +# |> DateTime.add(-1 * 60 * 60, :second) | |
| 249 | +# | |
| 250 | +# file_str = sh |> Timex.format!("%Y%m%d%H", :strftime) | |
| 251 | +# | |
| 252 | +# "https://s3-us-west-1.amazonaws.com//files.airnowtech.org/airnow/today/HourlyData_#{file_str}.dat" | |
| 253 | +# end | |
| 286 | 254 | |
| 287 | 255 | defp build_obs_url(ts \\ DateTime.utc_now()) do |
| 288 | 256 | sh = ts |> DateTime.add(-2 * 60 * 60, :second) |
@@ -292,9 +260,13 @@ defmodule RoomAirQuality.Worker do
| 292 | 260 | "https://s3-us-west-1.amazonaws.com//files.airnowtech.org/airnow/#{sh.year}/#{date_str}/HourlyAQObs_#{file_str}.dat" |
| 293 | 261 | end |
| 294 | 262 | |
| 263 | + def handle_cast(:refresh_db_cfg, state) do | |
| 264 | + IO.puts("rerere") | |
| 265 | + {:noreply, state} | |
| 266 | + end | |
| 267 | + | |
| 295 | 268 | def handle_cast(:update_static, state) do |
| 296 | 269 | Logger.info("AQI::#{state.id} updating data") |
| 297 | − cfg = Configuration.get_source!(state.id) | |
| 298 | 270 | |
| 299 | 271 | bcast(state.id, :downloading, 1, 10) |
| 300 | 272 | # case HTTPoison.get(build_todays_url()) do |
Parents: 060a00c