2018-10-24 10:43:30 +02:00
|
|
|
const db = require('server/models');
|
|
|
|
const {
|
|
|
|
getInformationFromValues,
|
|
|
|
getZScore,
|
|
|
|
getFastPValue,
|
|
|
|
getWeight,
|
|
|
|
} = require('server/models/utils/trendingAnalysis');
|
|
|
|
|
2018-10-25 20:52:27 +02:00
|
|
|
const logger = require('winston');
|
2018-10-24 10:43:30 +02:00
|
|
|
|
2018-10-25 20:52:27 +02:00
|
|
|
module.exports = async () => {
|
|
|
|
try {
|
|
|
|
const claims = await db.Trending.getTrendingClaims();
|
|
|
|
const claimViews = await db.Views.getUniqueViews();
|
2018-10-24 10:43:30 +02:00
|
|
|
|
2018-11-11 01:11:12 +01:00
|
|
|
if (claimViews.length <= 1) {
|
2018-10-25 20:52:27 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-10-24 10:43:30 +02:00
|
|
|
|
2018-10-25 20:52:27 +02:00
|
|
|
const time = Date.now();
|
2018-10-24 10:43:30 +02:00
|
|
|
|
2018-10-25 20:52:27 +02:00
|
|
|
// Must create statistical analytics before we can process zScores, etc
|
|
|
|
const viewsNumArray = claimViews.map((claimViewsEntry) => claimViewsEntry.views);
|
2018-10-24 10:43:30 +02:00
|
|
|
const {
|
2018-10-25 20:52:27 +02:00
|
|
|
mean,
|
|
|
|
standardDeviation,
|
|
|
|
} = getInformationFromValues(viewsNumArray);
|
|
|
|
|
2018-11-11 01:11:12 +01:00
|
|
|
for (let i = 0; i < claimViews.length; i++) {
|
2018-10-25 20:52:27 +02:00
|
|
|
let claimViewsEntry = claimViews[i];
|
|
|
|
|
|
|
|
const {
|
|
|
|
isChannel,
|
|
|
|
claimId,
|
|
|
|
publisherId,
|
|
|
|
} = claimViewsEntry;
|
|
|
|
|
|
|
|
const zScore = getZScore(claimViewsEntry.views, mean, standardDeviation);
|
|
|
|
const pValue = getFastPValue(zScore);
|
|
|
|
const weight = getWeight(zScore, pValue);
|
|
|
|
|
|
|
|
const trendingData = {
|
|
|
|
time,
|
2018-11-11 01:11:12 +01:00
|
|
|
isChannel : claimViewsEntry.isChannel,
|
|
|
|
claimId : claimViewsEntry.claimId,
|
|
|
|
publisherId : claimViewsEntry.publisherId,
|
2018-10-25 20:52:27 +02:00
|
|
|
intervalViews: claimViewsEntry.views,
|
|
|
|
weight,
|
|
|
|
zScore,
|
|
|
|
pValue,
|
|
|
|
};
|
|
|
|
|
|
|
|
db.Trending.create(trendingData);
|
|
|
|
}
|
2018-11-11 01:11:12 +01:00
|
|
|
} catch (e) {
|
2018-10-25 20:52:27 +02:00
|
|
|
logger.error('Error processing trending content:', e);
|
2018-10-24 10:43:30 +02:00
|
|
|
}
|
2018-11-11 01:11:12 +01:00
|
|
|
};
|