export function decodeDeltaEncoding()

in src/static/encoding.ts [31:56]


export function decodeDeltaEncoding(encodedData) {
    const { startEpoch, startVolume, timeMultiplier = TIME_MULTIPLIER, epochs, volumes } = encodedData;

    // Initialize the result array with the first point
    const result = [
        {
            epoch: startEpoch * timeMultiplier,
            volume: startVolume,
            createdAt: parseCreateTime(startEpoch * timeMultiplier)
        }
    ];

    // For each delta pair, calculate the original values
    for (let i = 0; i < epochs.length; i++) {
        const prevPoint = result[result.length - 1];
        const currentEpoch = prevPoint.epoch / timeMultiplier + epochs[i];

        result.push({
            epoch: currentEpoch * timeMultiplier,
            volume: prevPoint.volume + volumes[i],
            createdAt: parseCreateTime(currentEpoch * timeMultiplier)
        });
    }

    return result;
}