Support for ammunition type selection #32

Closed
opened 2022-11-29 09:20:28 -05:00 by aaron_nad · 7 comments

When adding a new ammo type, at present we are presented a default screen with all fields

Can we have a drop down for example that lets us choose from the following;

Shotgun
Rifle/pistol
Air rifle/pistol

For example

Depending on which ammo type has been selected, depends on what fields can be filled in, so more types of ammunition can be added to the database with better accuracy?

When it comes to disaplying them on the Catalog page, you are then presented with sections and in those sections the ammunition types and fields related to the specific ammunition?

I'll see if i can get a draft up of some visuals / code to help explain the above a little further.

When adding a new ammo type, at present we are presented a default screen with all fields Can we have a drop down for example that lets us choose from the following; Shotgun Rifle/pistol Air rifle/pistol For example Depending on which ammo type has been selected, depends on what fields can be filled in, so more types of ammunition can be added to the database with better accuracy? When it comes to disaplying them on the Catalog page, you are then presented with sections and in those sections the ammunition types and fields related to the specific ammunition? I'll see if i can get a draft up of some visuals / code to help explain the above a little further.
Author

Example schema for the shotgun ammo types. Im not familiar with elicir and ecto, so unsure on integrating with the rest of the configuration around refernces with AmmoType
https://gitea.bubbletea.dev/shibao/cannery/src/branch/dev/lib/cannery/ammo.ex
https://gitea.bubbletea.dev/shibao/cannery/src/branch/stable/lib/cannery/ammo/ammo_group.ex#L73

let alone cannery-web 😅

Example schema for the shotgun ammo types. Im not familiar with elicir and ecto, so unsure on integrating with the rest of the configuration around refernces with AmmoType https://gitea.bubbletea.dev/shibao/cannery/src/branch/dev/lib/cannery/ammo.ex https://gitea.bubbletea.dev/shibao/cannery/src/branch/stable/lib/cannery/ammo/ammo_group.ex#L73 let alone cannery-web 😅
Owner

AmmoType represents a type of ammo, and then AmmoGroup represents a single box or pack of ammo, but these are kind of internal application names.

what shotgun or air rifle-specific ammo stuff would you like to record? i think hiding/showing certain fields based on an ammo type type (god i need to get better at naming things) is a great idea 😄

AmmoType represents a type of ammo, and then AmmoGroup represents a single box or pack of ammo, but these are kind of internal application names. what shotgun or air rifle-specific ammo stuff would you like to record? i think hiding/showing certain fields based on an ammo type type (god i need to get better at naming things) is a great idea 😄
Author

I was thinking something along the lines of below for shotgun specific ammo

defmodule Cannery.Ammo.AmmoType do
  @moduledoc """
  An ammunition type.

  Contains statistical information about the ammunition.
  """

  use Ecto.Schema
  import Ecto.Changeset
  alias Cannery.Accounts.User
  alias Cannery.Ammo.{AmmoGroup, ShotgunAmmoType}
  alias Ecto.{Changeset, UUID}

  @derive {Jason.Encoder,
           only: [
             :id,
             :manufacturer, #who made the shell
             :name, #specific name of the shell - different to brand
             :desc, # Any other specifics about the shell that need to be noted down
             :wadding, #fibre / plastic / cork -
             :shot_type, # lead, steel - material that the shot is made up of
             :length, #in millimeters - length of shell once fired
             :head_size, #in millitmeters, depth of the brass head of cartidge
             :caliber, #12, 20, 410, 16 etc - e.g often referred to as gauage
             :shot_size, #size of shot in cartidge, 6, 7, 7.5, 8 etc - links to the size of the shot we are using - matches the pellet diameter (used to easily identify what we use the shell for)
             :pellet_diameter, #diameter of pellet in shot - in millitmeters - e.g 2.2mm, 2.3mm
             :load_grains, #size of load in the shell - e.g 21g, 26g, 27g 28g, 30g, 32g,
             :shot_charge_weight, #Weight of shot charge in ounces - e.g 11/12oz, 1oz, 2.5oz
             :muzzle_velocity,
             :chamber_size #Size of chamber shell can fit into - usually mneasured in inches

           ]}
  @primary_key {:id, :binary_id, autogenerate: true}
  @foreign_key_type :binary_id
  schema "shotgun_ammo_types" do
    field :manufacturer, :string
    field :name, :string
    field :desc, :string

    field :wadding, :string
    field :shot_type, :string
    field :length, :float
    field :head_size, :float
    field :caliber, :integer

    field :shot_size, :float
    field :pellet_diameter, :float
    field :load_grains, :integer
    field :shot_charge_weight,  :string

    field :muzzle_velocity, :integer
    field :chamber_size, :float

    belongs_to :user, User
    has_many :ammo_groups, AmmoGroup

    timestamps()
  end

  @type t :: %ShotgunAmmoType{
          id: id(),
          manufacturer: String.t(),
          name: String.t(),
          desc: String.t() | nil,
          wadding: String.t() | nil,
          shot_type: String.t() | nil,
          length: float() | nil,
          head_size: float() | nil,
          caliber: integer() | nil,
          shot_size: float() | nil,
          pellet_diameter: float() | nil,
          load_grains: integer() | nil,
          shot_charge_weight: String.t() | nil,
          muzzle_velocity: integer() | nil,
          chamber_size: float() | nil,
          user_id: User.id(),
          user: User.t() | nil,
          ammo_groups: [AmmoGroup.t()] | nil,
          inserted_at: NaiveDateTime.t(),
          updated_at: NaiveDateTime.t()
        }
  @type new_shotgun_ammo_type :: %ShotgunAmmoType{}
  @type id :: UUID.t()

  @spec changeset_fields() :: [atom()]
  defp changeset_fields,
    do: [
      :manufacturer,
      :name,
      :desc,
      :wadding,
      :shot_type,
      :length,
      :head_size,
      :caliber,
      :shot_size,
      :pellet_diameter,
      :load_grains,
      :shot_charge_weight,
      :muzzle_velocity,
      :chamber_size
    ]

  @doc false
  @spec create_changeset(new_shotgun_ammo_type(), User.t(), attrs :: map()) ::
          Changeset.t(new_shotgun_ammo_type())
  def create_changeset(ammo_type, %User{id: user_id}, attrs) do
    ammo_type
    |> change(user_id: user_id)
    |> cast(attrs, changeset_fields())
    |> validate_required([:name, :user_id])
  end

  @doc false
  @spec update_changeset(t() | new_shotgun_ammo_type(), attrs :: map()) ::
          Changeset.t(t() | new_shotgun_ammo_type())
  def update_changeset(ammo_type, attrs) do
    ammo_type
    |> cast(attrs, changeset_fields())
    |> validate_required(:name)
  end
end

I was thinking something along the lines of below for shotgun specific ammo ``` defmodule Cannery.Ammo.AmmoType do @moduledoc """ An ammunition type. Contains statistical information about the ammunition. """ use Ecto.Schema import Ecto.Changeset alias Cannery.Accounts.User alias Cannery.Ammo.{AmmoGroup, ShotgunAmmoType} alias Ecto.{Changeset, UUID} @derive {Jason.Encoder, only: [ :id, :manufacturer, #who made the shell :name, #specific name of the shell - different to brand :desc, # Any other specifics about the shell that need to be noted down :wadding, #fibre / plastic / cork - :shot_type, # lead, steel - material that the shot is made up of :length, #in millimeters - length of shell once fired :head_size, #in millitmeters, depth of the brass head of cartidge :caliber, #12, 20, 410, 16 etc - e.g often referred to as gauage :shot_size, #size of shot in cartidge, 6, 7, 7.5, 8 etc - links to the size of the shot we are using - matches the pellet diameter (used to easily identify what we use the shell for) :pellet_diameter, #diameter of pellet in shot - in millitmeters - e.g 2.2mm, 2.3mm :load_grains, #size of load in the shell - e.g 21g, 26g, 27g 28g, 30g, 32g, :shot_charge_weight, #Weight of shot charge in ounces - e.g 11/12oz, 1oz, 2.5oz :muzzle_velocity, :chamber_size #Size of chamber shell can fit into - usually mneasured in inches ]} @primary_key {:id, :binary_id, autogenerate: true} @foreign_key_type :binary_id schema "shotgun_ammo_types" do field :manufacturer, :string field :name, :string field :desc, :string field :wadding, :string field :shot_type, :string field :length, :float field :head_size, :float field :caliber, :integer field :shot_size, :float field :pellet_diameter, :float field :load_grains, :integer field :shot_charge_weight, :string field :muzzle_velocity, :integer field :chamber_size, :float belongs_to :user, User has_many :ammo_groups, AmmoGroup timestamps() end @type t :: %ShotgunAmmoType{ id: id(), manufacturer: String.t(), name: String.t(), desc: String.t() | nil, wadding: String.t() | nil, shot_type: String.t() | nil, length: float() | nil, head_size: float() | nil, caliber: integer() | nil, shot_size: float() | nil, pellet_diameter: float() | nil, load_grains: integer() | nil, shot_charge_weight: String.t() | nil, muzzle_velocity: integer() | nil, chamber_size: float() | nil, user_id: User.id(), user: User.t() | nil, ammo_groups: [AmmoGroup.t()] | nil, inserted_at: NaiveDateTime.t(), updated_at: NaiveDateTime.t() } @type new_shotgun_ammo_type :: %ShotgunAmmoType{} @type id :: UUID.t() @spec changeset_fields() :: [atom()] defp changeset_fields, do: [ :manufacturer, :name, :desc, :wadding, :shot_type, :length, :head_size, :caliber, :shot_size, :pellet_diameter, :load_grains, :shot_charge_weight, :muzzle_velocity, :chamber_size ] @doc false @spec create_changeset(new_shotgun_ammo_type(), User.t(), attrs :: map()) :: Changeset.t(new_shotgun_ammo_type()) def create_changeset(ammo_type, %User{id: user_id}, attrs) do ammo_type |> change(user_id: user_id) |> cast(attrs, changeset_fields()) |> validate_required([:name, :user_id]) end @doc false @spec update_changeset(t() | new_shotgun_ammo_type(), attrs :: map()) :: Changeset.t(t() | new_shotgun_ammo_type()) def update_changeset(ammo_type, attrs) do ammo_type |> cast(attrs, changeset_fields()) |> validate_required(:name) end end ```
Owner

I somehow totally forgot about this for a long time >_> but I'll do my best to get this in soon! This shouldn't be a difficult change, since the ammo type table already filters out unused columns, I think I'll just add them into the main table so you can sort/search on the individual fields

I somehow totally forgot about this for a long time >\_> but I'll do my best to get this in soon! This shouldn't be a difficult change, since the ammo type table already filters out unused columns, I think I'll just add them into the main table so you can sort/search on the individual fields
shibao added the
enhancement
label 2023-03-18 22:56:27 -04:00
shibao added this to the cannery project 2023-03-18 22:56:49 -04:00
shibao added the
high priority
label 2023-03-18 22:58:19 -04:00
Owner

After some discussion with friends, I think these will be the fields I'll be going with. Please let me know if there's anything that's missing from these fields! I'm trying to only add fields for things that someone would theoretically need to sort the tables on, and other information can go into the catch all Notes if it has some specifics (which won't be shown on the tables unfortunately)

    # common fields
    # https://shootersreference.com/reloadingdata/bullet_abbreviations/
    field :bullet_type, :string
    field :bullet_core, :string
    # also gauge for shotguns
    field :caliber, :string
    field :case_material, :string
    field :powder_type, :string
    field :grains, :integer
    field :pressure, :string
    field :primer_type, :string
    field :manufacturer, :string
    field :upc, :string
    
    field :tracer, :boolean, default: false
    field :incendiary, :boolean, default: false
    field :blank, :boolean, default: false
    field :corrosive, :boolean, default: false
    
    # rifle/pistol fields
    field :cartridge, :string
    field :jacket_type, :string
    field :powder_grains_per_charge, :integer
    field :muzzle_velocity, :integer
    field :firing_type, :string
    
    # shotgun fields
    field :wadding, :string
    field :shot_type, :string
    field :shot_material, :string
    field :shot_size, :string
    field :unfired_length, :string
    field :brass_height, :string
    field :chamber_size, :string
    field :load_grains, :integer
    field :shot_charge_weight,  :string
    field :dram_equivalent, :string
After some discussion with friends, I think these will be the fields I'll be going with. Please let me know if there's anything that's missing from these fields! I'm trying to only add fields for things that someone would theoretically need to sort the tables on, and other information can go into the catch all `Notes` if it has some specifics (which won't be shown on the tables unfortunately) ```elixir # common fields # https://shootersreference.com/reloadingdata/bullet_abbreviations/ field :bullet_type, :string field :bullet_core, :string # also gauge for shotguns field :caliber, :string field :case_material, :string field :powder_type, :string field :grains, :integer field :pressure, :string field :primer_type, :string field :manufacturer, :string field :upc, :string field :tracer, :boolean, default: false field :incendiary, :boolean, default: false field :blank, :boolean, default: false field :corrosive, :boolean, default: false # rifle/pistol fields field :cartridge, :string field :jacket_type, :string field :powder_grains_per_charge, :integer field :muzzle_velocity, :integer field :firing_type, :string # shotgun fields field :wadding, :string field :shot_type, :string field :shot_material, :string field :shot_size, :string field :unfired_length, :string field :brass_height, :string field :chamber_size, :string field :load_grains, :integer field :shot_charge_weight, :string field :dram_equivalent, :string ```
Owner

Just wanted to post some progress :)
Video preview

Example rifle/pistol type:
rifle/pistol

Example shotgun type:
shotgun

Just wanted to post some progress :) ![Video preview](https://misskey.bubbletea.dev/files/b5bff950-7aa8-4cd7-a5ce-2521378ec577) Example rifle/pistol type: ![rifle/pistol](https://misskey.bubbletea.dev/files/2bbc0b14-76d0-43bd-ae47-303a7e2d5497) Example shotgun type: ![shotgun](https://misskey.bubbletea.dev/files/153e33e2-4123-4c21-b936-b96e3e9e08ef)
Owner

One last update

This will be implemented in v0.9.0!

![One last update](https://misskey.bubbletea.dev/files/fe547d7a-ae07-46e5-8453-b36406eef23b) This will be implemented in v0.9.0!
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: shibao/cannery#32
No description provided.