auto style things

This commit is contained in:
Graham McIntire 2023-12-17 12:11:57 -06:00
parent e240954b25
commit da296d852d
47 changed files with 241 additions and 244 deletions

View file

@ -82,8 +82,7 @@
# You can customize the priority of any check # You can customize the priority of any check
# Priority values are: `low, normal, high, higher` # Priority values are: `low, normal, high, higher`
# #
{Credo.Check.Design.AliasUsage, {Credo.Check.Design.AliasUsage, [priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
[priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]},
# You can also customize the exit_status of each check. # You can also customize the exit_status of each check.
# If you don't want TODO comments to cause `mix credo` to fail, just # If you don't want TODO comments to cause `mix credo` to fail, just
# set this value to 0 (zero). # set this value to 0 (zero).

View file

@ -1,6 +1,6 @@
[ [
import_deps: [:ecto, :ecto_sql, :phoenix, :stream_data], import_deps: [:ecto, :ecto_sql, :phoenix, :stream_data],
subdirectories: ["priv/*/migrations"], subdirectories: ["priv/*/migrations"],
plugins: [Phoenix.LiveView.HTMLFormatter,Styler], plugins: [Phoenix.LiveView.HTMLFormatter, Styler],
inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"] inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"]
] ]

View file

@ -33,8 +33,7 @@ config :aprs, Aprs.Mailer, adapter: Swoosh.Adapters.Local
config :esbuild, config :esbuild,
version: "0.14.41", version: "0.14.41",
default: [ default: [
args: args: ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*),
~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*),
cd: Path.expand("../assets", __DIR__), cd: Path.expand("../assets", __DIR__),
env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)} env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)}
] ]
@ -62,7 +61,7 @@ config :phoenix, :json_library, Jason
config :aprs, config :aprs,
ecto_repos: [Aprs.Repo], ecto_repos: [Aprs.Repo],
aprs_is_server: System.get_env("APRS_SERVER", "dallas.aprs2.net"), aprs_is_server: System.get_env("APRS_SERVER", "dallas.aprs2.net"),
aprs_is_port: 14580, aprs_is_port: 14_580,
aprs_is_default_filter: System.get_env("APRS_FILTER"), aprs_is_default_filter: System.get_env("APRS_FILTER"),
aprs_is_login_id: System.get_env("APRS_CALLSIGN"), aprs_is_login_id: System.get_env("APRS_CALLSIGN"),
aprs_is_password: System.get_env("APRS_PASSCODE"), aprs_is_password: System.get_env("APRS_PASSCODE"),

View file

@ -66,7 +66,7 @@ if config_env() == :prod do
config :aprs, config :aprs,
ecto_repos: [Aprs.Repo], ecto_repos: [Aprs.Repo],
aprs_is_server: System.get_env("APRS_SERVER", "dallas.aprs2.net"), aprs_is_server: System.get_env("APRS_SERVER", "dallas.aprs2.net"),
aprs_is_port: 14580, aprs_is_port: 14_580,
aprs_is_default_filter: System.get_env("APRS_FILTER"), aprs_is_default_filter: System.get_env("APRS_FILTER"),
aprs_is_login_id: System.get_env("APRS_CALLSIGN"), aprs_is_login_id: System.get_env("APRS_CALLSIGN"),
aprs_is_password: System.get_env("APRS_PASSCODE") aprs_is_password: System.get_env("APRS_PASSCODE")

View file

@ -4,9 +4,11 @@ defmodule Aprs.Accounts do
""" """
import Ecto.Query, warn: false import Ecto.Query, warn: false
alias Aprs.Repo
alias Aprs.Accounts.{User, UserToken, UserNotifier} alias Aprs.Accounts.User
alias Aprs.Accounts.UserNotifier
alias Aprs.Accounts.UserToken
alias Aprs.Repo
## Database getters ## Database getters
@ -38,8 +40,7 @@ defmodule Aprs.Accounts do
nil nil
""" """
def get_user_by_email_and_password(email, password) def get_user_by_email_and_password(email, password) when is_binary(email) and is_binary(password) do
when is_binary(email) and is_binary(password) do
user = Repo.get_by(User, email: email) user = Repo.get_by(User, email: email)
if User.valid_password?(user, password), do: user if User.valid_password?(user, password), do: user
end end

View file

@ -1,5 +1,7 @@
defmodule Aprs.Accounts.User do defmodule Aprs.Accounts.User do
@moduledoc false
use Ecto.Schema use Ecto.Schema
import Ecto.Changeset import Ecto.Changeset
schema "users" do schema "users" do
@ -122,7 +124,7 @@ defmodule Aprs.Accounts.User do
Confirms the account by setting `confirmed_at`. Confirms the account by setting `confirmed_at`.
""" """
def confirm_changeset(user) do def confirm_changeset(user) do
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) now = NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
change(user, confirmed_at: now) change(user, confirmed_at: now)
end end

View file

@ -1,4 +1,5 @@
defmodule Aprs.Accounts.UserNotifier do defmodule Aprs.Accounts.UserNotifier do
@moduledoc false
import Swoosh.Email import Swoosh.Email
alias Aprs.Mailer alias Aprs.Mailer

View file

@ -1,6 +1,9 @@
defmodule Aprs.Accounts.UserToken do defmodule Aprs.Accounts.UserToken do
@moduledoc false
use Ecto.Schema use Ecto.Schema
import Ecto.Query import Ecto.Query
alias Aprs.Accounts.UserToken alias Aprs.Accounts.UserToken
@hash_algorithm :sha256 @hash_algorithm :sha256

View file

@ -1,11 +1,13 @@
defmodule Aprs.Archiver do defmodule Aprs.Archiver do
@moduledoc false
use GenServer use GenServer
alias AprsWeb.Endpoint
require Jason require Jason
require Logger require Logger
# alias Aprs.{Packet, Repo} # alias Aprs.{Packet, Repo}
alias AprsWeb.Endpoint
@topic "call" @topic "call"
# API # API

View file

@ -1,4 +1,5 @@
defmodule Aprs.Convert do defmodule Aprs.Convert do
@moduledoc false
def wind(speed, :ultimeter, :mph), do: speed * 0.0621371192 def wind(speed, :ultimeter, :mph), do: speed * 0.0621371192
def temp(value, :ultimeter, :f), do: value * 0.1 def temp(value, :ultimeter, :f), do: value * 0.1

View file

@ -1,6 +1,9 @@
defmodule Aprs.DataExtended do defmodule Aprs.DataExtended do
@moduledoc false
use Ecto.Schema use Ecto.Schema
import Ecto.Changeset import Ecto.Changeset
alias Aprs.DataExtended alias Aprs.DataExtended
embedded_schema do embedded_schema do

View file

@ -1,5 +1,7 @@
defmodule Aprs.Is do defmodule Aprs.Is do
@moduledoc false
use GenServer use GenServer
require Logger require Logger
@aprs_timeout 30 * 1000 @aprs_timeout 30 * 1000
@ -14,7 +16,7 @@ defmodule Aprs.Is do
Process.flag(:trap_exit, true) Process.flag(:trap_exit, true)
# Get startup parameters # Get startup parameters
server = Application.get_env(:aprs, :aprs_is_server, 'rotate.aprs2.net') server = Application.get_env(:aprs, :aprs_is_server, ~c"rotate.aprs2.net")
port = Application.get_env(:aprs, :aprs_is_port, 14_580) port = Application.get_env(:aprs, :aprs_is_port, 14_580)
default_filter = Application.get_env(:aprs, :aprs_is_default_filter, "r/33/-96/100") default_filter = Application.get_env(:aprs, :aprs_is_default_filter, "r/33/-96/100")
aprs_user_id = Application.get_env(:aprs, :aprs_is_login_id, "w5isp") aprs_user_id = Application.get_env(:aprs, :aprs_is_login_id, "w5isp")
@ -40,8 +42,9 @@ defmodule Aprs.Is do
# end # end
with {:ok, socket} <- connect_to_aprs_is(server, port), with {:ok, socket} <- connect_to_aprs_is(server, port),
:ok <- send_login_string(socket, aprs_user_id, aprs_passcode, default_filter), :ok <- send_login_string(socket, aprs_user_id, aprs_passcode, default_filter) do
timer <- create_timer(@aprs_timeout) do timer = create_timer(@aprs_timeout)
{:ok, {:ok,
%{ %{
server: server, server: server,

View file

@ -1,4 +1,5 @@
defmodule Aprs.Is.IsSupervisor do defmodule Aprs.Is.IsSupervisor do
@moduledoc false
use Supervisor use Supervisor
def start_link(opts) do def start_link(opts) do

View file

@ -1,3 +1,4 @@
defmodule Aprs.Mailer do defmodule Aprs.Mailer do
@moduledoc false
use Swoosh.Mailer, otp_app: :aprs use Swoosh.Mailer, otp_app: :aprs
end end

View file

@ -1,6 +1,9 @@
defmodule Aprs.Packet do defmodule Aprs.Packet do
@moduledoc false
use Aprs.Schema use Aprs.Schema
import Ecto.Changeset import Ecto.Changeset
alias Aprs.DataExtended alias Aprs.DataExtended
schema "packets" do schema "packets" do

View file

@ -1,3 +1,4 @@
defmodule Aprs.Presence do defmodule Aprs.Presence do
@moduledoc false
use Phoenix.Presence, otp_app: :aprs, pubsub_server: Aprs.PubSub use Phoenix.Presence, otp_app: :aprs, pubsub_server: Aprs.PubSub
end end

View file

@ -1,7 +1,9 @@
defmodule Aprs.Schema do defmodule Aprs.Schema do
@moduledoc false
defmacro __using__(_) do defmacro __using__(_) do
quote do quote do
use Ecto.Schema use Ecto.Schema
@primary_key {:id, :binary_id, autogenerate: true} @primary_key {:id, :binary_id, autogenerate: true}
@foreign_key_type :binary_id @foreign_key_type :binary_id
end end

View file

@ -24,9 +24,9 @@ defmodule AprsWeb do
use Phoenix.Router, helpers: false use Phoenix.Router, helpers: false
# Import common connection and controller functions to use in pipelines # Import common connection and controller functions to use in pipelines
import Plug.Conn
import Phoenix.Controller import Phoenix.Controller
import Phoenix.LiveView.Router import Phoenix.LiveView.Router
import Plug.Conn
end end
end end
@ -43,8 +43,8 @@ defmodule AprsWeb do
formats: [:html, :json], formats: [:html, :json],
layouts: [html: AprsWeb.Layouts] layouts: [html: AprsWeb.Layouts]
import Plug.Conn
import AprsWeb.Gettext import AprsWeb.Gettext
import Plug.Conn
unquote(verified_routes()) unquote(verified_routes())
end end
@ -83,10 +83,10 @@ defmodule AprsWeb do
defp html_helpers do defp html_helpers do
quote do quote do
# HTML escaping functionality # HTML escaping functionality
import Phoenix.HTML
# Core UI components and translation # Core UI components and translation
import AprsWeb.CoreComponents import AprsWeb.CoreComponents
import AprsWeb.Gettext import AprsWeb.Gettext
import Phoenix.HTML
# Shortcut for generating JS commands # Shortcut for generating JS commands
alias Phoenix.LiveView.JS alias Phoenix.LiveView.JS

View file

@ -11,9 +11,10 @@ defmodule AprsWeb.CoreComponents do
""" """
use Phoenix.Component use Phoenix.Component
alias Phoenix.LiveView.JS
import AprsWeb.Gettext import AprsWeb.Gettext
alias Phoenix.LiveView.JS
@doc """ @doc """
Renders a modal. Renders a modal.
@ -359,11 +360,9 @@ defmodule AprsWeb.CoreComponents do
""" """
end end
defp input_border([] = _errors), defp input_border([] = _errors), do: "border-zinc-300 focus:border-zinc-400 focus:ring-zinc-800/5"
do: "border-zinc-300 focus:border-zinc-400 focus:ring-zinc-800/5"
defp input_border([_ | _] = _errors), defp input_border([_ | _] = _errors), do: "border-rose-400 focus:border-rose-400 focus:ring-rose-400/10"
do: "border-rose-400 focus:border-rose-400 focus:ring-rose-400/10"
@doc """ @doc """
Renders a label. Renders a label.
@ -543,8 +542,7 @@ defmodule AprsWeb.CoreComponents do
JS.show(js, JS.show(js,
to: selector, to: selector,
transition: transition:
{"transition-all transform ease-out duration-300", {"transition-all transform ease-out duration-300", "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",
"opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95",
"opacity-100 translate-y-0 sm:scale-100"} "opacity-100 translate-y-0 sm:scale-100"}
) )
end end
@ -554,8 +552,7 @@ defmodule AprsWeb.CoreComponents do
to: selector, to: selector,
time: 200, time: 200,
transition: transition:
{"transition-all transform ease-in duration-200", {"transition-all transform ease-in duration-200", "opacity-100 translate-y-0 sm:scale-100",
"opacity-100 translate-y-0 sm:scale-100",
"opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"} "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"}
) )
end end

View file

@ -1,4 +1,5 @@
defmodule AprsWeb.Layouts do defmodule AprsWeb.Layouts do
@moduledoc false
use AprsWeb, :html use AprsWeb, :html
embed_templates "layouts/*" embed_templates "layouts/*"

View file

@ -1,5 +1,7 @@
defmodule AprsWeb.PacketsLive.Index do defmodule AprsWeb.PacketsLive.Index do
@moduledoc false
use AprsWeb, :live_view use AprsWeb, :live_view
alias AprsWeb.Endpoint alias AprsWeb.Endpoint
@impl true @impl true

View file

@ -1,4 +1,5 @@
defmodule AprsWeb.UserConfirmationInstructionsLive do defmodule AprsWeb.UserConfirmationInstructionsLive do
@moduledoc false
use AprsWeb, :live_view use AprsWeb, :live_view
alias Aprs.Accounts alias Aprs.Accounts
@ -16,8 +17,7 @@ defmodule AprsWeb.UserConfirmationInstructionsLive do
<p> <p>
<.link href={~p"/users/register"}>Register</.link> <.link href={~p"/users/register"}>Register</.link>
| | <.link href={~p"/users/log_in"}>Log in</.link>
<.link href={~p"/users/log_in"}>Log in</.link>
</p> </p>
""" """
end end

View file

@ -1,4 +1,5 @@
defmodule AprsWeb.UserConfirmationLive do defmodule AprsWeb.UserConfirmationLive do
@moduledoc false
use AprsWeb, :live_view use AprsWeb, :live_view
alias Aprs.Accounts alias Aprs.Accounts
@ -17,8 +18,7 @@ defmodule AprsWeb.UserConfirmationLive do
<p class="text-center mt-4"> <p class="text-center mt-4">
<.link href={~p"/users/register"}>Register</.link> <.link href={~p"/users/register"}>Register</.link>
| | <.link href={~p"/users/log_in"}>Log in</.link>
<.link href={~p"/users/log_in"}>Log in</.link>
</p> </p>
</div> </div>
""" """

View file

@ -1,4 +1,5 @@
defmodule AprsWeb.UserForgotPasswordLive do defmodule AprsWeb.UserForgotPasswordLive do
@moduledoc false
use AprsWeb, :live_view use AprsWeb, :live_view
alias Aprs.Accounts alias Aprs.Accounts
@ -21,8 +22,7 @@ defmodule AprsWeb.UserForgotPasswordLive do
</.simple_form> </.simple_form>
<p class="text-center mt-4"> <p class="text-center mt-4">
<.link href={~p"/users/register"}>Register</.link> <.link href={~p"/users/register"}>Register</.link>
| | <.link href={~p"/users/log_in"}>Log in</.link>
<.link href={~p"/users/log_in"}>Log in</.link>
</p> </p>
</div> </div>
""" """

View file

@ -1,4 +1,5 @@
defmodule AprsWeb.UserLoginLive do defmodule AprsWeb.UserLoginLive do
@moduledoc false
use AprsWeb, :live_view use AprsWeb, :live_view
def render(assigns) do def render(assigns) do

View file

@ -1,4 +1,5 @@
defmodule AprsWeb.UserRegistrationLive do defmodule AprsWeb.UserRegistrationLive do
@moduledoc false
use AprsWeb, :live_view use AprsWeb, :live_view
alias Aprs.Accounts alias Aprs.Accounts

View file

@ -1,4 +1,5 @@
defmodule AprsWeb.UserResetPasswordLive do defmodule AprsWeb.UserResetPasswordLive do
@moduledoc false
use AprsWeb, :live_view use AprsWeb, :live_view
alias Aprs.Accounts alias Aprs.Accounts
@ -33,8 +34,7 @@ defmodule AprsWeb.UserResetPasswordLive do
<p class="text-center mt-4"> <p class="text-center mt-4">
<.link href={~p"/users/register"}>Register</.link> <.link href={~p"/users/register"}>Register</.link>
| | <.link href={~p"/users/log_in"}>Log in</.link>
<.link href={~p"/users/log_in"}>Log in</.link>
</p> </p>
</div> </div>
""" """

View file

@ -1,4 +1,5 @@
defmodule AprsWeb.UserSettingsLive do defmodule AprsWeb.UserSettingsLive do
@moduledoc false
use AprsWeb, :live_view use AprsWeb, :live_view
alias Aprs.Accounts alias Aprs.Accounts

View file

@ -1,5 +1,7 @@
defmodule AprsWeb.Telemetry do defmodule AprsWeb.Telemetry do
@moduledoc false
use Supervisor use Supervisor
import Telemetry.Metrics import Telemetry.Metrics
def start_link(arg) do def start_link(arg) do
@ -70,8 +72,7 @@ defmodule AprsWeb.Telemetry do
), ),
summary("aprs.repo.query.idle_time", summary("aprs.repo.query.idle_time",
unit: {:native, :millisecond}, unit: {:native, :millisecond},
description: description: "The time the connection spent waiting before being checked out for the query"
"The time the connection spent waiting before being checked out for the query"
), ),
# VM Metrics # VM Metrics

View file

@ -1,8 +1,9 @@
defmodule AprsWeb.UserAuth do defmodule AprsWeb.UserAuth do
@moduledoc false
use AprsWeb, :verified_routes use AprsWeb, :verified_routes
import Plug.Conn
import Phoenix.Controller import Phoenix.Controller
import Plug.Conn
alias Aprs.Accounts alias Aprs.Accounts

View file

@ -3,44 +3,46 @@ defmodule Parser do
Main parsing library Main parsing library
""" """
# import Bitwise # import Bitwise
alias Aprs.{Convert, Packet} alias Aprs.Convert
alias Parser.Types.{MicE, Position} alias Aprs.Packet
alias Parser.Types.MicE
alias Parser.Types.Position
require Logger require Logger
def parse(message) do def parse(message) do
try do [sender, path, data] = String.split(message, [">", ":"], parts: 3)
[sender, path, data] = String.split(message, [">", ":"], parts: 3)
with [base_callsign, ssid] <- parse_callsign(sender), with [base_callsign, ssid] <- parse_callsign(sender),
data_type <- parse_datatype(String.first(data)), data_type = parse_datatype(String.first(data)),
data <- String.trim(data), data = String.trim(data),
[destination, path] <- String.split(path, ",", parts: 2), [destination, path] <- String.split(path, ",", parts: 2) do
data_extended <- parse_data(data_type, destination, data) do data_extended = parse_data(data_type, destination, data)
{:ok,
%Packet{ {:ok,
# TODO: temporary for liveview %Packet{
id: Ecto.UUID.generate(), # TODO: temporary for liveview
sender: sender, id: Ecto.UUID.generate(),
path: path, sender: sender,
destination: destination, path: path,
information_field: data, destination: destination,
data_type: data_type, information_field: data,
base_callsign: base_callsign, data_type: data_type,
ssid: ssid, base_callsign: base_callsign,
data_extended: data_extended ssid: ssid,
}} data_extended: data_extended
else }}
true -> else
{:error, "PARSE ERROR"} true ->
end {:error, "PARSE ERROR"}
rescue
_ ->
# Logger.debug("PARSE ERROR: " <> message)
{:ok, file} = File.open("./badpackets.txt", [:append])
IO.binwrite(file, message <> "\n\n")
File.close(file)
{:error, :invalid_packet}
end end
rescue
_ ->
# Logger.debug("PARSE ERROR: " <> message)
{:ok, file} = File.open("./badpackets.txt", [:append])
IO.binwrite(file, message <> "\n\n")
File.close(file)
{:error, :invalid_packet}
end end
def parse_callsign(callsign) do def parse_callsign(callsign) do
@ -80,11 +82,9 @@ defmodule Parser do
def parse_data(:mic_e_old, destination, data), do: parse_mic_e(destination, data) def parse_data(:mic_e_old, destination, data), do: parse_mic_e(destination, data)
def parse_data(:position, _destination, data), do: parse_position_without_timestamp(false, data) def parse_data(:position, _destination, data), do: parse_position_without_timestamp(false, data)
def parse_data(:position_with_message, _destination, data), def parse_data(:position_with_message, _destination, data), do: parse_position_without_timestamp(true, data)
do: parse_position_without_timestamp(true, data)
def parse_data(:timestamped_position, _destination, data), def parse_data(:timestamped_position, _destination, data), do: parse_position_with_timestamp(false, data)
do: parse_position_with_timestamp(false, data)
def parse_data( def parse_data(
:timestamped_position_with_message, :timestamped_position_with_message,
@ -94,14 +94,9 @@ defmodule Parser do
parse_position_with_datetime_and_weather(true, date_time_position, weather_report) parse_position_with_datetime_and_weather(true, date_time_position, weather_report)
end end
def parse_data(:timestamped_position_with_message, _destination, data), def parse_data(:timestamped_position_with_message, _destination, data), do: parse_position_with_timestamp(true, data)
do: parse_position_with_timestamp(true, data)
def parse_data( def parse_data(:message, _destination, <<":", addressee::binary-size(9), ":", message_text::binary>>) do
:message,
_destination,
<<":", addressee::binary-size(9), ":", message_text::binary>>
) do
# Aprs messages can have an optional message number tacked onto the end # Aprs messages can have an optional message number tacked onto the end
# for the purposes of acknowledging message receipt. # for the purposes of acknowledging message receipt.
# The sender tacks the message number onto the end of the message, # The sender tacks the message number onto the end of the message,
@ -129,13 +124,9 @@ defmodule Parser do
def parse_data(_type, _destination, _data), do: nil def parse_data(_type, _destination, _data), do: nil
def parse_position_with_datetime_and_weather( def parse_position_with_datetime_and_weather(aprs_messaging?, date_time_position_data, weather_report) do
aprs_messaging?, <<time::binary-size(7), latitude::binary-size(8), sym_table_id::binary-size(1), longitude::binary-size(9)>> =
date_time_position_data, date_time_position_data
weather_report
) do
<<time::binary-size(7), latitude::binary-size(8), sym_table_id::binary-size(1),
longitude::binary-size(9)>> = date_time_position_data
# position = Parser.Types.Position.from_aprs(latitude, longitude) # position = Parser.Types.Position.from_aprs(latitude, longitude)
%{latitude: lat, longitude: lon} = Parser.Types.Position.from_aprs(latitude, longitude) %{latitude: lat, longitude: lon} = Parser.Types.Position.from_aprs(latitude, longitude)
@ -153,8 +144,8 @@ defmodule Parser do
end end
def decode_compressed_position( def decode_compressed_position(
<<"/", latitude::binary-size(4), longitude::binary-size(4), _symbol::binary-size(1), <<"/", latitude::binary-size(4), longitude::binary-size(4), _symbol::binary-size(1), _cs::binary-size(2),
_cs::binary-size(2), _compression_type::binary-size(2), _rest::binary>> _compression_type::binary-size(2), _rest::binary>>
) do ) do
lat = convert_to_base91(latitude) lat = convert_to_base91(latitude)
lon = convert_to_base91(longitude) lon = convert_to_base91(longitude)
@ -214,32 +205,29 @@ defmodule Parser do
def parse_position_without_timestamp( def parse_position_without_timestamp(
aprs_messaging?, aprs_messaging?,
<<_dti::binary-size(1), latitude::binary-size(8), sym_table_id::binary-size(1), <<_dti::binary-size(1), latitude::binary-size(8), sym_table_id::binary-size(1), longitude::binary-size(9),
longitude::binary-size(9), symbol_code::binary-size(1), comment::binary>> symbol_code::binary-size(1), comment::binary>>
) do ) do
try do # position = Position.from_aprs(latitude, longitude)
# position = Position.from_aprs(latitude, longitude) %{latitude: lat, longitude: lon} = Parser.Types.Position.from_aprs(latitude, longitude)
%{latitude: lat, longitude: lon} = Parser.Types.Position.from_aprs(latitude, longitude)
%{ %{
latitude: lat, latitude: lat,
longitude: lon, longitude: lon,
symbol_table_id: sym_table_id, symbol_table_id: sym_table_id,
symbol_code: symbol_code, symbol_code: symbol_code,
comment: comment, comment: comment,
data_type: :position, data_type: :position,
aprs_messaging?: aprs_messaging? aprs_messaging?: aprs_messaging?
} }
rescue rescue
e -> Logger.error(Exception.format(:error, e, __STACKTRACE__)) e -> Logger.error(Exception.format(:error, e, __STACKTRACE__))
end
end end
def parse_position_without_timestamp( def parse_position_without_timestamp(
aprs_messaging?, aprs_messaging?,
<<_dti::binary-size(1), "/", latitude::binary-size(4), longitude::binary-size(4), <<_dti::binary-size(1), "/", latitude::binary-size(4), longitude::binary-size(4), sym_table_id::binary-size(1),
sym_table_id::binary-size(1), _cs::binary-size(2), _compression_type::binary-size(1), _cs::binary-size(2), _compression_type::binary-size(1), comment::binary>> = message
comment::binary>> = message
) do ) do
# {:ok, file} = File.open("./compressed.txt", [:append]) # {:ok, file} = File.open("./compressed.txt", [:append])
# IO.binwrite( # IO.binwrite(
@ -278,28 +266,25 @@ defmodule Parser do
def parse_position_with_timestamp( def parse_position_with_timestamp(
aprs_messaging?, aprs_messaging?,
<<_dti::binary-size(1), time::binary-size(7), latitude::binary-size(8), <<_dti::binary-size(1), time::binary-size(7), latitude::binary-size(8), sym_table_id::binary-size(1),
sym_table_id::binary-size(1), longitude::binary-size(9), symbol_code::binary-size(1), longitude::binary-size(9), symbol_code::binary-size(1), comment::binary>>
comment::binary>>
) do ) do
try do position = Position.from_aprs(latitude, longitude)
position = Position.from_aprs(latitude, longitude) %{latitude: lat, longitude: lon} = Parser.Types.Position.from_aprs(latitude, longitude)
%{latitude: lat, longitude: lon} = Parser.Types.Position.from_aprs(latitude, longitude)
%{ %{
latitude: lat, latitude: lat,
longitude: lon, longitude: lon,
position: position, position: position,
time: time, time: time,
symbol_table_id: sym_table_id, symbol_table_id: sym_table_id,
symbol_code: symbol_code, symbol_code: symbol_code,
comment: comment, comment: comment,
data_type: :position, data_type: :position,
aprs_messaging?: aprs_messaging? aprs_messaging?: aprs_messaging?
} }
rescue rescue
e -> Logger.error(Exception.format(:error, e, __STACKTRACE__)) e -> Logger.error(Exception.format(:error, e, __STACKTRACE__))
end
end end
def parse_mic_e(destination_field, information_field) do def parse_mic_e(destination_field, information_field) do
@ -356,7 +341,7 @@ defmodule Parser do
min = digits |> Enum.slice(2..3) |> Enum.join() |> String.to_integer() min = digits |> Enum.slice(2..3) |> Enum.join() |> String.to_integer()
fractional = digits |> Enum.slice(4..5) |> Enum.join() |> String.to_integer() fractional = digits |> Enum.slice(4..5) |> Enum.join() |> String.to_integer()
[ns, lo, ew] = destination_field |> to_charlist |> Enum.slice(3..5) [ns, lo, ew] = destination_field |> to_charlist() |> Enum.slice(3..5)
north_south_indicator = north_south_indicator =
case ns do case ns do
@ -405,7 +390,7 @@ defmodule Parser do
# Convert the bits to binary to get the array index # Convert the bits to binary to get the array index
index = message_bit_1 * 4 + message_bit_2 * 2 + message_bit_3 index = message_bit_1 * 4 + message_bit_2 * 2 + message_bit_3
# need to invert this from the actual array index # need to invert this from the actual array index
display_index = to_string(7 - index) |> String.pad_leading(2, "0") display_index = (7 - index) |> to_string() |> String.pad_leading(2, "0")
[message_code, message_description] = [message_code, message_description] =
case message_type do case message_type do
@ -432,9 +417,8 @@ defmodule Parser do
end end
def parse_mic_e_information( def parse_mic_e_information(
<<dti::binary-size(1), d28::integer, m28::integer, f28::integer, sp28::integer, <<dti::binary-size(1), d28::integer, m28::integer, f28::integer, sp28::integer, dc28::integer, se28::integer,
dc28::integer, se28::integer, symbol::binary-size(1), table::binary-size(1), symbol::binary-size(1), table::binary-size(1), message::binary>> = _information_field,
message::binary>> = _information_field,
longitude_offset longitude_offset
) do ) do
m = m =

View file

@ -54,12 +54,10 @@ defmodule Parser.Types.Position do
end end
defp convert_garbage_to_zero(value) do defp convert_garbage_to_zero(value) do
try do _ = String.to_float(value)
_ = String.to_float(value) value
value rescue
rescue ArgumentError -> "00000.00"
ArgumentError -> "00000.00"
end
end end
# def to_string(%__MODULE__{} = position) do # def to_string(%__MODULE__{} = position) do
@ -93,10 +91,5 @@ defmodule Parser.Types.Position do
# |> Float.round(2) # |> Float.round(2)
defp convert_fractional(fractional), defp convert_fractional(fractional),
do: do: fractional |> String.trim() |> String.pad_leading(4, "0") |> String.to_float() |> Kernel.*(60)
fractional
|> String.trim()
|> String.pad_leading(4, "0")
|> String.to_float()
|> Kernel.*(60)
end end

View file

@ -1,10 +1,11 @@
defmodule Aprs.AccountsTest do defmodule Aprs.AccountsTest do
use Aprs.DataCase use Aprs.DataCase
alias Aprs.Accounts
import Aprs.AccountsFixtures import Aprs.AccountsFixtures
alias Aprs.Accounts.{User, UserToken}
alias Aprs.Accounts
alias Aprs.Accounts.User
alias Aprs.Accounts.UserToken
describe "get_user_by_email/1" do describe "get_user_by_email/1" do
test "does not return the user if the email does not exist" do test "does not return the user if the email does not exist" do

View file

@ -1,5 +1,6 @@
defmodule Aprs.ConvertTest do defmodule Aprs.ConvertTest do
use ExUnit.Case use ExUnit.Case
alias Aprs.Convert alias Aprs.Convert
describe "wind/3" do describe "wind/3" do

View file

@ -56,13 +56,9 @@ defmodule AprsWeb.UserSessionControllerTest do
test "login following registration", %{conn: conn, user: user} do test "login following registration", %{conn: conn, user: user} do
conn = conn =
conn post(conn, ~p"/users/log_in", %{
|> post(~p"/users/log_in", %{
"_action" => "registered", "_action" => "registered",
"user" => %{ "user" => %{"email" => user.email, "password" => valid_user_password()}
"email" => user.email,
"password" => valid_user_password()
}
}) })
assert redirected_to(conn) == ~p"/" assert redirected_to(conn) == ~p"/"
@ -71,13 +67,9 @@ defmodule AprsWeb.UserSessionControllerTest do
test "login following password update", %{conn: conn, user: user} do test "login following password update", %{conn: conn, user: user} do
conn = conn =
conn post(conn, ~p"/users/log_in", %{
|> post(~p"/users/log_in", %{
"_action" => "password_updated", "_action" => "password_updated",
"user" => %{ "user" => %{"email" => user.email, "password" => valid_user_password()}
"email" => user.email,
"password" => valid_user_password()
}
}) })
assert redirected_to(conn) == ~p"/users/settings" assert redirected_to(conn) == ~p"/users/settings"

View file

@ -1,8 +1,8 @@
defmodule AprsWeb.UserConfirmationInstructionsLiveTest do defmodule AprsWeb.UserConfirmationInstructionsLiveTest do
use AprsWeb.ConnCase use AprsWeb.ConnCase
import Phoenix.LiveViewTest
import Aprs.AccountsFixtures import Aprs.AccountsFixtures
import Phoenix.LiveViewTest
alias Aprs.Accounts alias Aprs.Accounts
alias Aprs.Repo alias Aprs.Repo

View file

@ -1,8 +1,8 @@
defmodule AprsWeb.UserConfirmationLiveTest do defmodule AprsWeb.UserConfirmationLiveTest do
use AprsWeb.ConnCase use AprsWeb.ConnCase
import Phoenix.LiveViewTest
import Aprs.AccountsFixtures import Aprs.AccountsFixtures
import Phoenix.LiveViewTest
alias Aprs.Accounts alias Aprs.Accounts
alias Aprs.Repo alias Aprs.Repo

View file

@ -1,8 +1,8 @@
defmodule AprsWeb.UserForgotPasswordLiveTest do defmodule AprsWeb.UserForgotPasswordLiveTest do
use AprsWeb.ConnCase use AprsWeb.ConnCase
import Phoenix.LiveViewTest
import Aprs.AccountsFixtures import Aprs.AccountsFixtures
import Phoenix.LiveViewTest
alias Aprs.Accounts alias Aprs.Accounts
alias Aprs.Repo alias Aprs.Repo

View file

@ -1,8 +1,8 @@
defmodule AprsWeb.UserLoginLiveTest do defmodule AprsWeb.UserLoginLiveTest do
use AprsWeb.ConnCase use AprsWeb.ConnCase
import Phoenix.LiveViewTest
import Aprs.AccountsFixtures import Aprs.AccountsFixtures
import Phoenix.LiveViewTest
describe "Log in page" do describe "Log in page" do
test "renders log in page", %{conn: conn} do test "renders log in page", %{conn: conn} do
@ -45,9 +45,7 @@ defmodule AprsWeb.UserLoginLiveTest do
{:ok, lv, _html} = live(conn, ~p"/users/log_in") {:ok, lv, _html} = live(conn, ~p"/users/log_in")
form = form =
form(lv, "#login_form", form(lv, "#login_form", user: %{email: "test@email.com", password: "123456", remember_me: true})
user: %{email: "test@email.com", password: "123456", remember_me: true}
)
conn = submit_form(form, conn) conn = submit_form(form, conn)

View file

@ -1,8 +1,8 @@
defmodule AprsWeb.UserRegistrationLiveTest do defmodule AprsWeb.UserRegistrationLiveTest do
use AprsWeb.ConnCase use AprsWeb.ConnCase
import Phoenix.LiveViewTest
import Aprs.AccountsFixtures import Aprs.AccountsFixtures
import Phoenix.LiveViewTest
describe "Registration page" do describe "Registration page" do
test "renders registration page", %{conn: conn} do test "renders registration page", %{conn: conn} do

View file

@ -1,8 +1,8 @@
defmodule AprsWeb.UserResetPasswordLiveTest do defmodule AprsWeb.UserResetPasswordLiveTest do
use AprsWeb.ConnCase use AprsWeb.ConnCase
import Phoenix.LiveViewTest
import Aprs.AccountsFixtures import Aprs.AccountsFixtures
import Phoenix.LiveViewTest
alias Aprs.Accounts alias Aprs.Accounts
@ -39,9 +39,7 @@ defmodule AprsWeb.UserResetPasswordLiveTest do
result = result =
lv lv
|> element("#reset_password_form") |> element("#reset_password_form")
|> render_change( |> render_change(user: %{"password" => "secret12", "confirmation_password" => "secret123456"})
user: %{"password" => "secret12", "confirmation_password" => "secret123456"}
)
assert result =~ "should be at least 12 character" assert result =~ "should be at least 12 character"
assert result =~ "does not match password" assert result =~ "does not match password"

View file

@ -1,9 +1,10 @@
defmodule AprsWeb.UserSettingsLiveTest do defmodule AprsWeb.UserSettingsLiveTest do
use AprsWeb.ConnCase use AprsWeb.ConnCase
alias Aprs.Accounts
import Phoenix.LiveViewTest
import Aprs.AccountsFixtures import Aprs.AccountsFixtures
import Phoenix.LiveViewTest
alias Aprs.Accounts
describe "Settings page" do describe "Settings page" do
test "renders settings page", %{conn: conn} do test "renders settings page", %{conn: conn} do

View file

@ -1,10 +1,11 @@
defmodule AprsWeb.UserAuthTest do defmodule AprsWeb.UserAuthTest do
use AprsWeb.ConnCase, async: true use AprsWeb.ConnCase, async: true
alias Phoenix.LiveView import Aprs.AccountsFixtures
alias Aprs.Accounts alias Aprs.Accounts
alias AprsWeb.UserAuth alias AprsWeb.UserAuth
import Aprs.AccountsFixtures alias Phoenix.LiveView
@remember_me_cookie "_aprs_web_user_remember_me" @remember_me_cookie "_aprs_web_user_remember_me"
@ -139,7 +140,7 @@ defmodule AprsWeb.UserAuthTest do
end end
test "assigns nil to current_user assign if there isn't a user_token", %{conn: conn} do test "assigns nil to current_user assign if there isn't a user_token", %{conn: conn} do
session = conn |> get_session() session = get_session(conn)
{:cont, updated_socket} = {:cont, updated_socket} =
UserAuth.on_mount(:mount_current_user, %{}, session, %LiveView.Socket{}) UserAuth.on_mount(:mount_current_user, %{}, session, %LiveView.Socket{})
@ -173,7 +174,7 @@ defmodule AprsWeb.UserAuthTest do
end end
test "redirects to login page if there isn't a user_token ", %{conn: conn} do test "redirects to login page if there isn't a user_token ", %{conn: conn} do
session = conn |> get_session() session = get_session(conn)
socket = %LiveView.Socket{ socket = %LiveView.Socket{
endpoint: AprsWeb.Endpoint, endpoint: AprsWeb.Endpoint,
@ -200,7 +201,7 @@ defmodule AprsWeb.UserAuthTest do
end end
test "Don't redirect is there is no authenticated user", %{conn: conn} do test "Don't redirect is there is no authenticated user", %{conn: conn} do
session = conn |> get_session() session = get_session(conn)
assert {:cont, _updated_socket} = assert {:cont, _updated_socket} =
UserAuth.on_mount( UserAuth.on_mount(

View file

@ -75,64 +75,64 @@ defmodule Parser.ParserTest do
describe "parse_datatype/1" do describe "parse_datatype/1" do
test "position" do test "position" do
%{ Enum.each(
":" => :message, %{
">" => :status, ":" => :message,
"!" => :position, ">" => :status,
"/" => :timestamped_position, "!" => :position,
"=" => :position_with_message, "/" => :timestamped_position,
"@" => :timestamped_position_with_message, "=" => :position_with_message,
";" => :object, "@" => :timestamped_position_with_message,
"`" => :mic_e, ";" => :object,
"'" => :mic_e_old, "`" => :mic_e,
"_" => :weather, "'" => :mic_e_old,
"T" => :telemetry, "_" => :weather,
"$" => :raw_gps_ultimeter, "T" => :telemetry,
"<" => :station_capabilities, "$" => :raw_gps_ultimeter,
"?" => :query, "<" => :station_capabilities,
"{" => :user_defined, "?" => :query,
"}" => :third_party_traffic, "{" => :user_defined,
"" => :unknown_datatype "}" => :third_party_traffic,
} "" => :unknown_datatype
|> Enum.each(fn {key, value} -> },
assert Parser.parse_datatype(key) == value fn {key, value} -> assert Parser.parse_datatype(key) == value end
end) )
end end
end end
describe "parse_manufacturer/3" do describe "parse_manufacturer/3" do
test "with any manufacturer" do test "with any manufacturer" do
[ Enum.each(
%{matcher: [" ", nil, nil], result: "Original MIC-E"}, [
%{matcher: [">", nil, "="], result: "Kenwood TH-D72"}, %{matcher: [" ", nil, nil], result: "Original MIC-E"},
%{matcher: [">", nil, "^"], result: "Kenwood TH-D74"}, %{matcher: [">", nil, "="], result: "Kenwood TH-D72"},
%{matcher: [">", nil, nil], result: "Kenwood TH-D74A"}, %{matcher: [">", nil, "^"], result: "Kenwood TH-D74"},
%{matcher: ["]", nil, "="], result: "Kenwood DM-710"}, %{matcher: [">", nil, nil], result: "Kenwood TH-D74A"},
%{matcher: ["]", nil, nil], result: "Kenwood DM-700"}, %{matcher: ["]", nil, "="], result: "Kenwood DM-710"},
%{matcher: ["`", "_", " "], result: "Yaesu VX-8"}, %{matcher: ["]", nil, nil], result: "Kenwood DM-700"},
%{matcher: ["`", "_", "\""], result: "Yaesu FTM-350"}, %{matcher: ["`", "_", " "], result: "Yaesu VX-8"},
%{matcher: ["`", "_", "#"], result: "Yaesu VX-8G"}, %{matcher: ["`", "_", "\""], result: "Yaesu FTM-350"},
%{matcher: ["`", "_", "$"], result: "Yaesu FT1D"}, %{matcher: ["`", "_", "#"], result: "Yaesu VX-8G"},
%{matcher: ["`", "_", "%"], result: "Yaesu FTM-400DR"}, %{matcher: ["`", "_", "$"], result: "Yaesu FT1D"},
%{matcher: ["`", "_", ")"], result: "Yaesu FTM-100D"}, %{matcher: ["`", "_", "%"], result: "Yaesu FTM-400DR"},
%{matcher: ["`", "_", "("], result: "Yaesu FT2D"}, %{matcher: ["`", "_", ")"], result: "Yaesu FTM-100D"},
%{matcher: ["`", " ", "X"], result: "AP510"}, %{matcher: ["`", "_", "("], result: "Yaesu FT2D"},
%{matcher: ["`", nil, nil], result: "Mic-Emsg"}, %{matcher: ["`", " ", "X"], result: "AP510"},
%{matcher: ["'", "|", "3"], result: "Byonics TinyTrack3"}, %{matcher: ["`", nil, nil], result: "Mic-Emsg"},
%{matcher: ["'", "|", "4"], result: "Byonics TinyTrack4"}, %{matcher: ["'", "|", "3"], result: "Byonics TinyTrack3"},
%{matcher: ["'", ":", "4"], result: "SCS GmbH & Co. P4dragon DR-7400 modems"}, %{matcher: ["'", "|", "4"], result: "Byonics TinyTrack4"},
%{matcher: ["'", ":", "8"], result: "SCS GmbH & Co. P4dragon DR-7800 modems"}, %{matcher: ["'", ":", "4"], result: "SCS GmbH & Co. P4dragon DR-7400 modems"},
%{matcher: ["'", nil, nil], result: "McTrackr"}, %{matcher: ["'", ":", "8"], result: "SCS GmbH & Co. P4dragon DR-7800 modems"},
%{matcher: [nil, "\"", nil], result: "Hamhud ?"}, %{matcher: ["'", nil, nil], result: "McTrackr"},
%{matcher: [nil, "/", nil], result: "Argent ?"}, %{matcher: [nil, "\"", nil], result: "Hamhud ?"},
%{matcher: [nil, "^", nil], result: "HinzTec anyfrog"}, %{matcher: [nil, "/", nil], result: "Argent ?"},
%{matcher: [nil, "*", nil], result: "APOZxx www.KissOZ.dk Tracker. OZ1EKD and OZ7HVO"}, %{matcher: [nil, "^", nil], result: "HinzTec anyfrog"},
%{matcher: [nil, "~", nil], result: "Other"}, %{matcher: [nil, "*", nil], result: "APOZxx www.KissOZ.dk Tracker. OZ1EKD and OZ7HVO"},
%{matcher: [nil, nil, nil], result: :unknown_manufacturer} %{matcher: [nil, "~", nil], result: "Other"},
] %{matcher: [nil, nil, nil], result: :unknown_manufacturer}
|> Enum.each(fn %{matcher: [s1, s2, s3], result: result} -> ],
assert Parser.parse_manufacturer(s1, s2, s3) == result fn %{matcher: [s1, s2, s3], result: result} -> assert Parser.parse_manufacturer(s1, s2, s3) == result end
end) )
end end
end end

View file

@ -20,14 +20,14 @@ defmodule AprsWeb.ConnCase do
using do using do
quote do quote do
# The default endpoint for testing # The default endpoint for testing
@endpoint AprsWeb.Endpoint
use AprsWeb, :verified_routes use AprsWeb, :verified_routes
# Import conveniences for testing with connections # Import conveniences for testing with connections
import Plug.Conn
import Phoenix.ConnTest
import AprsWeb.ConnCase import AprsWeb.ConnCase
import Phoenix.ConnTest
import Plug.Conn
@endpoint AprsWeb.Endpoint
end end
end end

View file

@ -18,12 +18,12 @@ defmodule Aprs.DataCase do
using do using do
quote do quote do
alias Aprs.Repo import Aprs.DataCase
import Ecto import Ecto
import Ecto.Changeset import Ecto.Changeset
import Ecto.Query import Ecto.Query
import Aprs.DataCase
alias Aprs.Repo
end end
end end

View file

@ -1,5 +1,6 @@
defmodule Parser.Types.PositionTest do defmodule Parser.Types.PositionTest do
use ExUnit.Case use ExUnit.Case
alias Parser.Types.Position alias Parser.Types.Position
describe "from_aprs/2" do describe "from_aprs/2" do