Ejemplo n.º 1
0
	function getTemperaturesEvolution($date, $period)
	{
		$period = new Piwik_Period_Range($period, 'last30');
		$dateStart = $period->getDateStart()->get('Y-m-d'); // eg. "2009-04-01"
		$dateEnd = $period->getDateEnd()->get('Y-m-d'); // eg. "2009-04-30"
		
		// here you could select from your custom table in the database, eg.
		$query = "SELECT AVG(temperature)
					FROM server_temperatures
					WHERE date > ?
						AND date < ?
					GROUP BY date
					ORDER BY date ASC";
		//$result = Piwik_FetchAll($query, array($dateStart, $dateEnd));
		// to keep things simple, we generate the data
		foreach($period->getSubperiods() as $subPeriod)
		{
			$server1 = rand(50,90);
			$server2 = rand(40, 110);
			$value = array('server1' => $server1, 'server2' => $server2);
			$temperatures[$subPeriod->getLocalizedShortString()] = $value;
		}
		
		// convert this array to a DataTable object
		$dataTable = new Piwik_DataTable();
		$dataTable->addRowsFromArrayWithIndexLabel($temperatures);
		return $dataTable;
	}
Ejemplo n.º 2
0
 /**
  * Builds an array of Piwik_Archive of a given date range
  *
  * @param Piwik_Site $oSite 
  * @param string $strPeriod eg. 'day' 'week' etc.
  * @param string $strDate A date range, eg. 'last10', 'previous5' or 'YYYY-MM-DD,YYYY-MM-DD'
  */
 function __construct(Piwik_Site $oSite, $strPeriod, $strDate, Piwik_Segment $segment)
 {
     $rangePeriod = new Piwik_Period_Range($strPeriod, $strDate, $oSite->getTimezone());
     foreach ($rangePeriod->getSubperiods() as $subPeriod) {
         $startDate = $subPeriod->getDateStart();
         $archive = Piwik_Archive::build($oSite->getId(), $strPeriod, $startDate, $segment->getString());
         $archive->setSegment($segment);
         $this->archives[] = $archive;
     }
 }
Ejemplo n.º 3
0
 /**
  * Builds an array of Piwik_Archive of a given date range
  *
  * @param Piwik_Site $oSite 
  * @param string $strPeriod eg. 'day' 'week' etc.
  * @param string $strDate A date range, eg. 'last10', 'previous5' or 'YYYY-MM-DD,YYYY-MM-DD'
  */
 function __construct(Piwik_Site $oSite, $strPeriod, $strDate)
 {
     $rangePeriod = new Piwik_Period_Range($strPeriod, $strDate);
     foreach ($rangePeriod->getSubperiods() as $subPeriod) {
         $startDate = $subPeriod->getDateStart();
         $archive = Piwik_Archive::build($oSite->getId(), $strPeriod, $startDate);
         $archive->prepareArchive();
         $timestamp = $archive->getTimestampStartDate();
         $this->archives[$timestamp] = $archive;
     }
     ksort($this->archives);
 }
Ejemplo n.º 4
0
 /**
  * Builds an array of Piwik_Archive of a given date range
  *
  * @param Piwik_Site $oSite 
  * @param string $strPeriod eg. 'day' 'week' etc.
  * @param string $strDate A date range, eg. 'last10', 'previous5' or 'YYYY-MM-DD,YYYY-MM-DD'
  */
 function __construct(Piwik_Site $oSite, $strPeriod, $strDate)
 {
     $rangePeriod = new Piwik_Period_Range($strPeriod, $strDate);
     // TODO fix this when aggregating data from multiple websites
     // CAREFUL this class wouldnt work as is if handling archives from multiple websites
     // works only when managing archives from multiples dates/periods
     foreach ($rangePeriod->getSubperiods() as $subPeriod) {
         $startDate = $subPeriod->getDateStart();
         $archive = Piwik_Archive::build($oSite->getId(), $strPeriod, $startDate);
         $archive->prepareArchive();
         $timestamp = $archive->getTimestampStartDate();
         $this->archives[$timestamp] = $archive;
     }
     ksort($this->archives);
 }
Ejemplo n.º 5
0
 /**
  * Based on the period, date and evolution_{$period}_last_n query parameters,
  * calculates the date range this evolution chart will display data for.
  */
 private function calculateEvolutionDateRange()
 {
     $period = Piwik_Common::getRequestVar('period');
     $defaultLastN = self::getDefaultLastN($period);
     $this->originalDate = Piwik_Common::getRequestVar('date', 'last' . $defaultLastN, 'string');
     if ($period != 'range') {
         $this->alwaysShowLimitDropdown();
         // set the evolution_{$period}_last_n query param
         if (Piwik_Period_Range::parseDateRange($this->originalDate)) {
             // overwrite last_n param using the date range
             $oPeriod = new Piwik_Period_Range($period, $this->originalDate);
             $lastN = count($oPeriod->getSubperiods());
         } else {
             list($newDate, $lastN) = self::getDateRangeAndLastN($period, $this->originalDate, $defaultLastN);
             $this->setParametersToModify(array('date' => $newDate));
         }
         $lastNParamName = self::getLastNParamName($period);
         $this->setParametersToModify(array($lastNParamName => $lastN));
     }
 }