Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show how much time user spent during last 7 days #451

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,19 @@ cable 54 mins ██░░░░░░░░░
denAPI 40 mins ██░░░░░░░░░░░░░░░░░░░░░░░ 7.66%
```

`SHOW_LAST_7_DAY_CODE_TIME` flag can be set to `True` to show time you spent during the last 7 days

```text
⏳ WeekDays:
Monday 3 hrs 54 mins ████░░░░░░░░░░░░░░░░░░░░░ 14.94 %
Tuesday 7 hrs 36 mins ███████░░░░░░░░░░░░░░░░░░ 29.05 %
Wednesday 4 hrs 53 mins █████░░░░░░░░░░░░░░░░░░░░ 18.71 %
Thursday 3 hrs 26 mins ███░░░░░░░░░░░░░░░░░░░░░░ 13.12 %
Friday 3 hrs 41 mins ████░░░░░░░░░░░░░░░░░░░░░ 14.10 %
Saturday 0 secs ░░░░░░░░░░░░░░░░░░░░░░░░░ 00.00 %
Sunday 2 hrs 38 mins ███░░░░░░░░░░░░░░░░░░░░░░ 10.09 %
```

`SHOW_TIMEZONE` flag can be set to `False` to hide the time zone you are in

```text
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ inputs:
description: "Show Total Time you have coded"
default: "True"

SHOW_LAST_7_DAY_CODE_TIME:
required: false
description: "Show Code time during last 7 days"
default: "False"

COMMIT_BY_ME:
required: false
description: "Git commit with your own name and email"
Expand Down
21 changes: 21 additions & 0 deletions sources/graphics_list_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,24 @@ def make_language_per_repo_list(repositories: Dict) -> str:
top_language = max(list(language_count.keys()), key=lambda x: language_count[x]["count"])
title = f"**{FM.t('I Mostly Code in') % top_language}** \n\n" if len(repos_with_language) > 0 else ""
return f"{title}```text\n{make_list(names=names, texts=texts, percents=percents)}\n```\n\n"


def make_last_7_day_time_list(data: List) -> str:
"""
Calculate Time-related info, how much time in each of the last seven days user spent.

:param data: User summaries over last 7 days.
:returns: string representation of statistics.
"""
full_name = {day[:3]: day for day in WEEK_DAY_NAMES}
names = []
texts = []
percents = []
total_seconds = 0
for day in data:
names.append(FM.t(full_name[day["range"]["text"][:3]]))
texts.append(day["grand_total"]["text"])
percents.append(day["grand_total"]["total_seconds"])
total_seconds += day["grand_total"]["total_seconds"]
percents = [percent * 100. / total_seconds for percent in percents]
return make_list(names=names, texts=texts, percents=percents, top_num=7, sort=False)
10 changes: 8 additions & 2 deletions sources/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from manager_debug import init_debug_manager, DebugManager as DBM
from graphics_chart_drawer import create_loc_graph, GRAPH_PATH
from yearly_commit_calculator import calculate_commit_data
from graphics_list_formatter import make_list, make_commit_day_time_list, make_language_per_repo_list
from graphics_list_formatter import make_list, make_commit_day_time_list, make_language_per_repo_list, make_last_7_day_time_list


async def get_waka_time_stats(repositories: Dict, commit_dates: Dict) -> str:
Expand All @@ -31,11 +31,12 @@ async def get_waka_time_stats(repositories: Dict, commit_dates: Dict) -> str:
stats = str()

data = await DM.get_remote_json("waka_latest")
summary_data = await DM.get_remote_json("waka_summary")
if EM.SHOW_COMMIT or EM.SHOW_DAYS_OF_WEEK: # if any on flag is turned on then we need to calculate the data and print accordingly
DBM.i("Adding user commit day time info...")
stats += f"{await make_commit_day_time_list(data['data']['timezone'], repositories, commit_dates)}\n\n"

if EM.SHOW_TIMEZONE or EM.SHOW_LANGUAGE or EM.SHOW_EDITORS or EM.SHOW_PROJECTS or EM.SHOW_OS:
if EM.SHOW_TIMEZONE or EM.SHOW_LANGUAGE or EM.SHOW_EDITORS or EM.SHOW_PROJECTS or EM.SHOW_OS or EM.SHOW_LAST_7_DAY_CODE_TIME:
no_activity = FM.t("No Activity Tracked This Week")
stats += f"📊 **{FM.t('This Week I Spend My Time On')}** \n\n```text\n"

Expand Down Expand Up @@ -64,6 +65,11 @@ async def get_waka_time_stats(repositories: Dict, commit_dates: Dict) -> str:
os_list = no_activity if len(data["data"]["operating_systems"]) == 0 else make_list(data["data"]["operating_systems"])
stats += f"💻 {FM.t('operating system')}: \n{os_list}\n\n"

if EM.SHOW_LAST_7_DAY_CODE_TIME:
DBM.i("Adding user last 7 day coding time info...")
week_list = no_activity if len(summary_data["data"]) == 0 else make_last_7_day_time_list(summary_data["data"])
stats += f"⏳ {FM.t('Each Day')}: \n{week_list}\n\n"

stats = f"{stats[:-1]}```\n\n"

DBM.g("WakaTime stats added!")
Expand Down
1 change: 1 addition & 0 deletions sources/manager_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ async def init_download_manager(user_login: str):
linguist="https://cdn.jsdelivr.net/gh/github/linguist@master/lib/linguist/languages.yml",
waka_latest=f"https://wakatime.com/api/v1/users/current/stats/last_7_days?api_key={EM.WAKATIME_API_KEY}",
waka_all=f"https://wakatime.com/api/v1/users/current/all_time_since_today?api_key={EM.WAKATIME_API_KEY}",
waka_summary=f"https://wakatime.com/api/v1/users/current/summaries?api_key={EM.WAKATIME_API_KEY}&range=Last%207%20Days%20from%20Yesterday",
github_stats=f"https://github-contributions.vercel.app/api/v1/{user_login}",
)

Expand Down
1 change: 1 addition & 0 deletions sources/manager_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class EnvironmentManager:
SHOW_SHORT_INFO = getenv("INPUT_SHOW_SHORT_INFO", "True").lower() in _TRUTHY
SHOW_UPDATED_DATE = getenv("INPUT_SHOW_UPDATED_DATE", "True").lower() in _TRUTHY
SHOW_TOTAL_CODE_TIME = getenv("INPUT_SHOW_TOTAL_CODE_TIME", "True").lower() in _TRUTHY
SHOW_LAST_7_DAY_CODE_TIME = getenv("INPUT_SHOW_LAST_7_DAY_CODE_TIME", "False").lower() in _TRUTHY

COMMIT_BY_ME = getenv("INPUT_COMMIT_BY_ME", "False").lower() in _TRUTHY
COMMIT_MESSAGE = getenv("INPUT_COMMIT_MESSAGE", "Updated with Dev Metrics")
Expand Down
60 changes: 40 additions & 20 deletions sources/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
"private repository": "%d dépot privé",
"private repositories": "%d dépots privés",
"I am an Early": "Je suis un 🐤 du matin",
"I am a Night": "Je suis un 🦉 de nuit"
"I am a Night": "Je suis un 🦉 de nuit",
"Each Day": "Chaque jour"
},
"en": {
"Monday": "Monday",
Expand Down Expand Up @@ -71,7 +72,8 @@
"private repository": "%d Private Repository",
"private repositories": "%d Private Repositories",
"I am an Early": "I'm an Early 🐤",
"I am a Night": "I'm a Night 🦉"
"I am a Night": "I'm a Night 🦉",
"Each Day": "Each Day"
},
"bn": {
"Monday": "সোমবার",
Expand Down Expand Up @@ -108,7 +110,8 @@
"private repository": "%d টি ব্যক্তিগত Repository",
"private repositories": "%d টি ব্যক্তিগত Repositories",
"I am an Early": "আমি হলাম সকালের 🐤",
"I am a Night": "আমি হলাম রাতের 🦉"
"I am a Night": "আমি হলাম রাতের 🦉",
"Each Day": "প্রতিদিন"
},
"it": {
"Monday": "Lunedì",
Expand Down Expand Up @@ -145,7 +148,8 @@
"private repository": "%d Repository privata",
"private repositories": "%d Repositories private",
"I am an Early": "Sono un mattiniero 🐤",
"I am a Night": "Sono un notturno 🦉"
"I am a Night": "Sono un notturno 🦉",
"Each Day": "Ogni giorno"
},
"zh": {
"Monday": "星期一",
Expand Down Expand Up @@ -182,7 +186,8 @@
"private repository": "%d 个私人仓库",
"private repositories": "%d 个私人仓库",
"I am an Early": "我是早起的 🐤",
"I am a Night": "我是夜猫子 🦉"
"I am a Night": "我是夜猫子 🦉",
"Each Day": "每天"
},
"zh_TW": {
"Monday": "星期一",
Expand Down Expand Up @@ -219,7 +224,8 @@
"private repository": "%d 私人倉庫",
"private repositories": "%d 私人倉庫",
"I am an Early": "我是早起的",
"I am a Night": "我是夜貓子"
"I am a Night": "我是夜貓子",
"Each Day": "每天"
},
"ar": {
"Monday": "الأثنين",
Expand Down Expand Up @@ -256,7 +262,8 @@
"private repository": "%d المستودع الخاص",
"private repositories": "%d المستودعات الخاصة",
"I am an Early": "أنا كالعصفور 🐤 في الصباح",
"I am a Night": "أنا كالبومة 🦉 في الليل"
"I am a Night": "أنا كالبومة 🦉 في الليل",
"Each Day": "كل يوم"
},
"pt-BR": {
"Monday": "Segunda-Feira",
Expand Down Expand Up @@ -293,7 +300,8 @@
"private repository": "%d Repositório Privado",
"private repositories": "%d Repositórios Privados",
"I am an Early": "Eu sou diurno 🐤",
"I am a Night": "Eu sou noturno 🦉"
"I am a Night": "Eu sou noturno 🦉",
"Each Day": "Cada dia"
},
"pl": {
"Monday": "Poniedziałek",
Expand Down Expand Up @@ -330,7 +338,8 @@
"private repository": "%d prywatne repozytorium",
"private repositories": "%d prywatne repozytoria",
"I am an Early": "Jestem rannym 🐤",
"I am a Night": "Jestem nocną 🦉"
"I am a Night": "Jestem nocną 🦉",
"Each Day": "Każdego dnia"
},
"es": {
"Monday": "Lunes",
Expand Down Expand Up @@ -367,7 +376,8 @@
"private repository": "%d Repositorio Privado",
"private repositories": "%d Repositorios Privados",
"I am an Early": "Soy diurno 🐤",
"I am a Night": "Soy nocturno 🦉"
"I am a Night": "Soy nocturno 🦉",
"Each Day": "Cada día"
},
"gl": {
"Monday": "Luns",
Expand Down Expand Up @@ -404,7 +414,8 @@
"private repository": "%d Repositorio Privado",
"private repositories": "%d Repositorios Privados",
"I am an Early": "Sonche Jalo 🐤",
"I am a Night": "Sonche Moucho 🦉"
"I am a Night": "Sonche Moucho 🦉",
"Each Day": "Cada día"
},
"ko": {
"Monday": "월요일",
Expand Down Expand Up @@ -441,7 +452,8 @@
"private repository": "%d개의 Private Repository를 만들었어요.",
"private repositories": "%d개의 Private Repository를 만들었어요.",
"I am an Early": "저는 아침형 인간이에요. 🐤",
"I am a Night": "저는 저녁형 인간이에요. 🦉"
"I am a Night": "저는 저녁형 인간이에요. 🦉",
"Each Day": "매일"
},
"tr": {
"Monday": "Pazartesi",
Expand Down Expand Up @@ -478,7 +490,8 @@
"private repository": "%d Özel Depo",
"private repositories": "%d Özel Depolar",
"I am an Early": "Sabah 🐤'yum",
"I am a Night": "Gece 🦉'yum"
"I am a Night": "Gece 🦉'yum",
"Each Day": "Her Gün"
},
"ru": {
"Monday": "Понедельник",
Expand Down Expand Up @@ -515,7 +528,8 @@
"private repository": "%d Приватный репозиторий",
"private repositories": "%d Приватных репозиториев",
"I am an Early": "Я утренняя 🐤",
"I am a Night": "Я ночная 🦉"
"I am a Night": "Я ночная 🦉",
"Each Day": "каждый день"
},
"de": {
"Monday": "Montag",
Expand Down Expand Up @@ -552,7 +566,8 @@
"private repository": "%d privates Repository",
"private repositories": "%d private Repositories",
"I am an Early": "Ich bin ein Frühaufsteher 🐤",
"I am a Night": "Ich bin eine Nachteule 🦉"
"I am a Night": "Ich bin eine Nachteule 🦉",
"Each Day": "Jeden Tag"
},
"id": {
"Monday": "Senin",
Expand Down Expand Up @@ -589,7 +604,8 @@
"private repository": "%d Repositori pribadi",
"private repositories": "%d Repositori pribadi",
"I am an Early": "Aku orangnya diurnal 🐤",
"I am a Night": "Aku orangnya nokturnal 🦉"
"I am a Night": "Aku orangnya nokturnal 🦉",
"Each Day": "Setiap Hari"
},
"ca": {
"Monday": "Dilluns",
Expand Down Expand Up @@ -626,7 +642,8 @@
"private repository": "%d Repositori privats",
"private repositories": "%d Repositoris privats",
"I am an Early": "Sóc diürn 🐤",
"I am a Night": "Sóc nocturn 🦉"
"I am a Night": "Sóc nocturn 🦉",
"Each Day": "Cada dia"
},
"vn": {
"Monday": "Thứ Hai",
Expand Down Expand Up @@ -663,7 +680,8 @@
"private repository": "%d dự án riêng tư",
"private repositories": "%d dự án riêng tư",
"I am an Early": "Tôi không phải cú đêm 🐤",
"I am a Night": "Tôi là cú đêm 🦉"
"I am a Night": "Tôi là cú đêm 🦉",
"Each Day": "Mỗi ngày"
},
"uk": {
"Monday": "Понеділок",
Expand Down Expand Up @@ -700,7 +718,8 @@
"private repository": "%d Приватний репозиторій",
"private repositories": "%d Приватных репозиторіїв",
"I am an Early": "Я рання 🐤",
"I am a Night": "Я нічна 🦉"
"I am a Night": "Я нічна 🦉",
"Each Day": "Кожен день"
},
"fa": {
"Monday": "دوشنبه",
Expand Down Expand Up @@ -737,6 +756,7 @@
"private repository": "%d ریپوزیتوری‌ شخصی",
"private repositories": "%d ریپوزیتوری‌های شخصی",
"I am an Early": "من یک 🐤 سحر‌خیزم",
"I am a Night": "من یک 🦉 شبم"
"I am a Night": "من یک 🦉 شبم",
"Each Day": "هر روز"
}
}