Last active
January 21, 2021 18:41
-
-
Save FOLLGAD/619ec4f626d61365a0508fe1d6952e86 to your computer and use it in GitHub Desktop.
Wakatime data compiler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This is written for Deno, not node.js | |
| import { readJson } from "https://deno.land/std@0.63.0/fs/read_json.ts" | |
| /* | |
| A script I wrote to parse the data you can download from WakaTime, to display how many hours you spent working on specific | |
| projects. | |
| */ | |
| interface Duration { | |
| total_seconds: number | |
| } | |
| interface Project { | |
| grand_total: Duration | |
| name: string | |
| } | |
| interface Day { | |
| categories: [] | |
| date: string | |
| dependencies: [] | |
| editors: [] | |
| grand_total: { | |
| total_seconds: number | |
| } | |
| languages: [] | |
| machines: [] | |
| operating_systems: [] | |
| projects: Project[] | |
| } | |
| interface WakaTimeObj { | |
| days: Day[] | |
| range: { | |
| start: number | |
| end: number | |
| } | |
| user: Object | |
| } | |
| const d: any = await readJson("./JSON-FILE-FROM-WAKATIME.json") | |
| const data: WakaTimeObj = d | |
| const projCompilation: { [key: string]: number } = data.days.reduce( | |
| (acc, day) => { | |
| const ob: any = { ...acc } | |
| day.projects.forEach( | |
| (p) => | |
| (ob[p.name] = ob[p.name] | |
| ? ob[p.name] + p.grand_total.total_seconds | |
| : p.grand_total.total_seconds) | |
| ) | |
| return ob | |
| }, | |
| {} | |
| ) | |
| const secToHrs = (sec: number) => sec / 60 / 60 | |
| Object.keys(projCompilation) | |
| .sort() | |
| .forEach((a) => console.log(a, secToHrs(projCompilation[a]))) | |
| console.log("From:", new Date(data.range.start * 1000)) | |
| console.log("To:", new Date(data.range.end * 1000)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment