function formatPercent($subset, $total, $revert = false, $accuracy = 2) { MediaWiki\suppressWarnings(); $v = round(255 * $subset / $total); MediaWiki\restoreWarnings(); if ($revert) { # Weigh reverse with factor 20 so coloring takes effect more quickly as # this option is used solely for reporting 'bad' percentages. $v = $v * 20; if ($v > 255) { $v = 255; } $v = 255 - $v; } if ($v < 128) { # Red to Yellow $red = 'FF'; $green = sprintf('%02X', 2 * $v); } else { # Yellow to Green $red = sprintf('%02X', 2 * (255 - $v)); $green = 'FF'; } $blue = '00'; $color = $red . $green . $blue; $percent = parent::formatPercent($subset, $total, $revert, $accuracy); return 'style="background-color:#' . $color . ';"|' . $percent; }
<?php namespace JimmyDBurrell\DOBStats; require_once '../db.php'; require_once './vendor/autoload.php'; date_default_timezone_set('America/Chicago'); $dsn = "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME; $pdo = new \PDO($dsn, DB_USER, DB_PASS); $beginDateTime = new \DateTime(date('Y-m-d', strtotime('-4 days'))); $beginDate = $beginDateTime->format('Y-m-d'); $sql = 'SELECT id,dob,created_at FROM app where id_customer = 24 order by id desc limit 2500'; $stmt = $pdo->prepare($sql, [\PDO::ATTR_CURSOR => \PDO::CURSOR_SCROLL]); $stmt->execute(); $data = new DbRowIterator($stmt); echo 'Getting the age and date-of-birth for drivers who applied after ' . $beginDate . "<br />" . PHP_EOL; $lastPeriod = new LastPeriodIterator($data, $beginDate); $ageTalley = new TalleyAge(); foreach ($lastPeriod as $pos => $row) { if ($row->dob > "") { $dateDiff = new DateDiff($row->dob); $age = $dateDiff->diffInYears(); $ageTalley->countAndCategorize($age); } else { unset($age); } } // end foreach ($lastPeriod as $row) echo "Finished processing {$pos} driver records.<br />" . PHP_EOL; $output = new StatsOutput(); $output->cliOutput($ageTalley);