From 2588efcadbb6be0af7bf2cacacd1ad125bd47a39 Mon Sep 17 00:00:00 2001 From: txtxj <1418373194@qq.com> Date: Mon, 17 Apr 2023 01:45:36 +0800 Subject: [PATCH 1/4] feat: show how much time user spent during last 7 days --- README.md | 13 +++++++++++++ action.yml | 5 +++++ sources/graphics_list_formatter.py | 29 +++++++++++++++++++++++++++++ sources/main.py | 10 ++++++++-- sources/manager_download.py | 1 + sources/manager_environment.py | 1 + 6 files changed, 57 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 31da994a..2df268bf 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/action.yml b/action.yml index 8a413d84..15a909a1 100644 --- a/action.yml +++ b/action.yml @@ -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" diff --git a/sources/graphics_list_formatter.py b/sources/graphics_list_formatter.py index 929de8ee..a95d8238 100644 --- a/sources/graphics_list_formatter.py +++ b/sources/graphics_list_formatter.py @@ -141,3 +141,32 @@ 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 = { + "Mon": "Monday", + "Tue": "Tuesday", + "Wed": "Wednesday", + "Thu": "Thursday", + "Fri": "Friday", + "Sat": "Saturday", + "Sun": "Sunday" + } + 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) diff --git a/sources/main.py b/sources/main.py index d8d7955d..7ff68189 100644 --- a/sources/main.py +++ b/sources/main.py @@ -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: @@ -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" @@ -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"⏳ {'WeekDays'}: \n{week_list}\n\n" + stats = f"{stats[:-1]}```\n\n" DBM.g("WakaTime stats added!") diff --git a/sources/manager_download.py b/sources/manager_download.py index a90bf397..a81c2076 100644 --- a/sources/manager_download.py +++ b/sources/manager_download.py @@ -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}", ) diff --git a/sources/manager_environment.py b/sources/manager_environment.py index 33bbee44..6a453349 100644 --- a/sources/manager_environment.py +++ b/sources/manager_environment.py @@ -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") From df41a47390fe57b3bec8753165aab15995445862 Mon Sep 17 00:00:00 2001 From: txtxj <1418373194@qq.com> Date: Thu, 4 May 2023 21:52:55 +0800 Subject: [PATCH 2/4] feat: Add translations related to "Each Day" --- sources/main.py | 2 +- sources/translation.json | 60 ++++++++++++++++++++++++++-------------- 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/sources/main.py b/sources/main.py index 7ff68189..35cd013d 100644 --- a/sources/main.py +++ b/sources/main.py @@ -68,7 +68,7 @@ async def get_waka_time_stats(repositories: Dict, commit_dates: Dict) -> str: 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"⏳ {'WeekDays'}: \n{week_list}\n\n" + stats += f"⏳ {FM.t('Each Day')}: \n{week_list}\n\n" stats = f"{stats[:-1]}```\n\n" diff --git a/sources/translation.json b/sources/translation.json index 2d9642c3..dce93a84 100644 --- a/sources/translation.json +++ b/sources/translation.json @@ -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", @@ -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": "সোমবার", @@ -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ì", @@ -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": "星期一", @@ -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": "星期一", @@ -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": "الأثنين", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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": "월요일", @@ -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", @@ -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": "Понедельник", @@ -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", @@ -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", @@ -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", @@ -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", @@ -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": "Понеділок", @@ -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": "دوشنبه", @@ -737,6 +756,7 @@ "private repository": "%d ریپوزیتوری‌ شخصی", "private repositories": "%d ریپوزیتوری‌های شخصی", "I am an Early": "من یک 🐤 سحر‌خیزم", - "I am a Night": "من یک 🦉 شبم" + "I am a Night": "من یک 🦉 شبم", + "Each Day": "هر روز" } } From 47d8789752af54399ab370a7233bf1fe1a41441e Mon Sep 17 00:00:00 2001 From: Citrine Date: Mon, 8 May 2023 14:31:15 +0800 Subject: [PATCH 3/4] fix: Use the predefined WEEK_DAY_NAMES list --- sources/graphics_list_formatter.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/sources/graphics_list_formatter.py b/sources/graphics_list_formatter.py index a95d8238..c7f0971c 100644 --- a/sources/graphics_list_formatter.py +++ b/sources/graphics_list_formatter.py @@ -151,13 +151,13 @@ def make_last_7_day_time_list(data: List) -> str: :returns: string representation of statistics. """ full_name = { - "Mon": "Monday", - "Tue": "Tuesday", - "Wed": "Wednesday", - "Thu": "Thursday", - "Fri": "Friday", - "Sat": "Saturday", - "Sun": "Sunday" + "Mon": WEEK_DAY_NAMES[0], + "Tue": WEEK_DAY_NAMES[1], + "Wed": WEEK_DAY_NAMES[2], + "Thu": WEEK_DAY_NAMES[3], + "Fri": WEEK_DAY_NAMES[4], + "Sat": WEEK_DAY_NAMES[5], + "Sun": WEEK_DAY_NAMES[6] } names = [] texts = [] From 4b535ba9395cd9ae3bd7ec5bb6316d6cf09c777e Mon Sep 17 00:00:00 2001 From: Citrine Date: Tue, 9 May 2023 22:56:28 +0800 Subject: [PATCH 4/4] fix: remove useless weekday name keys --- sources/graphics_list_formatter.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/sources/graphics_list_formatter.py b/sources/graphics_list_formatter.py index c7f0971c..b104bf2d 100644 --- a/sources/graphics_list_formatter.py +++ b/sources/graphics_list_formatter.py @@ -150,15 +150,7 @@ def make_last_7_day_time_list(data: List) -> str: :param data: User summaries over last 7 days. :returns: string representation of statistics. """ - full_name = { - "Mon": WEEK_DAY_NAMES[0], - "Tue": WEEK_DAY_NAMES[1], - "Wed": WEEK_DAY_NAMES[2], - "Thu": WEEK_DAY_NAMES[3], - "Fri": WEEK_DAY_NAMES[4], - "Sat": WEEK_DAY_NAMES[5], - "Sun": WEEK_DAY_NAMES[6] - } + full_name = {day[:3]: day for day in WEEK_DAY_NAMES} names = [] texts = [] percents = []