diff --git a/app/Utils/StatsUtils.ts b/app/Utils/StatsUtils.ts index 8d9ed75..7813239 100644 --- a/app/Utils/StatsUtils.ts +++ b/app/Utils/StatsUtils.ts @@ -3,12 +3,12 @@ import CommandsRun from 'App/Models/CommandsRun' import BuildsRun from 'App/Models/BuildsRun' interface Time { - total_hours: number - total_minutes: number - total_seconds: number + hours: number + minutes: number + seconds: number } -interface Stats { +export interface Stats { range: { start: string end: string @@ -34,19 +34,23 @@ export async function getDevelopmentHours(start: string, end: string): Promise total += item.seconds) + const hours = Math.floor(total / 3600) + const minutes = Math.floor(total / 60) - hours * 60 + const seconds = Math.floor(total) - minutes * 60 + return { - total_hours: Number((total / 3600).toFixed(2)), - total_minutes: Number((total / 60).toFixed(2)), - total_seconds: Number(total.toFixed(2)), + hours, + minutes, + seconds, } } diff --git a/app/Utils/UpdateGithubReadme.ts b/app/Utils/UpdateGithubReadme.ts index e1f9ffa..f25e264 100644 --- a/app/Utils/UpdateGithubReadme.ts +++ b/app/Utils/UpdateGithubReadme.ts @@ -5,7 +5,7 @@ import { fetchDailyStatistics, fetchMonthlyStatistics, fetchStatistics, - fetchWeeklyStatistics, + fetchWeeklyStatistics, Stats, } from 'App/Utils/StatsUtils' export async function UpdateGithubReadme(): Promise { @@ -26,7 +26,7 @@ export async function UpdateGithubReadme(): Promise { const new_table = ` | Title | Daily | Weekly | Monthly | Total | | :------------------------------------------ | ----------: | ----------: | -----------: | -----------: | -| :hourglass_flowing_sand: Hours Spent Coding | **${daily_stats.development_time.total_hours}hrs** | **${weekly_stats.development_time.total_hours}hrs** | **${monthly_stats.development_time.total_hours}hrs** | **${total_stats.development_time.total_hours}hrs** | +| :hourglass_flowing_sand: Hours Spent Coding | **${getTotalHours(daily_stats)}hrs** | **${getTotalHours(weekly_stats)}hrs** | **${getTotalHours(monthly_stats)}hrs** | **${getTotalHours(total_stats)}hrs** | | :computer: Terminal Commands | **${daily_stats.commands_ran}** | **${weekly_stats.commands_ran}** | **${monthly_stats.commands_ran}** | **${total_stats.commands_ran}** | | :hammer: Docker Builds | **${daily_stats.builds_ran}** | **${weekly_stats.builds_ran}** | **${monthly_stats.builds_ran}** | **${total_stats.builds_ran}** |\n` const new_content = content.replace(old_table, new_table) @@ -50,3 +50,7 @@ export async function UpdateGithubReadme(): Promise { Logger.error('Error with updating statistics') } } + +function getTotalHours(stats: Stats): string { + return `${(stats.development_time.hours + stats.development_time.minutes * 60 + stats.development_time.seconds).toFixed(2)}hrs` +}