$stat = $article->getPoints($gStatsInterval, $gStatsStart); if ($stat !== null) { foreach ($stat as $k => $v) { $stat[$k] = $v * $weight; } $totalStats[] = $stat; $totalWeight += $weight; } } } /* summarize stats */ $sumArray = array(); foreach ($totalStats as $k => $subArray) { foreach ($subArray as $id => $value) { if (!isset($sumArray[$id])) { $sumArray[$id] = 0; } $sumArray[$id] += $value; } } foreach ($sumArray as $k => $v) { $sumArray[$k] = (int) ($sumArray[$k] / $totalWeight); } $spark = $sumArray; } else { $popularityList = new Toplist\OnsitePopularityList(); global $gStatsInterval; $spark = array_reverse($popularityList->getIndividual($laureate, $gStatsInterval)); } $api->write_headers(); $api->write_json($spark);
/* Get most viewed list for this subset of laureates */ $popularityList = new Toplist\WikipediaPopularityList($wpNames); $orderedList = $popularityList->getOrdered(); usort($list, function ($a, $b) use($orderedList) { $ida = $a['dbPedia']; $idb = $b['dbPedia']; $posa = array_search($ida, $orderedList); $posb = array_search($idb, $orderedList); return $posa > $posb ? 1 : -1; }); /* Truncate list to max length */ global $maxListItems; $maxListLength = @$parameters['length'] ?: $maxListItems; $list = array_values(array_slice($list, 0, $maxListLength)); } else { $popularityList = new Toplist\OnsitePopularityList(); $orderedList = $popularityList->getOrdered(); usort($list, function ($a, $b) use($orderedList) { $ida = $a['id']; $idb = $b['id']; $posa = array_search($ida, $orderedList); $posb = array_search($idb, $orderedList); return $posa < $posb ? 1 : -1; }); /* Truncate list to max length */ global $maxListItems; $maxListLength = @$parameters['length'] ?: $maxListItems; $list = array_values(array_slice($list, 0, $maxListLength)); } $api->write_headers(); $api->write_json($list);