From 8df5782640015a9a8e5833ac454d4221c50ee855 Mon Sep 17 00:00:00 2001 From: Nathan Bonnot Date: Wed, 8 Sep 2021 11:13:27 +0200 Subject: [PATCH 1/3] Statistics Comments --- .../Facebook/getters/getCommentsStatistics.ts | 37 +++++++++++++++++++ .../Reddit/getters/getCommentsStatistics.ts | 37 +++++++++++++++++++ 2 files changed, 74 insertions(+) create mode 100644 src/classes/Standardizer/plugins/Facebook/getters/getCommentsStatistics.ts create mode 100644 src/classes/Standardizer/plugins/Reddit/getters/getCommentsStatistics.ts 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..56484dad --- /dev/null +++ b/src/classes/Standardizer/plugins/Facebook/getters/getCommentsStatistics.ts @@ -0,0 +1,37 @@ +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)) + for (Nyear; entry.creationDate < end; Nyear += 1) { + Nyear += 1 + } + }) + + console.log((commentsData.data.length / Nyear)) + console.log(lastcomments) + 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..f722d64e --- /dev/null +++ b/src/classes/Standardizer/plugins/Reddit/getters/getCommentsStatistics.ts @@ -0,0 +1,37 @@ +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 + } + }) + + console.log((commentsData.data.length / Nyear)) + console.log(lastcomments) + return { + statistics: [ + { + type: StatisticType.NUMBER, + value: (commentsData.data.length / Nyear), + name: 'comments over Time', + }, + ], + parsedFiles: commentsData?.parsedFiles ?? [], + } +} \ No newline at end of file From 9eaaee4a92f14a456a3fa7e92ffad0e98754f72e Mon Sep 17 00:00:00 2001 From: Nathan Bonnot Date: Wed, 8 Sep 2021 14:06:14 +0200 Subject: [PATCH 2/3] fixed infinite loop --- .../plugins/Facebook/getters/getCommentsStatistics.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/classes/Standardizer/plugins/Facebook/getters/getCommentsStatistics.ts b/src/classes/Standardizer/plugins/Facebook/getters/getCommentsStatistics.ts index 56484dad..6d57592c 100644 --- a/src/classes/Standardizer/plugins/Facebook/getters/getCommentsStatistics.ts +++ b/src/classes/Standardizer/plugins/Facebook/getters/getCommentsStatistics.ts @@ -16,14 +16,12 @@ Facebook.prototype.getCommentsStatistics = async function getCommentsStatistics( return null } commentsData.data.forEach((entry) => { - const end = new Date(new Date().setFullYear(new Date().getFullYear() + Nyear)) - for (Nyear; entry.creationDate < end; Nyear += 1) { + const end = new Date(new Date().setFullYear(new Date().getFullYear() - Nyear)).getTime() + for (Nyear; entry.creationDate.getTime() < end; Nyear += 1) { Nyear += 1 + break } }) - - console.log((commentsData.data.length / Nyear)) - console.log(lastcomments) return { statistics: [ { From 9c07111786ae0c624f394d513f3854793bcd4e4b Mon Sep 17 00:00:00 2001 From: Nathan Bonnot Date: Wed, 8 Sep 2021 14:09:15 +0200 Subject: [PATCH 3/3] ... --- .../plugins/Reddit/getters/getCommentsStatistics.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/classes/Standardizer/plugins/Reddit/getters/getCommentsStatistics.ts b/src/classes/Standardizer/plugins/Reddit/getters/getCommentsStatistics.ts index f722d64e..c3dfcc0d 100644 --- a/src/classes/Standardizer/plugins/Reddit/getters/getCommentsStatistics.ts +++ b/src/classes/Standardizer/plugins/Reddit/getters/getCommentsStatistics.ts @@ -16,14 +16,12 @@ Reddit.prototype.getCommentsStatistics = async function getCommentsStatistics() return null } commentsData.data.forEach((entry) => { - const end = new Date(new Date().setFullYear(new Date().getFullYear() + Nyear)) + const end = new Date(new Date().setFullYear(new Date().getFullYear() - Nyear)) for (Nyear; entry.creationDate < end; Nyear += 1) { Nyear += 1 + break } }) - - console.log((commentsData.data.length / Nyear)) - console.log(lastcomments) return { statistics: [ { @@ -34,4 +32,4 @@ Reddit.prototype.getCommentsStatistics = async function getCommentsStatistics() ], parsedFiles: commentsData?.parsedFiles ?? [], } -} \ No newline at end of file +}