diff --git a/src/classes/Standardizer/plugins/Facebook/getters/getCommentsStatistics.ts b/src/classes/Standardizer/plugins/Facebook/getters/getCommentsStatistics.ts new file mode 100644 index 00000000..6d57592c --- /dev/null +++ b/src/classes/Standardizer/plugins/Facebook/getters/getCommentsStatistics.ts @@ -0,0 +1,35 @@ +import Facebook from '../Facebook' +import { StatisticType } from '../../../../../types/schemas/Statistic' + +Facebook.prototype.getCommentsStatistics = async function getCommentsStatistics() { + let Nyear = 1 + const commentsData = await this.getComments({ + parsingOptions: { + pagination: { + offset: 0, + items: Infinity, + }, + }, + }) + + if (!commentsData) { + return null + } + commentsData.data.forEach((entry) => { + const end = new Date(new Date().setFullYear(new Date().getFullYear() - Nyear)).getTime() + for (Nyear; entry.creationDate.getTime() < end; Nyear += 1) { + Nyear += 1 + break + } + }) + return { + statistics: [ + { + type: StatisticType.NUMBER, + value: (commentsData.data.length / Nyear), + name: 'comments over Time', + }, + ], + parsedFiles: commentsData?.parsedFiles ?? [], + } +} diff --git a/src/classes/Standardizer/plugins/Reddit/getters/getCommentsStatistics.ts b/src/classes/Standardizer/plugins/Reddit/getters/getCommentsStatistics.ts new file mode 100644 index 00000000..c3dfcc0d --- /dev/null +++ b/src/classes/Standardizer/plugins/Reddit/getters/getCommentsStatistics.ts @@ -0,0 +1,35 @@ +import Reddit from '../Reddit' +import { StatisticType } from '../../../../../types/schemas/Statistic' + +Reddit.prototype.getCommentsStatistics = async function getCommentsStatistics() { + let Nyear = 1 + const commentsData = await this.getComments({ + parsingOptions: { + pagination: { + offset: 0, + items: Infinity, + }, + }, + }) + + if (!commentsData) { + return null + } + commentsData.data.forEach((entry) => { + const end = new Date(new Date().setFullYear(new Date().getFullYear() - Nyear)) + for (Nyear; entry.creationDate < end; Nyear += 1) { + Nyear += 1 + break + } + }) + return { + statistics: [ + { + type: StatisticType.NUMBER, + value: (commentsData.data.length / Nyear), + name: 'comments over Time', + }, + ], + parsedFiles: commentsData?.parsedFiles ?? [], + } +}