Sort a list by integer with Elixir
Sort a list by integer with Elixir

Sort a list by integer with Elixir

  1. Fetch data from URL/li>
  2. Split each new line into a list item/li>
  3. Split each line into list items/li>
  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/”
    /li>

  5. Group by Video ID/li>
  6. Get Cache Hit and Misses for each Video/li>
  7. Calculate the Cache Hit Misses
  8. Sort by video id
  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
  def group_by_id(list) do
    Enum.group_by(list, fn [video_id, _] ->
      [video_id]
    end)
  end
Published
Categorized as Elixir

By mchavez

Michael Chavez is a web and software developer from San Francisco, California. His experience spans almost a decade, working with San Francisco Bay Area design and development agencies, and high-profile Silicon Valley start-ups and enterprises. After studying Multimedia at City College of San Francisco, Michael self-taught himself programming languages such as JavaScript, Node.js, PHP and founded the web development consultancy, Space-Rocket. Michael is currently working with the Elixir programming language.

Leave a comment

Your email address will not be published. Required fields are marked *