File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -70,3 +70,33 @@ export function createCategoryData(
7070 final : normalizeAllocations ( rawFinalAllocations ) ,
7171 } ;
7272}
73+
74+ export function createSectionData (
75+ data : ChartSection [ ]
76+ ) : { current : Allocations ; final : Allocations } {
77+ if ( ! data . length ) return { current : { } , final : { } } ;
78+ const rawCurrentAllocations : Allocations = { } ;
79+ const rawFinalAllocations : Allocations = { } ;
80+ const timestampNow : number = unixTimestampNow ( ) ;
81+
82+ data . forEach ( ( section : ChartSection ) => {
83+ const s = section ;
84+ if ( ! s ) return ;
85+ const currentEntryIndex = s . data . timestamps . findIndex (
86+ ( t : number ) => timestampNow - RESOLUTION_SECONDS < t && t < timestampNow
87+ ) ;
88+ const finalEntryIndex = s . data . unlocked . length - 1 ;
89+ const current =
90+ s . data . unlocked [
91+ currentEntryIndex == - 1 ? finalEntryIndex : currentEntryIndex
92+ ] ;
93+ const final = s . data . unlocked [ finalEntryIndex ] ;
94+ rawCurrentAllocations [ s . section ] = current ;
95+ rawFinalAllocations [ s . section ] = final ;
96+ } ) ;
97+
98+ return {
99+ current : normalizeAllocations ( rawCurrentAllocations ) ,
100+ final : normalizeAllocations ( rawFinalAllocations ) ,
101+ } ;
102+ }
You can’t perform that action at this time.
0 commit comments