@@ -66,65 +66,6 @@ function mergeDailyPoints(points: DailyRawPoint[]): DailyRawPoint[] {
6666 . map ( ( [ day , value ] ) => ( { day, value } ) )
6767}
6868
69- export function buildDailyEvolutionFromDaily ( daily : DailyRawPoint [ ] ) : DailyDataPoint [ ] {
70- return daily
71- . slice ( )
72- . sort ( ( a , b ) => a . day . localeCompare ( b . day ) )
73- . map ( item => {
74- const dayDate = parseIsoDate ( item . day )
75- const timestamp = dayDate . getTime ( )
76-
77- return { day : item . day , value : item . value , timestamp }
78- } )
79- }
80-
81- export function buildRollingWeeklyEvolutionFromDaily (
82- daily : DailyRawPoint [ ] ,
83- rangeStartIso : string ,
84- rangeEndIso : string ,
85- ) : WeeklyDataPoint [ ] {
86- const sorted = daily . slice ( ) . sort ( ( a , b ) => a . day . localeCompare ( b . day ) )
87- const rangeStartDate = parseIsoDate ( rangeStartIso )
88- const rangeEndDate = parseIsoDate ( rangeEndIso )
89-
90- const groupedByIndex = new Map < number , number > ( )
91-
92- for ( const item of sorted ) {
93- const itemDate = parseIsoDate ( item . day )
94- const dayOffset = Math . floor ( ( itemDate . getTime ( ) - rangeStartDate . getTime ( ) ) / 86400000 )
95- if ( dayOffset < 0 ) continue
96-
97- const weekIndex = Math . floor ( dayOffset / 7 )
98- groupedByIndex . set ( weekIndex , ( groupedByIndex . get ( weekIndex ) ?? 0 ) + item . value )
99- }
100-
101- return Array . from ( groupedByIndex . entries ( ) )
102- . sort ( ( [ a ] , [ b ] ) => a - b )
103- . map ( ( [ weekIndex , value ] ) => {
104- const weekStartDate = addDays ( rangeStartDate , weekIndex * 7 )
105- const weekEndDate = addDays ( weekStartDate , 6 )
106-
107- // Clamp weekEnd to the actual data range end date
108- const clampedWeekEndDate =
109- weekEndDate . getTime ( ) > rangeEndDate . getTime ( ) ? rangeEndDate : weekEndDate
110-
111- const weekStartIso = toIsoDateString ( weekStartDate )
112- const weekEndIso = toIsoDateString ( clampedWeekEndDate )
113-
114- const timestampStart = weekStartDate . getTime ( )
115- const timestampEnd = clampedWeekEndDate . getTime ( )
116-
117- return {
118- value,
119- weekKey : `${ weekStartIso } _${ weekEndIso } ` ,
120- weekStart : weekStartIso ,
121- weekEnd : weekEndIso ,
122- timestampStart,
123- timestampEnd,
124- }
125- } )
126- }
127-
12869/** Catmull-Rom monotone cubic spline — same algorithm as vue-data-ui's smoothPath for OG Images */
12970export function smoothPath ( pts : { x : number ; y : number } [ ] ) : string {
13071 if ( pts . length < 2 ) return '0,0'
@@ -162,42 +103,6 @@ export function smoothPath(pts: { x: number; y: number }[]): string {
162103 return out . join ( ' ' )
163104}
164105
165- export function buildMonthlyEvolutionFromDaily ( daily : DailyRawPoint [ ] ) : MonthlyDataPoint [ ] {
166- const sorted = daily . slice ( ) . sort ( ( a , b ) => a . day . localeCompare ( b . day ) )
167- const valuesByMonth = new Map < string , number > ( )
168-
169- for ( const item of sorted ) {
170- const month = item . day . slice ( 0 , 7 )
171- valuesByMonth . set ( month , ( valuesByMonth . get ( month ) ?? 0 ) + item . value )
172- }
173-
174- return Array . from ( valuesByMonth . entries ( ) )
175- . sort ( ( [ a ] , [ b ] ) => a . localeCompare ( b ) )
176- . map ( ( [ month , value ] ) => {
177- const monthStartDate = parseIsoDate ( `${ month } -01` )
178- const timestamp = monthStartDate . getTime ( )
179- return { month, value, timestamp }
180- } )
181- }
182-
183- export function buildYearlyEvolutionFromDaily ( daily : DailyRawPoint [ ] ) : YearlyDataPoint [ ] {
184- const sorted = daily . slice ( ) . sort ( ( a , b ) => a . day . localeCompare ( b . day ) )
185- const valuesByYear = new Map < string , number > ( )
186-
187- for ( const item of sorted ) {
188- const year = item . day . slice ( 0 , 4 )
189- valuesByYear . set ( year , ( valuesByYear . get ( year ) ?? 0 ) + item . value )
190- }
191-
192- return Array . from ( valuesByYear . entries ( ) )
193- . sort ( ( [ a ] , [ b ] ) => a . localeCompare ( b ) )
194- . map ( ( [ year , value ] ) => {
195- const yearStartDate = parseIsoDate ( `${ year } -01-01` )
196- const timestamp = yearStartDate . getTime ( )
197- return { year, value, timestamp }
198- } )
199- }
200-
201106const npmDailyRangeCache = import . meta. client ? new Map < string , Promise < DailyRawPoint [ ] > > ( ) : null
202107const likesEvolutionCache = import . meta. client ? new Map < string , Promise < DailyRawPoint [ ] > > ( ) : null
203108const contributorsEvolutionCache = import . meta. client
0 commit comments