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.
logging cleanup, foci
49855f9 · gmorell · 2026-04-23 14:21
Files changed
modified
apps/room_sanctum/lib/room_sanctum_web/components/query_geospatial_map.ex
+3
−3
@@ -83,7 +83,7 @@ defmodule RoomSanctumWeb.Components.QueryGeospatialMap do
| 83 | 83 | # Helper function to get queries that have geospatial data |
| 84 | 84 | defp get_mappable_queries(queries) do |
| 85 | 85 | # Debug log all incoming queries |
| 86 | − IO.inspect(length(queries), label: "Total queries received") | |
| 86 | +# IO.inspect(length(queries), label: "Total queries received") | |
| 87 | 87 | |
| 88 | 88 | filtered = queries |
| 89 | 89 | |> Enum.filter(fn query -> |
@@ -97,11 +97,11 @@ defmodule RoomSanctumWeb.Components.QueryGeospatialMap do
| 97 | 97 | result |
| 98 | 98 | end) |
| 99 | 99 | |
| 100 | − IO.inspect(length(filtered), label: "Filtered mappable queries") | |
| 100 | +# IO.inspect(length(filtered), label: "Filtered mappable queries") | |
| 101 | 101 | |
| 102 | 102 | mapped = filtered |> Enum.map(&format_query_for_map/1) |
| 103 | 103 | |
| 104 | − IO.inspect(length(mapped), label: "Final mapped queries") | |
| 104 | +# IO.inspect(length(mapped), label: "Final mapped queries") | |
| 105 | 105 | |
| 106 | 106 | mapped |
| 107 | 107 | end |
modified
apps/room_sanctum/lib/room_sanctum_web/live/cfg_foci_live/show.ex
+81
−1
@@ -3,6 +3,8 @@ defmodule RoomSanctumWeb.FociLive.Show do
| 3 | 3 | |
| 4 | 4 | alias RoomSanctum.Configuration |
| 5 | 5 | |
| 6 | + @foci_source_types [:aqi, :calendar, :ephem, :weather, :cronos] | |
| 7 | + | |
| 6 | 8 | @impl true |
| 7 | 9 | def mount(_params, _session, socket) do |
| 8 | 10 | {:ok, socket} |
@@ -10,10 +12,88 @@ defmodule RoomSanctumWeb.FociLive.Show do
| 10 | 12 | |
| 11 | 13 | @impl true |
| 12 | 14 | def handle_params(%{"id" => id}, _, socket) do |
| 15 | + foci = Configuration.get_foci!(id) | |
| 16 | + | |
| 13 | 17 | {:noreply, |
| 14 | 18 | socket |
| 15 | 19 | |> assign(:page_title, page_title(socket.assigns.live_action)) |
| 16 | − |> assign(:foci, Configuration.get_foci!(id))} | |
| 20 | + |> assign(:foci, foci) | |
| 21 | + |> assign_query_data(foci)} | |
| 22 | + end | |
| 23 | + | |
| 24 | + @impl true | |
| 25 | + def handle_event("create-queries-for-sources", params, socket) do | |
| 26 | + source_ids = | |
| 27 | + params | |
| 28 | + |> Map.get("source_ids", []) | |
| 29 | + |> Enum.map(&String.to_integer/1) | |
| 30 | + | |
| 31 | + foci = socket.assigns.foci | |
| 32 | + existing = socket.assigns.existing_queries_by_source | |
| 33 | + | |
| 34 | + results = | |
| 35 | + source_ids | |
| 36 | + |> Enum.map(&Configuration.get_source!/1) | |
| 37 | + |> Enum.filter(&(&1.type in @foci_source_types)) | |
| 38 | + |> Enum.reject(&Map.has_key?(existing, &1.id)) | |
| 39 | + |> Enum.map(&create_foci_query(&1, foci)) | |
| 40 | + | |
| 41 | + count = Enum.count(results, fn {status, _} -> status == :ok end) | |
| 42 | + | |
| 43 | + flash = | |
| 44 | + case count do | |
| 45 | + 0 -> "No queries created" | |
| 46 | + 1 -> "Created 1 query" | |
| 47 | + n -> "Created #{n} queries" | |
| 48 | + end | |
| 49 | + | |
| 50 | + {:noreply, | |
| 51 | + socket | |
| 52 | + |> put_flash(:info, flash) | |
| 53 | + |> assign_query_data(foci)} | |
| 54 | + end | |
| 55 | + | |
| 56 | + defp create_foci_query(source, foci) do | |
| 57 | + type_str = Atom.to_string(source.type) | |
| 58 | + | |
| 59 | + Configuration.create_query(%{ | |
| 60 | + user_id: foci.user_id, | |
| 61 | + source_id: source.id, | |
| 62 | + name: foci.name, | |
| 63 | + query: Map.put(default_query_for(source.type, foci.id), "__type__", type_str), | |
| 64 | + public: true | |
| 65 | + }) | |
| 66 | + end | |
| 67 | + | |
| 68 | + defp default_query_for(:aqi, foci_id), do: %{"foci_id" => foci_id} | |
| 69 | + defp default_query_for(:ephem, foci_id), do: %{"foci_id" => foci_id} | |
| 70 | + defp default_query_for(:weather, foci_id), do: %{"foci_id" => foci_id} | |
| 71 | + | |
| 72 | + defp default_query_for(:calendar, foci_id), | |
| 73 | + do: %{"foci_id" => foci_id, "days" => 7, "limit" => 50} | |
| 74 | + | |
| 75 | + defp default_query_for(:cronos, foci_id), | |
| 76 | + do: %{"foci_id" => foci_id, "modulo" => 1, "offset" => 0, "period" => "day"} | |
| 77 | + | |
| 78 | + defp assign_query_data(socket, foci) do | |
| 79 | + sources = | |
| 80 | + Configuration.list_cfg_sources({:user, foci.user_id}) | |
| 81 | + |> Enum.filter(&(&1.type in @foci_source_types)) | |
| 82 | + |> Enum.sort_by(&{&1.type, &1.name}) | |
| 83 | + | |
| 84 | + existing = | |
| 85 | + Configuration.list_cfg_queries({:user, foci.user_id}) | |
| 86 | + |> Enum.filter(fn q -> | |
| 87 | + case q.query do | |
| 88 | + %{foci_id: fid} -> fid == foci.id | |
| 89 | + _ -> false | |
| 90 | + end | |
| 91 | + end) | |
| 92 | + |> Map.new(fn q -> {q.source_id, q} end) | |
| 93 | + | |
| 94 | + socket | |
| 95 | + |> assign(:foci_sources, sources) | |
| 96 | + |> assign(:existing_queries_by_source, existing) | |
| 17 | 97 | end |
| 18 | 98 | |
| 19 | 99 | defp page_title(:show), do: "Foci Detail" |
modified
apps/room_sanctum/lib/room_sanctum_web/live/cfg_foci_live/show.html.heex
+63
−0
@@ -55,6 +55,69 @@
| 55 | 55 | </div> |
| 56 | 56 | <% end %> |
| 57 | 57 | |
| 58 | + <!-- Quick-add Queries Card --> | |
| 59 | + <div class="card card-compact w-full bg-base-100 shadow-xl"> | |
| 60 | + <div class="card-body"> | |
| 61 | + <h3 class="card-title">Quick-add Queries</h3> | |
| 62 | + <p class="text-sm text-gray-500"> | |
| 63 | + Create queries for sources that need a foci. New queries will be named "<%= @foci.name %>". | |
| 64 | + </p> | |
| 65 | + | |
| 66 | + <%= if Enum.empty?(@foci_sources) do %> | |
| 67 | + <div class="alert alert-info mt-2"> | |
| 68 | + <span>No foci-requiring sources available.</span> | |
| 69 | + </div> | |
| 70 | + <% else %> | |
| 71 | + <form phx-submit="create-queries-for-sources"> | |
| 72 | + <div class="overflow-x-auto"> | |
| 73 | + <table class="table table-compact w-full"> | |
| 74 | + <thead> | |
| 75 | + <tr> | |
| 76 | + <th></th> | |
| 77 | + <th>Source</th> | |
| 78 | + <th>Type</th> | |
| 79 | + <th></th> | |
| 80 | + </tr> | |
| 81 | + </thead> | |
| 82 | + <tbody> | |
| 83 | + <%= for source <- @foci_sources do %> | |
| 84 | + <% existing = Map.get(@existing_queries_by_source, source.id) %> | |
| 85 | + <tr> | |
| 86 | + <td> | |
| 87 | + <input | |
| 88 | + type="checkbox" | |
| 89 | + name="source_ids[]" | |
| 90 | + value={source.id} | |
| 91 | + class="checkbox" | |
| 92 | + disabled={!!existing} | |
| 93 | + checked={!!existing} | |
| 94 | + /> | |
| 95 | + </td> | |
| 96 | + <td><%= source.name %></td> | |
| 97 | + <td><span class="badge"><%= source.type %></span></td> | |
| 98 | + <td> | |
| 99 | + <%= if existing do %> | |
| 100 | + <.link | |
| 101 | + navigate={Routes.query_show_path(@socket, :show, existing.id)} | |
| 102 | + class="link link-primary text-sm" | |
| 103 | + > | |
| 104 | + <i class="fa-solid fa-arrow-up-right-from-square"></i> <%= existing.name %> | |
| 105 | + </.link> | |
| 106 | + <% end %> | |
| 107 | + </td> | |
| 108 | + </tr> | |
| 109 | + <% end %> | |
| 110 | + </tbody> | |
| 111 | + </table> | |
| 112 | + </div> | |
| 113 | + <div class="card-actions justify-end mt-2"> | |
| 114 | + <button type="submit" class="btn btn-primary btn-sm">Create Queries</button> | |
| 115 | + </div> | |
| 116 | + </form> | |
| 117 | + <% end %> | |
| 118 | + </div> | |
| 119 | + </div> | |
| 120 | + | |
| 58 | 121 | <!-- Map Preview Card --> |
| 59 | 122 | <div class="card card-compact w-full bg-base-100 shadow-xl"> |
| 60 | 123 | <div class="card-body"> |
modified
apps/room_sanctum/lib/room_sanctum_web/live/cfg_query_live/show.ex
+16
−16
@@ -111,7 +111,7 @@ defmodule RoomSanctumWeb.QueryLive.Show do
| 111 | 111 | def handle_info({:vehicle_positions_updated, vehicles}, socket) do |
| 112 | 112 | # Filter vehicles to only show those relevant to current query |
| 113 | 113 | filtered_vehicles = filter_vehicles_for_single_query(vehicles, socket.assigns.query) |
| 114 | − IO.inspect("Query Show: Filtered #{length(vehicles)} to #{length(filtered_vehicles)} vehicles for stop") | |
| 114 | +# IO.inspect("Query Show: Filtered #{length(vehicles)} to #{length(filtered_vehicles)} vehicles for stop") | |
| 115 | 115 | {:noreply, socket |> assign(:vehicle_positions, filtered_vehicles)} |
| 116 | 116 | end |
| 117 | 117 |
@@ -181,58 +181,58 @@ defmodule RoomSanctumWeb.QueryLive.Show do
| 181 | 181 | |
| 182 | 182 | # Helper function to filter vehicles for a single query |
| 183 | 183 | defp filter_vehicles_for_single_query(vehicles, query) do |
| 184 | − IO.inspect("=== SINGLE QUERY FILTERING DEBUG ===") | |
| 185 | − IO.inspect("Input vehicles count: #{length(vehicles)}") | |
| 186 | − IO.inspect("Query: #{query.name} (#{query.source.type})") | |
| 187 | − IO.inspect("Query data: #{inspect(query.query)}") | |
| 184 | +# IO.inspect("=== SINGLE QUERY FILTERING DEBUG ===") | |
| 185 | +# IO.inspect("Input vehicles count: #{length(vehicles)}") | |
| 186 | +# IO.inspect("Query: #{query.name} (#{query.source.type})") | |
| 187 | +# IO.inspect("Query data: #{inspect(query.query)}") | |
| 188 | 188 | |
| 189 | 189 | result = case query.query do |
| 190 | 190 | %{stop: stop_id} when is_binary(stop_id) -> |
| 191 | − IO.inspect("Processing stop query for stop_id: #{stop_id}") | |
| 191 | +# IO.inspect("Processing stop query for stop_id: #{stop_id}") | |
| 192 | 192 | # Get trips that serve this stop |
| 193 | 193 | try do |
| 194 | 194 | stop_trips = RoomSanctum.Storage.get_trips_for_stop(query.source.id, stop_id) |
| 195 | 195 | trip_ids = Enum.map(stop_trips, & &1.trip_id) |
| 196 | − IO.inspect("Found #{length(trip_ids)} trips serving stop #{stop_id}: #{Enum.take(trip_ids, 10)}") | |
| 196 | +# IO.inspect("Found #{length(trip_ids)} trips serving stop #{stop_id}: #{Enum.take(trip_ids, 10)}") | |
| 197 | 197 | |
| 198 | 198 | # Sample some vehicles |
| 199 | 199 | sample_vehicles = Enum.take(vehicles, 5) |
| 200 | − IO.inspect("Sample vehicle trip_ids: #{Enum.map(sample_vehicles, & &1.trip_id)}") | |
| 200 | +# IO.inspect("Sample vehicle trip_ids: #{Enum.map(sample_vehicles, & &1.trip_id)}") | |
| 201 | 201 | |
| 202 | 202 | filtered = vehicles |
| 203 | 203 | |> Enum.filter(fn vehicle -> |
| 204 | 204 | match = vehicle.trip_id && Enum.member?(trip_ids, vehicle.trip_id) |
| 205 | 205 | if match do |
| 206 | − IO.inspect("MATCHED vehicle: #{vehicle.vehicle_id} on trip #{vehicle.trip_id}") | |
| 206 | +# IO.inspect("MATCHED vehicle: #{vehicle.vehicle_id} on trip #{vehicle.trip_id}") | |
| 207 | 207 | end |
| 208 | 208 | match |
| 209 | 209 | end) |
| 210 | 210 | |
| 211 | − IO.inspect("Stop filtering result: #{length(filtered)} vehicles matched") | |
| 211 | +# IO.inspect("Stop filtering result: #{length(filtered)} vehicles matched") | |
| 212 | 212 | filtered |
| 213 | 213 | rescue |
| 214 | 214 | e -> |
| 215 | − IO.inspect("Error getting trips for stop #{stop_id}: #{inspect(e)}") | |
| 215 | +# IO.inspect("Error getting trips for stop #{stop_id}: #{inspect(e)}") | |
| 216 | 216 | [] |
| 217 | 217 | end |
| 218 | 218 | %{routes: route_ids} when is_list(route_ids) -> |
| 219 | − IO.inspect("Processing route query for route_ids: #{inspect(route_ids)}") | |
| 219 | +# IO.inspect("Processing route query for route_ids: #{inspect(route_ids)}") | |
| 220 | 220 | filtered = vehicles |
| 221 | 221 | |> Enum.filter(fn vehicle -> |
| 222 | 222 | match = vehicle.route_id && vehicle.route_id in route_ids |
| 223 | 223 | if match do |
| 224 | − IO.inspect("MATCHED vehicle: #{vehicle.vehicle_id} on route #{vehicle.route_id}") | |
| 224 | +# IO.inspect("MATCHED vehicle: #{vehicle.vehicle_id} on route #{vehicle.route_id}") | |
| 225 | 225 | end |
| 226 | 226 | match |
| 227 | 227 | end) |
| 228 | − IO.inspect("Route filtering result: #{length(filtered)} vehicles matched") | |
| 228 | +# IO.inspect("Route filtering result: #{length(filtered)} vehicles matched") | |
| 229 | 229 | filtered |
| 230 | 230 | _ -> |
| 231 | − IO.inspect("Unhandled query type: #{inspect(query.query)}") | |
| 231 | +# IO.inspect("Unhandled query type: #{inspect(query.query)}") | |
| 232 | 232 | [] |
| 233 | 233 | end |
| 234 | 234 | |
| 235 | − IO.inspect("=== SINGLE QUERY FILTERING COMPLETE: #{length(result)} vehicles ===") | |
| 235 | +# IO.inspect("=== SINGLE QUERY FILTERING COMPLETE: #{length(result)} vehicles ===") | |
| 236 | 236 | result |
| 237 | 237 | end |
| 238 | 238 |
Parents: d48398d