Files
fdn2/app/private/bin/convertStats.php
T
2022-09-11 18:16:13 +02:00

96 lines
2.5 KiB
PHP
Executable File

#!/usr/local/bin/php
<?php
/******************************************
* Author : Riccardo Di Dato
* Created On : Tue Aug 30 2022
* File : convertStats.php
*******************************************/
require_once(dirname(__FILE__)."/../load.php");
$iteration = 0;
function getModels() {
global $iteration;
$size = 1000;
$ret = GlobalVariables::get("dao")->query(
StatisticModel::class,
[],
[
'sort' => [
'date' => 1
],
'skip' => $iteration * $size,
'limit' => $size
]
);
$iteration++;
return $ret;
}
$lastCheckedMonth = "";
$lastCheckedDay = "";
$userMonth = [];
$userDay = [];
$models = getModels();
while (sizeof($models)>0) {
foreach ($models as $model) {
$ts = floor( strval($model->date) / 1000) ;
if (date("m", $ts) != $lastCheckedMonth) {
$lastCheckedMonth = date("m", $ts);
$userMonth = [];
}
if (date("d", $ts) != $lastCheckedDay) {
$lastCheckedDay = date("d", $ts);
$userDay = [];
}
if ($model->statType == StatisticModel::STAT_TYPE_NOTIZIA) {
AnalyticsHelper::notiziaImpression(
$model->content,
date("d", $ts),
date("m", $ts),
date("Y", $ts)
);
}
else if ($model->statType == StatisticModel::STAT_TYPE_PAGE) {
AnalyticsHelper::pageImpression(
$model->content->notizia,
date("d", $ts),
date("m", $ts),
date("Y", $ts),
!array_key_exists($model->user->id, $userDay),
!array_key_exists($model->user->id, $userMonth),
$model->user->isNew
);
}
else if ($model->statType == StatisticModel::STAT_TYPE_BANNER_CLICK) {
AnalyticsHelper::bannerClick(
$model->content->banner,
date("d", $ts),
date("m", $ts),
date("Y", $ts)
);
}
else if ($model->statType == StatisticModel::STAT_TYPE_BANNER_IMPRESSION) {
AnalyticsHelper::bannerImpression(
$model->content->banner,
date("d", $ts),
date("m", $ts),
date("Y", $ts)
);
}
$userDay[ $model->user->id ] = 1;
$userMonth[ $model->user->id ] = 1;
}
echo "Completed iteration $iteration", PHP_EOL;
$models = getModels();
}
?>