Page MenuHomec4science

min.php
No OneTemporary

File Metadata

Created
Fri, Nov 22, 01:21
<?php
function secondsToTime($seconds) {
$dtF = new DateTime('@0');
$dtT = new DateTime("@$seconds");
if($seconds < 60) {
$format = '%ss';
} elseif($seconds < 60*60) {
$format = '%imn %ss';
} elseif($seconds < 24*60*60) {
$format = '%hh %imn %ss';
} else {
$format = '%ad %hh %imn %ss';
}
return $dtF->diff($dtT)->format($format);
}
function csv(...$args) {
global $csv;
if($csv) {
echo implode(',', $args) . "\n";
}
}
function debug($txt, $short=0) {
global $debug;
if($debug && !$short) {
echo "$txt\n";
}
}
function test(
$minimum,
$last_commit,
$error_count,
$last_few_days,
$longest_wait) {
global $short;
debug("minimum=$minimum");
debug("last_commit=" . secondsToTime($last_commit));
if ($error_count > 0) {
debug("error_count=$error_count");
$smart_wait = (int)($minimum * $error_count);
debug('smart_wait=' . secondsToTime($smart_wait));
debug("---");
csv($minimum,
$last_commit,
$error_count,
$last_few_days,
$longest_wait,
(int)$smart_wait);
return;
}
$window_start = time() + $minimum;
$last_commit = time() - $last_commit;
if ($last_commit) {
$time_since_commit = ($window_start - $last_commit);
} else {
$time_since_commit = ($window_start - time() - (60*60*24*7)); // creation date
}
debug("time_since_commit=" . secondsToTime($time_since_commit));
debug("last_few_days=" . secondsToTime($last_few_days));
debug("longest_wait=" . secondsToTime($longest_wait));
if ($time_since_commit <= $last_few_days) {
debug("last commit less than 3 days", $short);
$smart_wait = ($time_since_commit / 600);
} else {
debug("last commit more than 3 days", $short);
$smart_wait = ($time_since_commit / 240);
}
debug("min($smart_wait, $longest_wait)", $short);
$smart_wait = min($smart_wait, $longest_wait);
debug("max($minimum, $smart_wait)", $short);
$smart_wait = max($minimum, $smart_wait);
debug("smart_wait=". secondsToTime((int)$smart_wait));
debug("---");
csv($minimum,
$last_commit,
$error_count,
$last_few_days,
$longest_wait,
(int)$smart_wait);
}
$debug = 1;
$short = 1;
$csv = 0;
csv('minimum',
'last_commit',
'error_count',
'last_few_days',
'longest_wait',
'smart_wait');
foreach(array(1, 15) as $minimum) {
foreach(array(60*60*24, 60*60*24*30) as $last_commit) {
test(
$minimum,
$last_commit,
0,
60*60*24*3,
60*60*6);
}
}
//foreach(array(1, 15) as $minimum) {
// foreach(array(60, 60*60, 60*60*24, 60*60*24*7, 60*60*24*30) as $last_commit) {
// foreach(array(60*60*24*3, 60*60*24) as $last_few_days) {
// foreach(array(60*60*6, 60*60*12, 60*60*24) as $longest_wait) {
// test(
// $minimum,
// $last_commit,
// 0,
// $last_few_days,
// $longest_wait);
// }
// }
// }
//}
//
//foreach(array(1, 15) as $minimum) {
// foreach(array(1, 100) as $error_count) {
// test(
// $minimum, 10,
// $error_count, 10, 10);
// }
//}

Event Timeline