@lightdash/common 0.1412.0 → 0.1413.0
Sign up to get free protection for your applications and to get access to all the features.
@@ -20,8 +20,14 @@ export declare const METRICS_EXPLORER_DATE_FORMAT = "YYYY-MM-DD";
|
|
20
20
|
export declare const getDateRangeFromString: (dateRange: [string, string]) => MetricExplorerDateRange;
|
21
21
|
export declare const getGrainForDateRange: (dateRange: [Date, Date]) => ImpelemntedTimeframe;
|
22
22
|
export declare const getMetricExplorerDateRangeFilters: (timeDimensionConfig: TimeDimensionConfig, dateRange: MetricExplorerDateRange) => DateFilter[];
|
23
|
-
export declare const
|
24
|
-
export declare const
|
23
|
+
export declare const MAX_SEGMENT_DIMENSION_UNIQUE_VALUES = 10;
|
24
|
+
export declare const getMetricExplorerDataPoints: (dimension: Dimension, metric: MetricWithAssociatedTimeDimension, metricRows: ResultRow[], segmentDimensionId: string | null) => {
|
25
|
+
dataPoints: Array<MetricExploreDataPoint>;
|
26
|
+
isSegmentDimensionFiltered: boolean;
|
27
|
+
};
|
28
|
+
export declare const getMetricExplorerDataPointsWithCompare: (dimension: Dimension, compareDimension: Dimension, metric: MetricWithAssociatedTimeDimension, metricRows: ResultRow[], compareMetricRows: ResultRow[], query: MetricExplorerQuery) => {
|
29
|
+
dataPoints: Array<MetricExploreDataPoint>;
|
30
|
+
};
|
25
31
|
/**
|
26
32
|
* Get the date range for a given time interval, based on the current date and the time interval
|
27
33
|
* Time grain Year: -> past 5 years (i.e. 5 completed years + this uncompleted year)
|
@@ -46,4 +52,6 @@ export declare const getDefaultTimeDimension: (metric: CompiledMetric, table?: C
|
|
46
52
|
export declare const getAvailableTimeDimensionsFromTables: (tables: Record<string, CompiledTable>) => (CompiledDimension & {
|
47
53
|
type: DimensionType.DATE | DimensionType.TIMESTAMP;
|
48
54
|
})[];
|
55
|
+
export declare const getAvailableSegmentDimensions: (dimensions: Dimension[]) => CompiledDimension[];
|
56
|
+
export declare const getAvailableCompareMetrics: (metrics: MetricWithAssociatedTimeDimension[]) => MetricWithAssociatedTimeDimension[];
|
49
57
|
export {};
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.getAvailableTimeDimensionsFromTables = exports.getDefaultTimeDimension = exports.getFirstAvailableTimeDimension = exports.DEFAULT_METRICS_EXPLORER_TIME_INTERVAL = exports.getDefaultDateRangeForMetricTotal = exports.getDefaultDateRangeFromInterval = exports.getMetricExplorerDataPointsWithCompare = exports.getMetricExplorerDataPoints = exports.getMetricExplorerDateRangeFilters = exports.getGrainForDateRange = exports.getDateRangeFromString = exports.METRICS_EXPLORER_DATE_FORMAT = exports.getDateCalcUtils = exports.getFieldIdForDateDimension = exports.assertUnimplementedTimeframe = void 0;
|
3
|
+
exports.getAvailableCompareMetrics = exports.getAvailableSegmentDimensions = exports.getAvailableTimeDimensionsFromTables = exports.getDefaultTimeDimension = exports.getFirstAvailableTimeDimension = exports.DEFAULT_METRICS_EXPLORER_TIME_INTERVAL = exports.getDefaultDateRangeForMetricTotal = exports.getDefaultDateRangeFromInterval = exports.getMetricExplorerDataPointsWithCompare = exports.getMetricExplorerDataPoints = exports.MAX_SEGMENT_DIMENSION_UNIQUE_VALUES = exports.getMetricExplorerDateRangeFilters = exports.getGrainForDateRange = exports.getDateRangeFromString = exports.METRICS_EXPLORER_DATE_FORMAT = exports.getDateCalcUtils = exports.getFieldIdForDateDimension = exports.assertUnimplementedTimeframe = void 0;
|
4
4
|
const tslib_1 = require("tslib");
|
5
5
|
const dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
6
6
|
const lodash_1 = require("lodash");
|
@@ -136,11 +136,22 @@ const parseDimensionValue = (value) => {
|
|
136
136
|
return null;
|
137
137
|
return String(value);
|
138
138
|
};
|
139
|
+
exports.MAX_SEGMENT_DIMENSION_UNIQUE_VALUES = 10;
|
139
140
|
const getMetricExplorerDataPoints = (dimension, metric, metricRows, segmentDimensionId) => {
|
140
141
|
const dimensionId = (0, item_1.getItemId)(dimension);
|
141
142
|
const metricId = (0, item_1.getItemId)(metric);
|
142
|
-
|
143
|
-
|
143
|
+
let filteredMetricRows = metricRows;
|
144
|
+
let isSegmentDimensionFiltered = false;
|
145
|
+
if (segmentDimensionId) {
|
146
|
+
const countUniqueValues = new Set(metricRows.map((row) => row[segmentDimensionId]?.value.raw)).size;
|
147
|
+
if (countUniqueValues > exports.MAX_SEGMENT_DIMENSION_UNIQUE_VALUES) {
|
148
|
+
isSegmentDimensionFiltered = true;
|
149
|
+
const first10Values = Array.from(new Set(metricRows.map((row) => row[segmentDimensionId]?.value.raw))).slice(0, exports.MAX_SEGMENT_DIMENSION_UNIQUE_VALUES);
|
150
|
+
filteredMetricRows = metricRows.filter((row) => first10Values.includes(row[segmentDimensionId]?.value.raw));
|
151
|
+
}
|
152
|
+
}
|
153
|
+
const groupByMetricRows = (0, lodash_1.groupBy)(filteredMetricRows, (row) => new Date(String(row[dimensionId].value.raw)).toISOString());
|
154
|
+
const dataPoints = Object.entries(groupByMetricRows).flatMap(([date, rows]) => rows.map((row) => {
|
144
155
|
const segmentValue = segmentDimensionId
|
145
156
|
? parseDimensionValue(row[segmentDimensionId]?.value.raw)
|
146
157
|
: null;
|
@@ -157,6 +168,10 @@ const getMetricExplorerDataPoints = (dimension, metric, metricRows, segmentDimen
|
|
157
168
|
},
|
158
169
|
};
|
159
170
|
}));
|
171
|
+
return {
|
172
|
+
dataPoints,
|
173
|
+
isSegmentDimensionFiltered,
|
174
|
+
};
|
160
175
|
};
|
161
176
|
exports.getMetricExplorerDataPoints = getMetricExplorerDataPoints;
|
162
177
|
const getMetricExplorerDataPointsWithCompare = (dimension, compareDimension, metric, metricRows, compareMetricRows, query) => {
|
@@ -190,7 +205,7 @@ const getMetricExplorerDataPointsWithCompare = (dimension, compareDimension, met
|
|
190
205
|
else if (query.comparison === metricsExplorer_1.MetricExplorerComparison.PREVIOUS_PERIOD) {
|
191
206
|
comparisonMetricLabel = 'Previous Period';
|
192
207
|
}
|
193
|
-
|
208
|
+
const dataPoints = Array.from(dates).map((date) => ({
|
194
209
|
date: new Date(date),
|
195
210
|
segment: null,
|
196
211
|
metric: {
|
@@ -203,6 +218,7 @@ const getMetricExplorerDataPointsWithCompare = (dimension, compareDimension, met
|
|
203
218
|
label: comparisonMetricLabel,
|
204
219
|
},
|
205
220
|
}));
|
221
|
+
return { dataPoints };
|
206
222
|
};
|
207
223
|
exports.getMetricExplorerDataPointsWithCompare = getMetricExplorerDataPointsWithCompare;
|
208
224
|
/**
|
@@ -305,3 +321,16 @@ const getAvailableTimeDimensionsFromTables = (tables) => Object.values(tables).f
|
|
305
321
|
!!dim.isIntervalBase &&
|
306
322
|
!dim.hidden));
|
307
323
|
exports.getAvailableTimeDimensionsFromTables = getAvailableTimeDimensionsFromTables;
|
324
|
+
const getAvailableSegmentDimensions = (dimensions) => dimensions
|
325
|
+
.filter((d) => !!d)
|
326
|
+
.filter((d) => d.type !== field_1.DimensionType.DATE &&
|
327
|
+
d.type !== field_1.DimensionType.TIMESTAMP &&
|
328
|
+
d.type !== field_1.DimensionType.NUMBER);
|
329
|
+
exports.getAvailableSegmentDimensions = getAvailableSegmentDimensions;
|
330
|
+
const getAvailableCompareMetrics = (metrics) => metrics
|
331
|
+
.filter((metric) => !!metric.timeDimension)
|
332
|
+
.filter((metric) => metric.type !== field_1.MetricType.STRING &&
|
333
|
+
metric.type !== field_1.MetricType.BOOLEAN &&
|
334
|
+
metric.type !== field_1.MetricType.DATE &&
|
335
|
+
metric.type !== field_1.MetricType.TIMESTAMP);
|
336
|
+
exports.getAvailableCompareMetrics = getAvailableCompareMetrics;
|