#4 - Conversione vecchi dati

This commit is contained in:
2022-09-11 10:16:29 +02:00
parent 051a6a8db2
commit b465e7ef43
3 changed files with 64 additions and 6 deletions
Regular → Executable
+40 -5
View File
@@ -1,4 +1,4 @@
#!/usr/bin/php
#!/usr/local/bin/php
<?php
/******************************************
* Author : Riccardo Di Dato
@@ -8,8 +8,10 @@
require_once(dirname(__FILE__)."/../load.php");
$iteration = 0;
function getModels() {
static $iteration = 0;
global $iteration;
$size = 1000;
$ret = GlobalVariables::get("dao")->query(
@@ -24,14 +26,47 @@ function getModels() {
return $ret;
}
exit;
// WIP
$models = getModels();
while (sizeof($models)>0) {
foreach ($models as $model) {
$ts = floor( strval($model->date) / 1000) ;
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),
$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)
);
}
}
echo "Completed iteration $iteration", PHP_EOL;
$models = getModels();
}
@@ -14,6 +14,21 @@ class PageViewStatsModel extends Model {
public static function getCollectionName(){
return "pageview_stats";
}
public static function new($page, $day, $month, $year) {
$time = strtotime("$year-$month-$day CET");
return new static(
(object)[
'page' => $page,
'y' => intval($year),
'm' => intval($month),
'd' => intval($day),
'time' => new MongoDB\BSON\UTCDateTime( $time * 1000 ),
'views' => 0,
'unique' => 0
]
);
}
public static function getFilter($page, $day, $month, $year) {
$time = strtotime("$year-$month-$day CET");
+8
View File
@@ -30,3 +30,11 @@ db.statistics.createIndex({"stat.type":1,"content.position":1})
db.notizia.ensureIndex({"about.author": "text",sottotitolo: "text",testo: "text",titolo: "text"},{weights: {"about.author": 1,sottotitolo: 7,testo: 5,titolo: 10},name: "notiziaDetails"})
db.article_stats.ensureIndex({ "notizia": 1, "time": 1, "deleted": 1 }, {name: "quick_upsert"})
db.banner_stats.ensureIndex({ "banner": 1, "time": 1, "deleted": 1 }, {name: "quick_upsert"})
db.pageview_stats.ensureIndex({ "deleted": 1, "time": 1, "page": 1 }, {name: "quick_upsert"})