You've already forked wakapi-readme-stats
documentation added, black linter added
This commit is contained in:
@@ -10,24 +10,39 @@ from manager_github import GitHubManager as GHM
|
||||
from manager_localization import LocalizationManager as LM
|
||||
|
||||
|
||||
DAY_TIME_EMOJI = ["🌞", "🌆", "🌃", "🌙"]
|
||||
DAY_TIME_NAMES = ["Morning", "Daytime", "Evening", "Night"]
|
||||
WEEK_DAY_NAMES = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
|
||||
DAY_TIME_EMOJI = ["🌞", "🌆", "🌃", "🌙"] # Emojis, representing different times of day.
|
||||
DAY_TIME_NAMES = ["Morning", "Daytime", "Evening", "Night"] # Localization identifiers for different times of day.
|
||||
WEEK_DAY_NAMES = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] # Localization identifiers for different days of week.
|
||||
|
||||
|
||||
class Symbol(Enum):
|
||||
"""
|
||||
Symbol version enum.
|
||||
Allows to retrieve symbols pairs by calling `Symbol.get_symbols(version)`.
|
||||
"""
|
||||
|
||||
VERSION_1 = "█", "░"
|
||||
VERSION_2 = "⣿", "⣀"
|
||||
VERSION_3 = "⬛", "⬜"
|
||||
|
||||
@staticmethod
|
||||
def get_symbols(version: int) -> Tuple[str, str]:
|
||||
"""
|
||||
Retrieves symbols pair for specified version.
|
||||
|
||||
:param version: Required symbols version.
|
||||
:returns: Two strings for filled and empty symbol value in a tuple.
|
||||
"""
|
||||
return Symbol[f"VERSION_{version}"].value
|
||||
|
||||
|
||||
def make_graph(percent: float):
|
||||
"""
|
||||
Make progress graph from API graph
|
||||
Make text progress bar.
|
||||
Length of the progress bar is 25 characters.
|
||||
|
||||
:param percent: Completion percent of the progress bar.
|
||||
:return: The string progress bar representation.
|
||||
"""
|
||||
done_block, empty_block = Symbol.get_symbols(EM.SYMBOL_VERSION)
|
||||
percent_quart = round(percent / 4)
|
||||
@@ -36,7 +51,20 @@ def make_graph(percent: float):
|
||||
|
||||
def make_list(data: List = None, names: List[str] = None, texts: List[str] = None, percents: List[float] = None, top_num: int = 5, sort: bool = True) -> str:
|
||||
"""
|
||||
Make List
|
||||
Make list of text progress bars with supportive info.
|
||||
Each row has the following structure: [name of the measure] [quantity description (with words)] [progress bar] [total percentage].
|
||||
Name of the measure: up to 25 characters.
|
||||
Quantity description: how many _things_ were found, up to 20 characters.
|
||||
Progress bar: measure percentage, 25 characters.
|
||||
Total percentage: floating point percentage.
|
||||
|
||||
:param data: list of dictionaries, each of them containing a measure (name, text and percent).
|
||||
:param names: list of names (names of measure), overloads data if defined.
|
||||
:param texts: list of texts (quantity descriptions), overloads data if defined.
|
||||
:param percents: list of percents (total percentages), overloads data if defined.
|
||||
:param top_num: how many measures to display, default: 5.
|
||||
:param sort: if measures should be sorted by total percentage, default: True.
|
||||
:returns: The string representation of the list.
|
||||
"""
|
||||
if data is not None:
|
||||
names = [value for item in data for key, value in item.items() if key == "name"] if names is None else names
|
||||
@@ -46,10 +74,16 @@ def make_list(data: List = None, names: List[str] = None, texts: List[str] = Non
|
||||
data = list(zip(names, texts, percents))
|
||||
top_data = sorted(data[:top_num], key=lambda record: record[2]) if sort else data[:top_num]
|
||||
data_list = [f"{n[:25]}{' ' * (25 - len(n))}{t}{' ' * (20 - len(t))}{make_graph(p)} {p:05.2f} % " for n, t, p in top_data]
|
||||
return '\n'.join(data_list)
|
||||
return "\n".join(data_list)
|
||||
|
||||
|
||||
async def make_commit_day_time_list(time_zone: str) -> str:
|
||||
"""
|
||||
Calculate commit-related info, how many commits were made, and at what time of day and day of week.
|
||||
|
||||
:param time_zone: User time zone.
|
||||
:returns: string representation of statistics.
|
||||
"""
|
||||
stats = str()
|
||||
|
||||
result = await DM.get_remote_graphql("repos_contributed_to", username=GHM.USER.login)
|
||||
@@ -62,8 +96,8 @@ async def make_commit_day_time_list(time_zone: str) -> str:
|
||||
result = await DM.get_remote_graphql("repo_committed_dates", owner=repository["owner"]["login"], name=repository["name"], id=GHM.USER.node_id)
|
||||
committed_dates = result["data"]["repository"]["defaultBranchRef"]["target"]["history"]["edges"]
|
||||
|
||||
for committedDate in committed_dates:
|
||||
local_date = datetime.strptime(committedDate["node"]["committedDate"], "%Y-%m-%dT%H:%M:%SZ")
|
||||
for committed_date in committed_dates:
|
||||
local_date = datetime.strptime(committed_date["node"]["committedDate"], "%Y-%m-%dT%H:%M:%SZ")
|
||||
date = local_date.replace(tzinfo=utc).astimezone(timezone(time_zone))
|
||||
|
||||
day_times[date.hour // 6] += 1
|
||||
@@ -74,14 +108,14 @@ async def make_commit_day_time_list(time_zone: str) -> str:
|
||||
day_times = day_times[1:] + day_times[:1]
|
||||
|
||||
dt_names = [f"{DAY_TIME_EMOJI[i]} {LM.t(DAY_TIME_NAMES[i])}" for i in range(len(day_times))]
|
||||
dt_texts = [f'{day_time} commits' for day_time in day_times]
|
||||
dt_texts = [f"{day_time} commits" for day_time in day_times]
|
||||
dt_percents = [round((day_time / sum_day) * 100, 2) for day_time in day_times]
|
||||
title = LM.t("I am an Early") if sum(day_times[0:2]) >= sum(day_times[2:4]) else LM.t("I am a Night")
|
||||
stats += f"**{title}** \n\n```text\n{make_list(names=dt_names, texts=dt_texts, percents=dt_percents, top_num=7, sort=False)}\n```\n"
|
||||
|
||||
if EM.SHOW_DAYS_OF_WEEK:
|
||||
wd_names = [LM.t(week_day) for week_day in WEEK_DAY_NAMES]
|
||||
wd_texts = [f'{week_day} commits' for week_day in week_days]
|
||||
wd_texts = [f"{week_day} commits" for week_day in week_days]
|
||||
wd_percents = [round((week_day / sum_week) * 100, 2) for week_day in week_days]
|
||||
title = LM.t("I am Most Productive on") % wd_names[wd_percents.index(max(wd_percents))]
|
||||
stats += f"📅 **{title}** \n\n```text\n{make_list(names=wd_names, texts=wd_texts, percents=wd_percents, top_num=7, sort=False)}\n```\n"
|
||||
@@ -90,6 +124,12 @@ async def make_commit_day_time_list(time_zone: str) -> str:
|
||||
|
||||
|
||||
def make_language_per_repo_list(repositories: Dict) -> str:
|
||||
"""
|
||||
Calculate language-related info, how many repositories in what language user has.
|
||||
|
||||
:param repositories: User repositories.
|
||||
:returns: string representation of statistics.
|
||||
"""
|
||||
language_count = dict()
|
||||
repos_with_language = [repo for repo in repositories["data"]["user"]["repositories"]["edges"] if repo["node"]["primaryLanguage"] is not None]
|
||||
for repo in repos_with_language:
|
||||
|
||||
Reference in New Issue
Block a user