688
672
* Retrieves the latest usage statistics from the database
674
public function getDataCoverageTimeline() {
676
// Define allowed date/time resolutions
677
$validRes = array('5m', '15m', '30m',
683
if ( isset($this->_options['resolution']) && $this->_options['resolution']!='') {
685
// Make sure a valid resolution was specified
686
if ( !in_array($this->_options['resolution'], $validRes) ) {
687
$msg = 'Invalid resolution specified. Valid options include: '
688
. implode(', ', $validRes);
689
throw new Exception($msg, 25);
691
$resolution = $this->_options['resolution'];
697
$magnitude = intval($resolution);
698
$period_abbr = ltrim($resolution, '0123456789');
702
if ( isset($this->_options['endDate']) ) {
703
$formatArr = Array('Y-m-d\TH:i:s\Z',
706
foreach ( $formatArr as $fmt ) {
707
$date = DateTime::createFromFormat(
708
$fmt, $this->_options['endDate'] );
709
if ( $date !== false ) {
714
if ( $date === false ) {
715
$date = new DateTime();
719
switch ($period_abbr) {
722
$stepSize = new DateInterval('PT'.($magnitude).'M');
723
$interval = new DateInterval('PT'.($magnitude*$steps).'M');
724
$endDate = clone $date;
725
$endDate->setTime(date_format($date,'H'), 59, 59);
726
$endDate->add(new DateInterval('PT1S'));
730
$stepSize = new DateInterval('PT'.($magnitude).'H');
731
$interval = new DateInterval('PT'.($magnitude*$steps).'H');
732
$date->setTime(date_format($date,'H'), 59, 59);
733
$endDate = clone $date;
734
$endDate->setTime(date_format($date,'H'), 59, 59);
735
$endDate->add(new DateInterval('PT1S'));
739
$stepSize = new DateInterval('P'.($magnitude).'D');
740
$interval = new DateInterval('P'.($magnitude*$steps).'D');
741
$endDate = clone $date;
742
$endDate->setTime(23, 59, 59);
743
$endDate->add(new DateInterval('PT1S'));
747
$stepSize = new DateInterval('P'.($magnitude).'W');
748
$interval = new DateInterval('P'.($magnitude*$steps).'W');
749
$endDate = clone $date;
750
$endDate->modify('first day of this week');
751
$endDate->add(new DateInterval('P2W'));
752
$endDate->setTime(23, 59, 59);
753
$endDate->add(new DateInterval('PT1S'));
757
$stepSize = new DateInterval('P'.($magnitude).'M');
758
$interval = new DateInterval('P'.($magnitude*$steps).'M');
759
$endDate = clone $date;
760
$endDate->modify('last day of this month');
761
$endDate->setTime(23, 59, 59);
762
$endDate->add(new DateInterval('PT1S'));
766
$stepSize = new DateInterval('P'.($magnitude).'Y');
767
$interval = new DateInterval('P'.($magnitude*$steps).'Y');
768
$endDate = clone $date;
769
$endDate->setDate(date_format($date,'Y'), 12, 31);
770
$endDate->setTime(23, 59, 59);
771
$endDate->add(new DateInterval('PT1S'));
774
$msg = 'Invalid resolution specified. Valid options include: '
775
. implode(', ', $validRes);
776
throw new Exception($msg, 25);
779
include_once 'src/Database/Statistics.php';
780
$statistics = new Database_Statistics();
783
$statistics->getDataCoverageTimeline(
794
* Retrieves the latest usage statistics from the database
690
796
public function updateDataCoverage() {
691
797
include_once 'src/Database/Statistics.php';
692
798
$statistics = new Database_Statistics();