From b465e7ef4380dbbe88f6915151b20c5a85a925ff Mon Sep 17 00:00:00 2001 From: Riccardo Di Dato Date: Sun, 11 Sep 2022 10:16:29 +0200 Subject: [PATCH] #4 - Conversione vecchi dati --- app/private/bin/convertStats.php | 45 ++++++++++++++++--- .../dao/models/stats/PageViewStatsModel.php | 15 +++++++ docs/tech/install.memo | 10 ++++- 3 files changed, 64 insertions(+), 6 deletions(-) mode change 100644 => 100755 app/private/bin/convertStats.php diff --git a/app/private/bin/convertStats.php b/app/private/bin/convertStats.php old mode 100644 new mode 100755 index 430a809..740e5c7 --- a/app/private/bin/convertStats.php +++ b/app/private/bin/convertStats.php @@ -1,4 +1,4 @@ -#!/usr/bin/php +#!/usr/local/bin/php 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(); } diff --git a/app/private/lib/dao/models/stats/PageViewStatsModel.php b/app/private/lib/dao/models/stats/PageViewStatsModel.php index 34a9716..60e7eb2 100644 --- a/app/private/lib/dao/models/stats/PageViewStatsModel.php +++ b/app/private/lib/dao/models/stats/PageViewStatsModel.php @@ -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"); diff --git a/docs/tech/install.memo b/docs/tech/install.memo index 34920ed..7ebb48e 100644 --- a/docs/tech/install.memo +++ b/docs/tech/install.memo @@ -29,4 +29,12 @@ db.statistics.createIndex({"user.id":1}) 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"}) \ No newline at end of file +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"})