From d47c2615d89c4e093b4597cbdb68737a44350d1b Mon Sep 17 00:00:00 2001 From: Quitterie Lucas Date: Mon, 19 Jul 2021 16:33:59 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8(dashboard)=20improve=20details=20D?= =?UTF-8?q?ashboard=20code=20structure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Details Dashboard file is restructured according to the common library proposed. Hence, the common library is also improved. --- src/dashboards/common.libsonnet | 50 +++++ src/dashboards/videos/common.libsonnet | 71 +++---- src/dashboards/videos/course.jsonnet | 83 ++++---- src/dashboards/videos/details.jsonnet | 252 ++++++----------------- src/dashboards/videos/statements.jsonnet | 57 ++--- 5 files changed, 217 insertions(+), 296 deletions(-) create mode 100644 src/dashboards/common.libsonnet diff --git a/src/dashboards/common.libsonnet b/src/dashboards/common.libsonnet new file mode 100644 index 0000000..1397049 --- /dev/null +++ b/src/dashboards/common.libsonnet @@ -0,0 +1,50 @@ +// General commons + +{ + fields: { + actor_account_name: 'actor.account.name.keyword', + course: 'object.definition.extensions.http://adlnet.gov/expapi/activities/course.keyword', + school: 'object.definition.extensions.https://w3id.org/xapi/acrossx/extensions/school.keyword', + session: 'object.definition.extensions.http://adlnet.gov/expapi/activities/module.keyword', + }, + metrics: { + count: { id: '1', type: 'count' }, + cardinality(field):: { + id: '1', + type: 'cardinality', + field: field, + }, + max(field):: { + id: '1', + type: 'max', + field: field, + }, + }, + objects: { + date_histogram(interval='auto', min_doc_count='1'):: { + id: 'date', + field: 'timestamp', + type: 'date_histogram', + settings: { + interval: interval, + min_doc_count: min_doc_count, + trimEdges: '0', + }, + }, + }, + tags: { + staff: 'staff', + teacher: 'teacher', + video: 'video', + xapi: 'xAPI', + }, + utils: { + double_escape_string(x):: std.strReplace(std.strReplace(x, ':', '\\\\:'), '/', '\\\\/'), + single_escape_string(x):: std.strReplace(std.strReplace(x, ':', '\\:'), '/', '\\/'), + }, + verb_ids: { + completed: 'http://adlnet.gov/expapi/verbs/completed', + initialized: 'http://adlnet.gov/expapi/verbs/initialized', + played: 'https://w3id.org/xapi/video/verbs/played', + }, +} diff --git a/src/dashboards/videos/common.libsonnet b/src/dashboards/videos/common.libsonnet index 9d32d08..f0ea4d5 100644 --- a/src/dashboards/videos/common.libsonnet +++ b/src/dashboards/videos/common.libsonnet @@ -1,74 +1,63 @@ +// Video commons + local grafana = import 'grafonnet/grafana.libsonnet'; local template = grafana.template; +local common = import '../common.libsonnet'; { - constants: { + datasources: { lrs: 'lrs', - verb_id_completed: 'http://adlnet.gov/expapi/verbs/completed', - verb_id_played: 'https://w3id.org/xapi/video/verbs/played', }, fields: { - actor_account_name: 'actor.account.name.keyword', context_extensions_completion_threshold: 'context.extensions.https://w3id.org/xapi/video/extensions/completion-threshold', - course: 'object.definition.extensions.http://adlnet.gov/expapi/activities/course.keyword', result_extensions_length: 'result.extensions.https://w3id.org/xapi/video/extensions/length', result_extensions_time: 'result.extensions.https://w3id.org/xapi/video/extensions/time', - school: 'object.definition.extensions.https://w3id.org/xapi/acrossx/extensions/school.keyword', - session: 'object.definition.extensions.http://adlnet.gov/expapi/activities/module.keyword', + verb_display_en_us: 'verb.display.en-US.keyword', video_id: 'object.id.keyword', }, - utils: { - double_escape_string(x):: std.strReplace(std.strReplace(x, ':', '\\\\:'), '/', '\\\\/'), - single_escape_string(x):: std.strReplace(std.strReplace(x, ':', '\\:'), '/', '\\/'), - }, - objects: { - count_metric: { id: '1', type: 'count' }, - date_histogram(interval='auto', min_doc_count='1'):: { - id: 'date', - field: 'timestamp', - type: 'date_histogram', - settings: { - interval: interval, - min_doc_count: min_doc_count, - trimEdges: '0', - }, - }, - }, queries: { school_course_session: '%(school)s:$SCHOOL AND %(course)s:$COURSE AND %(session)s:$SESSION' % { - school: $.utils.single_escape_string($.fields.school), - course: $.utils.single_escape_string($.fields.course), - session: $.utils.single_escape_string($.fields.session), + course: common.utils.single_escape_string(common.fields.course), + school: common.utils.single_escape_string(common.fields.school), + session: common.utils.single_escape_string(common.fields.session), }, + video_id: 'object.id.keyword:$VIDEO', }, templates: { course: template.new( name='COURSE', current='all', label='Course', - datasource=$.constants.lrs, + datasource=$.datasources.lrs, query='{"find": "terms", "field": "%(course)s", "query": "%(school)s:$SCHOOL"}' % { - course: $.fields.course, - school: $.utils.double_escape_string($.fields.school), + course: common.fields.course, + school: common.utils.double_escape_string(common.fields.school), }, refresh='time' ), + event_group_interval: template.custom( + name='EVENT_GROUP_INTERVAL', + current='30', + label='Event group interval', + query='1,10,20,30,60,120,180,300,600', + refresh='time' + ), school: template.new( name='SCHOOL', current='all', label='School', - datasource=$.constants.lrs, - query='{"find": "terms", "field": "%(school)s"}' % { school: $.fields.school }, + datasource=$.datasources.lrs, + query='{"find": "terms", "field": "%(school)s"}' % { school: common.fields.school }, refresh='time' ), session: template.new( name='SESSION', current='all', label='Session', - datasource=$.constants.lrs, + datasource=$.datasources.lrs, query='{"find": "terms", "field": "%(session)s", "query": "%(course)s:$COURSE"}' % { - session: $.fields.session, - course: $.utils.double_escape_string($.fields.course), + session: common.fields.session, + course: common.utils.double_escape_string(common.fields.course), }, refresh='time' ), @@ -79,6 +68,18 @@ local template = grafana.template; query='1d,7d,14d,21d,28d', refresh='time' ), + video: template.new( + name='VIDEO', + current='all', + label='Video', + datasource=$.datasources.lrs, + query='{"find": "terms", "field": "%(video_id)s", "query": "%(course)s:$COURSE AND %(session)s:$SESSION"}' % { + video_id: $.fields.video_id, + course: common.utils.double_escape_string(common.fields.course), + session: common.utils.double_escape_string(common.fields.session), + }, + refresh='time' + ), view_count_threshold: template.custom( name='VIEW_COUNT_THRESHOLD', current='30', diff --git a/src/dashboards/videos/course.jsonnet b/src/dashboards/videos/course.jsonnet index b379385..55d53c3 100644 --- a/src/dashboards/videos/course.jsonnet +++ b/src/dashboards/videos/course.jsonnet @@ -1,23 +1,24 @@ +// Video course dashboard + local grafana = import 'grafonnet/grafana.libsonnet'; local dashboard = grafana.dashboard; local elasticsearch = grafana.elasticsearch; local barGaugePanel = grafana.barGaugePanel; local graphPanel = grafana.graphPanel; local statPanel = grafana.statPanel; - -local common = import 'common.libsonnet'; - +local common = import '../common.libsonnet'; +local video_common = import 'common.libsonnet'; dashboard.new( 'Course', - tags=['xAPI', 'video', 'teacher'], + tags=[common.tags.xapi, common.tags.video, common.tags.teacher], editable=false ) -.addTemplate(common.templates.school) -.addTemplate(common.templates.course) -.addTemplate(common.templates.session) -.addTemplate(common.templates.view_count_threshold) -.addTemplate(common.templates.statements_interval) +.addTemplate(video_common.templates.school) +.addTemplate(video_common.templates.course) +.addTemplate(video_common.templates.session) +.addTemplate(video_common.templates.view_count_threshold) +.addTemplate(video_common.templates.statements_interval) .addPanel( statPanel.new( title='Views', @@ -29,18 +30,18 @@ dashboard.new( the video during the first seconds of the video. This time range is controlled by the `View count threshold` variable. |||, - datasource=common.constants.lrs, + datasource=video_common.datasources.lrs, graphMode='none', reducerFunction='sum' ).addTarget( elasticsearch.target( - datasource=common.constants.lrs, + datasource=video_common.datasources.lrs, query='%(course_query)s AND verb.id:"%(verb_played)s" AND %(time)s:[0 TO $VIEW_COUNT_THRESHOLD]' % { - course_query: common.queries.school_course_session, - verb_played: common.constants.verb_id_played, - time: common.utils.single_escape_string(common.fields.result_extensions_time), + course_query: video_common.queries.school_course_session, + verb_played: common.verb_ids.played, + time: common.utils.single_escape_string(video_common.fields.result_extensions_time), }, - metrics=[common.objects.count_metric], + metrics=[common.metrics.count], bucketAggs=[common.objects.date_histogram('$STATEMENTS_INTERVAL')], timeField='timestamp' ) @@ -54,17 +55,17 @@ dashboard.new( Total number of complete views of videos present in the selected course / session. A view is considered as complete when the completion threshold of the video has been reached. |||, - datasource=common.constants.lrs, + datasource=video_common.datasources.lrs, graphMode='none', reducerFunction='sum', ).addTarget( elasticsearch.target( - datasource=common.constants.lrs, + datasource=video_common.datasources.lrs, query='%(course_query)s AND verb.id:"%(verb_completed)s"' % { - course_query: common.queries.school_course_session, - verb_completed: common.constants.verb_id_completed, + course_query: video_common.queries.school_course_session, + verb_completed: common.verb_ids.completed, }, - metrics=[common.objects.count_metric], + metrics=[common.metrics.count], bucketAggs=[common.objects.date_histogram()], timeField='timestamp' ) @@ -78,16 +79,16 @@ dashboard.new( A view is counted when the user has clicked the play button in the interface in the first ${VIEW_COUNT_THRESHOLD} seconds of the video. |||, - datasource=common.constants.lrs, + datasource=video_common.datasources.lrs, ).addTarget( elasticsearch.target( - datasource=common.constants.lrs, + datasource=video_common.datasources.lrs, query='%(course_query)s AND verb.id:"%(verb_played)s" AND %(time)s:[0 TO $VIEW_COUNT_THRESHOLD]' % { - course_query: common.queries.school_course_session, - verb_played: common.constants.verb_id_played, - time: common.utils.single_escape_string(common.fields.result_extensions_time), + course_query: video_common.queries.school_course_session, + verb_played: common.verb_ids.played, + time: common.utils.single_escape_string(video_common.fields.result_extensions_time), }, - metrics=[common.objects.count_metric], + metrics=[common.metrics.count], bucketAggs=[common.objects.date_histogram('$STATEMENTS_INTERVAL')], timeField='timestamp' ) @@ -102,7 +103,7 @@ dashboard.new( On the X-axis is the number of statements. On the Y-axis is the number of users. |||, - datasource: common.constants.lrs, + datasource: video_common.datasources.lrs, fieldConfig: { defaults: { color: { @@ -126,7 +127,7 @@ dashboard.new( field: 'timestamp', id: '2', settings: { - interval: '3600000', + interval: '1h', min_doc_count: '1', }, type: 'histogram', @@ -143,8 +144,8 @@ dashboard.new( type: 'terms', }, ], - metrics: [common.objects.count_metric], - query: common.queries.school_course_session, + metrics: [common.metrics.count], + query: video_common.queries.school_course_session, refId: 'A', timeField: 'timestamp', }, @@ -179,7 +180,7 @@ dashboard.new( On the X-axis is the number of completed videos. On the Y-axis is the number of users. |||, - datasource: common.constants.lrs, + datasource: video_common.datasources.lrs, fieldConfig: { defaults: { color: { @@ -220,10 +221,10 @@ dashboard.new( type: 'terms', }, ], - metrics: [common.objects.count_metric], + metrics: [common.metrics.count], query: '%(course_query)s AND verb.id:"%(completed)s"' % { - course_query: common.queries.school_course_session, - completed: common.constants.verb_id_completed, + course_query: video_common.queries.school_course_session, + completed: common.verb_ids.completed, }, refId: 'A', timeField: 'timestamp', @@ -257,19 +258,19 @@ dashboard.new( description=||| The total count of views by video. |||, - datasource=common.constants.lrs, + datasource=video_common.datasources.lrs, ).addTarget( elasticsearch.target( - datasource=common.constants.lrs, + datasource=video_common.datasources.lrs, query='%(course_query)s AND verb.id:"%(verb_played)s" AND %(time)s:[0 TO $VIEW_COUNT_THRESHOLD]' % { - course_query: common.queries.school_course_session, - verb_played: common.constants.verb_id_played, - time: common.utils.single_escape_string(common.fields.result_extensions_time), + course_query: video_common.queries.school_course_session, + verb_played: common.verb_ids.played, + time: common.utils.single_escape_string(video_common.fields.result_extensions_time), }, - metrics=[common.objects.count_metric], + metrics=[common.metrics.count], bucketAggs=[ { - field: common.fields.video_id, + field: video_common.fields.video_id, id: '2', settings: { min_doc_count: '1', diff --git a/src/dashboards/videos/details.jsonnet b/src/dashboards/videos/details.jsonnet index 0b8a069..8a49494 100644 --- a/src/dashboards/videos/details.jsonnet +++ b/src/dashboards/videos/details.jsonnet @@ -1,111 +1,25 @@ +// Video details dashboard + local grafana = import 'grafonnet/grafana.libsonnet'; local dashboard = grafana.dashboard; local elasticsearch = grafana.elasticsearch; local graphPanel = grafana.graphPanel; local row = grafana.row; local statPanel = grafana.statPanel; -local template = grafana.template; - - -// Constants -local lrs = 'lrs'; -local actor_account_name_field = 'actor.account.name.keyword'; -local context_extensions_completion_threshold_field = 'context.extensions.https://w3id.org/xapi/video/extensions/completion-threshold'; -local course_field = 'object.definition.extensions.http://adlnet.gov/expapi/activities/course.keyword'; -local result_extensions_time_field = 'result.extensions.https://w3id.org/xapi/video/extensions/time'; -local school_field = 'object.definition.extensions.https://w3id.org/xapi/acrossx/extensions/school.keyword'; -local session_field = 'object.definition.extensions.http://adlnet.gov/expapi/activities/module.keyword'; -local verb_display_en_us_field = 'verb.display.en-US.keyword'; -local video_id_field = 'object.id.keyword'; -local verb_id_completed_value = 'http://adlnet.gov/expapi/verbs/completed'; -local verb_id_initialized_value = 'http://adlnet.gov/expapi/verbs/initialized'; -local verb_id_played_value = 'https://w3id.org/xapi/video/verbs/played'; - - -// Queries -local video_id_query = 'object.id.keyword:$VIDEO'; - -// Utils -local double_escape_string(x) = std.strReplace(std.strReplace(x, ':', '\\\\:'), '/', '\\\\/'); -local single_escape_string(x) = std.strReplace(std.strReplace(x, ':', '\\:'), '/', '\\/'); +local video_common = import 'common.libsonnet'; +local common = import '../common.libsonnet'; - -// Dashboard dashboard.new( 'Details', - tags=['xAPI', 'video', 'teacher'], + tags=[common.tags.xapi, common.tags.video, common.tags.teacher], editable=false ) -.addTemplate( - template.new( - name='SCHOOL', - current='all', - label='School', - datasource=lrs, - query='{"find": "terms", "field": "%(school)s"}' % { - school: school_field, - }, - refresh='time' - ) -) -.addTemplate( - template.new( - name='COURSE', - current='all', - label='Course', - datasource=lrs, - query='{"find": "terms", "field": "%(course)s", "query": "%(school)s:$SCHOOL"}' % { - course: course_field, - school: double_escape_string(school_field), - }, - refresh='time' - ) -) -.addTemplate( - template.new( - name='SESSION', - current='all', - label='Session', - datasource=lrs, - query='{"find": "terms", "field": "%(session)s", "query": "%(course)s:$COURSE"}' % { - session: session_field, - course: double_escape_string(course_field), - }, - refresh='time' - ) -) -.addTemplate( - template.new( - name='VIDEO', - current='all', - label='Video', - datasource=lrs, - query='{"find": "terms", "field": "%(video_id)s", "query": "%(course)s:$COURSE AND %(session)s:$SESSION"}' % { - video_id: video_id_field, - course: double_escape_string(course_field), - session: double_escape_string(session_field), - }, - refresh='time' - ) -) -.addTemplate( - template.custom( - name='VIEW_COUNT_THRESHOLD', - current='30', - label='View count threshold', - query='0,10,20,30,40,50,60', - refresh='time' - ) -) -.addTemplate( - template.custom( - name='EVENT_GROUP_INTERVAL', - current='30', - label='Event group interval', - query='1,10,20,30,60,120,180,300,600', - refresh='time' - ) -) +.addTemplate(video_common.templates.school) +.addTemplate(video_common.templates.course) +.addTemplate(video_common.templates.session) +.addTemplate(video_common.templates.video) +.addTemplate(video_common.templates.view_count_threshold) +.addTemplate(video_common.templates.event_group_interval) .addPanel( row.new(title='Views metrics', collapse=false), gridPos={ x: 0, y: 0, w: 24, h: 1 } @@ -121,24 +35,19 @@ dashboard.new( the video during the first seconds of the video. This time range is controlled by the `View count threshold` variable. |||, - datasource=lrs, + datasource=video_common.datasources.lrs, reducerFunction='sum', graphMode='none', unit='none' ).addTarget( elasticsearch.target( - datasource=lrs, + datasource=video_common.datasources.lrs, query='%(video_query)s AND verb.id:"%(verb_played)s" AND %(time)s:[0 TO $VIEW_COUNT_THRESHOLD]' % { - video_query: video_id_query, - verb_played: verb_id_played_value, - time: single_escape_string(result_extensions_time_field), + video_query: video_common.queries.video_id, + verb_played: common.verb_ids.played, + time: common.utils.single_escape_string(video_common.fields.result_extensions_time), }, - metrics=[ - { - id: '1', - type: 'count', - }, - ], + metrics=[common.metrics.count], bucketAggs=[ { id: 'date', @@ -163,29 +72,23 @@ dashboard.new( Unique views are views aggregated by users: each user can generate at most one view in this metric. |||, - datasource=lrs, + datasource=video_common.datasources.lrs, graphMode='none', reducerFunction='sum', unit='none', fields='/^Unique Count$/' ).addTarget( elasticsearch.target( - datasource=lrs, + datasource=video_common.datasources.lrs, query='%(video_query)s AND verb.id:"%(verb_played)s"' % { - video_query: video_id_query, - verb_played: verb_id_played_value, + video_query: video_common.queries.video_id, + verb_played: common.verb_ids.played, }, - metrics=[ - { - id: '1', - type: 'cardinality', - field: actor_account_name_field, - }, - ], + metrics=[common.metrics.cardinality(common.fields.actor_account_name)], bucketAggs=[ { id: 'name', - field: actor_account_name_field, + field: common.fields.actor_account_name, type: 'terms', settings: { order: 'desc', @@ -207,22 +110,17 @@ dashboard.new( Total number of complete views of selected video. A view is considered as complete when the completion threshold of the video has been reached. |||, - datasource=lrs, + datasource=video_common.datasources.lrs, graphMode='none', reducerFunction='sum', ).addTarget( elasticsearch.target( - datasource=lrs, + datasource=video_common.datasources.lrs, query='%(video_query)s AND verb.id:"%(verb_completed)s"' % { - video_query: video_id_query, - verb_completed: verb_id_completed_value, + video_query: video_common.queries.video_id, + verb_completed: common.verb_ids.completed, }, - metrics=[ - { - id: '1', - type: 'count', - }, - ], + metrics=[common.metrics.count], bucketAggs=[ { id: '5', @@ -245,29 +143,23 @@ dashboard.new( description=||| Total number of unique complete views of selected video. |||, - datasource=lrs, + datasource=video_common.datasources.lrs, graphMode='none', reducerFunction='sum', unit='none', fields='/^Unique Count$/' ).addTarget( elasticsearch.target( - datasource=lrs, + datasource=video_common.datasources.lrs, query='%(video_query)s AND verb.id:"%(verb_completed)s"' % { - video_query: video_id_query, - verb_completed: verb_id_completed_value, + video_query: video_common.queries.video_id, + verb_completed: common.verb_ids.completed, }, - metrics=[ - { - id: '1', - type: 'cardinality', - field: actor_account_name_field, - }, - ], + metrics=[common.metrics.cardinality(common.fields.actor_account_name)], bucketAggs=[ { id: '5', - field: actor_account_name_field, + field: common.fields.actor_account_name, type: 'terms', settings: { min_doc_count: '0', @@ -288,25 +180,19 @@ dashboard.new( description=||| Ratio of the video that needs to be seen to consider the video as completed. |||, - datasource=lrs, + datasource=video_common.datasources.lrs, graphMode='none', reducerFunction='max', unit='none', fields='/^Max context\\.extensions.https://w3id.org/xapi/video/extensions/completion\\-threshold$/' ).addTarget( elasticsearch.target( - datasource=lrs, + datasource=video_common.datasources.lrs, query='%(video_query)s AND verb.id:"%(verb_initialized)s"' % { - video_query: video_id_query, - verb_initialized: verb_id_initialized_value, + video_query: video_common.queries.video_id, + verb_initialized: common.verb_ids.initialized, }, - metrics=[ - { - id: '1', - type: 'max', - field: context_extensions_completion_threshold_field, - }, - ], + metrics=[common.metrics.max(video_common.fields.context_extensions_completion_threshold)], bucketAggs=[ { id: '2', @@ -328,21 +214,16 @@ dashboard.new( A view is counted when the user has clicked the play button in the interface in the first ${VIEW_COUNT_THRESHOLD} seconds of the video. |||, - datasource=lrs, + datasource=video_common.datasources.lrs, ).addTarget( elasticsearch.target( - datasource=lrs, + datasource=video_common.datasources.lrs, query='%(video_query)s AND verb.id:"%(verb_played)s" AND %(time)s:[0 TO $VIEW_COUNT_THRESHOLD]' % { - video_query: video_id_query, - verb_played: verb_id_played_value, - time: single_escape_string(result_extensions_time_field), + video_query: video_common.queries.video_id, + verb_played: common.verb_ids.played, + time: common.utils.single_escape_string(video_common.fields.result_extensions_time), }, - metrics=[ - { - id: '1', - type: 'count', - }, - ], + metrics=[common.metrics.count], bucketAggs=[ { id: 'date', @@ -367,19 +248,14 @@ dashboard.new( .addPanel( graphPanel.new( title='Verbs', - datasource=lrs, + datasource=video_common.datasources.lrs, bars=true, lines=false, ).addTarget( elasticsearch.target( - datasource=lrs, - query=video_id_query, - metrics=[ - { - id: '1', - type: 'count', - }, - ], + datasource=video_common.datasources.lrs, + query=video_common.queries.video_id, + metrics=[common.metrics.count], bucketAggs=[ { id: 'verb', @@ -414,26 +290,21 @@ dashboard.new( description=||| Distribution of events according to their type. |||, - datasource=lrs, + datasource=video_common.datasources.lrs, bars='true', lines='false', x_axis_mode='series', ).addTarget( elasticsearch.target( - datasource=lrs, + datasource=video_common.datasources.lrs, query='%(video_query)s' % { - video_query: video_id_query, + video_query: video_common.queries.video_id, }, - metrics=[ - { - id: '1', - type: 'count', - }, - ], + metrics=[common.metrics.count], bucketAggs=[ { id: '2', - field: verb_display_en_us_field, + field: video_common.fields.verb_display_en_us, type: 'terms', settings: { order: 'asc', @@ -472,7 +343,7 @@ dashboard.new( cacheTimeout: null, chartType: 'stacked bar chart', colorSch: [], - datasource: 'lrs', + datasource: video_common.datasources.lrs, fontColor: '#fff', fontSize: '80%', format: 'short', @@ -495,7 +366,7 @@ dashboard.new( alias: '', bucketAggs: [ { - field: result_extensions_time_field, + field: video_common.fields.result_extensions_time, id: '2', settings: { interval: '$EVENT_GROUP_INTERVAL', @@ -504,7 +375,7 @@ dashboard.new( type: 'histogram', }, { - field: verb_display_en_us_field, + field: video_common.fields.verb_display_en_us, id: '3', settings: { min_doc_count: '0', @@ -515,13 +386,8 @@ dashboard.new( type: 'terms', }, ], - metrics: [ - { - id: '1', - type: 'count', - }, - ], - query: video_id_query, + metrics: [common.metrics.count], + query: video_common.queries.video_id, refId: 'A', timeField: 'timestamp', }, diff --git a/src/dashboards/videos/statements.jsonnet b/src/dashboards/videos/statements.jsonnet index abedfd3..2f52741 100644 --- a/src/dashboards/videos/statements.jsonnet +++ b/src/dashboards/videos/statements.jsonnet @@ -1,33 +1,36 @@ +// Video statements dashboard + local grafana = import 'grafonnet/grafana.libsonnet'; local dashboard = grafana.dashboard; local elasticsearch = grafana.elasticsearch; local graphPanel = grafana.graphPanel; local statPanel = grafana.statPanel; +local common = import '../common.libsonnet'; +local video_common = import 'common.libsonnet'; -local common = import 'common.libsonnet'; dashboard.new( 'Statements', - tags=['xAPI', 'video', 'staff'], + tags=[common.tags.xapi, common.tags.video, common.tags.staff], editable=false ) -.addTemplate(common.templates.school) -.addTemplate(common.templates.course) -.addTemplate(common.templates.session) -.addTemplate(common.templates.statements_interval) +.addTemplate(video_common.templates.school) +.addTemplate(video_common.templates.course) +.addTemplate(video_common.templates.session) +.addTemplate(video_common.templates.statements_interval) .addPanel( statPanel.new( title='Statements', description=||| Total count of statements in the selected time range. |||, - datasource=common.constants.lrs, + datasource=video_common.datasources.lrs, reducerFunction='sum', ).addTarget( elasticsearch.target( - datasource=common.constants.lrs, - query=common.queries.school_course_session, - metrics=[common.objects.count_metric], + datasource=video_common.datasources.lrs, + query=video_common.queries.school_course_session, + metrics=[common.metrics.count], bucketAggs=[common.objects.date_histogram('$STATEMENTS_INTERVAL')], timeField='timestamp' ) @@ -40,17 +43,17 @@ dashboard.new( description=||| Total number of videos which had at least one interaction in the selected time range. |||, - datasource=common.constants.lrs, + datasource=video_common.datasources.lrs, reducerFunction='count', ).addTarget( elasticsearch.target( - datasource=common.constants.lrs, - query=common.queries.school_course_session, - metrics=[common.objects.count_metric], + datasource=video_common.datasources.lrs, + query=video_common.queries.school_course_session, + metrics=[common.metrics.count], bucketAggs=[ { id: 'video', - field: common.fields.video_id, + field: video_common.fields.video_id, type: 'terms', settings: { min_doc_count: '1', @@ -70,14 +73,14 @@ dashboard.new( Number of statements by ${STATEMENTS_INTERVAL}. The interval is controlled by the `Statements interval` variable |||, - datasource=common.constants.lrs, + datasource=video_common.datasources.lrs, bars=true, lines=false, ).addTarget( elasticsearch.target( - datasource=common.constants.lrs, - query=common.queries.school_course_session, - metrics=[common.objects.count_metric], + datasource=video_common.datasources.lrs, + query=video_common.queries.school_course_session, + metrics=[common.metrics.count], bucketAggs=[common.objects.date_histogram('$STATEMENTS_INTERVAL')], timeField='timestamp' ) @@ -91,7 +94,7 @@ dashboard.new( The distribution of the video durations in seconds. On the Y-axis is the video count and on the X-axis the duration. |||, - datasource: common.constants.lrs, + datasource: video_common.datasources.lrs, fieldConfig: { defaults: { color: { @@ -114,7 +117,7 @@ dashboard.new( { bucketAggs: [ { - field: common.fields.video_id, + field: video_common.fields.video_id, id: '3', settings: { min_doc_count: '0', @@ -127,12 +130,12 @@ dashboard.new( ], metrics: [ { - field: common.fields.result_extensions_length, + field: video_common.fields.result_extensions_length, id: '1', type: 'max', }, ], - query: common.queries.school_course_session, + query: video_common.queries.school_course_session, refId: 'A', timeField: 'timestamp', }, @@ -150,7 +153,7 @@ dashboard.new( The distribution of the completion threshold by video. On the Y-axis is the number of videos and on the X-axis the threshold interval. |||, - datasource: common.constants.lrs, + datasource: video_common.datasources.lrs, fieldConfig: { defaults: { color: { @@ -186,14 +189,14 @@ dashboard.new( ], metrics: [ { - field: common.fields.context_extensions_completion_threshold, + field: video_common.fields.context_extensions_completion_threshold, id: '1', type: 'max', }, ], query: '%(course_query)s AND verb.id:"%(completed)s"' % { - course_query: common.queries.school_course_session, - completed: common.constants.verb_id_completed, + course_query: video_common.queries.school_course_session, + completed: common.verb_ids.completed, }, refId: 'A', timeField: 'timestamp',