From ff5b7792998244ca7fdf54960404d3ec167384e7 Mon Sep 17 00:00:00 2001 From: Mauricio Munoz Date: Tue, 16 Apr 2024 17:30:22 -0700 Subject: [PATCH 1/3] Changing functions to arrow function --- backend/src/rating/ranking.ts | 51 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 27 deletions(-) diff --git a/backend/src/rating/ranking.ts b/backend/src/rating/ranking.ts index 0e5d319..fd5d855 100644 --- a/backend/src/rating/ranking.ts +++ b/backend/src/rating/ranking.ts @@ -34,7 +34,7 @@ export const WEIGHTS = { weight6: 0, }; -export const getExternalRanking = (videos: youtube_v3.Schema$Video[]) => { +export function getExternalRanking(videos: youtube_v3.Schema$Video[]) { const rawExternalScoreVideos = getRawExternalRanking(videos); const maxScores = getMaxScores(rawExternalScoreVideos); const normalizedExternalScoreVideos = getNormalizedExternalRanking( @@ -42,11 +42,11 @@ export const getExternalRanking = (videos: youtube_v3.Schema$Video[]) => { maxScores ); return getWeightedExternalRanking(normalizedExternalScoreVideos); -}; +} -export const getRawExternalRanking = ( +export function getRawExternalRanking( videos: youtube_v3.Schema$Video[] -): IRawYoutubeVideo[] => { +): IRawYoutubeVideo[] { return videos.map((video) => { const daysSincePublished = getDaysSincePublished(video.snippet.publishedAt); const yearsSincePublished = daysSincePublished / 365; @@ -72,12 +72,12 @@ export const getRawExternalRanking = ( }, }; }); -}; +} -export const getNormalizedExternalRanking = ( +export function getNormalizedExternalRanking( videos: IRawYoutubeVideo[], maxScores: IMaxScores -): INormalizedYoutubeVideo[] => { +): INormalizedYoutubeVideo[] { return videos.map((video) => { return { ...video, @@ -97,11 +97,11 @@ export const getNormalizedExternalRanking = ( }, }; }); -}; +} -export const getWeightedExternalRanking = ( +export function getWeightedExternalRanking( videos: INormalizedYoutubeVideo[] -): IWeightedYoutubeVideo[] => { +): IWeightedYoutubeVideo[] { return videos.map((video) => { const weighted_score = { date: video.normalized_score.date * WEIGHTS.weight1, @@ -121,11 +121,11 @@ export const getWeightedExternalRanking = ( final_score, }; }); -}; +} -export const getMaxScores = ( +export function getMaxScores( rawExternalRankingVideos: IRawYoutubeVideo[] -): IMaxScores => { +): IMaxScores { const maxScore = { dateXViews: 0, dateXLikes: 0, @@ -143,34 +143,31 @@ export const getMaxScores = ( } return maxScore; -}; +} -export const getDateScore = (yearsSincePublished: number) => { +export function getDateScore(yearsSincePublished: number) { // Following the function in https://docs.google.com/document/d/1zxYRyytmbbvfAZkQc8dampD9Vhun0XQtWepKYxWUTKo return Math.max(-Math.pow(1.6, yearsSincePublished) + 11, 0); -}; +} -export const getDateXViewsScore = ( - views: number, - daysSincePublished: number -) => { +export function getDateXViewsScore(views: number, daysSincePublished: number) { return views / daysSincePublished; -}; +} -export const getDateXLikes = (likes: number, daysSincePublished: number) => { +export function getDateXLikes(likes: number, daysSincePublished: number) { return likes / daysSincePublished; -}; +} -export const getUseOfChapters = (description: string) => { +export function getUseOfChapters(description: string) { const usesChapters = description.match("[0-9]:[0-9]"); return usesChapters !== null ? 1 : 0; -}; +} -export const getDaysSincePublished = (publishedAt: string) => { +export function getDaysSincePublished(publishedAt: string) { const publishedAtDate = parseISO(publishedAt); const daysSincePublished = differenceInCalendarDays( new Date(), publishedAtDate ); return daysSincePublished; -}; +} From 18c2e8f8de52a3ecba1c0196db9ceddb19fda42a Mon Sep 17 00:00:00 2001 From: Mauricio Munoz Date: Tue, 16 Apr 2024 17:30:40 -0700 Subject: [PATCH 2/3] Modifying value --- backend/src/rating/ranking.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/rating/ranking.ts b/backend/src/rating/ranking.ts index fd5d855..2c5c77a 100644 --- a/backend/src/rating/ranking.ts +++ b/backend/src/rating/ranking.ts @@ -49,7 +49,7 @@ export function getRawExternalRanking( ): IRawYoutubeVideo[] { return videos.map((video) => { const daysSincePublished = getDaysSincePublished(video.snippet.publishedAt); - const yearsSincePublished = daysSincePublished / 365; + const yearsSincePublished = daysSincePublished / 264; const rawDateScore = getDateScore(yearsSincePublished); const rawDateXViewsScore = getDateXViewsScore( From 6c336a4f665714e7e8bc9fb645c6bcff507fc644 Mon Sep 17 00:00:00 2001 From: Mauricio Munoz Date: Tue, 16 Apr 2024 17:31:23 -0700 Subject: [PATCH 3/3] Adding new variable --- backend/src/rating/ranking.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/backend/src/rating/ranking.ts b/backend/src/rating/ranking.ts index 2c5c77a..80034a1 100644 --- a/backend/src/rating/ranking.ts +++ b/backend/src/rating/ranking.ts @@ -35,6 +35,7 @@ export const WEIGHTS = { }; export function getExternalRanking(videos: youtube_v3.Schema$Video[]) { + const a = 2; const rawExternalScoreVideos = getRawExternalRanking(videos); const maxScores = getMaxScores(rawExternalScoreVideos); const normalizedExternalScoreVideos = getNormalizedExternalRanking(