diff --git a/collector/index.js b/collector/index.js index 5e86a97..572df55 100644 --- a/collector/index.js +++ b/collector/index.js @@ -19,7 +19,7 @@ const args = arg({ }); const enableGithub = args['--github'] && process.env.GH_TOKEN -const enableWakatime =args['--wakatime'] && process.env.WK_TOKEN +const enableWakatime =args['--wakatime'] && process.env.WK_COOKIE // Initializes the application based on provided arguments and environment variables. const Initializes = async () => { @@ -27,7 +27,7 @@ const Initializes = async () => { if (process.env.GH_TOKEN) logger.info(`'GH_TOKEN' is available`) if (enableGithub) logger.info(`API Github.com collector starting...`) - if (process.env.WK_TOKEN) logger.info(`'WK_TOKEN' is available`) + if (process.env.WK_COOKIE) logger.info(`'WK_COOKIE' is available`) if (enableWakatime) logger.info(`API Wakatime.com collector starting...`) } @@ -151,8 +151,8 @@ const collectWakaTime = async () => { // https://wakatime.com/api/v1/users/current/durations?api_key=f389e6d1-207e-4c49-9526-d2623ce7b6d1&date=2022-03-26 const coding = { - weekly_seconds: 0, average_seconds: 0, + weekly_seconds: 0, best_seconds: 0, daytime: [], weektime: [] @@ -165,7 +165,7 @@ const collectWakaTime = async () => { 'accept': 'application/json, text/javascript, */*; q=0.01', 'referer': 'https://wakatime.com/@dvgamerr', 'user-agent': fetchUserAgent(0), - 'cookie': process.env.WK_TOKEN, + 'cookie': process.env.WK_COOKIE, 'authority': 'wakatime.com' } }) @@ -175,6 +175,36 @@ const collectWakaTime = async () => { } const body = await res.json() + + const { days: dayOfYear } = body.data + + const idx = dayOfYear.length - 1 + for (let i = idx; i >= 0; i--) { + const totalDuration = dayOfYear[i].total + const dateDuration = dayjs(dayOfYear[i].date, 'YYYY-MM-DD') + coding.average_seconds += totalDuration + if (i > idx - 7) { + coding.weekly_seconds += totalDuration + + dateDuration + } + if (coding.best_seconds < totalDuration) coding.best_seconds = totalDuration + + // weekday + const dayInWeek = dateDuration.day() + const shiftWeek = dayInWeek - 1 < 0 ? 6 : dayInWeek - 1 + if (!coding.weektime[shiftWeek]) coding.weektime[shiftWeek] = { count: 0, duration: 0 } + coding.weektime[shiftWeek] = { + count: coding.weektime[shiftWeek].count + 1, + duration: coding.weektime[shiftWeek].duration + totalDuration, + } + } + coding.average_seconds = coding.average_seconds / dayOfYear.length + coding.weekly_seconds = coding.weekly_seconds / 7 + coding.weektime = coding.weektime.map(e => e.duration / e.count) + + logger.debug(coding) + await mergeJsonResponse(body, './src/i18n/insights.json') // for (let i = totalDay; i >= 0; i--) { @@ -185,7 +215,7 @@ const collectWakaTime = async () => { // const day = currentDate.add(i * -1, 'd').day() // wakaTask.push((async () => { // const { status, data: { data: durations } } = await apiWaka.request('GET /users/current/durations', { - // api_key: process.env.WK_TOKEN, + // api_key: process.env.WK_COOKIE, // date: dateFormat // }) // if (status !== 200) return logger.error(status) diff --git a/src/i18n/coding.json b/src/i18n/coding.json index c6aaa28..8721e74 100644 --- a/src/i18n/coding.json +++ b/src/i18n/coding.json @@ -84,12 +84,12 @@ 95 ], "weektime": [ - 125.65, - 112.12, - 111.32, - 124.95, - 135.05, - 53.68, - 52.85 + 7387.844356711541, + 10491.952919365383, + 8996.180162358487, + 9303.651937615385, + 6895.8477763461515, + 3726.3331686538468, + 2789.1322143653842 ] -} \ No newline at end of file +} diff --git a/src/i18n/experience.json b/src/i18n/experience.json index d127a5c..4d5f73c 100644 --- a/src/i18n/experience.json +++ b/src/i18n/experience.json @@ -3,8 +3,8 @@ "interview": false, "currencry": { "ccy": "USD", - "sell": 36.06, - "buy": 35.44 + "sell": 35.92, + "buy": 35.41 }, "salary": { "base": 71950, diff --git a/src/i18n/insights.json b/src/i18n/insights.json index bf45b84..5da5850 100644 --- a/src/i18n/insights.json +++ b/src/i18n/insights.json @@ -5099,11 +5099,11 @@ }, { "date": "2024-03-06", - "total": 28070.39642, + "total": 30262.969648, "categories": [ { "name": "Coding", - "total": 28070.39642 + "total": 30262.969648 } ] }