|
|
@@ -38,22 +38,23 @@ export class StatsHourlyAggregationService {
|
|
|
{
|
|
|
$project: {
|
|
|
adsId: { $toString: '$adsId' },
|
|
|
- // Convert seconds -> Date(ms), truncate to hour in GMT+8, convert back to seconds
|
|
|
hourStartAt: {
|
|
|
- $toLong: {
|
|
|
- $divide: [
|
|
|
- {
|
|
|
- $toLong: {
|
|
|
- $dateTrunc: {
|
|
|
- date: { $toDate: { $multiply: ['$clickedAt', 1000] } },
|
|
|
- unit: 'hour',
|
|
|
- timezone: '+08:00',
|
|
|
+ $subtract: [
|
|
|
+ {
|
|
|
+ $multiply: [
|
|
|
+ {
|
|
|
+ $floor: {
|
|
|
+ $divide: [
|
|
|
+ { $add: [{ $toLong: '$clickedAt' }, 28800] },
|
|
|
+ 3600,
|
|
|
+ ],
|
|
|
},
|
|
|
},
|
|
|
- },
|
|
|
- 1000,
|
|
|
- ],
|
|
|
- },
|
|
|
+ 3600,
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ 28800,
|
|
|
+ ],
|
|
|
},
|
|
|
},
|
|
|
},
|
|
|
@@ -127,20 +128,22 @@ export class StatsHourlyAggregationService {
|
|
|
channelId: 1,
|
|
|
uid: 1,
|
|
|
hourStartAt: {
|
|
|
- $toLong: {
|
|
|
- $divide: [
|
|
|
- {
|
|
|
- $toLong: {
|
|
|
- $dateTrunc: {
|
|
|
- date: { $toDate: { $multiply: ['$createAt', 1000] } },
|
|
|
- unit: 'hour',
|
|
|
- timezone: '+08:00',
|
|
|
+ $subtract: [
|
|
|
+ {
|
|
|
+ $multiply: [
|
|
|
+ {
|
|
|
+ $floor: {
|
|
|
+ $divide: [
|
|
|
+ { $add: [{ $toLong: '$createAt' }, 28800] },
|
|
|
+ 3600,
|
|
|
+ ],
|
|
|
},
|
|
|
},
|
|
|
- },
|
|
|
- 1000,
|
|
|
- ],
|
|
|
- },
|
|
|
+ 3600,
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ 28800,
|
|
|
+ ],
|
|
|
},
|
|
|
},
|
|
|
},
|