Related
My mPDF Class
$mpdf = new \Mpdf\Mpdf(['utf-8', 'A4-L', 1000000, 'cursive', 100000000000000, 100, 100, 0, 0, 0, 'L']);
I have use mPDF Update version
try it
$mpdf = new \Mpdf\Mpdf([
'tempDir' => __DIR__ . '/pdfdata',
'mode' => 'utf-8',
// 'format' => [24, 24],
'format' => 'A4',
'margin_left' => 0,
'margin_right' => 2,
'margin_bottom' => 2,
'margin_top' => 2,
'float' => 'left'
]);
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
I have an id that has a match nested deep in a map. I need to locate the match and return that map.
It's a bit more complicated than that though. Inside this large map there are keys called home and away and the id that I have could be nested in either one of those keys.
I'm trying to find a way to essentially flatten those two keys into one so that I can compare against all of the values.
CURRENT ATTEMPT:
Map.take(game, ["away", "home"]) |> Map.get("players")
But this return nil
To be a little more clear:
This is the method I'm using to dig into the map:
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
But as you can see the top Map.get needs to be dynamic to look for either home or away
MAP (I'm posting the entire thing but it's quite large)
%{"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, ...}},
Hopefully showing the map might help you understand what I'm trying to accomplish.
players is a list.
Map.take(game, ["away", "home"]) should definitely work, but Kernel.get_in/2 and using Access behaviour is way more idiomatic.
Everything you need is to intersperse Kernel.get_in/2 with Enum.find/2 for lookup:
game
|> get_in(~w|away players|)
|> Enum.find(fn e -> CONDITION end)
|> get_in(~w|statistics points|)
If you were to post MCVE instead of non-valid object, I could be able to test this.
I have a list of dataframes that look like (sample dput attached below):
[[1]]
SPY.HIGH SPY.ADX SPY.MA SPY.CLOSE
2014-08-11 -1 1 1 5
2014-08-12 -1 1 1 10
[[2]]]
MSCI.HIGH MSCI.ADX MSCI.MA MSCI.CLOSE
2014-08-29 -1 -1 1 3
2014-09-01 -1 1 1 1
2014-09-02 0 -1 0 2
I'm trying to create a function that would only sum up the last columns of the above data sample based on the conditions that the first column is nonzero, second column is positive and third column is nonnegative. I made the following attempt:
marketsum <- function(x) {
#Conditional columns
validrows <- FlaggingTrend[[x]][,1] != 0 | FlaggingTrend[[x]][,2] > 0 | FlaggingTrend[[x]][,3] != 0
# Only calculates the sum of fourth column for the rows if above conditions are met
sum(FlaggingTrend[[x]][validrows,4])
}
returnsum <- list()
# Use sapply to run function to work out sums
returnsum <- sapply(1:length(FlaggingTrend), function(x) marketsum(x))
However, I'm getting NA instead of summed values?
names close
1 EUR NA
2 JPY NA
3 GBP NA
4 CHF NA
5 AUD NA
6 CAD NA
7 NZD NA
I would appreciate help or guidance as to where I'm going wrong. Sample dput is attached below:
list(structure(list(EUR.CLOSE = c(-1, -1, -1, 0, 1, 0, 0, -1,
0, 1), EUR.CLOSE.1 = c(1, -1, -1, 1, 1, 1, 1, -1, -1, -1), EUR.50D = c(-1,
-1, -1, -1, -1, -1, -1, -1, -1, -1), EUR.CLOSE.2 = c(-0.0011268664916733,
-0.00423709498833686, -0.00188893142678216, 0.00217196364717242,
0.00686254162079234, -0.00544858088184653, -0.000188412624203348,
-0.00737591996472312, 0.00208590196044455, 0.00227057808051545
)), .Names = c("EUR.CLOSE", "EUR.CLOSE.1", "EUR.50D", "EUR.CLOSE.2"
), row.names = c("2017-02-10", "2017-02-13", "2017-02-14", "2017-02-15",
"2017-02-16", "2017-02-17", "2017-02-20", "2017-02-21", "2017-02-22",
"2017-02-23"), class = "data.frame"), structure(list(JPY.CLOSE = c(0,
0, 1, 0, -1, -1, 0, 1, 0, -1), JPY.CLOSE.1 = c(-1, -1, -1, -1,
-1, -1, -1, -1, -1, -1), JPY.50D = c(1, 1, 1, 1, 1, 1, 1, 1,
1, 1), JPY.CLOSE.2 = c(-0.000264935754629825, 0.00458231327013969,
0.00456141141766331, -0.000875580127735809, -0.00809151292488242,
-0.00353857410990255, 0.00230149698827908, 0.00511510066677001,
-0.00326005839636956, -0.00619690368354142)), .Names = c("JPY.CLOSE",
"JPY.CLOSE.1", "JPY.50D", "JPY.CLOSE.2"), row.names = c("2017-02-10",
"2017-02-13", "2017-02-14", "2017-02-15", "2017-02-16", "2017-02-17",
"2017-02-20", "2017-02-21", "2017-02-22", "2017-02-23"), class = "data.frame"),
structure(list(GBP.CLOSE = c(0, 1, 0, 0, 1, -1, 0, 0, 0,
1), GBP.CLOSE.1 = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), GBP.50D = c(-1,
-1, -1, -1, -1, -1, -1, -1, -1, -1), GBP.CLOSE.2 = c(-0.00048023051987453,
0.00279809911944895, -0.00464112219813048, -0.000561594944360089,
0.0022444899202175, -0.00618451029481418, 0.00410050825810596,
0.000802053299332334, -0.00184568523285542, 0.00847801606899046
)), .Names = c("GBP.CLOSE", "GBP.CLOSE.1", "GBP.50D", "GBP.CLOSE.2"
), row.names = c("2017-02-10", "2017-02-13", "2017-02-14",
"2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20", "2017-02-21",
"2017-02-22", "2017-02-23"), class = "data.frame"), structure(list(
CHF.OPEN = c(1, 0, 0, 0, -1, 0, 0, 1, 0, -1), CHF.OPEN.1 = c(-1,
-1, -1, -1, -1, -1, -1, -1, 1, -1), CHF50D = c(1, 1,
1, 1, 1, 1, 1, 1, 1, 1), CHF.OPEN.2 = c(0.000698567964139939,
0.00328669186857626, 0.00049704260678339, -0.000695928844511353,
-0.00838914337795957, 0.00550083899465574, 0.000199461454735274,
0.00685716972613716, 0.000594059423411153, -0.00396707849439904
)), .Names = c("CHF.OPEN", "CHF.OPEN.1", "CHF50D", "CHF.OPEN.2"
), row.names = c("2017-02-10", "2017-02-13", "2017-02-14",
"2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20", "2017-02-21",
"2017-02-22", "2017-02-23"), class = "data.frame"), structure(list(
AUD.CLOSE = c(1, 0, 0, 1, 0, -1, 0, 0, 1, 0), AUD.CLOSE.1 = c(1,
1, 1, 1, 1, 1, 1, 1, 1, 1), AUD.50D = c(-1, -1, -1, -1,
-1, -1, -1, -1, -1, -1), AUD.CLOSE.2 = c(0.00640566933128534,
-0.00444038864633145, 0.00300594880983807, 0.0061146355869709,
-0.00207738324513479, -0.00390676366154397, 0.00312663099943206,
-0.00169237819473061, 0.00364156989756792, 0.00155662244429539
)), .Names = c("AUD.CLOSE", "AUD.CLOSE.1", "AUD.50D",
"AUD.CLOSE.2"), row.names = c("2017-02-10", "2017-02-13",
"2017-02-14", "2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20",
"2017-02-21", "2017-02-22", "2017-02-23"), class = "data.frame"),
structure(list(CAD.CLOSE = c(-1, 0, 0, 0, 0, 1, 0, 1, 0,
-1), CAD.CLOSE.1 = c(-1, -1, -1, -1, -1, -1, -1, -1, -1,
-1), CAD.50D = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), CAD.CLOSE.2 = c(-0.00472778065310547,
-0.000917641725324381, 0.000382453058549392, 0.000305857167088586,
-0.000688310225637978, 0.00191080426541917, 0.000763300548471235,
0.00266697304419594, 0.00174871741959248, -0.00449199430572389
)), .Names = c("CAD.CLOSE", "CAD.CLOSE.1", "CAD.50D", "CAD.CLOSE.2"
), row.names = c("2017-02-10", "2017-02-13", "2017-02-14",
"2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20", "2017-02-21",
"2017-02-22", "2017-02-23"), class = "data.frame"), structure(list(
NZD.CLOSE = c(0, 0, 0, 1, 0, -1, 0, -1, 0, 1), NZD.CLOSE.1 = c(1,
1, 1, 1, 1, 1, 1, 1, 1, 1), NZD.50D = c(-1, -1, -1, -1,
-1, -1, -1, -1, -1, -1), NZD.CLOSE.2 = c(0.00041733324664972,
-0.00208841008727045, -0.000836586774949688, 0.00750420419797471,
-0.00180142777185216, -0.00389105549296664, 0.00111327592906424,
-0.00404153570815258, 0.00390244397693174, 0.00568695616893883
)), .Names = c("NZD.CLOSE", "NZD.CLOSE.1", "NZD.50D",
"NZD.CLOSE.2"), row.names = c("2017-02-10", "2017-02-13",
"2017-02-14", "2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20",
"2017-02-21", "2017-02-22", "2017-02-23"), class = "data.frame"),
structure(list(SEK.OPEN = c(1, 1, 0, 0, -1, 0, 1, 1, 0, 0
), SEK.OPEN.1 = c(-1, -1, -1, -1, -1, -1, -1, -1, -1, 1),
SEK.50D = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), SEK.OPEN.2 = c(0.00163829609003363,
0.0023181988913219, -0.000716164076936199, -0.00145628918509555,
-0.00677152707834994, 0.00582941106111079, 0.00270059947077783,
0.00455540960162004, -0.000256248852460228, 0.00199255363165785
)), .Names = c("SEK.OPEN", "SEK.OPEN.1", "SEK.50D", "SEK.OPEN.2"
), row.names = c("2017-02-10", "2017-02-13", "2017-02-14",
"2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20", "2017-02-21",
"2017-02-22", "2017-02-23"), class = "data.frame"), structure(list(
NOK.CLOSE = c(1, 0, 0, -1, -1, 0, 0, 1, 0, 0), NOK.CLOSE.1 = c(-1,
-1, -1, -1, -1, -1, -1, -1, -1, -1), NOK.50D = c(1, 1,
1, 1, 1, 1, 1, 1, 1, 1), NOK.CLOSE.2 = c(0.00323283885094217,
0.00303175214315887, 0.000941075635438882, -0.00716968871997281,
-0.00617111408142934, 0.00665069589528811, -0.000467589464977269,
0.00246736261239189, 0.000837040274633605, -0.00324444329976892
)), .Names = c("NOK.CLOSE", "NOK.CLOSE.1", "NOK.50D",
"NOK.CLOSE.2"), row.names = c("2017-02-10", "2017-02-13",
"2017-02-14", "2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20",
"2017-02-21", "2017-02-22", "2017-02-23"), class = "data.frame"),
structure(list(CZK.CLOSE = c(1, 1, 1, 0, -1, 0, 0, 1, 0,
-1), CZK.CLOSE.1 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0), CZK.50D = c(1,
1, 1, -1, -1, 1, -1, 1, -1, -1), CZK.CLOSE.2 = c(0.00144601789180365,
0.00379617459269976, 0.00202579528819546, -0.00220231606416821,
-0.00688897736863447, 0.00560532297819627, 0.000184602212216056,
0.00710284457208665, -0.00197121312914339, -0.00224919172846905
)), .Names = c("CZK.CLOSE", "CZK.CLOSE.1", "CZK.50D", "CZK.CLOSE.2"
), row.names = c("2017-02-10", "2017-02-13", "2017-02-14",
"2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20", "2017-02-21",
"2017-02-22", "2017-02-23"), class = "data.frame"), structure(list(
HUF.LOW.1 = c(0, 1, 1, 0, -1, 0, 0, 1, 0, 0), HUF.LOW.1.1 = c(-1,
-1, -1, -1, -1, -1, -1, 1, -1, 1), HUF.50D = c(1, 1,
1, 1, 1, 1, 1, 1, 1, 1), HUF.LOW.1.2 = c(0.0013470806658562,
0.00413351833762921, 0.000927691660614904, -0.00161542594720476,
-0.00908798735735505, 0.00843420139734707, -0.00110208028787984,
0.00632043873779775, -0.00133632598823841, 0.000719782039952932
)), .Names = c("HUF.LOW.1", "HUF.LOW.1.1", "HUF.50D",
"HUF.LOW.1.2"), row.names = c("2017-02-10", "2017-02-13",
"2017-02-14", "2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20",
"2017-02-21", "2017-02-22", "2017-02-23"), class = "data.frame"),
structure(list(ILS.LOW.1 = c(0, 0, 0, -1, -1, -1, 0, 0, 0,
0), ILS.LOW.1.1 = c(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1
), ILS.50D = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ILS.LOW.1.2 = c(0.000933818987030266,
0.000959590648321962, -0.00159982969276018, -0.00296644925366696,
-0.00509821862018822, -0.00393531505179312, 0.00242770943578163,
-0.00285991992901691, -0.000567559913074556, 0.00091874516690349
)), .Names = c("ILS.LOW.1", "ILS.LOW.1.1", "ILS.50D", "ILS.LOW.1.2"
), row.names = c("2017-02-10", "2017-02-13", "2017-02-14",
"2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20", "2017-02-21",
"2017-02-22", "2017-02-23"), class = "data.frame"), structure(list(
PLN.LOW.1 = c(0, 1, 0, 0, -1, 1, 0, 0, 0, 0), PLN.LOW.1.1 = c(-1,
-1, -1, -1, -1, -1, -1, -1, -1, -1), PLN.50D = c(1, 1,
1, 1, 1, 1, 1, 1, 1, 1), PLN.LOW.1.2 = c(-0.00274633685326608,
0.00755279414139087, 0.000417931735706034, -0.000491702529882065,
-0.00490565626173578, 0.00929781633628868, -0.00365469691428677,
0.00186580959045224, -0.00137446945036213, -0.00149934278232444
)), .Names = c("PLN.LOW.1", "PLN.LOW.1.1", "PLN.50D",
"PLN.LOW.1.2"), row.names = c("2017-02-10", "2017-02-13",
"2017-02-14", "2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20",
"2017-02-21", "2017-02-22", "2017-02-23"), class = "data.frame"),
structure(list(RUB.LOW.1 = c(-1, -1, -1, -1, 0, 0, 1, 0,
-1, 1), RUB.LOW.1.1 = c(-1, -1, -1, -1, -1, -1, -1, -1, -1,
-1), RUB.50D = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), RUB.LOW.1.2 = c(-0.00446008580014645,
-0.0121748200414373, -0.00422818336649922, -0.0153488129381678,
0.0022241309795028, 0.00590173583792808, 0.014758577509606,
-0.00824954514944221, -0.00941636498473652, 0.0111898627811513
)), .Names = c("RUB.LOW.1", "RUB.LOW.1.1", "RUB.50D", "RUB.LOW.1.2"
), row.names = c("2017-02-09", "2017-02-10", "2017-02-13",
"2017-02-14", "2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20",
"2017-02-21", "2017-02-22"), class = "data.frame"), structure(list(
TRY.HIGH.1 = c(0, 0, -1, 0, 0, -1, -1, 0, -1, -1), TRY.HIGH.1.1 = c(1,
1, 1, 1, 1, -1, -1, -1, -1, -1), TRY.50D = c(-1, -1,
-1, -1, -1, -1, -1, -1, -1, -1), TRY.HIGH.1.2 = c(0.00417356089701015,
-0.00686579177053992, -0.00568012668941198, 0.00229778255761226,
0.00204713949728741, -0.0100024127023963, -0.00176420367173535,
-0.00113183078791668, -0.011249649909296, -0.00307744199905646
)), .Names = c("TRY.HIGH.1", "TRY.HIGH.1.1", "TRY.50D",
"TRY.HIGH.1.2"), row.names = c("2017-02-10", "2017-02-13",
"2017-02-14", "2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20",
"2017-02-21", "2017-02-22", "2017-02-23"), class = "data.frame"),
structure(list(ZAR.LOW.1 = c(-1, 0, -1, -1, 0, 0, 0, 0, -1,
-1), ZAR.LOW.1.1 = c(-1, -1, -1, -1, -1, -1, -1, -1, -1,
-1), ZAR.50D = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), ZAR.LOW.1.2 = c(-0.0050112296343281,
-0.000119978703923884, -0.0173679300039469, -0.0145343910929765,
0.00897924634581271, 0.000421926368602055, 0.000521408427958114,
0.00716476609655059, -0.0126608692527035, -0.00785440574245699
)), .Names = c("ZAR.LOW.1", "ZAR.LOW.1.1", "ZAR.50D", "ZAR.LOW.1.2"
), row.names = c("2017-02-10", "2017-02-13", "2017-02-14",
"2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20", "2017-02-21",
"2017-02-22", "2017-02-23"), class = "data.frame"), structure(list(
BRL.LOW.1 = c(0, 0, -1, -1, 0, 1, 0, 0, -1, -1), BRL.LOW.1.1 = c(-1,
-1, -1, -1, -1, -1, -1, -1, -1, -1), BRL.50D = c(1, 1,
1, 1, 1, 1, 1, 1, 1, 1), BRL.LOW.1.2 = c(-0.00371652356533581,
-0.00160621962638552, -0.00832934597660584, -0.00902065874268554,
0.010543197464703, 0.00316721872930192, -0.00362049854021018,
0.00278119317749237, -0.0100617531753731, -0.0006199931673041
)), .Names = c("BRL.LOW.1", "BRL.LOW.1.1", "BRL.50D",
"BRL.LOW.1.2"), row.names = c("2017-02-10", "2017-02-13",
"2017-02-14", "2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20",
"2017-02-21", "2017-02-22", "2017-02-23"), class = "data.frame"),
structure(list(CLP.LOW.1 = c(-1, 0, 0, 0, 0, 1, 0, 0, 0,
0), CLP.LOW.1.1 = c(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1
), CLP.50D = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), CLP.LOW.1.2 = c(-0.00993671434599985,
0.00456853190734918, -0.00172828592427443, -0.00404432121904819,
-0.00048516719656444, 0.00933326604643625, -0.00561445365426927,
0.00353409520664982, -0.00208469536279665, -0.00105956972687871
)), .Names = c("CLP.LOW.1", "CLP.LOW.1.1", "CLP.50D", "CLP.LOW.1.2"
), row.names = c("2017-02-10", "2017-02-13", "2017-02-14",
"2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20", "2017-02-21",
"2017-02-22", "2017-02-23"), class = "data.frame"), structure(list(
COP.CLOSE = c(-1, 1, 0, 0, 0, 1, 0, 1, 0, -1), COP.CLOSE.1 = c(-1,
-1, -1, -1, -1, -1, -1, -1, -1, -1), COP.50D = c(1, 1,
1, 1, 1, 1, 1, 1, 1, 1), COP.CLOSE.2 = c(-0.00197341552292052,
0.00662211307234362, 0.000580874632634121, -0.00202234392720335,
0.00204668459925017, 0.00543743450560008, -0.00266994190200176,
0.00607751193077277, -0.00217715796204931, -0.00905605289811184
)), .Names = c("COP.CLOSE", "COP.CLOSE.1", "COP.50D",
"COP.CLOSE.2"), row.names = c("2017-02-10", "2017-02-13",
"2017-02-14", "2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20",
"2017-02-21", "2017-02-22", "2017-02-23"), class = "data.frame"),
structure(list(MXN.LOW.1 = c(0, 0, -1, 0, 0, 1, -1, -1, -1,
-1), MXN.LOW.1.1 = c(-1, -1, -1, -1, -1, -1, -1, -1, -1,
-1), MXN.50D = c(-1, -1, 1, 1, 1, 1, 1, 1, 1, 1), MXN.LOW.1.2 = c(-0.000211320384603475,
-0.00314066280938086, -0.00107540683430729, 0.000705557901050646,
0.00518510570127306, 0.00240140867288519, -0.00281365838425973,
-0.0177295559643031, -0.00536567713104841, -0.0121193389083811
)), .Names = c("MXN.LOW.1", "MXN.LOW.1.1", "MXN.50D", "MXN.LOW.1.2"
), row.names = c("2017-02-10", "2017-02-13", "2017-02-14",
"2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20", "2017-02-21",
"2017-02-22", "2017-02-23"), class = "data.frame"), structure(list(
PEN.HIGH.1 = c(-1, 0, -1, -1, 0, 1, -1, 0, -1, 0), PEN.HIGH.1.1 = c(-1,
-1, -1, -1, -1, -1, -1, -1, -1, -1), PEN.50D = c(1, 1,
1, 1, 1, 1, 1, 1, 1, 1), PEN.HIGH.1.2 = c(-0.00429316820091041,
0.00214888801033619, -0.000859001157250239, -0.0038438522704316,
0.00101621330746293, 0.00460618041489735, -0.00522194398115183,
0, -0.000462071629322658, -0.000154071335332739)), .Names = c("PEN.HIGH.1",
"PEN.HIGH.1.1", "PEN.50D", "PEN.HIGH.1.2"), row.names = c("2017-02-10",
"2017-02-13", "2017-02-14", "2017-02-15", "2017-02-16", "2017-02-17",
"2017-02-20", "2017-02-21", "2017-02-22", "2017-02-23"), class = "data.frame"),
structure(list(CNY.CLOSE = c(1, 0, -1, 0, -1, 1, 1, 1, 0,
-1), CNY.CLOSE.1 = c(-1, -1, -1, -1, -1, -1, -1, -1, -1,
-1), CNY.50D = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), CNY.CLOSE.2 = c(0.00135295379134326,
0.000247116371263401, -0.00184758230288495, 0.000524070878021865,
-0.0026376972616271, 0.001968002384513, 0.00174608993071379,
0.000799273430379666, -0.00090104498241117, -0.00170257391661588
)), .Names = c("CNY.CLOSE", "CNY.CLOSE.1", "CNY.50D", "CNY.CLOSE.2"
), row.names = c("2017-02-10", "2017-02-13", "2017-02-14",
"2017-02-15", "2017-02-16", "2017-02-17", "2017-02-20", "2017-02-21",
"2017-02-22", "2017-02-23"), class = "data.frame"), structure(list(
IDR.LOW.1 = c(-1, 0, 0, 0, 0, 0, 1, 1, 0, 0), IDR.LOW.1.1 = c(-1,
-1, -1, -1, -1, -1, -1, 1, -1, -1), IDR.50D = c(1, 1,
1, 1, 1, 1, 1, 1, 1, 1), IDR.LOW.1.2 = c(-0.00225360672301989,
0.00142787383820853, 0.000750694427567922, 0.000375135991193432,
-0.000825485019296579, 0.000975500021079156, 0.00157380030235466,
0.00142178345498323, -0.000448765901323256, -0.00119769458137853
)), .Names = c("IDR.LOW.1", "IDR.LOW.1.1", "IDR.50D",
"IDR.LOW.1.2"), row.names = c("2017-02-09", "2017-02-10",
"2017-02-13", "2017-02-14", "2017-02-16", "2017-02-17", "2017-02-20",
"2017-02-21", "2017-02-22", "2017-02-23"), class = "data.frame"),
structure(list(INR.LOW.1 = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1
), INR.LOW.1.1 = c(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1
), INR.50D = c(-1, -1, -1, -1, -1, -1, 0, -1, 0, -1), INR.LOW.1.2 = c(-0.000466530150061928,
-0.000531550320954643, -0.000443420116883253, -0.000392023361358795,
-0.000386278564721287, -0.000386427833512393, -0.000244913256195467,
-0.000181510566847898, -0.000126929400856568, -0.000132850348706803
)), .Names = c("INR.LOW.1", "INR.LOW.1.1", "INR.50D", "INR.LOW.1.2"
), row.names = c("2017-02-08", "2017-02-09", "2017-02-10",
"2017-02-13", "2017-02-14", "2017-02-15", "2017-02-16", "2017-02-17",
"2017-02-20", "2017-02-22"), class = "data.frame"), structure(list(
KRW.LOW.1 = c(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1),
KRW.LOW.1.1 = c(-1, -1, -1, -1, -1, -1, -1, 1, -1, -1
), KRW.50D = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), KRW.LOW.1.2 = c(0.000517860571988438,
0.000112542907102053, 0.00134952787013343, 0, -0.000337211266051574,
0.00112359562382647, 0.000449084996881899, 0.000785413785115541,
-0.00085276367906495, -0.000718681250895026)), .Names = c("KRW.LOW.1",
"KRW.LOW.1.1", "KRW.50D", "KRW.LOW.1.2"), row.names = c("2017-02-10",
"2017-02-13", "2017-02-14", "2017-02-15", "2017-02-16", "2017-02-17",
"2017-02-20", "2017-02-21", "2017-02-22", "2017-02-23"), class = "data.frame"))
Here is a way to address your problem, d being the content of your dput:
vapply(d, function(x) {
valid_rows <- x[, 1] != 0 | x[, 2] > 0 | x[, 3] != 0
sum(x[valid_rows, 4])
}, numeric(1))
A few things to note:
first you say " first column is nonzero, second column is positive and third column is nonnegative" but you use | in your conditions. | means OR, if you want AND you would need to use &. In that case though, some of your examples don't match any rows, so you would get a sum of 0. If it's not what you want you'll need to modify the code to return NA when there is no rows that match your conditions, for instance:
vapply(d, function(x) {
valid_rows <- x[, 1] != 0 & x[, 2] > 0 & x[, 3] != 0
if (sum(valid_rows) > 0)
sum(x[valid_rows, 4])
else
NA_real_
}, numeric(1))
second, for your last condition you say "third column is nonnegative", but you write FlaggingTrend[[x]][,3] != 0 which tests for values different from 0, not positive values.
third, it's best to not use global variables within your functions. It might lead to a lot of confusion down the road.
here, I use vapply to enforce the data type of the returned objects. It's safer than sapply whose behavior can change depending on the data type of the returned objects.
I just started using Here Maps. Before I used Google Direction, I want to try use 'Here Maps' API. This is example JSON result. After I got this result, How do I implement this into Polyline or Direction (MAP Here)? Thanks
{
RouteLinks: [
{
linkId: 25664478,
functionalClass: 5,
shape: "51.1017723 0.3934907 51.1018066 0.3933491 51.1018295 0.39326",
linkLength: 15.575699313408467
},
{
linkId: 25664473,
functionalClass: 4,
shape: "51.1018295 0.39326 51.1022491 0.39348",
linkLength: 44.17562556306323
},
{
linkId: 25664459,
functionalClass: 4,
shape: "51.1022491 0.39348 51.1022987 0.39351",
linkLength: 5.305684979980019
},
{
linkId: 781742854,
functionalClass: 4,
shape: "51.1022987 0.39351 51.1025505 0.39365",
linkLength: 26.670487136749067
},
{
linkId: 781742855,
functionalClass: 4,
shape: "51.1025505 0.39365 51.1027794 0.39378",
linkLength: 24.302012297623005
},
{
linkId: 25664450,
functionalClass: 4,
shape: "51.1027794 0.39378 51.1030807 0.39403",
linkLength: 33.974229462422905
},
{
linkId: 25664444,
functionalClass: 4,
shape: "51.1030807 0.39403 51.103241 0.39413",
linkLength: 17.215963662407898
},
{
linkId: 25664440,
functionalClass: 4,
shape: "51.103241 0.39413 51.1033783 0.39421 51.1035385 0.39433 51.1036797 0.39445",
linkLength: 48.32839625333388
},
{
linkId: 25664427,
functionalClass: 4,
shape: "51.1036797 0.39445 51.1038017 0.39454",
linkLength: 13.445306290244636
},
{
linkId: 860272608,
functionalClass: 4,
shape: "51.1038017 0.39454 51.1039391 0.39465",
linkLength: 15.378381014646559
},
{
linkId: 860272609,
functionalClass: 4,
shape: "51.1039391 0.39465 51.1041908 0.39484",
linkLength: 27.85427285471891
},
{
linkId: 781742870,
functionalClass: 4,
shape: "51.1041908 0.39484 51.1043282 0.39494 51.1045609 0.39506",
linkLength: 39.56626207722863
},
{
linkId: 781742871,
functionalClass: 4,
shape: "51.1045609 0.39506 51.1047287 0.39515 51.1050262 0.3953021",
linkLength: 48.951382959921716
}
],
TracePoints: [
{
confidenceValue: 1, linkIdMatched: 25664478, matchDistance: 1.46,
routeLinkSeqNrMatched: 0, lat: 51.10177, lon: 0.39349,
elevation: 0, speedMps: 0, headingDegreeNorthClockwise: 10000,
latMatched: 51.10178065190155, lonMatched: 0.3934977183445852,
timestamp: 0, headingMatched: 114.46568884011239,
minError: 1.3027890756593314
},
{
confidenceValue: 1, linkIdMatched: 25664478, matchDistance: 1.57,
routeLinkSeqNrMatched: 0, lat: 51.10181, lon: 0.39335,
elevation: 0, speedMps: 0, headingDegreeNorthClockwise: 10000,
latMatched: 51.10182, lonMatched: 0.39336,
timestamp: 0, headingMatched: -65.53429247174023,
minError: 1000000
},
{
confidenceValue: 1, linkIdMatched: 781742854, matchDistance: 1,
routeLinkSeqNrMatched: 4, lat: 51.10255, lon: 0.39366,
elevation: 0, speedMps: 0, headingDegreeNorthClockwise: 10000,
latMatched: 51.102547928304084, lonMatched: 0.3936687569824506,
timestamp: 0, headingMatched: 20.644254301899522,
minError: 0.6541474931313044
},
{
confidenceValue: 1, linkIdMatched: 860272608, matchDistance: 4.59,
routeLinkSeqNrMatched: 10, lat: 51.10398, lon: 0.39466,
elevation: 0, speedMps: 0, headingDegreeNorthClockwise: 10000,
latMatched: 51.10394, lonMatched: 0.39465,
timestamp: 0, headingMatched: 25.217234923243595,
minError: 1.2405405512432781
},
{
confidenceValue: 1, linkIdMatched: 1022687693, matchDistance: 1.33,
routeLinkSeqNrMatched: 14, lat: 51.10501, lon: 0.39533,
elevation: 0, speedMps: 0, headingDegreeNorthClockwise: 10000,
latMatched: 51.105012239590245, lonMatched: 0.39531827230152644,
timestamp: 0, headingMatched: 16.91643828307876,
minError: 0.8568378930601925
}
],
Warnings: [
{
"tracePointSeqNum": -1,
"routeLinkSeqNum": 3,
"category": 3,
"text": "Entering link 781742854 into forbidden driving direction"
}
],
MapVersion: "2013Q4" }
*linkId,shape is like that trip points which is given by Heremap api step1.
You just draw route by polyline function.
addPolylineToMap(map,linkId);
function addPolylineToMap(map,linkId) {
for (j = 0; j < (shape.length - 1); j = j + 2) {
var strip = new H.geo.Strip();
strip.pushPoint({lat: shape[j],lng: shape[j+1]});
}
}
Anyone able to help with the following problem:
Trying to draw a chart with four data series, two of which are scatter and one is spline. Purpose of the spline is just to draw a line between specific spots on the chart, not joining all of them together. The following is my code so far:
$(function () {
var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
type: 'scatter',
zoomType: 'xy'
},
title: {
text: ''
},
xAxis: {
type: 'datetime',
ordinal: false,
labels: {
formatter: function() {
return Highcharts.dateFormat('%H', this.value);
}
}
},
yAxis: {
categories: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
gridLineWidth: 0,
step: 1,
title: '',
labels: {
style: {
color: '#6D869F',
fontSize: '9px',
}
},
},
tooltip: {
formatter: function() {
return ''+
this.x +' cm, '+ this.y +' kg';
}
},
legend: {
layout: 'vertical',
align: 'left',
verticalAlign: 'top',
x: 100,
y: 70,
floating: true,
backgroundColor: '#FFFFFF',
borderWidth: 1
},
plotOptions: {
scatter: {
marker: {
radius: 5,
states: {
hover: {
enabled: true,
lineColor: 'rgb(100,100,100)'
}
}
},
states: {
hover: {
marker: {
enabled: false
}
}
}
}
},
series: [{
name: 'sleep time',
marker: {
symbol: 'circle',
},
color: '#81c65b',
data: [[Date.UTC(2012, 1, 1, 22, 15), 0],
[Date.UTC(2012, 1, 1, 20, 30), 3],
[Date.UTC(2012, 1, 1, 21, 45), 5],
[Date.UTC(2012, 1, 1, 22, 00), 6]]
},
{
name: 'wakeup time',
marker: {
symbol: 'circle',
fillColor: '#76a4fb',
},
data: [[Date.UTC(2012, 1, 2, 08, 15), 0],
[Date.UTC(2012, 1, 2, 07, 10), 1],
[Date.UTC(2012, 1, 2, 09, 20), 2],
[Date.UTC(2012, 1, 2, 07, 40), 3],
[Date.UTC(2012, 1, 2, 07, 30), 4],
[Date.UTC(2012, 1, 2, 08, 20), 5],
[Date.UTC(2012, 1, 2, 09, 30), 6]],
},
{
name: 'sleep time over average',
color: 'rgba(119, 152, 191, .5)',
marker: {
symbol: 'square',
fillColor: '#000',
},
data: [[Date.UTC(2012, 1, 1, 20, 15), 1],
[Date.UTC(2012, 1, 1, 23, 40), 2],
[Date.UTC(2012, 1, 1, 21, 20), 4]]
},
{
name: '',
legend: {
enabled: false,
},
color: '#d62a9c',
type: 'spline',
marker: {
enabled: false,
},
data: [[Date.UTC(2012, 1, 1, 22, 15), 0],
[Date.UTC(2012, 1, 2, 08, 15), 0],
[Date.UTC(2012, 1, 1, 20, 15), 1],
[Date.UTC(2012, 1, 2, 07, 10), 1],
[Date.UTC(2012, 1, 1, 23, 40), 2],
[Date.UTC(2012, 1, 2, 09, 20), 2],
[Date.UTC(2012, 1, 1, 20, 30), 3],
[Date.UTC(2012, 1, 2, 07, 40), 3],
[Date.UTC(2012, 1, 1, 21, 20), 4],
[Date.UTC(2012, 1, 2, 07, 30), 4],
[Date.UTC(2012, 1, 1, 21, 45), 5],
[Date.UTC(2012, 1, 2, 08, 20), 5],
[Date.UTC(2012, 1, 1, 22, 00), 6],
[Date.UTC(2012, 1, 2, 09, 30), 6]]
}]
});
});
});
My problem now is, in the spline series, if I add a null between elements to prevent plotting the line between two points, the whole plot goes mayhem. The idea is to draw lines only so that points which are vertically on the same line get joined, eg. in this case "sleep time" and "wakeup time". For example,
data: [
[Date.UTC(2012, 1, 1, 22, 15), 0],
[Date.UTC(2012, 1, 2, 08, 15), 0], null,
[Date.UTC(2012, 1, 1, 20, 15), 1],
[Date.UTC(2012, 1, 2, 07, 10), 1], null,
[Date.UTC(2012, 1, 1, 23, 40), 2],
...
You may try out the code at this jsfiddle.
Try the following.
data: [
[Date.UTC(2012, 1, 1, 22, 15), 0],
[Date.UTC(2012, 1, 2, 08, 15), 0],
[Date.UTC(2012, 1, 2, 08, 15), null],
[Date.UTC(2012, 1, 1, 20, 15), 1],
[Date.UTC(2012, 1, 2, 07, 10), 1],
[Date.UTC(2012, 1, 2, 08, 15), null],
[Date.UTC(2012, 1, 1, 23, 40), 2],
[Date.UTC(2012, 1, 2, 09, 20), 2],
[Date.UTC(2012, 1, 2, 08, 15), null],
...
]
As you can see you have to pass an array which the first value have to be any date.
Demo