async fetchSegmentation()

in resources/perf.webkit.org/public/v3/models/measurement-set.js [192:236]


    async fetchSegmentation(segmentationName, parameters, configType, includeOutliers, extendToFuture)
    {
        let cacheMap = this._segmentationCache.get(configType);
        if (!cacheMap) {
            cacheMap = new WeakMap;
            this._segmentationCache.set(configType, cacheMap);
        }

        const timeSeries = new TimeSeries;
        const idMap = {};
        const promises = [];
        for (const cluster of this._sortedClusters) {
            const clusterStart = timeSeries.length();
            cluster.addToSeries(timeSeries, configType, includeOutliers, idMap);
            const clusterEnd = timeSeries.length();
            promises.push(this._cachedClusterSegmentation(segmentationName, parameters, cacheMap,
                cluster, timeSeries, clusterStart, clusterEnd, idMap));
        }
        if (!timeSeries.length())
            return Promise.resolve(null);

        const clusterSegmentations = await Promise.all(promises);

        const segmentationSeries = [];
        const addSegmentMergingIdenticalSegments = (startingPoint, endingPoint) => {
            const value = Statistics.mean(timeSeries.valuesBetweenRange(startingPoint.seriesIndex, endingPoint.seriesIndex));
            if (!segmentationSeries.length || value !== segmentationSeries[segmentationSeries.length - 1].value) {
                segmentationSeries.push({value: value, time: startingPoint.time, seriesIndex: startingPoint.seriesIndex, interval: function () { return null; }});
                segmentationSeries.push({value: value, time: endingPoint.time, seriesIndex: endingPoint.seriesIndex, interval: function () { return null; }});
            } else
                segmentationSeries[segmentationSeries.length - 1].seriesIndex = endingPoint.seriesIndex;
        };

        let startingIndex = 0;
        for (const segmentation of clusterSegmentations) {
            for (const endingIndex of segmentation) {
                addSegmentMergingIdenticalSegments(timeSeries.findPointByIndex(startingIndex), timeSeries.findPointByIndex(endingIndex));
                startingIndex = endingIndex;
            }
        }
        if (extendToFuture)
            timeSeries.extendToFuture();
        addSegmentMergingIdenticalSegments(timeSeries.findPointByIndex(startingIndex), timeSeries.lastPoint());
        return segmentationSeries;
    }