@@ -111,12 +111,27 @@ export default defineComponent({
111111 try {
112112 this .isLoading = true ;
113113 console .log (' Fetching activity records using getter...' );
114+
114115 // Ensure the getter is called safely with proper error handling
115- const result = await this .activityRecordsGetter ();
116+ let result = await this .activityRecordsGetter ();
116117
118+ // Handle the result - ensure it's an array of activity records
117119 if (Array .isArray (result )) {
118- this .localActivityRecords = result ;
119- console .log (' Received activity records:' , this .localActivityRecords .length );
120+ // Filter out records with invalid timestamps before processing
121+ this .localActivityRecords = result .filter (record => {
122+ if (! record || ! record .timeStamp ) return false ;
123+
124+ // Basic validation check for timestamps
125+ try {
126+ const m = moment (record .timeStamp );
127+ return m .isValid () && m .year () > 2000 && m .year () < 2100 ;
128+ } catch (e ) {
129+ return false ;
130+ }
131+ });
132+
133+ console .log (` Received ${result .length } records, ${this .localActivityRecords .length } valid after filtering ` );
134+
120135 // Process the loaded records
121136 this .processRecords ();
122137 this .createWeeksData ();
@@ -153,34 +168,70 @@ export default defineComponent({
153168 return ;
154169 }
155170
156- records .forEach ((record ) => {
157- if (! record || typeof record !== ' object' ) {
158- console .warn (' Invalid record:' , record );
159- return ;
160- }
171+ // Sample logging of a few records to understand structure without flooding console
172+ const uniqueDates = new Set <string >();
173+ const dateDistribution: Record <string , number > = {};
174+ let validCount = 0 ;
175+ let invalidCount = 0 ;
176+
177+ for (let i = 0 ; i < records .length ; i ++ ) {
178+ const record = records [i ];
161179
162- if (! record .timeStamp ) {
163- console . warn ( ' Record missing timeStamp: ' , record ) ;
164- return ;
180+ if (! record || typeof record !== ' object ' || ! record .timeStamp ) {
181+ invalidCount ++ ;
182+ continue ;
165183 }
166184
167- // Make sure timeStamp is properly handled
168- let date;
169185 try {
170- // Try to parse the timestamp
171- const m = moment (record .timeStamp );
172- if (m .isValid ()) {
173- date = m .format (' YYYY-MM-DD' );
174- data [date ] = (data [date ] || 0 ) + 1 ;
186+ // Attempt to normalize the timestamp
187+ let normalizedDate: string ;
188+
189+ if (typeof record .timeStamp === ' string' ) {
190+ // For ISO strings, parse directly with moment
191+ normalizedDate = moment (record .timeStamp ).format (' YYYY-MM-DD' );
192+ } else if (typeof record .timeStamp === ' number' ) {
193+ // For numeric timestamps, use Date constructor then moment
194+ normalizedDate = moment (new Date (record .timeStamp )).format (' YYYY-MM-DD' );
195+ } else if (typeof record .timeStamp === ' object' ) {
196+ // For objects (like Moment), try toString() or direct parsing
197+ if (typeof record .timeStamp .format === ' function' ) {
198+ // It's likely a Moment object
199+ normalizedDate = record .timeStamp .format (' YYYY-MM-DD' );
200+ } else if (record .timeStamp instanceof Date ) {
201+ normalizedDate = moment (record .timeStamp ).format (' YYYY-MM-DD' );
202+ } else {
203+ // Try to parse it as a string representation
204+ normalizedDate = moment (String (record .timeStamp )).format (' YYYY-MM-DD' );
205+ }
206+ } else {
207+ // Unhandled type
208+ invalidCount ++ ;
209+ continue ;
210+ }
211+
212+ // Verify the date is valid before using it
213+ if (moment (normalizedDate , ' YYYY-MM-DD' , true ).isValid ()) {
214+ data [normalizedDate ] = (data [normalizedDate ] || 0 ) + 1 ;
215+ uniqueDates .add (normalizedDate );
216+
217+ // Track distribution by month for debugging
218+ const month = normalizedDate .substring (0 , 7 ); // YYYY-MM
219+ dateDistribution [month ] = (dateDistribution [month ] || 0 ) + 1 ;
220+
221+ validCount ++ ;
175222 } else {
176- console . warn ( ' Invalid date from record: ' , record ) ;
223+ invalidCount ++ ;
177224 }
178225 } catch (e ) {
179- console . error ( ' Error processing record date: ' , e , record ) ;
226+ invalidCount ++ ;
180227 }
181- });
228+ }
229+
230+ // Log summary statistics
231+ console .log (` Processed ${validCount } valid dates, ${invalidCount } invalid dates ` );
232+ console .log (` Found ${uniqueDates .size } unique dates ` );
233+ console .log (' Date distribution by month:' , dateDistribution );
182234
183- console .log (' Processed heatmap data:' , Object .keys (data ).length , ' unique dates' );
184235 this .heatmapData = data ;
185236 },
186237
@@ -194,7 +245,17 @@ export default defineComponent({
194245 const day = start .clone ().startOf (' week' );
195246
196247 console .log (' Creating weeks data from' , start .format (' YYYY-MM-DD' ), ' to' , end .format (' YYYY-MM-DD' ));
248+
249+ // Ensure we have data to display
250+ if (Object .keys (this .heatmapData ).length === 0 ) {
251+ console .log (' No heatmap data available to display' );
252+ }
197253
254+ // For debugging, log some sample dates from the heatmap data
255+ const sampleDates = Object .keys (this .heatmapData ).slice (0 , 5 );
256+ console .log (' Sample dates in heatmap data:' , sampleDates );
257+
258+ // Build the week data structure
198259 while (day .isSameOrBefore (end )) {
199260 const weekData: DayData [] = [];
200261 for (let i = 0 ; i < 7 ; i ++ ) {
@@ -215,8 +276,17 @@ export default defineComponent({
215276 }
216277
217278 console .log (' Weeks data created, maxInRange:' , this .maxInRange );
218- console .log (' First week sample:' , this .weeks [0 ]);
219- console .log (' Last week sample:' , this .weeks [this .weeks .length - 1 ]);
279+
280+ // Calculate summary stats for display
281+ let totalDaysWithActivity = 0 ;
282+ let totalActivity = 0 ;
283+
284+ Object .values (this .heatmapData ).forEach (count => {
285+ totalDaysWithActivity ++ ;
286+ totalActivity += count ;
287+ });
288+
289+ console .log (` Activity summary: ${totalActivity } activities across ${totalDaysWithActivity } days ` );
220290 },
221291
222292 getColor(count : number ): string {
0 commit comments