~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to api/src/Module/WebClient.php

  • Committer: jeff Stys
  • Date: 2014-10-15 18:56:44 UTC
  • Revision ID: jstys@sesda3.com-20141015185644-mrgwlk83a3t4ai3z
Added two APIs, updated API docs, added database methods to enable movie re-generation, modified data coverage timeline statistics database table, skip missing JP2 files during JPX generation and log missing filenames, updated flowplayer from version 3.2.8 to version 5.4.6, optimized event marker PNG file sizes.

CREATE TABLE `data_coverage_30_min` (
  `date` datetime NOT NULL,
  `sourceId` int(10) unsigned NOT NULL,
  `count` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`date`,`sourceId`),
  KEY `index1` (`date`),
  KEY `index2` (`sourceId`),
  KEY `index3` (`sourceId`,`date`),
  KEY `index4` (`date`,`sourceId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

Show diffs side-by-side

added added

removed removed

Lines of Context:
368
368
    }
369
369
 
370
370
    /**
371
 
     * Re-generate a screenshot using the metadata stored in the 
 
371
     * Re-generate a screenshot using the metadata stored in the
372
372
     * `screenshots` database table.
373
373
     *
374
374
     * @return
657
657
        include_once 'src/Database/Statistics.php';
658
658
        $statistics = new Database_Statistics();
659
659
 
660
 
/*
661
 
        print_r(
662
 
            array(
663
 
                '_options' => $this->_options
664
 
            )
665
 
        );
666
 
        print_r(
667
 
            array(
668
 
                'interval'  => $interval,
669
 
                'steps'     => $steps,
670
 
                'stepSize'  => $stepSize,
671
 
                'endDate'   => $endDate
672
 
            )
673
 
        );
674
 
*/
675
 
 
676
660
        $this->_printJSON(
677
661
            $statistics->getDataCoverage(
678
662
                $resolution,
687
671
    /**
688
672
     * Retrieves the latest usage statistics from the database
689
673
     */
 
674
    public function getDataCoverageTimeline() {
 
675
 
 
676
        // Define allowed date/time resolutions
 
677
        $validRes = array('5m', '15m', '30m',
 
678
                          '1h',
 
679
                          '1D',
 
680
                          '1W',
 
681
                          '1M', '3M',
 
682
                          '1Y');
 
683
        if ( isset($this->_options['resolution']) && $this->_options['resolution']!='') {
 
684
 
 
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);
 
690
            }
 
691
            $resolution = $this->_options['resolution'];
 
692
        }
 
693
        else {
 
694
            $resolution = '1h';
 
695
        }
 
696
 
 
697
        $magnitude   = intval($resolution);
 
698
        $period_abbr = ltrim($resolution, '0123456789');
 
699
 
 
700
 
 
701
        $date = false;
 
702
        if ( isset($this->_options['endDate']) ) {
 
703
            $formatArr = Array('Y-m-d\TH:i:s\Z',
 
704
                               'Y-m-d\TH:i:s.u\Z',
 
705
                               '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 ) {
 
710
                    break;
 
711
                }
 
712
            }
 
713
        }
 
714
        if ( $date === false ) {
 
715
            $date = new DateTime();
 
716
        }
 
717
 
 
718
 
 
719
        switch ($period_abbr) {
 
720
        case 'm':
 
721
            $steps    = 30;
 
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'));
 
727
            break;
 
728
        case 'h':
 
729
            $steps    = 24;
 
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'));
 
736
            break;
 
737
        case 'D':
 
738
            $steps = 30;
 
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'));
 
744
            break;
 
745
        case 'W':
 
746
            $steps = 36;
 
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'));
 
754
            break;
 
755
        case 'M':
 
756
            $steps = 36;
 
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'));
 
763
            break;
 
764
        case 'Y':
 
765
            $steps = 25;
 
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'));
 
772
            break;
 
773
        default:
 
774
            $msg = 'Invalid resolution specified. Valid options include: '
 
775
                 . implode(', ', $validRes);
 
776
            throw new Exception($msg, 25);
 
777
        }
 
778
 
 
779
        include_once 'src/Database/Statistics.php';
 
780
        $statistics = new Database_Statistics();
 
781
 
 
782
        $this->_printJSON(
 
783
            $statistics->getDataCoverageTimeline(
 
784
                $resolution,
 
785
                $endDate,
 
786
                $interval,
 
787
                $stepSize,
 
788
                $steps
 
789
            )
 
790
        );
 
791
    }
 
792
 
 
793
    /**
 
794
     * Retrieves the latest usage statistics from the database
 
795
     */
690
796
    public function updateDataCoverage() {
691
797
        include_once 'src/Database/Statistics.php';
692
798
        $statistics = new Database_Statistics();
1147
1253
        return true;
1148
1254
    }
1149
1255
}
1150
 
?>
 
 
b'\\ No newline at end of file'
 
1256
?>