11local state = require (" codeme.profile.state" )
22local fmt = require (" codeme.profile.formatters" )
33local ui = require (" codeme.ui" )
4+ local helpers = require (" codeme.profile.helpers" )
45
56local M = {}
67
@@ -45,11 +46,11 @@ function M.get_weekday_date(weekday, monday)
4546end
4647
4748function M .render ()
48- local s = state .stats
49+ local globalStats = state .stats
4950 local lines = {}
5051
51- local this_week = s .this_week or {}
52- local last_week = s .last_week or {}
52+ local this_week = globalStats .this_week or {}
53+ local last_week = globalStats .last_week or {}
5354
5455 local week_time = this_week .total_time or 0
5556 local last_week_time = last_week .total_time or 0
@@ -72,7 +73,7 @@ function M.render()
7273 -- Calculate week boundaries
7374 local week_monday , week_sunday , today = M .get_week_boundaries ()
7475
75- local daily_activity = s .daily_activity or {}
76+ local daily_activity = globalStats .daily_activity or {}
7677
7778 table.insert (lines , { { " 📊 Daily Breakdown (Mon-Sun)" , " exgreen" } })
7879 table.insert (lines , {})
@@ -93,32 +94,35 @@ function M.render()
9394 day_stat = { time = 0 , lines = 0 , files = 0 }
9495 end
9596
96- local session_count = this_week .session_count
97+ local session_count = day_stat .session_count or 0
98+ local time_value = day_stat .time or 0
99+ local lines_value = day_stat .lines or 0
100+ local has_activity = time_value > 0 or lines_value > 0 or session_count > 0
97101
98- if day_stat . time > max_day_time then
99- max_day_time = day_stat . time
102+ if time_value > max_day_time then
103+ max_day_time = time_value
100104 max_day_data = {
101105 day_name = day_name ,
102106 date = expected_date ,
103- time = day_stat . time ,
104- lines = day_stat . lines or 0 ,
107+ time = time_value ,
108+ lines = lines_value ,
105109 sessions = session_count ,
106110 }
107111 end
108112
109113 local day_label = day_name :sub (1 , 3 )
110- local date_label = expected_date :sub (6 , 10 ) -- MM-DD format
111- local time_str = fmt .fmt_time (day_stat .time )
112- local lines_str = fmt .fmt_num (day_stat .lines or 0 )
113- local sessions_str = tostring (session_count )
114- local trend_str = day_stat .time > 0 and " ↗" or " -"
114+ local date_str = tostring (expected_date )
115+ local date_label = date_str :sub (6 , 10 ) -- MM-DD
116+
117+ local time_str = has_activity and fmt .fmt_time (time_value ) or " -"
118+ local lines_str = has_activity and fmt .fmt_num (lines_value ) or " -"
119+ local sessions_str = has_activity and tostring (session_count ) or " -"
120+ local trend_str = time_value > 0 and " ↗" or " -"
115121
116- -- Mark today with a star
117122 if expected_date == today then
118123 day_label = day_label .. " ★"
119124 end
120125
121- -- Show "-" for future dates
122126 if expected_date > today then
123127 time_str = " -"
124128 lines_str = " -"
@@ -146,48 +150,45 @@ function M.render()
146150 table.insert (lines , { { " 📌 Week Summary" , " exgreen" } })
147151 table.insert (lines , {})
148152
149- -- ✅ Most Productive Day (from backend records)
150- local records = s .records or {}
151- local most_productive_day = records .most_productive_day or {}
153+ local most_productive_day = globalStats .this_week .most_productive_day or {}
152154
153155 if most_productive_day .time and most_productive_day .time > 0 then
154156 table.insert (lines , {
155157 { " • Most Productive: " , " commentfg" },
156- { most_productive_day .weekday or " Unknown " , " exgreen" },
158+ { most_productive_day .weekday or " " , " exgreen" },
157159 { " , " .. fmt .fmt_date_full (most_productive_day .date or " " ), " commentfg" },
158160 { string.format (" (%s)" , fmt .fmt_time (most_productive_day .time )), " exyellow" },
159161 })
160162
161163 -- Session details
162- if most_productive_day .sessions and most_productive_day .sessions > 0 then
164+ if most_productive_day .session_count and most_productive_day .session_count > 0 then
163165 table.insert (lines , {
164166 { " ↳ Sessions: " , " commentfg" },
165- { tostring (most_productive_day .sessions ), " exgreen" },
167+ { tostring (most_productive_day .session_count ), " exgreen" },
166168 { string.format (" , %s lines" , fmt .fmt_num (most_productive_day .lines or 0 )), " commentfg" },
167169 })
168170 end
169171
170- -- Top languages
171- if most_productive_day .languages and # most_productive_day .languages > 0 then
172- local languages_result = table.concat (most_productive_day .languages , " , " )
173- table.insert (lines , {
174- { " ↳ Languages: " , " commentfg" },
175- { languages_result , " exgreen" },
176- })
177- end
178-
179172 -- Main projects
180173 if most_productive_day .projects and # most_productive_day .projects > 0 then
181- local projects_result = table.concat (most_productive_day .projects , " , " )
174+ local projects_result = helpers . top_items (most_productive_day .projects , 3 )
182175 table.insert (lines , {
183176 { " ↳ Projects: " , " commentfg" },
184177 { projects_result , " exyellow" },
185178 })
186179 end
187180
181+ -- Top languages
182+ if most_productive_day .languages and # most_productive_day .languages > 0 then
183+ local languages_result = helpers .top_items (most_productive_day .languages , 5 )
184+ table.insert (lines , {
185+ { " ↳ Languages: " , " commentfg" },
186+ { languages_result , " exgreen" },
187+ })
188+ end
189+
188190 table.insert (lines , {})
189191 elseif max_day_data and max_day_time > 0 then
190- -- Fallback to calculated data
191192 table.insert (lines , {
192193 { " • Most Productive: " , " commentfg" },
193194 { max_day_data .day_name , " exgreen" },
@@ -287,7 +288,7 @@ function M.render()
287288 end
288289
289290 -- ✅ Productivity Trend (from backend)
290- local productivity_trend = s .productivity_trend or " "
291+ local productivity_trend = globalStats .productivity_trend or " "
291292 if productivity_trend ~= " " then
292293 local trend_text
293294 local trend_color
@@ -312,7 +313,7 @@ function M.render()
312313 table.insert (lines , {})
313314
314315 -- ✅ Heatmap (from backend weekly_heatmap)
315- local hm = s .weekly_heatmap
316+ local hm = globalStats .weekly_heatmap
316317 if hm and # hm > 0 then
317318 table.insert (lines , { { " 📅 Activity Heatmap" , " exgreen" } })
318319 table.insert (lines , {})
0 commit comments