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.
previews in pythiae + preview setup + updated readme
5426bc6 · gmorell · 2023-03-31 03:50
Files changed
modified
README.md
+18
−1
| 1 | + | |
| 1 | 2 | # ApollosCrib |
| 2 | 3 | |
| 3 | −**TODO: Add description** | |
| 4 | +A generalized automated data collection platform, for the purpose of collecting and displaying timely data for wherever you may be. | |
| 5 | + | |
| 6 | +It supports the collection of data from 8 generalized sources at this time: | |
| 7 | + | |
| 8 | +- GTFS (+RT) | |
| 9 | +- GBFS | |
| 10 | +- iCal | |
| 11 | +- Tidal | |
| 12 | +- Ephem | |
| 13 | +- AirNow | |
| 14 | +- OpenWeather | |
| 15 | +- Cronos | |
| 16 | + | |
| 17 | +These can be formed into reusable queries against these sources into visions, and the ability to publish the result of these visions to relevant consumers via MQTT topics for downstream consumption. | |
| 18 | + | |
| 19 | +## Public Demo | |
| 4 | 20 | |
| 21 | +The public demo instance https://ac.gmp.io/ is here, and the landing data displays queries for various entities around Assembly Row, Somerville, MA, US |
modified
apps/room_hermes/config/runtime.exs
+0
−2
| 12 | 12 | config :room_hermes, RoomHermesWeb.Endpoint, server: true |
| 13 | 13 | end |
| 14 | 14 | |
| 15 | −config :room_hermes, :rabbit, username: System.get_env("AMQP_USER"), password: System.get_env("AMQP_PASSWORD") | |
| 16 | − | |
| 17 | 15 | if config_env() == :prod do |
| 18 | 16 | database_url = |
| 19 | 17 | System.get_env("DATABASE_URL") || |
modified
apps/room_hermes/lib/room_hermes_web/controllers/user_controller.ex
+8
−15
| 6 | 6 | |
| 7 | 7 | action_fallback RoomHermesWeb.FallbackController |
| 8 | 8 | |
| 9 | − def create(conn, %{"username" => username, "password" => password} = args) do | |
| 10 | − # rabbit decided to misbehave and pass even the local auth thru rabbitauth so we're doing a short circuit | |
| 11 | − envauth = Application.get_env(:room_hermes, :rabbit) | |
| 12 | − cond do | |
| 13 | − username == envauth[:username] && password == envauth[:password] -> send_resp(conn, :ok, "allow") | |
| 14 | − true -> | |
| 15 | − case args["client_id"] == username do | |
| 16 | − true -> | |
| 17 | − case Accounts.find_rabbit_user(username, password) do | |
| 18 | − nil -> send_resp(conn, :ok, "deny") | |
| 19 | − val -> send_resp(conn, :ok, "allow") | |
| 20 | − end | |
| 21 | − false -> send_resp(conn, :ok, "deny") | |
| 22 | − end | |
| 9 | + def create(conn, %{"username" => username, "password" => password, "client_id" => client_id}) do | |
| 10 | + case client_id == username do | |
| 11 | + true -> | |
| 12 | + case Accounts.find_rabbit_user(username, password) do | |
| 13 | + nil -> send_resp(conn, :ok, "deny") | |
| 14 | + val -> send_resp(conn, :ok, "allow") | |
| 23 | 15 | end |
| 24 | − | |
| 16 | + false -> send_resp(conn, :ok, "deny") | |
| 17 | + end | |
| 25 | 18 | end |
| 26 | 19 | end |
modified
apps/room_sanctum/lib/room_sanctum/configuration.ex
+2
−0
| 480 | 480 | """ |
| 481 | 481 | def get_pythiae!(id), do: Repo.get!(Pythiae, id) |
| 482 | 482 | |
| 483 | + def get_pythiae!(:name, name), do: Repo.get_by(Pythiae, name: name) | |
| 484 | + | |
| 483 | 485 | def get_pythiae(:vision, id) do |
| 484 | 486 | from(p in Pythiae, where: ^id in p.visions) |> Repo.all |
| 485 | 487 | end |
added
apps/room_sanctum/lib/room_sanctum_web/live/cfg_pythiae_live/public.ex
+70
−0
| 1 | +defmodule RoomSanctumWeb.PythiaeLive.Public do | |
| 2 | + use RoomSanctumWeb, :live_view_a | |
| 3 | + | |
| 4 | + alias RoomSanctum.Configuration | |
| 5 | + | |
| 6 | + @impl true | |
| 7 | + def mount(_params, _session, socket) do | |
| 8 | + if connected?(socket), do: Process.send_after(self(), :update, 500) | |
| 9 | + {:ok, socket} | |
| 10 | + end | |
| 11 | + | |
| 12 | + @impl true | |
| 13 | + def handle_info(:update_sec, socket) do | |
| 14 | + pythiae = Configuration.get_pythiae(:vision, socket.assigns.vision_id) | |
| 15 | + {:noreply, socket |> assign(:pythiae, pythiae)} | |
| 16 | + end | |
| 17 | + | |
| 18 | + defp page_title(:show), do: "Show Pythiae" | |
| 19 | + | |
| 20 | + @impl true | |
| 21 | + def handle_params(%{"name" => name}, _, socket) do | |
| 22 | + {:noreply, | |
| 23 | + socket | |
| 24 | + |> assign(:page_title, page_title(socket.assigns.live_action)) | |
| 25 | + |> assign(:pythiae, Configuration.get_pythiae!(:name, name)) | |
| 26 | + |> assign(:preview, []) | |
| 27 | + |> assign(:preview_mode, :basic) | |
| 28 | + } | |
| 29 | + end | |
| 30 | + | |
| 31 | + @impl true | |
| 32 | + def handle_info(:update, socket) do | |
| 33 | + Process.send_after(self(), :update, 15000) | |
| 34 | + %{data: data, queries: queries} = RoomSanctum.Worker.Vision.get_state(socket.assigns.pythiae.curr_vision) | |
| 35 | + {:noreply, socket |> assign(:preview, data) |> assign(:queries, queries)} | |
| 36 | + end | |
| 37 | + | |
| 38 | + defp condense({id, type}, data) do | |
| 39 | + RoomSanctum.Condenser.BasicMQTT.condense({id, type}, data) | |
| 40 | + end | |
| 41 | + | |
| 42 | + defp icon(type) do | |
| 43 | + RoomSanctumWeb.IconHelpers.icon(type) | |
| 44 | + end | |
| 45 | + | |
| 46 | + def preview(condensed, {id, type}) do | |
| 47 | + %{data: condensed, id: id, type: type} | |
| 48 | + end | |
| 49 | + | |
| 50 | + defp get_query_data(item, queries, size \\ 8) do | |
| 51 | + as_map = queries |> Enum.map(fn x -> {x.id, x} end) |> Enum.into(%{}) | |
| 52 | + case Map.get(as_map, item) do | |
| 53 | + nil -> item | |
| 54 | + val -> | |
| 55 | + case (val.name |> String.length > size) do | |
| 56 | + true -> s = val.name |> String.slice(0, size) | |
| 57 | + s <> "..." | |
| 58 | + false -> val.name | |
| 59 | + end | |
| 60 | + end | |
| 61 | + end | |
| 62 | + | |
| 63 | + defp get_query_data_icon(item, queries) do | |
| 64 | + as_map = queries |> Enum.map(fn x -> {x.id, x} end) |> Enum.into(%{}) | |
| 65 | + case Map.get(as_map, item) do | |
| 66 | + nil -> "" | |
| 67 | + val -> icon(val.source.type) | |
| 68 | + end | |
| 69 | + end | |
| 70 | +end |
added
apps/room_sanctum/lib/room_sanctum_web/live/cfg_pythiae_live/public.html.heex
+24
−0
Click to load diff…
modified
apps/room_sanctum/lib/room_sanctum_web/live/cfg_pythiae_live/show.ex
+67
−1
Click to load diff…
modified
apps/room_sanctum/lib/room_sanctum_web/live/cfg_pythiae_live/show.html.heex
+52
−4
Click to load diff…
modified
apps/room_sanctum/lib/room_sanctum_web/live/landing_live/index.html.heex
+2
−0
Click to load diff…
modified
apps/room_sanctum/lib/room_sanctum_web/router.ex
+6
−1
Click to load diff…
added
apps/room_sanctum/lib/room_sanctum_web/templates/layout/root_public.html.heex
+20
−0
Click to load diff…
modified
config/dev.exs
+1
−1
Click to load diff…
modified
config/runtime.exs
+0
−2
Click to load diff…
Parents: 3697d24