Skip to content

Instantly share code, notes, and snippets.

@pfrenssen
Last active September 27, 2018 07:45
Show Gist options
  • Save pfrenssen/0325239897a704a1bbdd950e97fb6164 to your computer and use it in GitHub Desktop.
Save pfrenssen/0325239897a704a1bbdd950e97fb6164 to your computer and use it in GitHub Desktop.
Work on Joinup or OpenEuropa?
#!/usr/bin/env php
<?php
const JOINUP_RATIO = 0.667;
$times = [];
foreach (['Joinup', 'NextEuropa', 'OpenEuropa'] as $project) {
do {
$time = readline("Time spent on $project: ");
} while (!is_numeric($time));
$times[$project] = $time;
}
do {
$work_days = readline("Total number of work days this month: ");
} while (!is_numeric($work_days));
$total_time = array_sum($times);
$month_time = $work_days * 8;
$times['OpenEuropa'] = $total_time - $times['Joinup'];
$ratio = $times['Joinup'] / $total_time;
$project = $ratio < JOINUP_RATIO ? 'Joinup' : 'OpenEuropa';
$target_total_time = $project === 'OpenEuropa' ? $times['Joinup'] * 1 / JOINUP_RATIO : $times['OpenEuropa'] * 1 / (1 - JOINUP_RATIO);
$remaining_time = $project === 'OpenEuropa' ? (1 - JOINUP_RATIO) * $target_total_time - $times['OpenEuropa'] : JOINUP_RATIO * $target_total_time - $times['Joinup'];
$remaining_hours = floor($remaining_time);
$remaining_minutes = floor(fmod($remaining_time, 1) * 60);
print "Work on $project for $remaining_hours hours $remaining_minutes minutes.\n";
// Calculate the total remaining time this month.
$total_remaining = $month_time - $total_time;
foreach (['Joinup', 'OpenEuropa'] as $project) {
$ratio = $project === 'Joinup' ? JOINUP_RATIO : 1 - JOINUP_RATIO;
$total_project_time = $month_time * $ratio;
$remaining_project_time = $total_project_time - $times[$project];
$remaining_project_hours = floor($remaining_project_time);
$remaining_project_minutes = floor(fmod($remaining_project_time, 1) * 60);
print "Remaining time for $project this month: $remaining_project_hours hours $remaining_project_minutes minutes.\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment