Sort a list by integer with Elixir

  1. Fetch data from URL
  2. Split each new line into a list item
  3. Split each line into list items
  4. ~~Find the six-digit video ID from the URL, it should be the first integer in HTTP paths of:
    • c13.adrise.tv/04C0BF/v2/sources/content-owners/
    • c13.adrise.tv/04C0BF/ads/transcodes/~~
  5. Group by Video ID
  6. Get Cache Hit and Misses for each Video
  7. Calculate the Cache Hit Misses
  8. Sort by video ID
sort-a-list-by-integer.test.ex

import AccessLogApp.CLI, only: [
  ...
  sort_by_field: 2
]

test "Sort by field name" do
  list = [
    %{:video_id => 9478, "TCP_hit_percentage" => "75%"},
    %{:video_id => 234567, "TCP_hit_percentage" => "100%"},
    %{:video_id => 9999, "TCP_hit_percentage" => "100%"},
    %{:video_id => 004567, "TCP_hit_percentage" => "100%"},
    %{:video_id => 123456, "TCP_hit_percentage" => "0%"},
    %{:video_id => 009899, "TCP_hit_percentage" => "100%"},
  ]
  result = sort_by_field(list, :video_id)
  assert result ==  [
    %{:video_id => 004567, "TCP_hit_percentage" => "100%"},
    %{:video_id => 9478, "TCP_hit_percentage" => "75%"},
    %{:video_id => 009899, "TCP_hit_percentage" => "100%"},
     %{:video_id => 9999, "TCP_hit_percentage" => "100%"},
    %{:video_id => 123456, "TCP_hit_percentage" => "0%"},
    %{:video_id => 234567, "TCP_hit_percentage" => "100%"}
  ]
end
sort-a-list-by-integer.ex

def group_by_id(list) do
  Enum.group_by(list, fn [video_id, _] ->
    [video_id]
  end)
end

Launch Your Project

Get your project off the ground with Space-Rocket! Fill out the form below to get started.

Space-Rocket pin icon