@@ -90,38 +90,17 @@ def make_list(
9090 :returns: The string representation of the list.
9191 """
9292 if data is not None :
93- names = (
94- [value for item in data for key , value in item .items () if key == "name" ]
95- if names is None
96- else names
97- )
98- texts = (
99- [value for item in data for key , value in item .items () if key == "text" ]
100- if texts is None
101- else texts
102- )
103- percents = (
104- [value for item in data for key , value in item .items () if key == "percent" ]
105- if percents is None
106- else percents
107- )
93+ names = [value for item in data for key , value in item .items () if key == "name" ] if names is None else names
94+ texts = [value for item in data for key , value in item .items () if key == "text" ] if texts is None else texts
95+ percents = [value for item in data for key , value in item .items () if key == "percent" ] if percents is None else percents
10896
10997 data = list (zip (names , texts , percents ))
110- top_data = (
111- sorted (data [:top_num ], key = lambda record : record [2 ], reverse = True )
112- if sort
113- else data [:top_num ]
114- )
115- data_list = [
116- f"{ n [:25 ]} { ' ' * (25 - len (n ))} { t } { ' ' * (20 - len (t ))} { make_graph (p )} { p :05.2f} % "
117- for n , t , p in top_data
118- ]
98+ top_data = sorted (data [:top_num ], key = lambda record : record [2 ], reverse = True ) if sort else data [:top_num ]
99+ 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 ]
119100 return "\n " .join (data_list )
120101
121102
122- async def make_commit_day_time_list (
123- time_zone : str , repositories : Dict , commit_dates : Dict
124- ) -> str :
103+ async def make_commit_day_time_list (time_zone : str , repositories : Dict , commit_dates : Dict ) -> str :
125104 """
126105 Calculate commit-related info, how many commits were made, and at what time of day and day of week.
127106
@@ -132,19 +111,13 @@ async def make_commit_day_time_list(
132111 """
133112 stats = str ()
134113 day_times = [0 ] * 4 # 0 - 6, 6 - 12, 12 - 18, 18 - 24
135- week_days = [
136- 0
137- ] * 7 # Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
114+ week_days = [0 ] * 7 # Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
138115
139116 for repository in repositories :
140117 if repository ["name" ] not in commit_dates .keys ():
141118 continue
142119
143- for committed_date in [
144- commit_date
145- for branch in commit_dates [repository ["name" ]].values ()
146- for commit_date in branch .values ()
147- ]:
120+ for committed_date in [commit_date for branch in commit_dates [repository ["name" ]].values () for commit_date in branch .values ()]:
148121 local_date = datetime .strptime (committed_date , "%Y-%m-%dT%H:%M:%SZ" )
149122 date = local_date .replace (tzinfo = utc ).astimezone (timezone (time_zone ))
150123
@@ -156,33 +129,17 @@ async def make_commit_day_time_list(
156129 day_times = day_times [1 :] + day_times [:1 ]
157130
158131 if EM .SHOW_COMMIT :
159- dt_names = [
160- f"{ DAY_TIME_EMOJI [i ]} { FM .t (DAY_TIME_NAMES [i ])} "
161- for i in range (len (day_times ))
162- ]
132+ dt_names = [f"{ DAY_TIME_EMOJI [i ]} { FM .t (DAY_TIME_NAMES [i ])} " for i in range (len (day_times ))]
163133 dt_texts = [f"{ day_time } commits" for day_time in day_times ]
164- dt_percents = [
165- 0 if sum_day == 0 else round ((day_time / sum_day ) * 100 , 2 )
166- for day_time in day_times
167- ]
168- title = (
169- FM .t ("I am an Early" )
170- if sum (day_times [0 :2 ]) >= sum (day_times [2 :4 ])
171- else FM .t ("I am a Night" )
172- )
134+ dt_percents = [0 if sum_day == 0 else round ((day_time / sum_day ) * 100 , 2 ) for day_time in day_times ]
135+ title = FM .t ("I am an Early" ) if sum (day_times [0 :2 ]) >= sum (day_times [2 :4 ]) else FM .t ("I am a Night" )
173136 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 "
174137
175138 if EM .SHOW_DAYS_OF_WEEK :
176139 wd_names = [FM .t (week_day ) for week_day in WEEK_DAY_NAMES ]
177140 wd_texts = [f"{ week_day } commits" for week_day in week_days ]
178- wd_percents = [
179- 0 if sum_week == 0 else round ((week_day / sum_week ) * 100 , 2 )
180- for week_day in week_days
181- ]
182- title = (
183- FM .t ("I am Most Productive on" )
184- % wd_names [wd_percents .index (max (wd_percents ))]
185- )
141+ wd_percents = [0 if sum_week == 0 else round ((week_day / sum_week ) * 100 , 2 ) for week_day in week_days ]
142+ title = FM .t ("I am Most Productive on" ) % wd_names [wd_percents .index (max (wd_percents ))]
186143 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 "
187144
188145 return stats
@@ -196,30 +153,16 @@ def make_language_per_repo_list(repositories: Dict) -> str:
196153 :returns: string representation of statistics.
197154 """
198155 language_count = dict ()
199- repos_with_language = [
200- repo for repo in repositories if repo ["primaryLanguage" ] is not None
201- ]
156+ repos_with_language = [repo for repo in repositories if repo ["primaryLanguage" ] is not None ]
202157 for repo in repos_with_language :
203158 language = repo ["primaryLanguage" ]["name" ]
204159 language_count [language ] = language_count .get (language , {"count" : 0 })
205160 language_count [language ]["count" ] += 1
206161
207162 names = list (language_count .keys ())
208- texts = [
209- f"{ language_count [lang ]['count' ]} { 'repo' if language_count [lang ]['count' ] == 1 else 'repos' } "
210- for lang in names
211- ]
212- percents = [
213- round (language_count [lang ]["count" ] / len (repos_with_language ) * 100 , 2 )
214- for lang in names
215- ]
216-
217- top_language = max (
218- list (language_count .keys ()), key = lambda x : language_count [x ]["count" ]
219- )
220- title = (
221- f"**{ FM .t ('I Mostly Code in' ) % top_language } ** \n \n "
222- if len (repos_with_language ) > 0
223- else ""
224- )
163+ texts = [f"{ language_count [lang ]['count' ]} { 'repo' if language_count [lang ]['count' ] == 1 else 'repos' } " for lang in names ]
164+ percents = [round (language_count [lang ]["count" ] / len (repos_with_language ) * 100 , 2 ) for lang in names ]
165+
166+ top_language = max (list (language_count .keys ()), key = lambda x : language_count [x ]["count" ])
167+ title = f"**{ FM .t ('I Mostly Code in' ) % top_language } ** \n \n " if len (repos_with_language ) > 0 else ""
225168 return f"{ title } ```text\n { make_list (names = names , texts = texts , percents = percents )} \n ```\n \n "
0 commit comments