Add "new games" on top of discover main screen, move "Last updated" to own category
authorChristian Weiske <cweiske@cweiske.de>
Mon, 28 Dec 2020 19:40:19 +0000 (20:40 +0100)
committerChristian Weiske <cweiske@cweiske.de>
Mon, 28 Dec 2020 19:40:19 +0000 (20:40 +0100)
Resolves: https://github.com/ouya-saviors/ouya-game-data/issues/109

bin/filters.php
bin/import-game-data.php

index fc16ef3636569802790a20ecb56b986a58543b47..9cac07a2e613e64e0e71cd69637cc64bd923e8f0 100644 (file)
@@ -78,6 +78,19 @@ function filterBySearchWord($origGames, $searchWord)
     return $filtered;
 }
 
+function filterLastAdded($origGames, $limit)
+{
+    $games = array_values($origGames);
+    usort(
+        $games,
+        function ($gameA, $gameB) {
+            return strtotime($gameB->firstRelease->date) - strtotime($gameA->firstRelease->date);
+        }
+    );
+
+    return array_slice($games, 0, $limit);
+}
+
 function filterLastUpdated($origGames, $limit)
 {
     $games = array_values($origGames);
index c0b500c18198d86d22826a6344c319f122453b60..76d1312a14ac3f65f5b9c3f965aa779d1becb41a 100755 (executable)
@@ -166,8 +166,8 @@ function buildDiscover(array $games)
     ];
 
     addDiscoverRow(
-        $data, 'Last Updated',
-        filterLastUpdated($games, 10)
+        $data, 'New games',
+        filterLastAdded($games, 10)
     );
     addDiscoverRow(
         $data, 'Best rated',
@@ -188,6 +188,7 @@ function buildDiscover(array $games)
             'Best rated',
             'Most rated',
             'Random',
+            'Last updated',
         ]
     );
     writeJson(
@@ -205,6 +206,10 @@ function buildDiscover(array $games)
             filterRandom($games, 99)
         )
     );
+    writeJson(
+        'api/v1/discover-data/' . categoryPath('Last updated') . '.json',
+        buildSpecialCategory('Last updated', filterLastUpdated($games, 99))
+    );
 
     $players = [
         //1 => '1 player',
@@ -814,7 +819,9 @@ function addMissingGameProperties($game)
         $game->rating->count = 0;
     }
 
+    $game->firstRelease  = null;
     $game->latestRelease = null;
+    $firstReleaseTimestamp  = null;
     $latestReleaseTimestamp = 0;
     foreach ($game->releases as $release) {
         if (!isset($release->publicSize)) {
@@ -829,6 +836,15 @@ function addMissingGameProperties($game)
             $game->latestRelease    = $release;
             $latestReleaseTimestamp = $releaseTimestamp;
         }
+        if ($firstReleaseTimestamp === null
+            || $releaseTimestamp < $firstReleaseTimestamp
+        ) {
+            $game->firstRelease    = $release;
+            $firstReleaseTimestamp = $releaseTimestamp;
+        }
+    }
+    if ($game->firstRelease === null) {
+        error('No first release for ' . $game->packageName);
     }
     if ($game->latestRelease === null) {
         error('No latest release for ' . $game->packageName);