public static function getCollectionTimePlayed() { foreach ($GLOBALS['data']['gamesCollection'] as $gameId => $gameProperties) { if (isset($GLOBALS['data']['arrayTotalPlays'][$gameId])) { $gamePlayed = $GLOBALS['data']['arrayTotalPlays'][$gameId]['plays']; usort($gamePlayed, 'App\\Lib\\Utility::compareDate'); $dateTimestamp = end($gamePlayed)['date']; $totalPlay = 0; foreach ($gamePlayed as $playDetail) { $totalPlay += $playDetail['quantity']; } $gameLessTimePlayed[] = ['id' => $gameId, 'name' => $gameProperties['name'], 'url' => Utility::urlToGame($gameId), 'totalPlays' => $totalPlay, 'date' => $dateTimestamp, 'dateFormated' => Carbon::createFromTimestamp($dateTimestamp)->formatLocalized('%e %b %Y'), 'since' => Carbon::createFromTimestamp($dateTimestamp)->diffForHumans()]; } else { // Never played this game $gameLessTimePlayed[] = ['id' => $gameId, 'name' => $gameProperties['name'], 'url' => Utility::urlToGame($gameId), 'totalPlays' => 0, 'date' => '', 'dateFormated' => '', 'since' => '']; } } usort($gameLessTimePlayed, 'App\\Lib\\Utility::compareDate'); return $gameLessTimePlayed; }
public function home() { $paramsMenu = Page::getMenuParams(); $arrayRawGamesOwned = BGGData::getGamesOwned(); $arrayGamesDetails = BGGData::getDetailOwned($arrayRawGamesOwned); $arrayRawUserInfos = BGGData::getUserInfos(); $arrayUserInfos = UserInfos::getUserInformations($arrayRawUserInfos); $arrayRawGamesAndExpansionsOwned = BGGData::getGamesAndExpansionsOwned(); Stats::getCollectionArrays($arrayRawGamesOwned); Stats::getOwnedRelatedArrays($arrayGamesDetails); Stats::getOwnedExpansionLink($arrayRawGamesAndExpansionsOwned); $params['userinfo'] = $arrayUserInfos; $allMechanics = []; $arrayGames = []; foreach ($GLOBALS['data']['gamesCollection'] as $idGame => $gameProperties) { $classes = []; $arrayGame = $this->preProcessGameInfo($gameProperties); if ($arrayGame['playingtime'] <= 30) { $classes[] = '30minus'; } elseif ($arrayGame['playingtime'] > 30 && $arrayGame['playingtime'] <= 60) { $classes[] = '31to60'; } elseif ($arrayGame['playingtime'] > 61 && $arrayGame['playingtime'] <= 120) { $classes[] = '61to120'; } elseif ($arrayGame['playingtime'] > 120) { $classes[] = '121plus'; } if (isset($gameProperties['detail']['boardgamemechanic'])) { foreach ($gameProperties['detail']['boardgamemechanic'] as $mechanic) { $classes[] = Utility::getKeyByString($mechanic['value']); $allMechanics[] = $mechanic['value']; } } if ($arrayGame['minplayer'] && $arrayGame['maxplayer']) { $begin = (int) $arrayGame['minplayer']; $end = (int) $arrayGame['maxplayer']; if ($begin == 1) { $classes[] = 'players_solo'; } if ($end >= 7) { $classes[] = 'players_plus'; } for ($i = $begin; $i <= $end; $i++) { $classes[] = 'players_' . $i; if (isset($gameProperties['poll']['process_suggested_numplayers']['best']) && $gameProperties['poll']['process_suggested_numplayers']['best'] == $i) { $classes[] = 'players_' . $i . '_best'; } if (isset($gameProperties['poll']['process_suggested_numplayers']['recommended']) && $gameProperties['poll']['process_suggested_numplayers']['recommended'] == $i) { $classes[] = 'players_' . $i . '_recommended'; } } } $arrayGame['class'] = implode(' ', $classes); $arrayGame['tooltip'] = 'Nombre de parties joués : ' . $arrayGame['numplays']; if ($arrayGame['minplayer'] > 0 && $arrayGame['maxplayer'] > 0) { $arrayGame['tooltip'] .= '<br>Nombre de joueurs : ' . $arrayGame['minplayer'] . ' à ' . $arrayGame['maxplayer']; } $arrayGame['tooltip'] .= '<br>Durée d\'une partie : ' . $arrayGame['playingtime'] . ' minutes'; $arrayGame['tooltip'] .= '<br>Évaluation : ' . $gameProperties['rating'] . ' / 10'; if (isset($gameProperties['privateinfo']['@attributes']['acquisitiondate'])) { $arrayGame['tooltip'] .= '<br>Date d\'acquisition : ' . $gameProperties['privateinfo']['@attributes']['acquisitiondate']; } $arrayGames[$idGame] = $arrayGame; } $params['games'] = $arrayGames; $mechanics = array_values(array_unique($allMechanics)); foreach ($mechanics as $mechanic) { $params['mechanics'][Utility::getKeyByString($mechanic)] = $mechanic; } ksort($params['mechanics']); $params = array_merge($params, $paramsMenu); return \View::make('collection', $params); }
public static function getDetailOwned(&$arrayRawGamesOwned) { $arrayGamesDetails = []; if (isset($arrayRawGamesOwned['item'])) { foreach ($arrayRawGamesOwned['item'] as $key => $game) { $arrayId[] = $game['@attributes']['objectid']; $arrayRawGamesOwned['item'][$key]['detail'] = []; } } $arrayChunk = array_chunk($arrayId, 40, true); foreach ($arrayChunk as $key => $arrayIds) { $strIds = implode(',', $arrayIds); $urlBGG = BGGUrls::getDetail($strIds); $fromBGG = self::getBGGUrl($urlBGG); $fromBGG = Utility::bggGetMultiple($fromBGG); foreach ($fromBGG['item'] as $gameDetail) { $arrayGamesDetails[$gameDetail['@attributes']['id']] = $gameDetail; } } return $arrayGamesDetails; }
public static function getMostDesignerOwned() { $arrayDesignerFrequency = []; foreach ($GLOBALS['data']['gamesCollection'] as $gameId => $game) { if (isset($game['detail']['boardgamedesigner'])) { $designerArray = $game['detail']['boardgamedesigner']; foreach ($designerArray as $designer) { if ($designer['value'] != '(Uncredited)') { $arrayDesignerFrequency[$designer['id']]['name'] = $designer['value']; $arrayDesignerFrequency[$designer['id']]['games'][$gameId] = $game['name']; Utility::arrayIncrementValue($arrayDesignerFrequency, $designer['id'], 1, 'nbOwned'); } } } } uasort($arrayDesignerFrequency, 'App\\Lib\\Utility::compareOwned'); return array_slice($arrayDesignerFrequency, 0, 20, true); }
public function tobuy() { $arrayRawUserInfos = BGGData::getUserInfos(); $arrayRawGamesOwned = BGGData::getGamesOwned(); $arrayRawGamesPreviouslyOwned = BGGData::getGamesPreviouslyOwned(); $arrayGamesDetails = BGGData::getDetailOwned($arrayRawGamesOwned); $arrayRawGamesRated = BGGData::getGamesRated(); $arrayRawGamesPlays = BGGData::getPlays(); $arrayGamesHot = BGGData::getHotWithDetails(); $arrayUserInfos = UserInfos::getUserInformations($arrayRawUserInfos); Stats::getRatedRelatedArrays($arrayRawGamesRated); Stats::getCollectionArrays($arrayRawGamesOwned); Stats::getCollectionArrays($arrayRawGamesPreviouslyOwned, 'gamesPrevOwned'); Stats::getOwnedRelatedArrays($arrayGamesDetails); Stats::getPlaysRelatedArrays($arrayRawGamesPlays); $params['userinfo'] = $arrayUserInfos; $gamesToBuy = []; // High rated $highRating = []; foreach ($GLOBALS['data']['gamesRated'] as $idGame => $ratedGame) { if (!isset($GLOBALS['data']['gamesCollection'][$idGame]) && !isset($GLOBALS['data']['gamesPrevOwned'][$idGame])) { $highRating[$idGame] = $ratedGame; } } uasort($highRating, 'App\\Lib\\Utility::compareOrderRating'); $highRating = array_slice($highRating, 0, 50, true); foreach ($highRating as &$game) { $game['weight'] = $game['rating']; $game['rating'] .= ' / 10'; } Utility::normalizeArray($highRating, 'weight'); $this->compileGameArray($gamesToBuy, $highRating, 'Bien classé', 1, 'rating'); // Played frequently $playsFrequently = []; foreach ($GLOBALS['data']['arrayTotalPlays'] as $idGame => $game) { if (!isset($GLOBALS['data']['gamesCollection'][$idGame]) && !isset($GLOBALS['data']['gamesPrevOwned'][$idGame])) { $playsFrequently[$idGame] = $game; } } usort($playsFrequently, 'App\\Lib\\Utility::compareOrderNbPlayed'); $playsFrequently = array_slice($playsFrequently, 0, 50, true); foreach ($playsFrequently as &$game) { $game['weight'] = $game['nbPlayed']; $game['nbPlayed'] .= ' parties'; } Utility::normalizeArray($playsFrequently, 'weight'); $this->compileGameArray($gamesToBuy, $playsFrequently, 'Joué souvent', 1, 'nbPlayed'); // Game hot of the same author $gameWithDesignerHot = []; $mostDesigner = Graphs::getMostDesignerOwned(); foreach ($arrayGamesHot as $idGame => $game) { if (!isset($GLOBALS['data']['gamesCollection'][$idGame]) && !isset($GLOBALS['data']['gamesPrevOwned'][$idGame])) { if (isset($game['detail']['boardgamedesigner'])) { foreach ($game['detail']['boardgamedesigner'] as $hotDesigner) { if (isset($mostDesigner[$hotDesigner['id']])) { $gameWithDesignerHot[$idGame] = $game; $gameWithDesignerHot[$idGame]['weight'] = $mostDesigner[$hotDesigner['id']]['nbOwned']; $gameWithDesignerHot[$idGame]['designer'] = $mostDesigner[$hotDesigner['id']]['name']; } } } } } Utility::normalizeArray($gameWithDesignerHot, 'weight'); $this->compileGameArray($gamesToBuy, $gameWithDesignerHot, 'Jeu d\'un auteur apprécié', 1, 'designer'); usort($gamesToBuy, 'App\\Lib\\Utility::compareOrderWeight'); $params['games'] = $gamesToBuy; return \View::make('rapports_tobuy', $params); }
public function home() { $paramsMenu = Page::getMenuParams(); // Games owned $arrayRawGamesOwned = BGGData::getGamesOwned(); Stats::getCollectionArrays($arrayRawGamesOwned); Stats::getOwnedRelatedArrays(BGGData::getDetailOwned($arrayRawGamesOwned)); unset($arrayRawGamesOwned); // Games and expansions owned Stats::getAcquisitionRelatedArrays(BGGData::getGamesAndExpansionsOwned()); // Games played Stats::getPlaysRelatedArrays(BGGData::getPlays()); // Games rated Stats::getRatedRelatedArrays(BGGData::getGamesRated()); // User infos $arrayUserInfos = UserInfos::getUserInformations(BGGData::getUserInfos()); $totalPlayGameCollection = 0; $totalGameOwnedNotPlayed = 0; foreach ($GLOBALS['data']['gamesCollection'] as $idGame => $game) { if (isset($GLOBALS['data']['arrayTotalPlays'][$idGame])) { $totalPlayGameCollection += $GLOBALS['data']['arrayTotalPlays'][$idGame]['nbPlayed']; } else { $totalGameOwnedNotPlayed++; } } $params['userinfo'] = $arrayUserInfos; $params['stats']['nbGamesOwned'] = count($GLOBALS['data']['gamesCollection']); $params['stats']['nbGamesAndExpansionsOwned'] = $GLOBALS['data']['nbGamesAndExpansionsOwned']; $params['stats']['nbPlaysTotal'] = $GLOBALS['data']['countAllPlays']; $params['stats']['nbPlaysDifferentGame'] = count($GLOBALS['data']['arrayTotalPlays']); $params['stats']['averagePlayByMonth'] = 0; $params['stats']['averagePlayDifferentByMonth'] = 0; if (count($GLOBALS['data']['arrayPlaysByMonth']) > 0) { $params['stats']['averagePlayByMonth'] = round($GLOBALS['data']['countAllPlays'] / count($GLOBALS['data']['arrayPlaysByMonth'])); $params['stats']['averagePlayDifferentByMonth'] = round(count($GLOBALS['data']['arrayTotalPlays']) / count($GLOBALS['data']['arrayPlaysByMonth'])); } $params['stats']['hindex'] = $GLOBALS['data']['hindex']; $params['stats']['averageAcquisitionByMonth'] = ''; if (SessionManager::ifLoginAsSelf()) { if (count($GLOBALS['data']['acquisitionsByMonth']) > 0) { $params['stats']['averageAcquisitionByMonth'] = round($GLOBALS['data']['totalWithAcquisitionDate'] / count($GLOBALS['data']['acquisitionsByMonth'])); } } $params['stats']['averageValueGames'] = ''; $params['stats']['totalValueGames'] = ''; if (SessionManager::ifLoginAsSelf()) { if (count($GLOBALS['data']['arrayValuesGames']) > 0) { $params['stats']['averageValueGames'] = Utility::displayMoney($GLOBALS['data']['totalGamesValue'] / count($GLOBALS['data']['arrayValuesGames'])); } $params['stats']['totalValueGames'] = Utility::displayMoney($GLOBALS['data']['totalGamesValue']); } $params['stats']['nbPlayAveragePlayCollectionGame'] = round($totalPlayGameCollection / count($GLOBALS['data']['gamesCollection']), 2); $params['stats']['nbPlayAverageByDay'] = 0; $params['stats']['nbPlayDifferentAverageByDay'] = 0; if (isset($GLOBALS['data']['nbDaysSinceFirstPlay'])) { $params['stats']['nbPlayAverageByDay'] = round($GLOBALS['data']['countAllPlays'] / $GLOBALS['data']['nbDaysSinceFirstPlay'], 2); $params['stats']['nbPlayDifferentAverageByDay'] = round(count($GLOBALS['data']['arrayTotalPlays']) / $GLOBALS['data']['nbDaysSinceFirstPlay'], 2); } $params['stats']['nbGameOwnedNotPlayed'] = $totalGameOwnedNotPlayed; if (count($GLOBALS['data']['gamesCollection']) > 0) { $params['stats']['percentGameOwnedNotPlayed'] = Utility::displayPercent(round($totalGameOwnedNotPlayed / count($GLOBALS['data']['gamesCollection']) * 100, 2)); } $params['graphs']['byMonth'] = Graphs::getPlayByMonth(); $params['graphs']['byYear'] = Graphs::getPlayByYear(); $params['graphs']['byDayWeek'] = Graphs::getPlayByDayWeek(); $params['graphs']['mostPlayed'] = Graphs::getMostPlayed(); $params['graphs']['nbPlayer'] = Graphs::getNbPlayerCollection(); $params['graphs']['acquisitionByMonth'] = Graphs::getAcquisitionByMonth(); $params['graphs']['mostType'] = Graphs::getMostType(); $params['graphs']['playsByRating'] = Graphs::getPlayByRating(); $params['graphs']['playsByLength'] = Graphs::getPlayByLength(); $params['table']['ownedTimePlayed'] = Graphs::getOwnedTimePlayed(); $params['table']['mostDesigner'] = Graphs::getMostDesignerOwned(); $params['table']['ownedRentable'] = Graphs::getOwnedRentable(); $params = array_merge($params, $paramsMenu); return \View::make('stats', $params); }