-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dan Abrey
committed
Nov 23, 2019
1 parent
3927fe8
commit 2d83fd5
Showing
8 changed files
with
473 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
|
||
namespace DanAbrey\ESPNCollegeFootballStats\Extractor; | ||
|
||
use DanAbrey\ESPNCollegeFootballStats\PlayerSeason; | ||
use DanAbrey\ESPNCollegeFootballStats\TeamSeason; | ||
use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer; | ||
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; | ||
use Symfony\Component\Serializer\Serializer; | ||
|
||
class TeamStatsExtractor | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
private $data; | ||
|
||
private const MAP = [ | ||
'Rushing' => [ | ||
'rushingAttempts', | ||
'rushingYards', | ||
'rushingTouchdowns', | ||
], | ||
'Receiving' => [ | ||
'receptions', | ||
'receivingYards', | ||
'receivingTouchdowns', | ||
], | ||
'Passing' => [ | ||
'passingTouchdowns', | ||
'passingYards', | ||
'passingAttempts', | ||
'completions', | ||
'interceptions', | ||
'sacks', | ||
] | ||
]; | ||
|
||
public function __construct(string $json) | ||
{ | ||
$this->data = json_decode($json, true); | ||
} | ||
|
||
public function extractSeasonData() | ||
{ | ||
$teamSeason = []; | ||
$teamSeason['year'] = $this->data['requestedSeason']['year']; | ||
|
||
foreach ($this->data['teamTotals'] as $category) { | ||
$categoryName = $category['displayName']; | ||
|
||
if (!array_key_exists($categoryName, self::MAP)) { | ||
continue; | ||
} | ||
|
||
foreach ($category['stats'] as $stat) { | ||
if (!in_array($stat['name'], self::MAP[$categoryName])) { | ||
continue; | ||
} | ||
|
||
$teamSeason[$stat['name']] = str_replace(',', '', $stat['value']); | ||
} | ||
} | ||
|
||
$normalizers = [new ArrayDenormalizer(), new ObjectNormalizer()]; | ||
$serializer = new Serializer($normalizers); | ||
|
||
return $serializer->denormalize($teamSeason, TeamSeason::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
namespace DanAbrey\ESPNCollegeFootballStats; | ||
|
||
class Team | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $seasons = []; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getId(): string | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @param string $id | ||
*/ | ||
public function setId(string $id): void | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getSeasons(): array | ||
{ | ||
return $this->seasons; | ||
} | ||
|
||
/** | ||
* @param array $seasons | ||
*/ | ||
public function setSeasons(array $seasons): void | ||
{ | ||
$this->seasons = $seasons; | ||
} | ||
} |
Oops, something went wrong.