This commit is contained in:
2020-12-19 21:16:44 +01:00
parent 48fa997811
commit 7478e85bae
11 changed files with 149 additions and 44 deletions

View File

@@ -0,0 +1,31 @@
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import Location from "App/Models/Location";
import StoreValidator from "App/Validators/locations/StoreValidator";
export default class LocationsController {
public async get ({ response }: HttpContextContract) {
const location = await Location.query().orderBy('since', 'desc').firstOrFail()
return response.status(200).send({
place: location.place,
left: location.left,
since: location.since
})
}
public async history ({ response }: HttpContextContract) {
const locations = await Location.query().orderBy('since', 'desc')
return response.status(200).send({
locations
})
}
public async set ({ request, response }: HttpContextContract) {
const data = await request.validate(StoreValidator)
await Location.create(data)
return response.status(200).send({
message: 'Location successfully added !'
})
}
}

View File

@@ -1,31 +1,44 @@
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import {getTotalStats, getWeeklyStats, getMonthlyStats, getOtherStats} from 'App/Helpers/StatsHelper'
import DockerBuild from "App/Models/DockerBuild";
import DockerCommand from "App/Models/DockerCommand";
export default class StatsController {
public async get ({response}: HttpContextContract) {
return response.status(200).send({
daily: this.getDailyStats(),
weekly: this.getWeeklyStats(),
monthly: this.getMontlyStats()
weekly: getWeeklyStats(),
monthly: getMonthlyStats(),
total: getTotalStats(),
other : getOtherStats()
})
}
getDailyStats() {
return {
development_hours: 0
public async incrementBuild () {
const date = new Date()
const last_entry = await DockerBuild.findBy('created_at', date)
if (last_entry) {
last_entry.builds = last_entry.builds ++
await last_entry.save()
} else {
await DockerBuild.create({
builds: BigInt(1)
})
}
}
getWeeklyStats() {
return {
development_hours: 0
}
}
public async incrementCommand () {
const date = new Date()
const last_entry = await DockerCommand.findBy('created_at', date)
getMontlyStats() {
return {
development_hours: 0
if (last_entry) {
last_entry.commands = last_entry.commands ++
await last_entry.save()
} else {
await DockerCommand.create({
commands: BigInt(1)
})
}
}

View File

@@ -0,0 +1,59 @@
import DockerCommand from "App/Models/DockerCommand";
import axios from "axios";
import DockerBuild from "App/Models/DockerBuild";
async function getWeeklyStats() {
const commands = await DockerCommand.query().where('created_at', '>', new Date().getTime() - 1000 * 60 * 60 * 24 * 7)
const {data} = await axios.get('https://wakatime.com/api/v1/users/arthurdanjou/stats/last_7_days')
const builds = await DockerBuild.query().where('created_at', '>', new Date().getMonth() - 1)
return {
development_hours: data.data.total_seconds / 60 / 60,
docker_commands_run: commands.length,
docker_build_count: builds.length,
best_project: data.data.projects[0]
}
}
async function getMonthlyStats() {
const commands = await DockerCommand.query().where('created_at', '>', new Date().getMonth() - 1)
const {data} = await axios.get('https://wakatime.com/api/v1/users/arthurdanjou/stats/last_30_days')
const builds = await DockerBuild.query().where('created_at', '>', new Date().getMonth() - 1)
return {
development_hours: data.data.total_seconds / 60 / 60,
docker_commands_run: commands.length,
docker_build_count: builds.length,
best_project: data.data.projects[0]
}
}
async function getTotalStats() {
const commands = await DockerCommand.query()
const {data} = await axios.get('https://wakatime.com/api/v1/users/arthurdanjou/all_time_since_today')
const builds = await DockerBuild.query()
return {
development_hours: data.data.seconds,
docker_commands_run: commands.length,
docker_build_count: builds.length
}
}
async function getOtherStats() {
const {data} = await axios.get('https://wakatime.com/api/v1/users/arthurdanjou/stats/last_year')
return {
daily_average: data.data.daily_average / 60 / 60,
editors: [
'WebStorm',
'Intellij Idea',
'PyCharm',
'GoLang',
'DataGrip'
],
operating_systems: 'Windows'
}
}
export {getMonthlyStats, getTotalStats, getWeeklyStats, getOtherStats}

View File

@@ -6,7 +6,7 @@ export default class DockerBuild extends BaseModel {
public id: number
@column()
public build: bigint
public builds: bigint
@column.dateTime({ autoCreate: true })
public createdAt: DateTime

View File

@@ -6,7 +6,7 @@ export default class DockerCommand extends BaseModel {
public id: number
@column()
public command: string
public commands: bigint
@column.dateTime({ autoCreate: true })
public createdAt: DateTime

View File

@@ -9,7 +9,7 @@ export default class Location extends BaseModel {
public since: DateTime
@column()
public location: string
public place: string
@column()
public left: string

View File

@@ -1,19 +0,0 @@
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import {schema} from '@ioc:Adonis/Core/Validator'
export default class UpdateValidator {
constructor (private ctx: HttpContextContract) {
}
public schema = schema.create({
place: schema.string.optional(),
since: schema.date.optional(),
left: schema.string.optional(),
})
public cacheKey = this.ctx.routeKey
public messages = {
required: 'Le champ {{field}} doit être valide !'
}
}

View File

@@ -13,5 +13,7 @@ export default class StateValidator {
})
public messages = {}
public messages = {
required: 'Le champ {{field}} doit être valide !',
}
}