Created
February 20, 2021 10:00
-
-
Save cygeorgel/c0cc8ad13eea1fd8d321a0deac428ee6 to your computer and use it in GitHub Desktop.
Simple info about running streak
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
public function handle() | |
{ | |
// I get manually the data from Strava | |
$start = '2020-04-25'; | |
$data['2020']['mileage'] = 2183.5; | |
$data['2020']['time'] = 231; | |
$data['2021']['mileage'] = 526.5; | |
$data['2021']['time'] = 49; | |
$mileage = 0; | |
$time = 0; | |
$start = Carbon::createFromFormat('Y-m-d', $start); | |
$diff = $start->diff(); | |
$y0 = $start->format('Y'); | |
$yC = now()->format('Y'); | |
$this->info('------------'); | |
$this->info('#100DaysOfRunning'); | |
$this->info('Running streak started on ' . $start->format('d/m/Y')); | |
for ($y=$y0; $y<=$yC; $y++) { | |
$this->info('------------'); | |
$this->info('*** Data for ' . $y . ' ***'); | |
if(isset($data[$y]['mileage'])) { | |
$mileage += $data[$y]['mileage']; | |
$message = 'Mileage for ' . $y . ': ' . $data[$y]['mileage'] . ' km'; | |
if ($y == now()->format('Y')) { | |
$message .= ' and counting...'; | |
} | |
$this->info($message); | |
} | |
if(isset($data[$y]['time'])) { | |
$time += $data[$y]['time']; | |
$message = 'Running time for ' . $y . ': ' . $data[$y]['time'] . ' hours'; | |
if ($y == now()->format('Y')) { | |
$message .= ' and counting...'; | |
} | |
$this->info($message); | |
} | |
} | |
$this->info('------------'); | |
$this->info('Total mileage is:' . $mileage . ' km'); | |
$this->info('Total running time is: ' . $time . ' hours'); | |
$this->info('*** Current run streak is: ' . $diff->days . ' days ***'); | |
$this->info('------------'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment