From 1a07e7ce5f75e8d4fd1407c684f197a510d361f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Petran=C3=ADk?= Date: Thu, 20 Jun 2024 12:37:39 +0200 Subject: [PATCH] Replace enums with const array of string (aggregations, metrics, query (ad) attributes, query filter operators) --- .../src/types/aggregations.ts | 19 +- .../src/types/metric.ts | 21 +- .../src/types/queryAdAttributes.ts | 452 ++++++------------ .../src/types/queryAttributes.ts | 416 ++++++---------- .../src/types/queryFilter.ts | 29 +- .../src/utils/filterUtils.test.ts | 82 +--- .../src/utils/filterUtils.ts | 196 ++++---- 7 files changed, 437 insertions(+), 778 deletions(-) diff --git a/bitmovin-analytics-datasource/src/types/aggregations.ts b/bitmovin-analytics-datasource/src/types/aggregations.ts index 4f98f5e..b69001c 100644 --- a/bitmovin-analytics-datasource/src/types/aggregations.ts +++ b/bitmovin-analytics-datasource/src/types/aggregations.ts @@ -1,15 +1,10 @@ import type { SelectableValue } from '@grafana/data'; -export type Aggregation = 'count' | 'sum' | 'avg' | 'min' | 'max' | 'stddev' | 'percentile' | 'variance' | 'median'; +const AGGREGATIONS = ['count', 'sum', 'avg', 'min', 'max', 'stddev', 'percentile', 'variance', 'median'] as const; -export const SELECTABLE_AGGREGATIONS: Array> = [ - { value: 'count', label: 'Count' }, - { value: 'sum', label: 'Sum' }, - { value: 'avg', label: 'Avg' }, - { value: 'min', label: 'Min' }, - { value: 'max', label: 'Max' }, - { value: 'stddev', label: 'Stddev' }, - { value: 'percentile', label: 'Percentile' }, - { value: 'variance', label: 'Variance' }, - { value: 'median', label: 'Median' }, -]; +export type Aggregation = (typeof AGGREGATIONS)[number]; + +export const SELECTABLE_AGGREGATIONS: Array> = AGGREGATIONS.map((aggregation) => ({ + value: aggregation, + label: aggregation, +})); diff --git a/bitmovin-analytics-datasource/src/types/metric.ts b/bitmovin-analytics-datasource/src/types/metric.ts index 37743ba..9ef61f1 100644 --- a/bitmovin-analytics-datasource/src/types/metric.ts +++ b/bitmovin-analytics-datasource/src/types/metric.ts @@ -1,19 +1,14 @@ import { SelectableValue } from '@grafana/data'; -export enum METRICS { - AVG_CONCURRENTVIEWERS = 'avg-concurrentviewers', - MAX_CONCURRENTVIEWERS = 'max-concurrentviewers', - AVG_DROPPED_FRAMES = 'avg-dropped-frames', -} +const METRICS = ['avg-concurrentviewers', 'max-concurrentviewers', 'avg-dropped-frames'] as const; -export type Metric = (typeof METRICS)[keyof typeof METRICS]; +export type Metric = (typeof METRICS)[number]; -export const SELECTABLE_METRICS: Array> = [ - { value: METRICS.AVG_CONCURRENTVIEWERS, label: 'Avg Concurrent Viewers' }, - { value: METRICS.MAX_CONCURRENTVIEWERS, label: 'Max Concurrent Viewers' }, - { value: METRICS.AVG_DROPPED_FRAMES, label: 'Avg Dropped Frames' }, -]; +export const SELECTABLE_METRICS: Array> = METRICS.map((metric) => ({ + value: metric, + label: metric, +})); -export const isMetric = (value: string): boolean => { - return Object.values(METRICS).includes(value as Metric); +export const isMetric = (value: string): value is Metric => { + return METRICS.includes(value as Metric); }; diff --git a/bitmovin-analytics-datasource/src/types/queryAdAttributes.ts b/bitmovin-analytics-datasource/src/types/queryAdAttributes.ts index 2d2b012..5bfbd76 100644 --- a/bitmovin-analytics-datasource/src/types/queryAdAttributes.ts +++ b/bitmovin-analytics-datasource/src/types/queryAdAttributes.ts @@ -1,301 +1,159 @@ import { SelectableValue } from '@grafana/data'; -export enum QUERY_AD_ATTRIBUTES { - ADVERTISER_NAME = 'ADVERTISER_NAME', - AD_CLICKTHROUGH_URL = 'AD_CLICKTHROUGH_URL', - AD_DESCRIPTION = 'AD_DESCRIPTION', - AD_DURATION = 'AD_DURATION', - AD_FALLBACK_INDEX = 'AD_FALLBACK_INDEX', - AD_ID = 'AD_ID', - AD_ID_PLAYER = 'AD_ID_PLAYER', - AD_IMPRESSION_ID = 'AD_IMPRESSION_ID', - AD_IS_PERSISTENT = 'AD_IS_PERSISTENT', - AD_MODULE = 'AD_MODULE', - AD_OFFSET = 'AD_OFFSET', - AD_PLAYBACK_HEIGHT = 'AD_PLAYBACK_HEIGHT', - AD_PLAYBACK_WIDTH = 'AD_PLAYBACK_WIDTH', - AD_POSITION = 'AD_POSITION', - AD_PRELOAD_OFFSET = 'AD_PRELOAD_OFFSET', - AD_REPLACE_CONTENT_DURATION = 'AD_REPLACE_CONTENT_DURATION', - AD_SCHEDULE_TIME = 'AD_SCHEDULE_TIME', - AD_SKIPPABLE = 'AD_SKIPPABLE', - AD_SKIP_AFTER = 'AD_SKIP_AFTER', - AD_STARTUP_TIME = 'AD_STARTUP_TIME', - AD_SYSTEM = 'AD_SYSTEM', - AD_TAG_PATH = 'AD_TAG_PATH', - AD_TAG_SERVER = 'AD_TAG_SERVER', - AD_TAG_TYPE = 'AD_TAG_TYPE', - AD_TAG_URL = 'AD_TAG_URL', - AD_TITLE = 'AD_TITLE', - AD_WRAPPER_ADS_COUNT = 'AD_WRAPPER_ADS_COUNT', - ANALYTICS_VERSION = 'ANALYTICS_VERSION', - APIORG_ID = 'APIORG_ID', - APIUSER_ID = 'APIUSER_ID', - API_FRAMEWORK = 'API_FRAMEWORK', - AUDIO_BITRATE = 'AUDIO_BITRATE', - AUTOPLAY = 'AUTOPLAY', - BROWSER = 'BROWSER', - BROWSER_IS_BOT = 'BROWSER_IS_BOT', - BROWSER_VERSION_MAJOR = 'BROWSER_VERSION_MAJOR', - BROWSER_VERSION_MINOR = 'BROWSER_VERSION_MINOR', - CDN_PROVIDER = 'CDN_PROVIDER', - CITY = 'CITY', - CLICKED = 'CLICKED', - CLICK_PERCENTAGE = 'CLICK_PERCENTAGE', - CLICK_POSITION = 'CLICK_POSITION', - CLICK_RATE = 'CLICK_RATE', - CLIENT_TIME = 'CLIENT_TIME', - CLOSED = 'CLOSED', - CLOSE_PERCENTAGE = 'CLOSE_PERCENTAGE', - CLOSE_POSITION = 'CLOSE_POSITION', - COMPLETED = 'COMPLETED', - COUNTRY = 'COUNTRY', - CREATIVE_AD_ID = 'CREATIVE_AD_ID', - CREATIVE_ID = 'CREATIVE_ID', - CUSTOM_DATA_10 = 'CUSTOM_DATA_10', - CUSTOM_DATA_11 = 'CUSTOM_DATA_11', - CUSTOM_DATA_12 = 'CUSTOM_DATA_12', - CUSTOM_DATA_13 = 'CUSTOM_DATA_13', - CUSTOM_DATA_14 = 'CUSTOM_DATA_14', - CUSTOM_DATA_15 = 'CUSTOM_DATA_15', - CUSTOM_DATA_16 = 'CUSTOM_DATA_16', - CUSTOM_DATA_17 = 'CUSTOM_DATA_17', - CUSTOM_DATA_18 = 'CUSTOM_DATA_18', - CUSTOM_DATA_19 = 'CUSTOM_DATA_19', - CUSTOM_DATA_1 = 'CUSTOM_DATA_1', - CUSTOM_DATA_20 = 'CUSTOM_DATA_20', - CUSTOM_DATA_21 = 'CUSTOM_DATA_21', - CUSTOM_DATA_22 = 'CUSTOM_DATA_22', - CUSTOM_DATA_23 = 'CUSTOM_DATA_23', - CUSTOM_DATA_24 = 'CUSTOM_DATA_24', - CUSTOM_DATA_25 = 'CUSTOM_DATA_25', - CUSTOM_DATA_26 = 'CUSTOM_DATA_26', - CUSTOM_DATA_27 = 'CUSTOM_DATA_27', - CUSTOM_DATA_28 = 'CUSTOM_DATA_28', - CUSTOM_DATA_29 = 'CUSTOM_DATA_29', - CUSTOM_DATA_2 = 'CUSTOM_DATA_2', - CUSTOM_DATA_30 = 'CUSTOM_DATA_30', - CUSTOM_DATA_3 = 'CUSTOM_DATA_3', - CUSTOM_DATA_4 = 'CUSTOM_DATA_4', - CUSTOM_DATA_5 = 'CUSTOM_DATA_5', - CUSTOM_DATA_6 = 'CUSTOM_DATA_6', - CUSTOM_DATA_7 = 'CUSTOM_DATA_7', - CUSTOM_DATA_8 = 'CUSTOM_DATA_8', - CUSTOM_DATA_9 = 'CUSTOM_DATA_9', - CUSTOM_USER_ID = 'CUSTOM_USER_ID', - DAY = 'DAY', - DAYPART = 'DAYPART', - DEAL_ID = 'DEAL_ID', - DEVICE_TYPE = 'DEVICE_TYPE', - DOMAIN = 'DOMAIN', - ERROR_CODE = 'ERROR_CODE', - ERROR_MESSAGE = 'ERROR_MESSAGE', - EXPERIMENT_NAME = 'EXPERIMENT_NAME', - HOUR = 'HOUR', - IP_ADDRESS = 'IP_ADDRESS', - ISP = 'ISP', - IS_LINEAR = 'IS_LINEAR', - LANGUAGE = 'LANGUAGE', - LICENSE_KEY = 'LICENSE_KEY', - MANIFEST_DOWNLOAD_TIME = 'MANIFEST_DOWNLOAD_TIME', - MEDIA_PATH = 'MEDIA_PATH', - MEDIA_SERVER = 'MEDIA_SERVER', - MEDIA_URL = 'MEDIA_URL', - MIDPOINT = 'MIDPOINT', - MINUTE = 'MINUTE', - MIN_SUGGESTED_DURATION = 'MIN_SUGGESTED_DURATION', - MONTH = 'MONTH', - OPERATINGSYSTEM = 'OPERATINGSYSTEM', - OPERATINGSYSTEM_VERSION_MAJOR = 'OPERATINGSYSTEM_VERSION_MAJOR', - OPERATINGSYSTEM_VERSION_MINOR = 'OPERATINGSYSTEM_VERSION_MINOR', - PAGE_LOAD_TIME = 'PAGE_LOAD_TIME', - PAGE_LOAD_TYPE = 'PAGE_LOAD_TYPE', - PATH = 'PATH', - PERCENTAGE_IN_VIEWPORT = 'PERCENTAGE_IN_VIEWPORT', - PLATFORM = 'PLATFORM', - PLAYER = 'PLAYER', - PLAYER_KEY = 'PLAYER_KEY', - PLAYER_STARTUPTIME = 'PLAYER_STARTUPTIME', - PLAYER_TECH = 'PLAYER_TECH', - PLAYER_VERSION = 'PLAYER_VERSION', - PLAY_PERCENTAGE = 'PLAY_PERCENTAGE', - QUARTILE_1 = 'QUARTILE_1', - QUARTILE_3 = 'QUARTILE_3', - REGION = 'REGION', - SCREEN_HEIGHT = 'SCREEN_HEIGHT', - SCREEN_WIDTH = 'SCREEN_WIDTH', - SIZE = 'SIZE', - SKIPPED = 'SKIPPED', - SKIP_PERCENTAGE = 'SKIP_PERCENTAGE', - SKIP_POSITION = 'SKIP_POSITION', - STARTED = 'STARTED', - STREAM_FORMAT = 'STREAM_FORMAT', - SURVEY_URL = 'SURVEY_URL', - TIME = 'TIME', - TIME_HOVERED = 'TIME_HOVERED', - TIME_IN_VIEWPORT = 'TIME_IN_VIEWPORT', - TIME_PLAYED = 'TIME_PLAYED', - TIME_TO_FIRST_AD = 'TIME_TO_FIRST_AD', - TIME_UNTIL_HOVER = 'TIME_UNTIL_HOVER', - UNIVERSAL_AD_ID_REGISTRY = 'UNIVERSAL_AD_ID_REGISTRY', - UNIVERSAL_AD_ID_VALUE = 'UNIVERSAL_AD_ID_VALUE', - USER_ID = 'USER_ID', - VIDEO_BITRATE = 'VIDEO_BITRATE', - VIDEO_ID = 'VIDEO_ID', - VIDEO_IMPRESSION_ID = 'VIDEO_IMPRESSION_ID', - VIDEO_TITLE = 'VIDEO_TITLE', - VIDEO_WINDOW_HEIGHT = 'VIDEO_WINDOW_HEIGHT', - VIDEO_WINDOW_WIDTH = 'VIDEO_WINDOW_WIDTH', - YEAR = 'YEAR', -} +const QUERY_AD_ATTRIBUTES = [ + 'ADVERTISER_NAME', + 'AD_CLICKTHROUGH_URL', + 'AD_DESCRIPTION', + 'AD_DURATION', + 'AD_FALLBACK_INDEX', + 'AD_ID', + 'AD_ID_PLAYER', + 'AD_IMPRESSION_ID', + 'AD_IS_PERSISTENT', + 'AD_MODULE', + 'AD_OFFSET', + 'AD_PLAYBACK_HEIGHT', + 'AD_PLAYBACK_WIDTH', + 'AD_POSITION', + 'AD_PRELOAD_OFFSET', + 'AD_REPLACE_CONTENT_DURATION', + 'AD_SCHEDULE_TIME', + 'AD_SKIPPABLE', + 'AD_SKIP_AFTER', + 'AD_STARTUP_TIME', + 'AD_SYSTEM', + 'AD_TAG_PATH', + 'AD_TAG_SERVER', + 'AD_TAG_TYPE', + 'AD_TAG_URL', + 'AD_TITLE', + 'AD_WRAPPER_ADS_COUNT', + 'ANALYTICS_VERSION', + 'APIORG_ID', + 'APIUSER_ID', + 'API_FRAMEWORK', + 'AUDIO_BITRATE', + 'AUTOPLAY', + 'BROWSER', + 'BROWSER_IS_BOT', + 'BROWSER_VERSION_MAJOR', + 'BROWSER_VERSION_MINOR', + 'CDN_PROVIDER', + 'CITY', + 'CLICKED', + 'CLICK_PERCENTAGE', + 'CLICK_POSITION', + 'CLICK_RATE', + 'CLIENT_TIME', + 'CLOSED', + 'CLOSE_PERCENTAGE', + 'CLOSE_POSITION', + 'COMPLETED', + 'COUNTRY', + 'CREATIVE_AD_ID', + 'CREATIVE_ID', + 'CUSTOM_DATA_1', + 'CUSTOM_DATA_10', + 'CUSTOM_DATA_11', + 'CUSTOM_DATA_12', + 'CUSTOM_DATA_13', + 'CUSTOM_DATA_14', + 'CUSTOM_DATA_15', + 'CUSTOM_DATA_16', + 'CUSTOM_DATA_17', + 'CUSTOM_DATA_18', + 'CUSTOM_DATA_19', + 'CUSTOM_DATA_2', + 'CUSTOM_DATA_20', + 'CUSTOM_DATA_21', + 'CUSTOM_DATA_22', + 'CUSTOM_DATA_23', + 'CUSTOM_DATA_24', + 'CUSTOM_DATA_25', + 'CUSTOM_DATA_26', + 'CUSTOM_DATA_27', + 'CUSTOM_DATA_28', + 'CUSTOM_DATA_29', + 'CUSTOM_DATA_3', + 'CUSTOM_DATA_30', + 'CUSTOM_DATA_4', + 'CUSTOM_DATA_5', + 'CUSTOM_DATA_6', + 'CUSTOM_DATA_7', + 'CUSTOM_DATA_8', + 'CUSTOM_DATA_9', + 'CUSTOM_USER_ID', + 'DAY', + 'DAYPART', + 'DEAL_ID', + 'DEVICE_TYPE', + 'DOMAIN', + 'ERROR_CODE', + 'ERROR_MESSAGE', + 'EXPERIMENT_NAME', + 'HOUR', + 'IP_ADDRESS', + 'ISP', + 'IS_LINEAR', + 'LANGUAGE', + 'LICENSE_KEY', + 'MANIFEST_DOWNLOAD_TIME', + 'MEDIA_PATH', + 'MEDIA_SERVER', + 'MEDIA_URL', + 'MIDPOINT', + 'MINUTE', + 'MIN_SUGGESTED_DURATION', + 'MONTH', + 'OPERATINGSYSTEM', + 'OPERATINGSYSTEM_VERSION_MAJOR', + 'OPERATINGSYSTEM_VERSION_MINOR', + 'PAGE_LOAD_TIME', + 'PAGE_LOAD_TYPE', + 'PATH', + 'PERCENTAGE_IN_VIEWPORT', + 'PLATFORM', + 'PLAYER', + 'PLAYER_KEY', + 'PLAYER_STARTUPTIME', + 'PLAYER_TECH', + 'PLAYER_VERSION', + 'PLAY_PERCENTAGE', + 'QUARTILE_1', + 'QUARTILE_3', + 'REGION', + 'SCREEN_HEIGHT', + 'SCREEN_WIDTH', + 'SIZE', + 'SKIPPED', + 'SKIP_PERCENTAGE', + 'SKIP_POSITION', + 'STARTED', + 'STREAM_FORMAT', + 'SURVEY_URL', + 'TIME', + 'TIME_HOVERED', + 'TIME_IN_VIEWPORT', + 'TIME_PLAYED', + 'TIME_TO_FIRST_AD', + 'TIME_UNTIL_HOVER', + 'UNIVERSAL_AD_ID_REGISTRY', + 'UNIVERSAL_AD_ID_VALUE', + 'USER_ID', + 'VIDEO_BITRATE', + 'VIDEO_ID', + 'VIDEO_IMPRESSION_ID', + 'VIDEO_TITLE', + 'VIDEO_WINDOW_HEIGHT', + 'VIDEO_WINDOW_WIDTH', + 'YEAR', +] as const; -export type QueryAdAttribute = keyof typeof QUERY_AD_ATTRIBUTES; +export type QueryAdAttribute = (typeof QUERY_AD_ATTRIBUTES)[number]; -export const SELECTABLE_QUERY_AD_ATTRIBUTES: Array> = [ - { value: QUERY_AD_ATTRIBUTES.ADVERTISER_NAME, label: 'Advertiser Name' }, - { value: QUERY_AD_ATTRIBUTES.AD_CLICKTHROUGH_URL, label: 'Ad Clickthrough Url' }, - { value: QUERY_AD_ATTRIBUTES.AD_DESCRIPTION, label: 'Ad Description' }, - { value: QUERY_AD_ATTRIBUTES.AD_DURATION, label: 'Ad Duration' }, - { value: QUERY_AD_ATTRIBUTES.AD_FALLBACK_INDEX, label: 'Ad Fallback Position' }, - { value: QUERY_AD_ATTRIBUTES.AD_ID, label: 'Ad Id' }, - { value: QUERY_AD_ATTRIBUTES.AD_ID_PLAYER, label: 'Ad Id Player' }, - { value: QUERY_AD_ATTRIBUTES.AD_IMPRESSION_ID, label: 'Ad Impression Id' }, - { value: QUERY_AD_ATTRIBUTES.AD_IS_PERSISTENT, label: 'Ad Is Persistent' }, - { value: QUERY_AD_ATTRIBUTES.AD_MODULE, label: 'Ad Module' }, - { value: QUERY_AD_ATTRIBUTES.AD_OFFSET, label: 'Ad Offset' }, - { value: QUERY_AD_ATTRIBUTES.AD_PLAYBACK_HEIGHT, label: 'Ad Playback Height' }, - { value: QUERY_AD_ATTRIBUTES.AD_PLAYBACK_WIDTH, label: 'Ad Playback Width' }, - { value: QUERY_AD_ATTRIBUTES.AD_POSITION, label: 'Ad Position' }, - { value: QUERY_AD_ATTRIBUTES.AD_PRELOAD_OFFSET, label: 'Ad Preload Offset' }, - { value: QUERY_AD_ATTRIBUTES.AD_REPLACE_CONTENT_DURATION, label: 'Ad Replace Content Duration' }, - { value: QUERY_AD_ATTRIBUTES.AD_SCHEDULE_TIME, label: 'Ad Schedule Time' }, - { value: QUERY_AD_ATTRIBUTES.AD_SKIPPABLE, label: 'Ad Skippable' }, - { value: QUERY_AD_ATTRIBUTES.AD_SKIP_AFTER, label: 'Ad Skip After' }, - { value: QUERY_AD_ATTRIBUTES.AD_STARTUP_TIME, label: 'Ad Startup Time' }, - { value: QUERY_AD_ATTRIBUTES.AD_SYSTEM, label: 'Ad System' }, - { value: QUERY_AD_ATTRIBUTES.AD_TAG_PATH, label: 'Ad Tag Path' }, - { value: QUERY_AD_ATTRIBUTES.AD_TAG_SERVER, label: 'Tag Server' }, - { value: QUERY_AD_ATTRIBUTES.AD_TAG_TYPE, label: 'Tag Type' }, - { value: QUERY_AD_ATTRIBUTES.AD_TAG_URL, label: 'Ad Tag Url' }, - { value: QUERY_AD_ATTRIBUTES.AD_TITLE, label: 'Ad Title' }, - { value: QUERY_AD_ATTRIBUTES.AD_WRAPPER_ADS_COUNT, label: 'Wrapper Position' }, - { value: QUERY_AD_ATTRIBUTES.ANALYTICS_VERSION, label: 'Analytics Version' }, - { value: QUERY_AD_ATTRIBUTES.APIORG_ID, label: 'Api Organization Id' }, - { value: QUERY_AD_ATTRIBUTES.APIUSER_ID, label: 'Api User Id' }, - { value: QUERY_AD_ATTRIBUTES.API_FRAMEWORK, label: 'Api Framework' }, - { value: QUERY_AD_ATTRIBUTES.AUDIO_BITRATE, label: 'Audio Bitrate' }, - { value: QUERY_AD_ATTRIBUTES.AUTOPLAY, label: 'Autoplay' }, - { value: QUERY_AD_ATTRIBUTES.BROWSER, label: 'Browser' }, - { value: QUERY_AD_ATTRIBUTES.BROWSER_IS_BOT, label: 'Is Bot' }, - { value: QUERY_AD_ATTRIBUTES.BROWSER_VERSION_MAJOR, label: 'Browser Version Major' }, - { value: QUERY_AD_ATTRIBUTES.BROWSER_VERSION_MINOR, label: 'Browser Version Minor' }, - { value: QUERY_AD_ATTRIBUTES.CDN_PROVIDER, label: 'Cdn Provider' }, - { value: QUERY_AD_ATTRIBUTES.CITY, label: 'City' }, - { value: QUERY_AD_ATTRIBUTES.CLICKED, label: 'Clicked' }, - { value: QUERY_AD_ATTRIBUTES.CLICK_PERCENTAGE, label: 'Click Percentage' }, - { value: QUERY_AD_ATTRIBUTES.CLICK_POSITION, label: 'Click Position' }, - { value: QUERY_AD_ATTRIBUTES.CLICK_RATE, label: 'Click Rate' }, - { value: QUERY_AD_ATTRIBUTES.CLIENT_TIME, label: 'Client Time' }, - { value: QUERY_AD_ATTRIBUTES.CLOSED, label: 'Closed' }, - { value: QUERY_AD_ATTRIBUTES.CLOSE_PERCENTAGE, label: 'Close Percentage' }, - { value: QUERY_AD_ATTRIBUTES.CLOSE_POSITION, label: 'Close Position' }, - { value: QUERY_AD_ATTRIBUTES.COMPLETED, label: 'Completed' }, - { value: QUERY_AD_ATTRIBUTES.COUNTRY, label: 'Country' }, - { value: QUERY_AD_ATTRIBUTES.CREATIVE_AD_ID, label: 'Creative Ad Id' }, - { value: QUERY_AD_ATTRIBUTES.CREATIVE_ID, label: 'Creative Id' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_10, label: 'Custom Data 10' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_11, label: 'Custom Data 11' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_12, label: 'Custom Data 12' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_13, label: 'Custom Data 13' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_14, label: 'Custom Data 14' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_15, label: 'Custom Data 15' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_16, label: 'Custom Data 16' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_17, label: 'Custom Data 17' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_18, label: 'Custom Data 18' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_19, label: 'Custom Data 19' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_1, label: 'Custom Data 1' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_20, label: 'Custom Data 20' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_21, label: 'Custom Data 21' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_22, label: 'Custom Data 22' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_23, label: 'Custom Data 23' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_24, label: 'Custom Data 24' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_25, label: 'Custom Data 25' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_26, label: 'Custom Data 26' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_27, label: 'Custom Data 27' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_28, label: 'Custom Data 28' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_29, label: 'Custom Data 29' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_2, label: 'Custom Data 2' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_30, label: 'Custom Data 30' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_3, label: 'Custom Data 3' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_4, label: 'Custom Data 4' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_5, label: 'Custom Data 5' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_6, label: 'Custom Data 6' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_7, label: 'Custom Data 7' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_8, label: 'Custom Data 8' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_DATA_9, label: 'Custom Data 9' }, - { value: QUERY_AD_ATTRIBUTES.CUSTOM_USER_ID, label: 'Custom User Id' }, - { value: QUERY_AD_ATTRIBUTES.DAY, label: 'Day' }, - { value: QUERY_AD_ATTRIBUTES.DAYPART, label: 'Daypart' }, - { value: QUERY_AD_ATTRIBUTES.DEAL_ID, label: 'Deal Id' }, - { value: QUERY_AD_ATTRIBUTES.DEVICE_TYPE, label: 'Device Type' }, - { value: QUERY_AD_ATTRIBUTES.DOMAIN, label: 'Domain' }, - { value: QUERY_AD_ATTRIBUTES.ERROR_CODE, label: 'Error Code' }, - { value: QUERY_AD_ATTRIBUTES.ERROR_MESSAGE, label: 'Error Message' }, - { value: QUERY_AD_ATTRIBUTES.EXPERIMENT_NAME, label: 'Experiment Name' }, - { value: QUERY_AD_ATTRIBUTES.HOUR, label: 'Hour' }, - { value: QUERY_AD_ATTRIBUTES.IP_ADDRESS, label: 'Ip Address' }, - { value: QUERY_AD_ATTRIBUTES.ISP, label: 'Internet Service Provider' }, - { value: QUERY_AD_ATTRIBUTES.IS_LINEAR, label: 'Is Linear' }, - { value: QUERY_AD_ATTRIBUTES.LANGUAGE, label: 'Language' }, - { value: QUERY_AD_ATTRIBUTES.LICENSE_KEY, label: 'License Key' }, - { value: QUERY_AD_ATTRIBUTES.MANIFEST_DOWNLOAD_TIME, label: 'Manifest Download Time' }, - { value: QUERY_AD_ATTRIBUTES.MEDIA_PATH, label: 'Media Path' }, - { value: QUERY_AD_ATTRIBUTES.MEDIA_SERVER, label: 'Creative Server' }, - { value: QUERY_AD_ATTRIBUTES.MEDIA_URL, label: 'Media Url' }, - { value: QUERY_AD_ATTRIBUTES.MIDPOINT, label: 'Midpoint' }, - { value: QUERY_AD_ATTRIBUTES.MINUTE, label: 'Minute' }, - { value: QUERY_AD_ATTRIBUTES.MIN_SUGGESTED_DURATION, label: 'Min Suggested Duration' }, - { value: QUERY_AD_ATTRIBUTES.MONTH, label: 'Month' }, - { value: QUERY_AD_ATTRIBUTES.OPERATINGSYSTEM, label: 'Operating System' }, - { value: QUERY_AD_ATTRIBUTES.OPERATINGSYSTEM_VERSION_MAJOR, label: 'Operating System Version Major' }, - { value: QUERY_AD_ATTRIBUTES.OPERATINGSYSTEM_VERSION_MINOR, label: 'Operating System Version Minor' }, - { value: QUERY_AD_ATTRIBUTES.PAGE_LOAD_TIME, label: 'Page Load Time' }, - { value: QUERY_AD_ATTRIBUTES.PAGE_LOAD_TYPE, label: 'Page Load Type' }, - { value: QUERY_AD_ATTRIBUTES.PATH, label: 'Path' }, - { value: QUERY_AD_ATTRIBUTES.PERCENTAGE_IN_VIEWPORT, label: 'Percentage In Viewport' }, - { value: QUERY_AD_ATTRIBUTES.PLATFORM, label: 'Platform' }, - { value: QUERY_AD_ATTRIBUTES.PLAYER, label: 'Player Software' }, - { value: QUERY_AD_ATTRIBUTES.PLAYER_KEY, label: 'Player Key' }, - { value: QUERY_AD_ATTRIBUTES.PLAYER_STARTUPTIME, label: 'Player Startuptime' }, - { value: QUERY_AD_ATTRIBUTES.PLAYER_TECH, label: 'Player Technology' }, - { value: QUERY_AD_ATTRIBUTES.PLAYER_VERSION, label: 'Player Software Version' }, - { value: QUERY_AD_ATTRIBUTES.PLAY_PERCENTAGE, label: 'Play Percentage' }, - { value: QUERY_AD_ATTRIBUTES.QUARTILE_1, label: 'Quartile 1' }, - { value: QUERY_AD_ATTRIBUTES.QUARTILE_3, label: 'Quartile 3' }, - { value: QUERY_AD_ATTRIBUTES.REGION, label: 'Region' }, - { value: QUERY_AD_ATTRIBUTES.SCREEN_HEIGHT, label: 'Screen Height' }, - { value: QUERY_AD_ATTRIBUTES.SCREEN_WIDTH, label: 'Screen Width' }, - { value: QUERY_AD_ATTRIBUTES.SIZE, label: 'Size' }, - { value: QUERY_AD_ATTRIBUTES.SKIPPED, label: 'Skipped' }, - { value: QUERY_AD_ATTRIBUTES.SKIP_PERCENTAGE, label: 'Skip Percentage' }, - { value: QUERY_AD_ATTRIBUTES.SKIP_POSITION, label: 'Skip Position' }, - { value: QUERY_AD_ATTRIBUTES.STARTED, label: 'Started' }, - { value: QUERY_AD_ATTRIBUTES.STREAM_FORMAT, label: 'Stream Format' }, - { value: QUERY_AD_ATTRIBUTES.SURVEY_URL, label: 'Survey Url' }, - { value: QUERY_AD_ATTRIBUTES.TIME, label: 'Time' }, - { value: QUERY_AD_ATTRIBUTES.TIME_HOVERED, label: 'Time Hovered' }, - { value: QUERY_AD_ATTRIBUTES.TIME_IN_VIEWPORT, label: 'Time In Viewport' }, - { value: QUERY_AD_ATTRIBUTES.TIME_PLAYED, label: 'Time Played' }, - { value: QUERY_AD_ATTRIBUTES.TIME_TO_FIRST_AD, label: 'Time To First Ad' }, - { value: QUERY_AD_ATTRIBUTES.TIME_UNTIL_HOVER, label: 'Time Until Hover' }, - { value: QUERY_AD_ATTRIBUTES.UNIVERSAL_AD_ID_REGISTRY, label: 'Universal Ad Id Registry' }, - { value: QUERY_AD_ATTRIBUTES.UNIVERSAL_AD_ID_VALUE, label: 'Universal Ad Id Value' }, - { value: QUERY_AD_ATTRIBUTES.USER_ID, label: 'User Id' }, - { value: QUERY_AD_ATTRIBUTES.VIDEO_BITRATE, label: 'Video Bitrate' }, - { value: QUERY_AD_ATTRIBUTES.VIDEO_ID, label: 'Video Id' }, - { value: QUERY_AD_ATTRIBUTES.VIDEO_IMPRESSION_ID, label: 'Video Impression Id' }, - { value: QUERY_AD_ATTRIBUTES.VIDEO_TITLE, label: 'Video Title' }, - { value: QUERY_AD_ATTRIBUTES.VIDEO_WINDOW_HEIGHT, label: 'Video Window Height' }, - { value: QUERY_AD_ATTRIBUTES.VIDEO_WINDOW_WIDTH, label: 'Video Window Width' }, - { value: QUERY_AD_ATTRIBUTES.YEAR, label: 'Year' }, -]; +export const SELECTABLE_QUERY_AD_ATTRIBUTES: Array> = QUERY_AD_ATTRIBUTES.map( + (queryAdAttribute) => ({ + value: queryAdAttribute, + label: queryAdAttribute, + }) +); diff --git a/bitmovin-analytics-datasource/src/types/queryAttributes.ts b/bitmovin-analytics-datasource/src/types/queryAttributes.ts index b38d92b..af42b6a 100644 --- a/bitmovin-analytics-datasource/src/types/queryAttributes.ts +++ b/bitmovin-analytics-datasource/src/types/queryAttributes.ts @@ -1,277 +1,147 @@ import { SelectableValue } from '@grafana/data'; -export enum QUERY_ATTRIBUTES { - AD = 'AD', - ANALYTICS_VERSION = 'ANALYTICS_VERSION', - AUDIO_BITRATE = 'AUDIO_BITRATE', - AUDIO_CODEC = 'AUDIO_CODEC', - AUDIO_LANGUAGE = 'AUDIO_LANGUAGE', - AUTOPLAY = 'AUTOPLAY', - BROWSER = 'BROWSER', - BROWSER_IS_BOT = 'BROWSER_IS_BOT', - BROWSER_VERSION_MAJOR = 'BROWSER_VERSION_MAJOR', - BROWSER_VERSION_MINOR = 'BROWSER_VERSION_MINOR', - BUFFERED = 'BUFFERED', - CAST_TECH = 'CAST_TECH', - CDN_PROVIDER = 'CDN_PROVIDER', - CITY = 'CITY', - CLIENT_TIME = 'CLIENT_TIME', - CONTEXT = 'CONTEXT', - COUNTRY = 'COUNTRY', - CUSTOM_DATA_10 = 'CUSTOM_DATA_10', - CUSTOM_DATA_11 = 'CUSTOM_DATA_11', - CUSTOM_DATA_12 = 'CUSTOM_DATA_12', - CUSTOM_DATA_13 = 'CUSTOM_DATA_13', - CUSTOM_DATA_14 = 'CUSTOM_DATA_14', - CUSTOM_DATA_15 = 'CUSTOM_DATA_15', - CUSTOM_DATA_16 = 'CUSTOM_DATA_16', - CUSTOM_DATA_17 = 'CUSTOM_DATA_17', - CUSTOM_DATA_18 = 'CUSTOM_DATA_18', - CUSTOM_DATA_19 = 'CUSTOM_DATA_19', - CUSTOM_DATA_1 = 'CUSTOM_DATA_1', - CUSTOM_DATA_20 = 'CUSTOM_DATA_20', - CUSTOM_DATA_21 = 'CUSTOM_DATA_21', - CUSTOM_DATA_22 = 'CUSTOM_DATA_22', - CUSTOM_DATA_23 = 'CUSTOM_DATA_23', - CUSTOM_DATA_24 = 'CUSTOM_DATA_24', - CUSTOM_DATA_25 = 'CUSTOM_DATA_25', - CUSTOM_DATA_26 = 'CUSTOM_DATA_26', - CUSTOM_DATA_27 = 'CUSTOM_DATA_27', - CUSTOM_DATA_28 = 'CUSTOM_DATA_28', - CUSTOM_DATA_29 = 'CUSTOM_DATA_29', - CUSTOM_DATA_2 = 'CUSTOM_DATA_2', - CUSTOM_DATA_30 = 'CUSTOM_DATA_30', - CUSTOM_DATA_3 = 'CUSTOM_DATA_3', - CUSTOM_DATA_4 = 'CUSTOM_DATA_4', - CUSTOM_DATA_5 = 'CUSTOM_DATA_5', - CUSTOM_DATA_6 = 'CUSTOM_DATA_6', - CUSTOM_DATA_7 = 'CUSTOM_DATA_7', - CUSTOM_DATA_8 = 'CUSTOM_DATA_8', - CUSTOM_DATA_9 = 'CUSTOM_DATA_9', - CUSTOM_USER_ID = 'CUSTOM_USER_ID', - DAY = 'DAY', - DAYPART = 'DAYPART', - DEVICE_CLASS = 'DEVICE_CLASS', - DEVICE_TYPE = 'DEVICE_TYPE', - DOMAIN = 'DOMAIN', - DOWNLOAD_SPEED = 'DOWNLOAD_SPEED', - DRM_LOAD_TIME = 'DRM_LOAD_TIME', - DRM_TYPE = 'DRM_TYPE', - DROPPED_FRAMES = 'DROPPED_FRAMES', - DURATION = 'DURATION', - ERROR_CODE = 'ERROR_CODE', - ERROR_MESSAGE = 'ERROR_MESSAGE', - ERROR_PERCENTAGE = 'ERROR_PERCENTAGE', - EXPERIMENT_NAME = 'EXPERIMENT_NAME', - FUNCTION = 'FUNCTION', - HOUR = 'HOUR', - ID = 'ID', - IMPRESSION_ID = 'IMPRESSION_ID', - INITIAL_TIME_TO_TARGET_LATENCY = 'INITIAL_TIME_TO_TARGET_LATENCY', - IP_ADDRESS = 'IP_ADDRESS', - ISP = 'ISP', - IS_CASTING = 'IS_CASTING', - IS_LIVE = 'IS_LIVE', - IS_LOW_LATENCY = 'IS_LOW_LATENCY', - IS_MUTED = 'IS_MUTED', - LANGUAGE = 'LANGUAGE', - LATENCY = 'LATENCY', - LICENSE_KEY = 'LICENSE_KEY', - M3U8_URL = 'M3U8_URL', - MINUTE = 'MINUTE', - MONTH = 'MONTH', - MPD_URL = 'MPD_URL', - OPERATINGSYSTEM = 'OPERATINGSYSTEM', - OPERATINGSYSTEM_VERSION_MAJOR = 'OPERATINGSYSTEM_VERSION_MAJOR', - OPERATINGSYSTEM_VERSION_MINOR = 'OPERATINGSYSTEM_VERSION_MINOR', - ORGANIZATION = 'ORGANIZATION', - PAGE_LOAD_TIME = 'PAGE_LOAD_TIME', - PAGE_LOAD_TYPE = 'PAGE_LOAD_TYPE', - PATH = 'PATH', - PAUSED = 'PAUSED', - PLATFORM = 'PLATFORM', - PLAYED = 'PLAYED', - PLAYER = 'PLAYER', - PLAYER_STARTUPTIME = 'PLAYER_STARTUPTIME', - PLAYER_TECH = 'PLAYER_TECH', - PLAYER_VERSION = 'PLAYER_VERSION', - PLAY_ATTEMPTS = 'PLAY_ATTEMPTS', - PROG_URL = 'PROG_URL', - REBUFFER_PERCENTAGE = 'REBUFFER_PERCENTAGE', - REGION = 'REGION', - SCALE_FACTOR = 'SCALE_FACTOR', - SCREEN_HEIGHT = 'SCREEN_HEIGHT', - SCREEN_ORIENTATION = 'SCREEN_ORIENTATION', - SCREEN_WIDTH = 'SCREEN_WIDTH', - SEEKED = 'SEEKED', - SIZE = 'SIZE', - STARTUPTIME = 'STARTUPTIME', - STATE = 'STATE', - STREAM_FORMAT = 'STREAM_FORMAT', - SUBTITLE_ENABLED = 'SUBTITLE_ENABLED', - SUBTITLE_LANGUAGE = 'SUBTITLE_LANGUAGE', - SUPPORTED_VIDEO_CODECS = 'SUPPORTED_VIDEO_CODECS', - TARGET_LATENCY = 'TARGET_LATENCY', - TARGET_LATENCY_DELTA = 'TARGET_LATENCY_DELTA', - TIME = 'TIME', - TIME_TO_TARGET_LATENCY = 'TIME_TO_TARGET_LATENCY', - USER_ID = 'USER_ID', - VIDEOSTART_FAILED = 'VIDEOSTART_FAILED', - VIDEOSTART_FAILED_REASON = 'VIDEOSTART_FAILED_REASON', - VIDEOTIME_END = 'VIDEOTIME_END', - VIDEOTIME_START = 'VIDEOTIME_START', - VIDEO_BITRATE = 'VIDEO_BITRATE', - VIDEO_CODEC = 'VIDEO_CODEC', - VIDEO_CODEC_TYPE = 'VIDEO_CODEC_TYPE', - VIDEO_DURATION = 'VIDEO_DURATION', - VIDEO_ID = 'VIDEO_ID', - VIDEO_PLAYBACK_HEIGHT = 'VIDEO_PLAYBACK_HEIGHT', - VIDEO_PLAYBACK_WIDTH = 'VIDEO_PLAYBACK_WIDTH', - VIDEO_SEGMENTS_DOWNLOADED = 'VIDEO_SEGMENTS_DOWNLOADED', - VIDEO_SEGMENTS_DOWNLOAD_SIZE = 'VIDEO_SEGMENTS_DOWNLOAD_SIZE', - VIDEO_STARTUPTIME = 'VIDEO_STARTUPTIME', - VIDEO_TITLE = 'VIDEO_TITLE', - VIDEO_WINDOW_HEIGHT = 'VIDEO_WINDOW_HEIGHT', - VIDEO_WINDOW_WIDTH = 'VIDEO_WINDOW_WIDTH', - VIEWTIME = 'VIEWTIME', - YEAR = 'YEAR', -} +const QUERY_ATTRIBUTES = [ + 'AD', + 'ANALYTICS_VERSION', + 'AUDIO_BITRATE', + 'AUDIO_CODEC', + 'AUDIO_LANGUAGE', + 'AUTOPLAY', + 'BROWSER', + 'BROWSER_IS_BOT', + 'BROWSER_VERSION_MAJOR', + 'BROWSER_VERSION_MINOR', + 'BUFFERED', + 'CAST_TECH', + 'CDN_PROVIDER', + 'CITY', + 'CLIENT_TIME', + 'CONTEXT', + 'COUNTRY', + 'CUSTOM_DATA_1', + 'CUSTOM_DATA_10', + 'CUSTOM_DATA_11', + 'CUSTOM_DATA_12', + 'CUSTOM_DATA_13', + 'CUSTOM_DATA_14', + 'CUSTOM_DATA_15', + 'CUSTOM_DATA_16', + 'CUSTOM_DATA_17', + 'CUSTOM_DATA_18', + 'CUSTOM_DATA_19', + 'CUSTOM_DATA_2', + 'CUSTOM_DATA_20', + 'CUSTOM_DATA_21', + 'CUSTOM_DATA_22', + 'CUSTOM_DATA_23', + 'CUSTOM_DATA_24', + 'CUSTOM_DATA_25', + 'CUSTOM_DATA_26', + 'CUSTOM_DATA_27', + 'CUSTOM_DATA_28', + 'CUSTOM_DATA_29', + 'CUSTOM_DATA_3', + 'CUSTOM_DATA_30', + 'CUSTOM_DATA_4', + 'CUSTOM_DATA_5', + 'CUSTOM_DATA_6', + 'CUSTOM_DATA_7', + 'CUSTOM_DATA_8', + 'CUSTOM_DATA_9', + 'CUSTOM_USER_ID', + 'DAY', + 'DAYPART', + 'DEVICE_CLASS', + 'DEVICE_TYPE', + 'DOMAIN', + 'DOWNLOAD_SPEED', + 'DRM_LOAD_TIME', + 'DRM_TYPE', + 'DROPPED_FRAMES', + 'DURATION', + 'ERROR_CODE', + 'ERROR_MESSAGE', + 'ERROR_PERCENTAGE', + 'EXPERIMENT_NAME', + 'FUNCTION', + 'HOUR', + 'ID', + 'IMPRESSION_ID', + 'INITIAL_TIME_TO_TARGET_LATENCY', + 'IP_ADDRESS', + 'ISP', + 'IS_CASTING', + 'IS_LIVE', + 'IS_LOW_LATENCY', + 'IS_MUTED', + 'LANGUAGE', + 'LATENCY', + 'LICENSE_KEY', + 'M3U8_URL', + 'MINUTE', + 'MONTH', + 'MPD_URL', + 'OPERATINGSYSTEM', + 'OPERATINGSYSTEM_VERSION_MAJOR', + 'OPERATINGSYSTEM_VERSION_MINOR', + 'ORGANIZATION', + 'PAGE_LOAD_TIME', + 'PAGE_LOAD_TYPE', + 'PATH', + 'PAUSED', + 'PLATFORM', + 'PLAYED', + 'PLAYER', + 'PLAYER_STARTUPTIME', + 'PLAYER_TECH', + 'PLAYER_VERSION', + 'PLAY_ATTEMPTS', + 'PROG_URL', + 'REBUFFER_PERCENTAGE', + 'REGION', + 'SCALE_FACTOR', + 'SCREEN_HEIGHT', + 'SCREEN_ORIENTATION', + 'SCREEN_WIDTH', + 'SEEKED', + 'SIZE', + 'STARTUPTIME', + 'STATE', + 'STREAM_FORMAT', + 'SUBTITLE_ENABLED', + 'SUBTITLE_LANGUAGE', + 'SUPPORTED_VIDEO_CODECS', + 'TARGET_LATENCY', + 'TARGET_LATENCY_DELTA', + 'TIME', + 'TIME_TO_TARGET_LATENCY', + 'USER_ID', + 'VIDEOSTART_FAILED', + 'VIDEOSTART_FAILED_REASON', + 'VIDEOTIME_END', + 'VIDEOTIME_START', + 'VIDEO_BITRATE', + 'VIDEO_CODEC', + 'VIDEO_CODEC_TYPE', + 'VIDEO_DURATION', + 'VIDEO_ID', + 'VIDEO_PLAYBACK_HEIGHT', + 'VIDEO_PLAYBACK_WIDTH', + 'VIDEO_SEGMENTS_DOWNLOADED', + 'VIDEO_SEGMENTS_DOWNLOAD_SIZE', + 'VIDEO_STARTUPTIME', + 'VIDEO_TITLE', + 'VIDEO_WINDOW_HEIGHT', + 'VIDEO_WINDOW_WIDTH', + 'VIEWTIME', + 'YEAR', +] as const; -export type QueryAttribute = keyof typeof QUERY_ATTRIBUTES; +export type QueryAttribute = (typeof QUERY_ATTRIBUTES)[number]; -export const SELECTABLE_QUERY_ATTRIBUTES: Array> = [ - { value: QUERY_ATTRIBUTES.AD, label: 'Ad' }, - { value: QUERY_ATTRIBUTES.ANALYTICS_VERSION, label: 'Analytics Software Version' }, - { value: QUERY_ATTRIBUTES.AUDIO_BITRATE, label: 'Audio Bitrate' }, - { value: QUERY_ATTRIBUTES.AUDIO_CODEC, label: 'Audio Codec' }, - { value: QUERY_ATTRIBUTES.AUDIO_LANGUAGE, label: 'Audio Language' }, - { value: QUERY_ATTRIBUTES.AUTOPLAY, label: 'Autoplay' }, - { value: QUERY_ATTRIBUTES.BROWSER, label: 'Browser' }, - { value: QUERY_ATTRIBUTES.BROWSER_IS_BOT, label: 'Is Bot' }, - { value: QUERY_ATTRIBUTES.BROWSER_VERSION_MAJOR, label: 'Browser Version Major' }, - { value: QUERY_ATTRIBUTES.BROWSER_VERSION_MINOR, label: 'Browser Version Minor' }, - { value: QUERY_ATTRIBUTES.BUFFERED, label: 'Buffered' }, - { value: QUERY_ATTRIBUTES.CAST_TECH, label: 'Casting Tech' }, - { value: QUERY_ATTRIBUTES.CDN_PROVIDER, label: 'Cdn Provider' }, - { value: QUERY_ATTRIBUTES.CITY, label: 'City' }, - { value: QUERY_ATTRIBUTES.CLIENT_TIME, label: 'Client Time' }, - { value: QUERY_ATTRIBUTES.CONTEXT, label: 'Context' }, - { value: QUERY_ATTRIBUTES.COUNTRY, label: 'Country' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_10, label: 'Custom Data 10' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_11, label: 'Custom Data 11' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_12, label: 'Custom Data 12' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_13, label: 'Custom Data 13' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_14, label: 'Custom Data 14' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_15, label: 'Custom Data 15' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_16, label: 'Custom Data 16' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_17, label: 'Custom Data 17' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_18, label: 'Custom Data 18' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_19, label: 'Custom Data 19' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_1, label: 'Custom Data 1' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_20, label: 'Custom Data 20' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_21, label: 'Custom Data 21' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_22, label: 'Custom Data 22' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_23, label: 'Custom Data 23' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_24, label: 'Custom Data 24' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_25, label: 'Custom Data 25' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_26, label: 'Custom Data 26' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_27, label: 'Custom Data 27' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_28, label: 'Custom Data 28' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_29, label: 'Custom Data 29' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_2, label: 'Custom Data 2' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_30, label: 'Custom Data 30' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_3, label: 'Custom Data 3' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_4, label: 'Custom Data 4' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_5, label: 'Custom Data 5' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_6, label: 'Custom Data 6' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_7, label: 'Custom Data 7' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_8, label: 'Custom Data 8' }, - { value: QUERY_ATTRIBUTES.CUSTOM_DATA_9, label: 'Custom Data 9' }, - { value: QUERY_ATTRIBUTES.CUSTOM_USER_ID, label: 'Custom User Id' }, - { value: QUERY_ATTRIBUTES.DAY, label: 'Day' }, - { value: QUERY_ATTRIBUTES.DAYPART, label: 'Daypart' }, - { value: QUERY_ATTRIBUTES.DEVICE_CLASS, label: 'Device Class' }, - { value: QUERY_ATTRIBUTES.DEVICE_TYPE, label: 'Device Type' }, - { value: QUERY_ATTRIBUTES.DOMAIN, label: 'Domain' }, - { value: QUERY_ATTRIBUTES.DOWNLOAD_SPEED, label: 'Download Speed' }, - { value: QUERY_ATTRIBUTES.DRM_LOAD_TIME, label: 'Drm Load Time' }, - { value: QUERY_ATTRIBUTES.DRM_TYPE, label: 'Drm Type' }, - { value: QUERY_ATTRIBUTES.DROPPED_FRAMES, label: 'Dropped Frames' }, - { value: QUERY_ATTRIBUTES.DURATION, label: 'Duration' }, - { value: QUERY_ATTRIBUTES.ERROR_CODE, label: 'Error Code' }, - { value: QUERY_ATTRIBUTES.ERROR_MESSAGE, label: 'Error Message' }, - { value: QUERY_ATTRIBUTES.ERROR_PERCENTAGE, label: 'Error Percentage' }, - { value: QUERY_ATTRIBUTES.EXPERIMENT_NAME, label: 'Experiment Name' }, - { value: QUERY_ATTRIBUTES.FUNCTION, label: 'Function' }, - { value: QUERY_ATTRIBUTES.HOUR, label: 'Hour' }, - { value: QUERY_ATTRIBUTES.ID, label: 'Id' }, - { value: QUERY_ATTRIBUTES.IMPRESSION_ID, label: 'Impression Id' }, - { value: QUERY_ATTRIBUTES.INITIAL_TIME_TO_TARGET_LATENCY, label: 'Initial Time to Target Latency' }, - { value: QUERY_ATTRIBUTES.IP_ADDRESS, label: 'Ip Address' }, - { value: QUERY_ATTRIBUTES.ISP, label: 'Internet Service Provider' }, - { value: QUERY_ATTRIBUTES.IS_CASTING, label: 'Casting' }, - { value: QUERY_ATTRIBUTES.IS_LIVE, label: 'Live' }, - { value: QUERY_ATTRIBUTES.IS_LOW_LATENCY, label: 'Is Low Latency' }, - { value: QUERY_ATTRIBUTES.IS_MUTED, label: 'Muted' }, - { value: QUERY_ATTRIBUTES.LANGUAGE, label: 'Language' }, - { value: QUERY_ATTRIBUTES.LATENCY, label: 'Latency' }, - { value: QUERY_ATTRIBUTES.LICENSE_KEY, label: 'License Key' }, - { value: QUERY_ATTRIBUTES.M3U8_URL, label: 'M3U8 Url' }, - { value: QUERY_ATTRIBUTES.MINUTE, label: 'Minute' }, - { value: QUERY_ATTRIBUTES.MONTH, label: 'Month' }, - { value: QUERY_ATTRIBUTES.MPD_URL, label: 'MPD Url' }, - { value: QUERY_ATTRIBUTES.OPERATINGSYSTEM, label: 'Operating System' }, - { value: QUERY_ATTRIBUTES.OPERATINGSYSTEM_VERSION_MAJOR, label: 'Operating System Version Major' }, - { value: QUERY_ATTRIBUTES.OPERATINGSYSTEM_VERSION_MINOR, label: 'Operating System Version Minor' }, - { value: QUERY_ATTRIBUTES.ORGANIZATION, label: 'Organization' }, - { value: QUERY_ATTRIBUTES.PAGE_LOAD_TIME, label: 'Page Load Time' }, - { value: QUERY_ATTRIBUTES.PAGE_LOAD_TYPE, label: 'Page Load Type' }, - { value: QUERY_ATTRIBUTES.PATH, label: 'Path' }, - { value: QUERY_ATTRIBUTES.PAUSED, label: 'Paused' }, - { value: QUERY_ATTRIBUTES.PLATFORM, label: 'Platform' }, - { value: QUERY_ATTRIBUTES.PLAYED, label: 'Played' }, - { value: QUERY_ATTRIBUTES.PLAYER, label: 'Player Software' }, - { value: QUERY_ATTRIBUTES.PLAYER_STARTUPTIME, label: 'Player Startuptime' }, - { value: QUERY_ATTRIBUTES.PLAYER_TECH, label: 'Player Technology' }, - { value: QUERY_ATTRIBUTES.PLAYER_VERSION, label: 'Player Software Version' }, - { value: QUERY_ATTRIBUTES.PLAY_ATTEMPTS, label: 'play Attempts' }, - { value: QUERY_ATTRIBUTES.PROG_URL, label: 'Prog Url' }, - { value: QUERY_ATTRIBUTES.REBUFFER_PERCENTAGE, label: 'Rebuffer Percentage' }, - { value: QUERY_ATTRIBUTES.REGION, label: 'Region' }, - { value: QUERY_ATTRIBUTES.SCALE_FACTOR, label: 'Scale Factor' }, - { value: QUERY_ATTRIBUTES.SCREEN_HEIGHT, label: 'Screen Height' }, - { value: QUERY_ATTRIBUTES.SCREEN_ORIENTATION, label: 'Screen Orientation' }, - { value: QUERY_ATTRIBUTES.SCREEN_WIDTH, label: 'Screen Width' }, - { value: QUERY_ATTRIBUTES.SEEKED, label: 'Seeked' }, - { value: QUERY_ATTRIBUTES.SIZE, label: 'Size' }, - { value: QUERY_ATTRIBUTES.STARTUPTIME, label: 'Startuptime' }, - { value: QUERY_ATTRIBUTES.STATE, label: 'State' }, - { value: QUERY_ATTRIBUTES.STREAM_FORMAT, label: 'Stream Format' }, - { value: QUERY_ATTRIBUTES.SUBTITLE_ENABLED, label: 'Subtitle Enabled' }, - { value: QUERY_ATTRIBUTES.SUBTITLE_LANGUAGE, label: 'Subtitle Language' }, - { value: QUERY_ATTRIBUTES.SUPPORTED_VIDEO_CODECS, label: 'Supported Video Codecs' }, - { value: QUERY_ATTRIBUTES.TARGET_LATENCY, label: 'Target Latency' }, - { value: QUERY_ATTRIBUTES.TARGET_LATENCY_DELTA, label: 'Target Latency Delta' }, - { value: QUERY_ATTRIBUTES.TIME, label: 'Time' }, - { value: QUERY_ATTRIBUTES.TIME_TO_TARGET_LATENCY, label: 'Time to Target Latency' }, - { value: QUERY_ATTRIBUTES.USER_ID, label: 'User Id' }, - { value: QUERY_ATTRIBUTES.VIDEOSTART_FAILED, label: 'Video Start Failed' }, - { value: QUERY_ATTRIBUTES.VIDEOSTART_FAILED_REASON, label: 'Video Start Failed Reason' }, - { value: QUERY_ATTRIBUTES.VIDEOTIME_END, label: 'Videotime End' }, - { value: QUERY_ATTRIBUTES.VIDEOTIME_START, label: 'Videotime Start' }, - { value: QUERY_ATTRIBUTES.VIDEO_BITRATE, label: 'Video Bitrate' }, - { value: QUERY_ATTRIBUTES.VIDEO_CODEC, label: 'Video Codec' }, - { value: QUERY_ATTRIBUTES.VIDEO_CODEC_TYPE, label: 'Video Codec Type' }, - { value: QUERY_ATTRIBUTES.VIDEO_DURATION, label: 'Video Duration' }, - { value: QUERY_ATTRIBUTES.VIDEO_ID, label: 'Video Id' }, - { value: QUERY_ATTRIBUTES.VIDEO_PLAYBACK_HEIGHT, label: 'Video Playback Height' }, - { value: QUERY_ATTRIBUTES.VIDEO_PLAYBACK_WIDTH, label: 'Video Playback Width' }, - { value: QUERY_ATTRIBUTES.VIDEO_SEGMENTS_DOWNLOADED, label: 'Video Segments Downloaded' }, - { value: QUERY_ATTRIBUTES.VIDEO_SEGMENTS_DOWNLOAD_SIZE, label: 'Video Segments Download Size' }, - { value: QUERY_ATTRIBUTES.VIDEO_STARTUPTIME, label: 'Video Startuptime' }, - { value: QUERY_ATTRIBUTES.VIDEO_TITLE, label: 'Video Title' }, - { value: QUERY_ATTRIBUTES.VIDEO_WINDOW_HEIGHT, label: 'Video Window Height' }, - { value: QUERY_ATTRIBUTES.VIDEO_WINDOW_WIDTH, label: 'Video Window Width' }, - { value: QUERY_ATTRIBUTES.VIEWTIME, label: 'Viewtime' }, - { value: QUERY_ATTRIBUTES.YEAR, label: 'Year' }, -]; +export const SELECTABLE_QUERY_ATTRIBUTES: Array> = QUERY_ATTRIBUTES.map( + (queryAttribute) => ({ + value: queryAttribute, + label: queryAttribute, + }) +); diff --git a/bitmovin-analytics-datasource/src/types/queryFilter.ts b/bitmovin-analytics-datasource/src/types/queryFilter.ts index ba1c86a..727be73 100644 --- a/bitmovin-analytics-datasource/src/types/queryFilter.ts +++ b/bitmovin-analytics-datasource/src/types/queryFilter.ts @@ -1,32 +1,13 @@ -import { SelectableValue } from '@grafana/data'; import { QueryAdAttribute } from './queryAdAttributes'; import { QueryAttribute } from './queryAttributes'; +import type { SelectableValue } from '@grafana/data'; -export enum QUERY_FILTER_OPERATORS { - GT = 'GT', - GTE = 'GTE', - LT = 'LT', - LTE = 'LTE', - EQ = 'EQ', - NE = 'NE', - CONTAINS = 'CONTAINS', - NOTCONTAINS = 'NOTCONTAINS', - IN = 'IN', -} +const QUERY_FILTER_OPERATORS = ['GT', 'GTE', 'LT', 'LTE', 'EQ', 'NE', 'CONTAINS', 'NOTCONTAINS', 'IN'] as const; -export type QueryFilterOperator = keyof typeof QUERY_FILTER_OPERATORS; +export type QueryFilterOperator = (typeof QUERY_FILTER_OPERATORS)[number]; -export const SELECTABLE_QUERY_FILTER_OPERATORS: Array> = [ - { value: QUERY_FILTER_OPERATORS.GT, label: QUERY_FILTER_OPERATORS.GT }, - { value: QUERY_FILTER_OPERATORS.GTE, label: QUERY_FILTER_OPERATORS.GTE }, - { value: QUERY_FILTER_OPERATORS.LT, label: QUERY_FILTER_OPERATORS.LT }, - { value: QUERY_FILTER_OPERATORS.LTE, label: QUERY_FILTER_OPERATORS.LTE }, - { value: QUERY_FILTER_OPERATORS.EQ, label: QUERY_FILTER_OPERATORS.EQ }, - { value: QUERY_FILTER_OPERATORS.NE, label: QUERY_FILTER_OPERATORS.NE }, - { value: QUERY_FILTER_OPERATORS.CONTAINS, label: QUERY_FILTER_OPERATORS.CONTAINS }, - { value: QUERY_FILTER_OPERATORS.NOTCONTAINS, label: QUERY_FILTER_OPERATORS.NOTCONTAINS }, - { value: QUERY_FILTER_OPERATORS.IN, label: QUERY_FILTER_OPERATORS.IN }, -]; +export const SELECTABLE_QUERY_FILTER_OPERATORS: Array> = + QUERY_FILTER_OPERATORS.map((o) => ({ value: o, label: o })); export type QueryFilter = { name: QueryAdAttribute | QueryAttribute; diff --git a/bitmovin-analytics-datasource/src/utils/filterUtils.test.ts b/bitmovin-analytics-datasource/src/utils/filterUtils.test.ts index 878c1f0..7315396 100644 --- a/bitmovin-analytics-datasource/src/utils/filterUtils.test.ts +++ b/bitmovin-analytics-datasource/src/utils/filterUtils.test.ts @@ -1,12 +1,9 @@ import { convertFilterValueToProperType, mapQueryFilterValueToRawFilterValue } from './filterUtils'; -import { QUERY_ATTRIBUTES } from '../types/queryAttributes'; -import { QUERY_FILTER_OPERATORS } from '../types/queryFilter'; -import { QUERY_AD_ATTRIBUTES } from '../types/queryAdAttributes'; describe('convertFilterValueToProperType', () => { it('should return null if rawValue is empty and attribute a NullFilter', () => { //arrange & act - const result = convertFilterValueToProperType('', QUERY_ATTRIBUTES.CUSTOM_DATA_1, QUERY_FILTER_OPERATORS.IN, false); + const result = convertFilterValueToProperType('', 'CUSTOM_DATA_1', 'IN', false); //assert expect(result).toBeNull(); @@ -14,21 +11,14 @@ describe('convertFilterValueToProperType', () => { it('should throw an error if value for IN filter is not a json array', () => { //arrange & act && assert - expect(() => - convertFilterValueToProperType('Firefox', QUERY_ATTRIBUTES.BROWSER, QUERY_FILTER_OPERATORS.IN, false) - ).toThrow( + expect(() => convertFilterValueToProperType('Firefox', 'BROWSER', 'IN', false)).toThrow( new Error('Couldn\'t parse IN filter, please provide data in JSON array form (e.g.: ["Firefox", "Chrome"]).') ); }); it('should correctly parse value for IN filter', () => { //arrange & act - const result = convertFilterValueToProperType( - '["Firefox", "Safari"]', - QUERY_ATTRIBUTES.BROWSER, - QUERY_FILTER_OPERATORS.IN, - false - ); + const result = convertFilterValueToProperType('["Firefox", "Safari"]', 'BROWSER', 'IN', false); //assert expect(result).toEqual(['Firefox', 'Safari']); @@ -36,12 +26,7 @@ describe('convertFilterValueToProperType', () => { it('should correctly convert to boolean value for ad attributes', () => { //arrange & act - const result = convertFilterValueToProperType( - 'true', - QUERY_AD_ATTRIBUTES.IS_LINEAR, - QUERY_FILTER_OPERATORS.EQ, - true - ); + const result = convertFilterValueToProperType('true', 'IS_LINEAR', 'EQ', true); //assert expect(result).toEqual(true); @@ -49,12 +34,7 @@ describe('convertFilterValueToProperType', () => { it('should correctly convert to int value for ad attributes', () => { //arrange & act - const result = convertFilterValueToProperType( - '2000', - QUERY_AD_ATTRIBUTES.CLICK_POSITION, - QUERY_FILTER_OPERATORS.EQ, - true - ); + const result = convertFilterValueToProperType('2000', 'CLICK_POSITION', 'EQ', true); //assert expect(result).toEqual(2000); @@ -62,19 +42,14 @@ describe('convertFilterValueToProperType', () => { it('should throw error if int parsing fails for ad attributes', () => { //arrange & act & assert - expect(() => - convertFilterValueToProperType('true', QUERY_AD_ATTRIBUTES.CLICK_POSITION, QUERY_FILTER_OPERATORS.EQ, true) - ).toThrow(new Error(`Couldn't parse filter value, please provide data as an integer number`)); + expect(() => convertFilterValueToProperType('true', 'CLICK_POSITION', 'EQ', true)).toThrow( + new Error(`Couldn't parse filter value, please provide data as an integer number`) + ); }); it('should correctly convert to float value for ad attributes', () => { //arrange & act - const result = convertFilterValueToProperType( - '12.56', - QUERY_AD_ATTRIBUTES.CLICK_PERCENTAGE, - QUERY_FILTER_OPERATORS.EQ, - true - ); + const result = convertFilterValueToProperType('12.56', 'CLICK_PERCENTAGE', 'EQ', true); //assert expect(result).toEqual(12.56); @@ -82,19 +57,14 @@ describe('convertFilterValueToProperType', () => { it('should throw error if float parsing fails for ad attributes', () => { //arrange & act & assert - expect(() => - convertFilterValueToProperType('two', QUERY_AD_ATTRIBUTES.CLICK_PERCENTAGE, QUERY_FILTER_OPERATORS.EQ, true) - ).toThrow(new Error(`Couldn't parse filter value, please provide data as a floating point number`)); + expect(() => convertFilterValueToProperType('two', 'CLICK_PERCENTAGE', 'EQ', true)).toThrow( + new Error(`Couldn't parse filter value, please provide data as a floating point number`) + ); }); it('should correctly convert to boolean value for attributes', () => { //arrange & act - const result = convertFilterValueToProperType( - 'true', - QUERY_ATTRIBUTES.IS_CASTING, - QUERY_FILTER_OPERATORS.EQ, - false - ); + const result = convertFilterValueToProperType('true', 'IS_CASTING', 'EQ', false); //assert expect(result).toEqual(true); @@ -102,12 +72,7 @@ describe('convertFilterValueToProperType', () => { it('should correctly convert to int value for attributes', () => { //arrange & act - const result = convertFilterValueToProperType( - '2000', - QUERY_AD_ATTRIBUTES.AUDIO_BITRATE, - QUERY_FILTER_OPERATORS.EQ, - false - ); + const result = convertFilterValueToProperType('2000', 'AUDIO_BITRATE', 'EQ', false); //assert expect(result).toEqual(2000); @@ -115,19 +80,14 @@ describe('convertFilterValueToProperType', () => { it('should throw error if int parsing fails for attributes', () => { //arrange & act & assert - expect(() => - convertFilterValueToProperType('zero', QUERY_ATTRIBUTES.AUDIO_BITRATE, QUERY_FILTER_OPERATORS.EQ, false) - ).toThrow(new Error(`Couldn't parse filter value, please provide data as an integer number`)); + expect(() => convertFilterValueToProperType('zero', 'AUDIO_BITRATE', 'EQ', false)).toThrow( + new Error(`Couldn't parse filter value, please provide data as an integer number`) + ); }); it('should correctly convert to float value for attributes', () => { //arrange & act - const result = convertFilterValueToProperType( - '12.56', - QUERY_ATTRIBUTES.ERROR_PERCENTAGE, - QUERY_FILTER_OPERATORS.EQ, - false - ); + const result = convertFilterValueToProperType('12.56', 'ERROR_PERCENTAGE', 'EQ', false); //assert expect(result).toEqual(12.56); @@ -135,9 +95,9 @@ describe('convertFilterValueToProperType', () => { it('should throw error if float parsing fails for attributes', () => { //arrange & act & assert - expect(() => - convertFilterValueToProperType('two', QUERY_ATTRIBUTES.ERROR_PERCENTAGE, QUERY_FILTER_OPERATORS.EQ, false) - ).toThrow(new Error(`Couldn't parse filter value, please provide data as a floating point number`)); + expect(() => convertFilterValueToProperType('two', 'ERROR_PERCENTAGE', 'EQ', false)).toThrow( + new Error(`Couldn't parse filter value, please provide data as a floating point number`) + ); }); }); diff --git a/bitmovin-analytics-datasource/src/utils/filterUtils.ts b/bitmovin-analytics-datasource/src/utils/filterUtils.ts index a0c0ff6..572c436 100644 --- a/bitmovin-analytics-datasource/src/utils/filterUtils.ts +++ b/bitmovin-analytics-datasource/src/utils/filterUtils.ts @@ -1,8 +1,8 @@ import { isEmpty } from 'lodash'; -import { QUERY_AD_ATTRIBUTES, QueryAdAttribute } from '../types/queryAdAttributes'; -import { QUERY_FILTER_OPERATORS, QueryFilterOperator, QueryFilterValue } from '../types/queryFilter'; -import { QUERY_ATTRIBUTES, QueryAttribute } from '../types/queryAttributes'; +import { QueryAdAttribute } from '../types/queryAdAttributes'; +import { QueryFilterOperator, QueryFilterValue } from '../types/queryFilter'; +import { QueryAttribute } from '../types/queryAttributes'; /** * Convert QueryFilter value to string to correctly display the value in the Input Element. @@ -21,43 +21,43 @@ export const mapQueryFilterValueToRawFilterValue = (filterValue: QueryFilterValu const isNullFilter = (filterAttribute: QueryAttribute | QueryAdAttribute): boolean => { switch (filterAttribute) { - case QUERY_ATTRIBUTES.CDN_PROVIDER: - case QUERY_ATTRIBUTES.CUSTOM_DATA_1: - case QUERY_ATTRIBUTES.CUSTOM_DATA_2: - case QUERY_ATTRIBUTES.CUSTOM_DATA_3: - case QUERY_ATTRIBUTES.CUSTOM_DATA_4: - case QUERY_ATTRIBUTES.CUSTOM_DATA_5: - case QUERY_ATTRIBUTES.CUSTOM_DATA_6: - case QUERY_ATTRIBUTES.CUSTOM_DATA_7: - case QUERY_ATTRIBUTES.CUSTOM_DATA_8: - case QUERY_ATTRIBUTES.CUSTOM_DATA_9: - case QUERY_ATTRIBUTES.CUSTOM_DATA_10: - case QUERY_ATTRIBUTES.CUSTOM_DATA_11: - case QUERY_ATTRIBUTES.CUSTOM_DATA_12: - case QUERY_ATTRIBUTES.CUSTOM_DATA_13: - case QUERY_ATTRIBUTES.CUSTOM_DATA_14: - case QUERY_ATTRIBUTES.CUSTOM_DATA_15: - case QUERY_ATTRIBUTES.CUSTOM_DATA_16: - case QUERY_ATTRIBUTES.CUSTOM_DATA_17: - case QUERY_ATTRIBUTES.CUSTOM_DATA_18: - case QUERY_ATTRIBUTES.CUSTOM_DATA_19: - case QUERY_ATTRIBUTES.CUSTOM_DATA_20: - case QUERY_ATTRIBUTES.CUSTOM_DATA_21: - case QUERY_ATTRIBUTES.CUSTOM_DATA_22: - case QUERY_ATTRIBUTES.CUSTOM_DATA_23: - case QUERY_ATTRIBUTES.CUSTOM_DATA_24: - case QUERY_ATTRIBUTES.CUSTOM_DATA_25: - case QUERY_ATTRIBUTES.CUSTOM_DATA_26: - case QUERY_ATTRIBUTES.CUSTOM_DATA_27: - case QUERY_ATTRIBUTES.CUSTOM_DATA_28: - case QUERY_ATTRIBUTES.CUSTOM_DATA_29: - case QUERY_ATTRIBUTES.CUSTOM_DATA_30: - case QUERY_ATTRIBUTES.CUSTOM_USER_ID: - case QUERY_ATTRIBUTES.EXPERIMENT_NAME: - case QUERY_ATTRIBUTES.ISP: - case QUERY_ATTRIBUTES.PLAYER_TECH: - case QUERY_ATTRIBUTES.PLAYER_VERSION: - case QUERY_ATTRIBUTES.VIDEO_ID: + case 'CDN_PROVIDER': + case 'CUSTOM_DATA_1': + case 'CUSTOM_DATA_2': + case 'CUSTOM_DATA_3': + case 'CUSTOM_DATA_4': + case 'CUSTOM_DATA_5': + case 'CUSTOM_DATA_6': + case 'CUSTOM_DATA_7': + case 'CUSTOM_DATA_8': + case 'CUSTOM_DATA_9': + case 'CUSTOM_DATA_10': + case 'CUSTOM_DATA_11': + case 'CUSTOM_DATA_12': + case 'CUSTOM_DATA_13': + case 'CUSTOM_DATA_14': + case 'CUSTOM_DATA_15': + case 'CUSTOM_DATA_16': + case 'CUSTOM_DATA_17': + case 'CUSTOM_DATA_18': + case 'CUSTOM_DATA_19': + case 'CUSTOM_DATA_20': + case 'CUSTOM_DATA_21': + case 'CUSTOM_DATA_22': + case 'CUSTOM_DATA_23': + case 'CUSTOM_DATA_24': + case 'CUSTOM_DATA_25': + case 'CUSTOM_DATA_26': + case 'CUSTOM_DATA_27': + case 'CUSTOM_DATA_28': + case 'CUSTOM_DATA_29': + case 'CUSTOM_DATA_30': + case 'CUSTOM_USER_ID': + case 'EXPERIMENT_NAME': + case 'ISP': + case 'PLAYER_TECH': + case 'PLAYER_VERSION': + case 'VIDEO_ID': return true; default: return false; @@ -74,29 +74,29 @@ const parseValueForInFilter = (rawValue: string) => { const convertFilterForAds = (rawValue: string, filterAttribute: QueryAdAttribute) => { switch (filterAttribute) { - case QUERY_AD_ATTRIBUTES.IS_LINEAR: + case 'IS_LINEAR': return rawValue === 'true'; - case QUERY_AD_ATTRIBUTES.AD_STARTUP_TIME: - case QUERY_AD_ATTRIBUTES.AD_WRAPPER_ADS_COUNT: - case QUERY_AD_ATTRIBUTES.AUDIO_BITRATE: - case QUERY_AD_ATTRIBUTES.CLICK_POSITION: - case QUERY_AD_ATTRIBUTES.CLOSE_POSITION: - case QUERY_AD_ATTRIBUTES.ERROR_CODE: - case QUERY_AD_ATTRIBUTES.MANIFEST_DOWNLOAD_TIME: - case QUERY_AD_ATTRIBUTES.MIN_SUGGESTED_DURATION: - case QUERY_AD_ATTRIBUTES.PAGE_LOAD_TIME: - case QUERY_AD_ATTRIBUTES.PLAYER_STARTUPTIME: - case QUERY_AD_ATTRIBUTES.SCREEN_HEIGHT: - case QUERY_AD_ATTRIBUTES.SCREEN_WIDTH: - case QUERY_AD_ATTRIBUTES.SKIP_POSITION: - case QUERY_AD_ATTRIBUTES.TIME_HOVERED: - case QUERY_AD_ATTRIBUTES.TIME_IN_VIEWPORT: - case QUERY_AD_ATTRIBUTES.TIME_PLAYED: - case QUERY_AD_ATTRIBUTES.TIME_UNTIL_HOVER: - case QUERY_AD_ATTRIBUTES.VIDEO_BITRATE: - case QUERY_AD_ATTRIBUTES.VIDEO_WINDOW_HEIGHT: - case QUERY_AD_ATTRIBUTES.VIDEO_WINDOW_WIDTH: { + case 'AD_STARTUP_TIME': + case 'AD_WRAPPER_ADS_COUNT': + case 'AUDIO_BITRATE': + case 'CLICK_POSITION': + case 'CLOSE_POSITION': + case 'ERROR_CODE': + case 'MANIFEST_DOWNLOAD_TIME': + case 'MIN_SUGGESTED_DURATION': + case 'PAGE_LOAD_TIME': + case 'PLAYER_STARTUPTIME': + case 'SCREEN_HEIGHT': + case 'SCREEN_WIDTH': + case 'SKIP_POSITION': + case 'TIME_HOVERED': + case 'TIME_IN_VIEWPORT': + case 'TIME_PLAYED': + case 'TIME_UNTIL_HOVER': + case 'VIDEO_BITRATE': + case 'VIDEO_WINDOW_HEIGHT': + case 'VIDEO_WINDOW_WIDTH': { const parsedValue = parseInt(rawValue, 10); if (isNaN(parsedValue)) { throw new Error(`Couldn't parse filter value, please provide data as an integer number`); @@ -104,10 +104,10 @@ const convertFilterForAds = (rawValue: string, filterAttribute: QueryAdAttribute return parsedValue; } - case QUERY_AD_ATTRIBUTES.CLICK_PERCENTAGE: - case QUERY_AD_ATTRIBUTES.CLOSE_PERCENTAGE: - case QUERY_AD_ATTRIBUTES.PERCENTAGE_IN_VIEWPORT: - case QUERY_AD_ATTRIBUTES.SKIP_PERCENTAGE: { + case 'CLICK_PERCENTAGE': + case 'CLOSE_PERCENTAGE': + case 'PERCENTAGE_IN_VIEWPORT': + case 'SKIP_PERCENTAGE': { const parsedValue = parseFloat(rawValue); if (isNaN(parsedValue)) { throw new Error(`Couldn't parse filter value, please provide data as a floating point number`); @@ -122,38 +122,38 @@ const convertFilterForAds = (rawValue: string, filterAttribute: QueryAdAttribute const convertFilter = (rawValue: string, filterAttribute: QueryAttribute) => { switch (filterAttribute) { - case QUERY_ATTRIBUTES.IS_CASTING: - case QUERY_ATTRIBUTES.IS_LIVE: - case QUERY_ATTRIBUTES.IS_MUTED: + case 'IS_CASTING': + case 'IS_LIVE': + case 'IS_MUTED': return rawValue === 'true'; - case QUERY_ATTRIBUTES.AUDIO_BITRATE: - case QUERY_ATTRIBUTES.BUFFERED: - case QUERY_ATTRIBUTES.CLIENT_TIME: - case QUERY_ATTRIBUTES.DOWNLOAD_SPEED: - case QUERY_ATTRIBUTES.DRM_LOAD_TIME: - case QUERY_ATTRIBUTES.DROPPED_FRAMES: - case QUERY_ATTRIBUTES.DURATION: - case QUERY_ATTRIBUTES.ERROR_CODE: - case QUERY_ATTRIBUTES.PAGE_LOAD_TIME: - case QUERY_ATTRIBUTES.PAGE_LOAD_TYPE: - case QUERY_ATTRIBUTES.PAUSED: - case QUERY_ATTRIBUTES.PLAYED: - case QUERY_ATTRIBUTES.PLAYER_STARTUPTIME: - case QUERY_ATTRIBUTES.SCREEN_HEIGHT: - case QUERY_ATTRIBUTES.SCREEN_WIDTH: - case QUERY_ATTRIBUTES.SEEKED: - case QUERY_ATTRIBUTES.STARTUPTIME: - case QUERY_ATTRIBUTES.VIDEO_BITRATE: - case QUERY_ATTRIBUTES.VIDEO_DURATION: - case QUERY_ATTRIBUTES.VIDEO_PLAYBACK_HEIGHT: - case QUERY_ATTRIBUTES.VIDEO_PLAYBACK_WIDTH: - case QUERY_ATTRIBUTES.VIDEO_STARTUPTIME: - case QUERY_ATTRIBUTES.VIDEO_WINDOW_HEIGHT: - case QUERY_ATTRIBUTES.VIDEO_WINDOW_WIDTH: - case QUERY_ATTRIBUTES.VIDEOTIME_END: - case QUERY_ATTRIBUTES.VIDEOTIME_START: - case QUERY_ATTRIBUTES.VIEWTIME: { + case 'AUDIO_BITRATE': + case 'BUFFERED': + case 'CLIENT_TIME': + case 'DOWNLOAD_SPEED': + case 'DRM_LOAD_TIME': + case 'DROPPED_FRAMES': + case 'DURATION': + case 'ERROR_CODE': + case 'PAGE_LOAD_TIME': + case 'PAGE_LOAD_TYPE': + case 'PAUSED': + case 'PLAYED': + case 'PLAYER_STARTUPTIME': + case 'SCREEN_HEIGHT': + case 'SCREEN_WIDTH': + case 'SEEKED': + case 'STARTUPTIME': + case 'VIDEO_BITRATE': + case 'VIDEO_DURATION': + case 'VIDEO_PLAYBACK_HEIGHT': + case 'VIDEO_PLAYBACK_WIDTH': + case 'VIDEO_STARTUPTIME': + case 'VIDEO_WINDOW_HEIGHT': + case 'VIDEO_WINDOW_WIDTH': + case 'VIDEOTIME_END': + case 'VIDEOTIME_START': + case 'VIEWTIME': { const parsedValue = parseInt(rawValue, 10); if (isNaN(parsedValue)) { throw new Error(`Couldn't parse filter value, please provide data as an integer number`); @@ -161,8 +161,8 @@ const convertFilter = (rawValue: string, filterAttribute: QueryAttribute) => { return parsedValue; } - case QUERY_ATTRIBUTES.ERROR_PERCENTAGE: - case QUERY_ATTRIBUTES.REBUFFER_PERCENTAGE: { + case 'ERROR_PERCENTAGE': + case 'REBUFFER_PERCENTAGE': { const parsedValue = parseFloat(rawValue); if (isNaN(parsedValue)) { throw new Error(`Couldn't parse filter value, please provide data as a floating point number`); @@ -194,7 +194,7 @@ export const convertFilterValueToProperType = ( return null; } - if (filterOperator === QUERY_FILTER_OPERATORS.IN) { + if (filterOperator === 'IN') { try { return parseValueForInFilter(rawValue); } catch (e) {