Files
fdn2/app/private/bin/convertStats.php
2022-09-23 01:33:08 +02:00

106 lines
2.8 KiB
PHP
Executable File

#!/usr/local/bin/php
<?php
/******************************************
* Author : Riccardo Di Dato
* Created On : Tue Aug 30 2022
* File : convertStats.php
*******************************************/
die();
require_once(dirname(__FILE__)."/../load.php");
$iteration = 0;
function getModels() {
global $iteration;
$size = 1000;
$ret = GlobalVariables::get("dao")->query(
StatisticModel::class,
[
'transfered' => [
'$ne' => true
]
],
[
'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,
date("d", $ts),
date("m", $ts),
date("Y", $ts),
is_null($model->user) || !array_key_exists($model->user->id, $userDay),
is_null($model->user) || !array_key_exists($model->user->id, $userMonth),
is_null($model->user) || $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)
);
}
if (!is_null($model->user)) {
$userDay[ $model->user->id ] = 1;
$userMonth[ $model->user->id ] = 1;
}
$model->transfered = true;
GlobalVariables::get("dao")->save($model);
}
echo "Completed iteration $iteration", PHP_EOL;
$models = getModels();
}
?>