组合两个不同键的值

时间:2017-12-15 06:53:25

标签: dictionary elixir phoenix-framework

我有一个ID嵌套在地图深处的匹配。我需要找到匹配并返回该地图。

虽然比这复杂一点。在这张大地图中,有一些名为homeaway的密钥,我拥有的ID可以嵌套在其中一个密钥中。

我正试图找到一种方法将这两个键基本上拼合成一个,以便我可以与所有值进行比较。

当前的尝试:

Map.take(game, ["away", "home"]) |> Map.get("players")

但这会返回nil

要更清楚一点:

这是我用来挖掘地图的方法:

  defp evaluate_player_points(game, question) do
    Map.get(game, "away")
      |> Map.get("players")
      |> Enum.find(fn %{"id" => id} -> question.player_id == id end)
      |> Map.get("statistics")
      |> Map.get("points")
  end

但正如您所看到的,顶部Map.get需要动态才能查找homeaway

MAP(我发布了整件事,但它非常大)

    %{"attendance" => 13548,
  "away" => %{"alias" => "DET", "bonus" => true,
    "coaches" => [%{"first_name" => "Charles", "full_name" => "Charles Klask",
       "last_name" => "Klask", "position" => "Assistant Coach",
       "reference" => "202894"},
     %{"first_name" => "Aaron", "full_name" => "Aaron Gray",
       "last_name" => "Gray", "position" => "Assistant Coach",
       "reference" => "1628254"},
     %{"first_name" => "Stan", "full_name" => "Stan Van Gundy",
       "id" => "e4abb843-1259-4aee-95f3-2ab748d510e4",
       "last_name" => "Van Gundy", "position" => "Head Coach",
       "reference" => "1277"},
     %{"first_name" => "Bob", "full_name" => "Bob Beyer",
       "last_name" => "Beyer", "position" => "Assistant Coach",
       "reference" => "2630"},
     %{"first_name" => "Jon", "full_name" => "Jon Ishop",
       "last_name" => "Ishop", "position" => "Trainer",
       "reference" => "202605"},
     %{"first_name" => "Otis", "full_name" => "Otis Smith",
       "last_name" => "Smith", "position" => "Assistant Coach",
       "reference" => "2542"},
     %{"first_name" => "Malik", "full_name" => "Malik Allen",
       "last_name" => "Allen", "position" => "Assistant Coach",
       "reference" => "204229"},
     %{"first_name" => "Tim", "full_name" => "Tim Hardaway",
       "last_name" => "Hardaway", "position" => "Assistant Coach",
       "reference" => "204230"}],
    "id" => "583ec928-fb46-11e1-82cb-f4ce4684ea4c", "market" => "Detroit",
    "name" => "Pistons",
    "players" => [%{"active" => true, "first_name" => "Reggie",
       "full_name" => "Reggie Jackson",
       "id" => "7b745dde-a011-45a8-98a8-460a9facb3ce", "jersey_number" => "1",
       "last_name" => "Jackson", "played" => true, "position" => "G",
       "primary_position" => "PG", "reference" => "202704", "starter" => true,
       "statistics" => %{"efficiency" => 2, "triple_double" => false,
         "defensive_rating" => 110.206452594306, "second_chance_att" => 0,
         "points" => 11, "minus" => 60, "points_in_paint_att" => 7,
         "blocks" => 0, "double_double" => false,
         "defensive_rebounds_pct" => 0.0, "points_off_turnovers" => 3,
         "two_points_att" => 8, "flagrant_fouls" => 0, "steals" => 0,
         "fast_break_att" => 1, "offensive_rating" => 89.2874338761532,
         "offensive_rebounds" => 0, "second_chance_pct" => 0.0,
         "true_shooting_att" => 11.0, "two_points_pct" => 50.0,
         "points_in_paint" => 6, "assists_turnover_ratio" => 1.25,
         "steals_pct" => 0.0, "rebounds_pct" => 0.0, "field_goals_made" => 5,
         "periods" => [%{"efficiency" => 6, "number" => 1, ...},
          %{"efficiency" => -3, ...}, %{...}, ...], "offensive_fouls" => 0,
         "free_throws_pct" => 0.0, "points_in_paint_made" => 3, ...}},
     %{"first_name" => "Luis", "full_name" => "Luis Montero",
       "id" => "9304e1de-0d5a-4ccb-9409-100342405041", "jersey_number" => "44",
       "last_name" => "Montero", "position" => "G-F",
       "primary_position" => "SG", "reference" => "1626242",
       "statistics" => %{"efficiency" => 0, "triple_double" => false,
         "second_chance_att" => 0, "points" => 0, "minus" => 0,
         "points_in_paint_att" => 0, "blocks" => 0, "double_double" => false,
         "defensive_rebounds_pct" => 0.0, "points_off_turnovers" => 0,
         "two_points_att" => 0, "flagrant_fouls" => 0, "steals" => 0,
         "fast_break_att" => 0, "offensive_rebounds" => 0,
         "second_chance_pct" => 0.0, "true_shooting_att" => 0.0,
         "two_points_pct" => 0.0, "points_in_paint" => 0,
         "assists_turnover_ratio" => 0, "steals_pct" => 0.0,
         "rebounds_pct" => 0.0, "field_goals_made" => 0,
         "periods" => [%{"efficiency" => 0, "number" => 1,
            "second_chance_att" => 0, "points" => 0, "minus" => 0,
            "points_in_paint_att" => 0, ...},
          %{"efficiency" => 0, "number" => 2, "second_chance_att" => 0,
            "points" => 0, "minus" => 0, ...},
          %{"efficiency" => 0, "number" => 3, "second_chance_att" => 0,
            "points" => 0, ...},
          %{"efficiency" => 0, "number" => 4, "second_chance_att" => 0,
            "points" => 0, ...}], "offensive_fouls" => 0,
         "free_throws_pct" => 0.0, "points_in_paint_made" => 0,
         "second_chance_pts" => 0, "true_shooting_pct" => 0,
         "free_throws_made" => 0, "three_points_pct" => 0.0, ...}},
     %{"active" => true, "first_name" => "Stanley",
       "full_name" => "Stanley Johnson",
       "id" => "6ed42a42-6fd6-464c-8425-7e40489c679f", "jersey_number" => "7",
       "last_name" => "Johnson", "played" => true, "position" => "F",
       "primary_position" => "SF", "reference" => "1626169",
       "statistics" => %{"efficiency" => 4, "triple_double" => false,
         "defensive_rating" => 107.894802391447, "second_chance_att" => 1,
         "points" => 2, "minus" => 32, "points_in_paint_att" => 1,
         "blocks" => 0, "double_double" => false,
         "defensive_rebounds_pct" => 16.6695606876194,
         "points_off_turnovers" => 0, "two_points_att" => 1,
         "flagrant_fouls" => 0, "steals" => 0, "fast_break_att" => 0,
         "offensive_rating" => 128.304656155027, "offensive_rebounds" => 0,
         "second_chance_pct" => 100.0, "true_shooting_att" => 2.0,
         "two_points_pct" => 100.0, "points_in_paint" => 2,
         "assists_turnover_ratio" => 0, "steals_pct" => 0.0,
         "rebounds_pct" => 8.12641083521444, "field_goals_made" => 1,
         "periods" => [%{"efficiency" => 0, ...}, %{...}, ...],
         "offensive_fouls" => 0, "free_throws_pct" => 0.0, ...}},
     %{"active" => true, "first_name" => "Boban",
       "full_name" => "Boban Marjanovic",
       "id" => "24c17409-ac10-4859-be6c-59d6cc6b5810", "jersey_number" => "51",
       "last_name" => "Marjanovic", "position" => "C",
       "primary_position" => "C", "reference" => "1626246",
       "statistics" => %{"efficiency" => 0, "triple_double" => false,
         "second_chance_att" => 0, "points" => 0, "minus" => 0,
         "points_in_paint_att" => 0, "blocks" => 0, "double_double" => false,
         "defensive_rebounds_pct" => 0.0, "points_off_turnovers" => 0,
         "two_points_att" => 0, "flagrant_fouls" => 0, "steals" => 0,
         "fast_break_att" => 0, "offensive_rebounds" => 0,
         "second_chance_pct" => 0.0, "true_shooting_att" => 0.0,
         "two_points_pct" => 0.0, "points_in_paint" => 0,
         "assists_turnover_ratio" => 0, "steals_pct" => 0.0,
         "rebounds_pct" => 0.0, "field_goals_made" => 0,
         "periods" => [%{"efficiency" => 0, "number" => 1,
            "second_chance_att" => 0, ...},
          %{"efficiency" => 0, "number" => 2, ...}, %{"efficiency" => 0, ...},
          %{"efficiency" => 0, ...}], "offensive_fouls" => 0,
         "free_throws_pct" => 0.0, "points_in_paint_made" => 0,
         "second_chance_pts" => 0, ...}},
     %{"first_name" => "Dwight", "full_name" => "Dwight Buycks",
       "id" => "14d86dbd-5e05-4a2e-951b-96d4e1e2e8f1", "jersey_number" => "20",
       "last_name" => "Buycks", "position" => "G", "primary_position" => "PG",
       "reference" => "202779",
       "statistics" => %{"efficiency" => 0, "triple_double" => false,
         "second_chance_att" => 0, "points" => 0, "minus" => 0,
         "points_in_paint_att" => 0, "blocks" => 0, "double_double" => false,
         "defensive_rebounds_pct" => 0.0, "points_off_turnovers" => 0,
         "two_points_att" => 0, "flagrant_fouls" => 0, "steals" => 0,
         "fast_break_att" => 0, "offensive_rebounds" => 0,
         "second_chance_pct" => 0.0, "true_shooting_att" => 0.0,
         "two_points_pct" => 0.0, "points_in_paint" => 0,
         "assists_turnover_ratio" => 0, "steals_pct" => 0.0,
         "rebounds_pct" => 0.0, "field_goals_made" => 0,
         "periods" => [%{"efficiency" => 0, "number" => 1,
            "second_chance_att" => 0, ...},
          %{"efficiency" => 0, "number" => 2, ...}, %{"efficiency" => 0, ...},
          %{"efficiency" => 0, ...}], "offensive_fouls" => 0,
         "free_throws_pct" => 0.0, "points_in_paint_made" => 0,
         "second_chance_pts" => 0, ...}},
     %{"active" => true, "first_name" => "Avery",
       "full_name" => "Avery Bradley",
       "id" => "b23917d2-bb0d-49fa-a384-80d994561d0c", "jersey_number" => "22",
       "last_name" => "Bradley", "played" => true, "position" => "G",
       "primary_position" => "SG", "reference" => "202340", "starter" => true,
       "statistics" => %{"efficiency" => 12, "triple_double" => false,
         "defensive_rating" => 105.701631730746, "second_chance_att" => 2,
         "points" => 18, "minus" => 56, "points_in_paint_att" => 10,
         "blocks" => 0, "double_double" => false,
         "defensive_rebounds_pct" => 4.60962258715068,
         "points_off_turnovers" => 0, "two_points_att" => 13,
         "flagrant_fouls" => 0, "steals" => 1, "fast_break_att" => 3,
         "offensive_rating" => 122.024148849322, "offensive_rebounds" => 0,
         "second_chance_pct" => 50.0, "true_shooting_att" => 15.88,
         "two_points_pct" => 38.5, "points_in_paint" => 8,
         "assists_turnover_ratio" => 3.0, "steals_pct" => 1.96604637903408,
         "rebounds_pct" => 2.24719101123596, ...}},
     %{"first_name" => "Jon", "full_name" => "Jon Leuer",
       "id" => "ee9ddf70-f50d-49b0-846c-f83719b095d8", "jersey_number" => "30",
       "last_name" => "Leuer", "position" => "F", "primary_position" => "PF",
       "reference" => "202720",
       "statistics" => %{"efficiency" => 0, "triple_double" => false,
         "second_chance_att" => 0, "points" => 0, "minus" => 0,
         "points_in_paint_att" => 0, "blocks" => 0, "double_double" => false,
         "defensive_rebounds_pct" => 0.0, "points_off_turnovers" => 0,
         "two_points_att" => 0, "flagrant_fouls" => 0, "steals" => 0,
         "fast_break_att" => 0, "offensive_rebounds" => 0,
         "second_chance_pct" => 0.0, "true_shooting_att" => 0.0,
         "two_points_pct" => 0.0, "points_in_paint" => 0,
         "assists_turnover_ratio" => 0, "steals_pct" => 0.0,
         "rebounds_pct" => 0.0, "field_goals_made" => 0,
         "periods" => [%{"efficiency" => 0, ...}, %{...}, ...],
         "offensive_fouls" => 0, "free_throws_pct" => 0.0, ...}},
     %{"active" => true, "first_name" => "Andre",
       "full_name" => "Andre Drummond",
       "id" => "440b769d-2b8b-477f-80d7-cb21d83c0d52", "jersey_number" => "0",
       "last_name" => "Drummond", "played" => true, "position" => "C",
       "primary_position" => "C", "reference" => "203083", "starter" => true,
       "statistics" => %{"efficiency" => 35, "triple_double" => false,
         "defensive_rating" => 90.4494098612691, "second_chance_att" => 4,
         "points" => 12, "minus" => 72, "points_in_paint_att" => 11,
         "blocks" => 2, "double_double" => true,
         "defensive_rebounds_pct" => 46.3954893274265,
         "points_off_turnovers" => 2, "two_points_att" => 11,
         "flagrant_fouls" => 0, "steals" => 2, "fast_break_att" => 0,
         "offensive_rating" => 119.432386646934, "offensive_rebounds" => 7,
         "second_chance_pct" => 25.0, "true_shooting_att" => 12.76,
         "two_points_pct" => 36.4, "points_in_paint" => 8,
         "assists_turnover_ratio" => 2.67, ...}},
     %{"active" => true, "first_name" => "Anthony",
       "full_name" => "Anthony Tolliver",
       "id" => "33a91bda-9f4d-4f80-97d8-9bc574f6afc2", "jersey_number" => "43",
       "last_name" => "Tolliver", "played" => true, "position" => "F",
       "primary_position" => "PF", "reference" => "201229",
       "statistics" => %{"efficiency" => 2, "triple_double" => false,
         "defensive_rating" => 108.985437894358, "second_chance_att" => 0,
         "points" => 6, "minus" => 27, "points_in_paint_att" => 1,
         "blocks" => 0, "double_double" => false,
         "defensive_rebounds_pct" => 8.1595255235908,
         "points_off_turnovers" => 0, "two_points_att" => 1,
         "flagrant_fouls" => 0, "steals" => 0, "fast_break_att" => 0,
         "offensive_rating" => 87.2688729807194, "offensive_rebounds" => 1,
         "second_chance_pct" => 0.0, "true_shooting_att" => 5.0,
         "two_points_pct" => 0.0, "points_in_paint" => 0,
         "assists_turnover_ratio" => 0.0, ...}},
     %{"active" => true, "first_name" => "Langston",
       "full_name" => "Langston Galloway",
       "id" => "138f5c1f-b8e6-4e7c-b8ef-ecb7faa7b936", "jersey_number" => "9",
       "last_name" => "Galloway", "played" => true, "position" => "G",
       "primary_position" => "PG", "reference" => "204038",
       "statistics" => %{"efficiency" => 16, "triple_double" => false,
         "defensive_rating" => 97.5742878357504, "second_chance_att" => 2,
         "points" => 17, "minus" => 30, "points_in_paint_att" => 0,
         "blocks" => 0, "double_double" => false,
         "defensive_rebounds_pct" => 11.3872249570014,
         "points_off_turnovers" => 8, "two_points_att" => 2,
         "flagrant_fouls" => 0, "steals" => 2, "fast_break_att" => 3,
         "offensive_rating" => 149.110748320568, "offensive_rebounds" => 1,
         "second_chance_pct" => 50.0, "true_shooting_att" => 11.0,
         "two_points_pct" => 50.0, "points_in_paint" => 0, ...}},
     %{"active" => true, "first_name" => "Luke", "full_name" => "Luke Kennard",
       "id" => "a537047d-c29f-4dfe-99b0-3bac4e258dc7", "jersey_number" => "5",
       "last_name" => "Kennard", "played" => true, "position" => "G",
       "primary_position" => "SG", "reference" => "1628379",
       "statistics" => %{"efficiency" => 1, "triple_double" => false,
         "defensive_rating" => 93.8002338872659, "second_chance_att" => 2,
         "points" => 4, "minus" => 29, "points_in_paint_att" => 1,
         "blocks" => 1, "double_double" => false,
         "defensive_rebounds_pct" => 6.39360639360639,
         "points_off_turnovers" => 4, "two_points_att" => 4,
         "flagrant_fouls" => 0, "steals" => 2, "fast_break_att" => 2,
         "offensive_rating" => 61.1978132880953, "offensive_rebounds" => 1,
         "second_chance_pct" => 50.0, "true_shooting_att" => 8.88,
         "two_points_pct" => 25.0, ...}},
     %{"active" => true, "first_name" => "Ish", "full_name" => "Ish Smith",
       "id" => "05a90cd6-73de-43d5-9d30-bc2588d03262", "jersey_number" => "14",
       "last_name" => "Smith", "played" => true, "position" => "G",
       "primary_position" => "PG", "reference" => "202397",
       "statistics" => %{"efficiency" => -3, "triple_double" => false,
         "defensive_rating" => 105.148783281487, "second_chance_att" => 0,
         "points" => 4, "minus" => 19, "points_in_paint_att" => 3,
         "blocks" => 0, "double_double" => false,
         "defensive_rebounds_pct" => 11.988011988012,
         "points_off_turnovers" => 0, "two_points_att" => 5,
         "flagrant_fouls" => 0, "steals" => 0, "fast_break_att" => 1,
         "offensive_rating" => 79.5442808328467, "offensive_rebounds" => 0,
         "second_chance_pct" => 0.0, "true_shooting_att" => 5.0, ...}},
     %{"active" => true, "first_name" => "Tobias",
       "full_name" => "Tobias Harris",
       "id" => "82f09975-6a8d-42e4-b42c-a52b9349ed50", "jersey_number" => "34",
       "last_name" => "Harris", "played" => true, "position" => "F",
       "primary_position" => "PF", "reference" => "202699", "starter" => true,
       "statistics" => %{"efficiency" => 20, "triple_double" => false,
         "defensive_rating" => 103.725507249097, "second_chance_att" => 1,
         "points" => 19, "minus" => 59, "points_in_paint_att" => 3,
         "blocks" => 0, "double_double" => false,
         "defensive_rebounds_pct" => 15.91537661625,
         "points_off_turnovers" => 2, "two_points_att" => 8,
         "flagrant_fouls" => 0, "steals" => 1, "fast_break_att" => 0,
         "offensive_rating" => 151.395288813852, "offensive_rebounds" => 0,
         ...}},
     %{"active" => true, "first_name" => "Eric", "full_name" => "Eric Moreland",
       "id" => "e54fcd7e-82d0-4599-9d64-ac14532f0cde", "jersey_number" => "24",
       "last_name" => "Moreland", "played" => true, "position" => "F-C",
       "primary_position" => "PF", "reference" => "203961",
       "statistics" => %{"efficiency" => 9, "triple_double" => false,
         "defensive_rating" => 92.9346584762599, "second_chance_att" => 1,
         "points" => 0, "minus" => 17, "points_in_paint_att" => 2,
         "blocks" => 0, "double_double" => false,
         "defensive_rebounds_pct" => 55.8286525605163,
         "points_off_turnovers" => 0, "two_points_att" => 2,
         "flagrant_fouls" => 0, "steals" => 1, "fast_break_att" => 0,
         "offensive_rating" => 85.0907292301888, "offensive_rebounds" => 4,
         ...}},
     %{"active" => true, "first_name" => "Reggie",
       "full_name" => "Reggie Bullock",
       "id" => "42fa4c2c-6520-4d04-a753-cfe4a5c5e2e1", "jersey_number" => "25",
       "last_name" => "Bullock", "played" => true, "position" => "F",
       "primary_position" => "SF", "reference" => "203493", "starter" => true,
       "statistics" => %{"efficiency" => 6, "triple_double" => false,
         "defensive_rating" => 104.77107348445, "second_chance_att" => 3,
         "points" => 10, "minus" => 49, "points_in_paint_att" => 4,
         "blocks" => 0, "double_double" => false,
         "defensive_rebounds_pct" => 5.14933887316374,
         "points_off_turnovers" => 3, "two_points_att" => 4,
         "flagrant_fouls" => 0, "steals" => 1, "fast_break_att" => 0, ...}},
     %{"active" => true, "first_name" => "Henry",
       "full_name" => "Henry Ellenson",
       "id" => "eef64529-e381-43d1-a72b-8dcde914fee9", "jersey_number" => "8",
       "last_name" => "Ellenson", "played" => true, "position" => "F",
       "primary_position" => "PF", "reference" => "1627740",
       "statistics" => %{"efficiency" => 2, "triple_double" => false,
         "defensive_rating" => 110.995584750072, "second_chance_att" => 1,
         "points" => 2, "minus" => 5, "points_in_paint_att" => 0, "blocks" => 0,
         "double_double" => false, "defensive_rebounds_pct" => 0.0,
         "points_off_turnovers" => 0, "two_points_att" => 1,
         "flagrant_fouls" => 0, "steals" => 0, "fast_break_att" => 0,
         "offensive_rating" => 200.0, ...}}], "points" => 105,
    "reference" => "1610612765",
    "scoring" => [%{"number" => 1, "points" => 30, "sequence" => 1,
       "type" => "quarter"},
     %{"number" => 2, "points" => 29, "sequence" => 2, "type" => "quarter"},
     %{"number" => 3, "points" => 26, "sequence" => 3, "type" => "quarter"},
     %{"number" => 4, "points" => 20, "sequence" => 4, "type" => "quarter"}],
    "statistics" => %{"efficiency" => 106,
      "defensive_rating" => 99.5188101487314, "second_chance_att" => 17,
      "points" => 105, "team_tech_fouls" => 0, "team_offensive_rebounds" => 8,
      "points_in_paint_att" => 43, "blocks" => 3, "bench_points" => 35,
      "points_off_turnovers" => 22, "player_tech_fouls" => 1,
      "two_points_att" => 60, "flagrant_fouls" => 0, "steals" => 10,
      "fast_break_att" => 10, "offensive_rating" => 109.05691732447,
      "offensive_rebounds" => 14, "second_chance_pct" => 47.1,
      "possessions" => 96.28, "true_shooting_att" => 95.28,
      "biggest_lead" => 24, "two_points_pct" => 46.7, "points_in_paint" => 38,
      "total_fouls" => 23, "assists_turnover_ratio" => 1.73, "ejections" => 0,
      "field_goals_made" => 41,
      "periods" => [%{"efficiency" => 28, "number" => 1,
         "defensive_rating" => 128.737541528239, "second_chance_att" => 5,
         "points" => 30, "team_tech_fouls" => 0, "team_offensive_rebounds" => 2,
         "points_in_paint_att" => 12, "blocks" => 2, ...},
       %{"efficiency" => 35, "number" => 2,
         "defensive_rating" => 68.5557586837294, "second_chance_att" => 5,
         "points" => 29, "team_tech_fouls" => 0, "team_offensive_rebounds" => 3,
         "points_in_paint_att" => 14, ...},
       %{"efficiency" => 29, "number" => 3,
         "defensive_rating" => 77.9896013864818, "second_chance_att" => 2,
         "points" => 26, "team_tech_fouls" => 0, "team_offensive_rebounds" => 3,
         ...},
       %{"efficiency" => 14, "number" => 4,
         "defensive_rating" => 120.535714285714, "second_chance_att" => 5,
         "points" => 20, "team_tech_fouls" => 0, "team_offensive_rebounds" => 0,
         ...}], "offensive_fouls" => 1, "free_throws_pct" => 83.3,
      "offensive_points_per_possession" => 1.09, "total_rebounds" => 57,
      "points_in_paint_made" => 19, "second_chance_pts" => 18,
      "true_shooting_pct" => 55.1, "free_throws_made" => 10,
      "three_points_pct" => 43.3, "rebounds" => 46, ...}}, "clock" => "00:00",
  "coverage" => "full", "duration" => "2:06", "entry_mode" => "WEBSOCKET",
  "home" => %{"alias" => "ATL", "bonus" => true,
    "coaches" => [%{"first_name" => "Ben", "full_name" => "Ben Sullivan",
       "last_name" => "Sullivan", "position" => "Assistant Coach",
       "reference" => "204224"},
     %{"first_name" => "Scottie", "full_name" => "Scottie Parker",
       "last_name" => "Parker", "position" => "Trainer",
       "reference" => "1628764"},
     %{"first_name" => "Pat", "full_name" => "Pat St. Andrews",
       "last_name" => "St. Andrews", "position" => "Assistant Coach",
       "reference" => "1628784"},
     %{"first_name" => "Darvin", "full_name" => "Darvin Ham",
       "last_name" => "Ham", "position" => "Assistant Coach",
       "reference" => "203005"},
     %{"first_name" => "Mike", "full_name" => "Mike Budenholzer",
       "id" => "6c9c23f1-d87d-4aca-8414-3d86b0b3993e",
       "last_name" => "Budenholzer", "position" => "Head Coach",
       "reference" => "1371"},
     %{"first_name" => "Chris", "full_name" => "Chris Jent",
       "last_name" => "Jent", "position" => "Assistant Coach",
       "reference" => "2607"},
     %{"first_name" => "Wally", "full_name" => "Wally Blase",
       "last_name" => "Blase", "position" => "Trainer", "reference" => "2150"},
     %{"first_name" => "Taylor", "full_name" => "Taylor Jenkins",
       "last_name" => "Jenkins", "position" => "Assistant Coach",
       "reference" => "203624"},
     %{"first_name" => "Charles", "full_name" => "Charles Lee",
       "last_name" => "Lee", "position" => "Assistant Coach",
       "reference" => "204225"}],
    "id" => "583ecb8f-fb46-11e1-82cb-f4ce4684ea4c", "market" => "Atlanta",
    "name" => "Hawks",
    "players" => [%{"first_name" => "Mike", "full_name" => "Mike Muscala",
       "id" => "7c636961-816a-4b44-8991-671df9d91d9c", "jersey_number" => "31",
       "last_name" => "Muscala", "position" => "F-C",
       "primary_position" => "PF", "reference" => "203488",
       "statistics" => %{"efficiency" => 0, "triple_double" => false,
         "second_chance_att" => 0, "points" => 0, "minus" => 0,
         "points_in_paint_att" => 0, "blocks" => 0, "double_double" => false,
         "defensive_rebounds_pct" => 0.0, "points_off_turnovers" => 0,
         "two_points_att" => 0, "flagrant_fouls" => 0, "steals" => 0,
         "fast_break_att" => 0, "offensive_rebounds" => 0,
         "second_chance_pct" => 0.0, "true_shooting_att" => 0.0,
         "two_points_pct" => 0.0, "points_in_paint" => 0,
         "assists_turnover_ratio" => 0, "steals_pct" => 0.0,
         "rebounds_pct" => 0.0, "field_goals_made" => 0,
         "periods" => [%{"efficiency" => 0, "number" => 1, ...},
          %{"efficiency" => 0, ...}, %{...}, ...], "offensive_fouls" => 0,
         "free_throws_pct" => 0.0, "points_in_paint_made" => 0, ...}},
     %{"active" => true, "first_name" => "Kent", "full_name" => "Kent Bazemore",
       "id" => "2c157857-fffd-4eb5-8e2a-b28ebea8da77", "jersey_number" => "24",
       "last_name" => "Bazemore", "played" => true, "position" => "G",
       "primary_position" => "SG", "reference" => "203145", "starter" => true,
       "statistics" => %{"efficiency" => 8, "triple_double" => false,
         "defensive_rating" => 106.069502377609, "second_chance_att" => 1,
         "points" => 8, "minus" => 50, "points_in_paint_att" => 3,
         "blocks" => 3, "double_double" => false,
         "defensive_rebounds_pct" => 20.1416207710464,
         "points_off_turnovers" => 0, "two_points_att" => 4,
         "flagrant_fouls" => 0, "steals" => 0, "fast_break_att" => 0,
         "offensive_rating" => 82.2342730948014, "offensive_rebounds" => 1,
         "second_chance_pct" => 0.0, "true_shooting_att" => 10.88,
         "two_points_pct" => 0.0, "points_in_paint" => 0,
         "assists_turnover_ratio" => 2.0, "steals_pct" => 0.0, ...}},
     %{"active" => true, "first_name" => "Luke", "full_name" => "Luke Babbitt",
       "id" => "d8298a51-2639-422a-869b-61c6fe27afd1", "jersey_number" => "8",
       "last_name" => "Babbitt", "played" => true, "position" => "F",
       "primary_position" => "SF", "reference" => "202337",
       "statistics" => %{"efficiency" => 10, "triple_double" => false,
         "defensive_rating" => 112.231151758584, "second_chance_att" => 0,
         "points" => 7, "minus" => 41, "points_in_paint_att" => 0,
         "blocks" => 0, "double_double" => false,
         "defensive_rebounds_pct" => 20.0888186193587,
         "points_off_turnovers" => 0, "two_points_att" => 1,
         "flagrant_fouls" => 0, "steals" => 0, "fast_break_att" => 0,
         "offensive_rating" => 135.261953010297, "offensive_rebounds" => 0,
         "second_chance_pct" => 0.0, "true_shooting_att" => 5.76,
         "two_points_pct" => 0.0, "points_in_paint" => 0,
         "assists_turnover_ratio" => 0, "steals_pct" => 0.0, ...}},
     %{"active" => true, "first_name" => "DeAndre'",
       "full_name" => "DeAndre' Bembry",
       "id" => "db42a3d8-e493-4f0e-aa9f-149397877fea", "jersey_number" => "95",
       "last_name" => "Bembry", "played" => true, "position" => "F-G",
       "primary_position" => "SF", "reference" => "1627761",
       "statistics" => %{"efficiency" => -5, "triple_double" => false,
         "defensive_rating" => 119.305763024204, "second_chance_att" => 0,
         "points" => 0, "minus" => 40, "points_in_paint_att" => 2,
         "blocks" => 1, "double_double" => false,
         "defensive_rebounds_pct" => 0.0, "points_off_turnovers" => 0,
         "two_points_att" => 2, "flagrant_fouls" => 0, "steals" => 0,
         "fast_break_att" => 0, "offensive_rating" => 15.8695381624177,
         "offensive_rebounds" => 0, "second_chance_pct" => 0.0,
         "true_shooting_att" => 3.0, "two_points_pct" => 0.0,
         "points_in_paint" => 0, "assists_turnover_ratio" => 0.5, ...}},

希望显示地图可能有助于您了解我正在努力实现的目标。

1 个答案:

答案 0 :(得分:3)

players 是一个列表

Map.take(game, ["away", "home"])绝对可行,但Kernel.get_in/2并使用Access行为更为惯用。

您需要的一切是将Kernel.get_in/2Enum.find/2一起散布以进行查找:

game
|> get_in(~w|away players|)
|> Enum.find(fn e -> CONDITION end)
|> get_in(~w|statistics points|)

如果您要发布MCVE而不是无效对象,我可以测试它。