mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-14 20:19:26 +01:00
Update stats
This commit is contained in:
@@ -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<T
|
||||
|
||||
if (!development_time) {
|
||||
return {
|
||||
total_hours: 0,
|
||||
total_minutes: 0,
|
||||
total_seconds: 0,
|
||||
hours: 0,
|
||||
minutes: 0,
|
||||
seconds: 0,
|
||||
}
|
||||
}
|
||||
|
||||
let total = 0
|
||||
development_time.forEach(item => 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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
fetchDailyStatistics,
|
||||
fetchMonthlyStatistics,
|
||||
fetchStatistics,
|
||||
fetchWeeklyStatistics,
|
||||
fetchWeeklyStatistics, Stats,
|
||||
} from 'App/Utils/StatsUtils'
|
||||
|
||||
export async function UpdateGithubReadme(): Promise<void> {
|
||||
@@ -26,7 +26,7 @@ export async function UpdateGithubReadme(): Promise<void> {
|
||||
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<void> {
|
||||
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`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user