Skip to content

Commit

Permalink
Merge branch 'migrate-to-react' into feat/AN-4043_setup-ci-on-every-push
Browse files Browse the repository at this point in the history
  • Loading branch information
MGJamJam authored Apr 17, 2024
2 parents fb23952 + 894c591 commit e24bb41
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 24 deletions.
3 changes: 2 additions & 1 deletion bitmovin-analytics-datasource/src/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { catchError, lastValueFrom, map, Observable, of } from 'rxjs';

import { MixedDataRowList, MyDataSourceOptions, MyQuery, NumberDataRowList } from './types';
import { transformGroupedTimeSeriesData, transformSimpleTimeSeries, transformTableData } from './utils/dataUtils';
import { QueryInterval } from './utils/intervalUtils';

type AnalyticsQuery = {
filters: Array<{ name: string; operator: string; value: number }>;
Expand All @@ -20,7 +21,7 @@ type AnalyticsQuery = {
start: Date;
end: Date;
licenseKey: string;
interval?: string;
interval?: QueryInterval;
};

export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
Expand Down
9 changes: 0 additions & 9 deletions bitmovin-analytics-datasource/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@ export interface MyDataSourceOptions extends DataSourceJsonData {
adAnalytics?: boolean;
}

export enum QUERY_INTERVAL {
SECOND = 'SECOND',
MINUTE = 'MINUTE',
HOUR = 'HOUR',
DAY = 'DAY',
MONTH = 'MONTH',
AUTO = 'AUTO',
}

export type MixedDataRow = Array<string | number>;
export type MixedDataRowList = MixedDataRow[];

Expand Down
8 changes: 4 additions & 4 deletions bitmovin-analytics-datasource/src/utils/dataUtils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { differenceWith, sortBy, zip } from 'lodash';
import { intervalToMilliseconds } from './intervalUtils';
import { intervalToMilliseconds, QueryInterval } from './intervalUtils';
import { Field, FieldType } from '@grafana/data';
import { MixedDataRow, MixedDataRowList, NumberDataRow, NumberDataRowList } from '../types';

Expand All @@ -16,7 +16,7 @@ export function padAndSortTimeSeries(
data: MixedDataRowList,
startTimestamp: number,
endTimestamp: number,
interval: string
interval: QueryInterval
): MixedDataRowList {
if (data.length === 0) {
return [];
Expand Down Expand Up @@ -66,7 +66,7 @@ export function transformGroupedTimeSeriesData(
dataRows: MixedDataRowList,
startTimestamp: number,
endTimestamp: number,
interval: string
interval: QueryInterval
): Array<Partial<Field>> {
if (dataRows.length === 0) {
return [];
Expand Down Expand Up @@ -129,7 +129,7 @@ export function transformSimpleTimeSeries(
columnName: string,
startTimestamp: number,
endTimestamp: number,
interval: string
interval: QueryInterval
): Array<Partial<Field>> {
if (dataRows.length === 0) {
return [];
Expand Down
16 changes: 6 additions & 10 deletions bitmovin-analytics-datasource/src/utils/intervalUtils.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import { QUERY_INTERVAL } from '../types';
export type QueryInterval = 'MINUTE' | 'HOUR' | 'DAY';

/**
* Get corresponding interval in milliseconds.
*
* @param {String} interval The interval
* @param {QueryInterval} interval The interval
* @returns {number} Interval in milliseconds or -1 if unknown.
*/
export const intervalToMilliseconds = (interval: string): number => {
export const intervalToMilliseconds = (interval: QueryInterval): number => {
switch (interval) {
case QUERY_INTERVAL.SECOND:
return 1000;
case QUERY_INTERVAL.MINUTE:
case 'MINUTE':
return 1000 * 60;
case QUERY_INTERVAL.HOUR:
case 'HOUR':
return 1000 * 60 * 60;
case QUERY_INTERVAL.DAY:
case 'DAY':
return 1000 * 60 * 60 * 24;
case QUERY_INTERVAL.MONTH:
return 1000 * 60 * 60 * 24 * 30;
default:
return -1;
}
Expand Down

0 comments on commit e24bb41

Please sign in to comment.