/** * Another example method that returns a data table. * @param int $idSite * @param string $period * @param string $date * @param bool|string $segment * @return DataTable */ public function getAgencyInformation($idSite, $period, $date, $segment = false) { $dataTable = Archive::getDataTableFromArchive('ClientCertificates_GetAgencyInformation', $idSite, $period, $date, $segment, false); $dataTable->queueFilter(function (DataTable $table) use($idSite, $period, $date, $segment) { // Set new summed unique users column into daily unique users column so they can be displayed in the same column // when viewing a date range and not just a single day. $visitsSummary = VisitsSummaryAPI::getInstance(); foreach ($table->getRows() as $visitRow) { $agency = $visitRow->getColumn('label'); $segmentString = 'agency==' . $agency; if ($segment) { $segmentString .= ';' . $segment; } $newSegment = new Segment($segmentString, $idSite); $data = $visitsSummary->getUniqueVisitors($idSite, $period, $date, $newSegment); $data->queueFilter(function (DataTable $uniqueTable) use($visitRow, $agency) { $rows = $uniqueTable->getRows(); $uniqueVisitors = $rows[0]->getColumn('nb_uniq_visitors'); $visitRow->setColumn(\Piwik\Metrics::INDEX_NB_USERS, $uniqueVisitors); }); $data->applyQueuedFilters(); } }); $dataTable->queueFilter('ReplaceColumnNames'); $dataTable->queueFilter('ReplaceSummaryRowLabel'); return $dataTable; }
protected function prefixColumns($table, $period) { $rename = array(); foreach (APIVisitsSummary::getInstance()->getColumns($period) as $oldColumn) { $rename[$oldColumn] = $oldColumn . self::COLUMN_SUFFIX; } $table->filter('ReplaceColumnNames', array($rename)); }
public function setUp() { $archivingTables = ArchiveTableCreator::getTablesArchivesInstalled(); if (empty($archivingTables)) { $this->archivingLaunched = true; APIVisitsSummary::getInstance()->get(self::$fixture->idSite, self::$fixture->period, self::$fixture->date); } }
public static function setUpBeforeClass() { parent::setUpBeforeClass(); // make sure archiving is initiated so there is data in the archive tables VisitsSummaryAPI::getInstance()->get(self::$fixture->idSite, 'month', '2010-03-01'); VisitsSummaryAPI::getInstance()->get(self::$fixture->idSite, 'month', '2010-03-01', 'browserCode==FF'); VisitsSummaryAPI::getInstance()->get(self::$fixture->idSite, 'month', '2010-03-01', 'daysSinceFirstVisit==2'); }
public function getTotalValue($idSite, $period, $date, $metric, $segment) { $visits = VisitsSummaryAPI::getInstance()->get($idSite, $period, $date, $segment); $firstRow = $visits->getFirstRow(); if (empty($firstRow)) { return 0; } $totalValue = $firstRow->getColumn($metric); return (int) $totalValue; }
/** * @group Benchmarks */ public function testArchivingProcess() { if ($this->archivingLaunched) { echo "NOTE: Had to archive data, memory results will not be accurate. Run again for better results."; } Rules::$archivingDisabledByTests = true; $period = Period\Factory::build(self::$fixture->period, Date::factory(self::$fixture->date)); $dateRange = $period->getDateStart() . ',' . $period->getDateEnd(); API::getInstance()->get(self::$fixture->idSite, 'day', $dateRange); }
public function setUp() { foreach ($this->fixtures as $fixture) { $fixture->setUp(); } Option::set("Tests.forcedNowTimestamp", $this->now->getTimestamp()); // launch archiving so tests don't run out of time $date = Date::factory($this->dateTime)->toString(); VisitsSummaryAPI::getInstance()->get($this->idSite, 'year', $date); VisitsSummaryAPI::getInstance()->get($this->idSite, 'year', $date, urlencode($this->segment)); }
public function setUp() { parent::setUp(); // make sure site has an early enough creation date (for period selector tests) Db::get()->update(Common::prefixTable("site"), array('ts_created' => '2011-01-01'), "idsite = 1"); $this->addOverlayVisits(); $this->addNewSitesForSiteSelector(); DbHelper::createAnonymousUser(); UsersManagerAPI::getInstance()->setSuperUserAccess('superUserLogin', true); Option::set("Tests.forcedNowTimestamp", $this->now->getTimestamp()); // launch archiving so tests don't run out of time $date = Date::factory($this->dateTime)->toString(); VisitsSummaryAPI::getInstance()->get($this->idSite, 'year', $date); VisitsSummaryAPI::getInstance()->get($this->idSite, 'year', $date, urlencode($this->segment)); }
public function test_getIdSitesToArchiveWhenNoVisits_CanBeUsedToTriggerArchiving_EvenIfSiteHasNoVisits() { // add our mock archiver instance // TODO: should use a dummy plugin that is activated for this test explicitly, but that can be tricky, especially in the future PluginsArchiver::$archivers['VisitsSummary'] = 'Piwik\\Tests\\Integration\\ArchiveWithNoVisitsTest_MockArchiver'; // initiate archiving w/o adding the event and make sure no methods are called VisitsSummaryAPI::getInstance()->get($idSite = 1, 'week', '2012-01-01'); $this->assertEmpty(ArchiveWithNoVisitsTest_MockArchiver::$methodsCalled); // mark our only site as should archive when no visits $eventDispatcher = $this->getEventDispatcher(); $eventDispatcher->addObserver('Archiving.getIdSitesToArchiveWhenNoVisits', function (&$idSites) { $idSites[] = 1; }); Cache::getTransientCache()->flushAll(); // initiate archiving and make sure both aggregate methods are called correctly VisitsSummaryAPI::getInstance()->get($idSite = 1, 'week', '2012-01-10'); $expectedMethodCalls = array('aggregateDayReport', 'aggregateDayReport', 'aggregateDayReport', 'aggregateDayReport', 'aggregateDayReport', 'aggregateDayReport', 'aggregateDayReport', 'aggregateMultipleReports'); $this->assertEquals($expectedMethodCalls, ArchiveWithNoVisitsTest_MockArchiver::$methodsCalled); }
public function setUp() { self::downloadGeoIpDbs(); parent::setUp(); self::updateDatabase(); // make sure site has an early enough creation date (for period selector tests) Db::get()->update(Common::prefixTable("site"), array('ts_created' => '2011-01-01'), "idsite = 1"); // for proper geolocation LocationProvider::setCurrentProvider(LocationProvider\GeoIp\Php::ID); IPAnonymizer::deactivate(); $this->addOverlayVisits(); $this->addNewSitesForSiteSelector(); DbHelper::createAnonymousUser(); UsersManagerAPI::getInstance()->setSuperUserAccess('superUserLogin', true); SitesManagerAPI::getInstance()->updateSite(1, null, null, true); // create non super user UsersManagerAPI::getInstance()->addUser('oliverqueen', 'smartypants', '*****@*****.**'); UsersManagerAPI::getInstance()->setUserAccess('oliverqueen', 'view', array(1)); // launch archiving so UI test requests don't launch it VisitsSummaryAPI::getInstance()->get('all', 'year', '2012-08-09'); }
public function performSetUp($setupEnvironmentOnly = false) { $this->extraTestEnvVars = array('loadRealTranslations' => 1); parent::performSetUp($setupEnvironmentOnly); $this->createSegments(); $this->setupDashboards(); $visitorIdDeterministic = bin2hex(Db::fetchOne("SELECT idvisitor FROM " . Common::prefixTable('log_visit') . " WHERE idsite = 2 AND location_latitude IS NOT NULL LIMIT 1")); $this->testEnvironment->forcedIdVisitor = $visitorIdDeterministic; $this->testEnvironment->overlayUrl = $this->getLocalTestSiteUrl(); $this->createOverlayTestSite(); $forcedNowTimestamp = Option::get("Tests.forcedNowTimestamp"); if ($forcedNowTimestamp == false) { throw new Exception("Incorrect fixture setup, Tests.forcedNowTimestamp option does not exist! Run the setup again."); } $this->testEnvironment->forcedNowTimestamp = $forcedNowTimestamp; $this->testEnvironment->save(); // launch archiving so tests don't run out of time print "Archiving in fixture set up..."; VisitsSummaryAPI::getInstance()->get('all', 'year', '2012-08-09'); VisitsSummaryAPI::getInstance()->get('all', 'year', '2012-08-09', urlencode(OmniFixture::DEFAULT_SEGMENT)); print "Done."; }
private function isUsedInSite($idSite, $period, $date) { $result = VisitsSummaryApi::getInstance()->get($idSite, $period, $date, false, 'nb_users'); return $this->hasDataTableUsers($result); }
/** * @group Benchmarks */ public function testArchivingProcess() { API::getInstance()->get(self::$fixture->idSite, self::$fixture->period, self::$fixture->date); }