コード例 #1
0
 public static function getAllSectorGraphData($sectorLimit)
 {
     $graphData = array();
     $mostRecentDate = SectorHistoricals::getMostRecentSectorHistoricalsDate();
     $sectors = SectorHistoricals::where('date', $mostRecentDate)->where('sector', '!=', 'All')->orderBy('total_sector_market_cap', 'DESC')->limit(SectorHistoricals::sectorLimitToNumber($sectorLimit))->get();
     $allSectorsMarketCap = SectorHistoricals::where(['date' => $mostRecentDate, 'sector' => 'All'])->pluck('total_sector_market_cap');
     foreach ($sectors as $sector) {
         if ($sector->sector != 'All') {
             if ($allSectorsMarketCap > 0 && $sector->total_sector_market_cap > 0) {
                 $sectorPercent = 100 / $allSectorsMarketCap * $sector->total_sector_market_cap;
             } else {
                 $sectorPercent = 0;
             }
             array_push($graphData, array($sector->sector, round($sectorPercent, 2)));
         }
     }
     return $graphData;
 }