/** * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; under version 2 * of the License (non-upgradable). * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Copyright (c) 2015-2021 (original work) Open Assessment Technologies SA ; */ define([ 'jquery', 'lodash', 'i18n', 'async', 'context', 'helpers', 'taoClientDiagnostic/tools/stats', 'taoQtiItem/qtiItem/core/Loader', 'taoQtiItem/qtiCommonRenderer/renderers/Renderer', 'taoClientDiagnostic/tools/getConfig', 'taoClientDiagnostic/tools/getLabels', 'taoClientDiagnostic/tools/getStatus' ], function($, _, __, async, context, helpers, stats, Loader, Renderer, getConfig, getLabels, getStatus) { 'use strict'; /** * Duration of one second (in milliseconds) * @type {number} * @private */ const _second = 1000; /** * Default timeout duration * @type {number} * @private */ const _defaultTimeout = 30 * _second; /** * Default number of renderings by samples * @type {number} * @private */ const _defaultOccurrencesCount = 10; /** * List of default samples * @type {Array} * @private */ const _defaultSamples = [ 'taoClientDiagnostic/tools/performances/data/sample1/', 'taoClientDiagnostic/tools/performances/data/sample2/', 'taoClientDiagnostic/tools/performances/data/sample3/' ]; /** * Default values for the performances tester * @type {object} * @private */ const _defaults = { id: 'performances', // The threshold for optimal performances optimal: 0.025, // The threshold for minimal performances threshold: 0.25 }; /** * A list of thresholds for performances check * @type {Array} * @private */ const _thresholds = [ { threshold: 0, message: __('Very slow performances'), type: 'error' }, { threshold: 33, message: __('Average performances'), type: 'warning' }, { threshold: 66, message: __('Good performances'), type: 'success' } ]; /** * List of translated texts per level. * The level is provided through the config as a numeric value, starting from 1. * @type {object} * @private */ const _messages = [ // level 1 { title: __('Workstation performances'), status: __('Checking the performances...'), performancesMin: __('Minimum rendering time'), performancesMax: __('Maximum rendering time'), performancesAverage: __('Average rendering time') } ]; /** * Base text used to build sample identifiers * @type {string} * @private */ const _sampleBaseId = 'sample'; /** * Loads a page inside a div and compute the time to load * @param {object} data The descriptor of the page to load * @param {Function} done A callback function called to provide the result * @private */ function loadItem(data, done) { //item location config const qtiJsonFile = `${data.url}qti.json`; const urlTokens = data.url.split('/'); const extension = urlTokens[0]; const fullpath = require.s.contexts._.config.paths[extension]; const baseUrl = data.url.replace(extension, fullpath); const loader = new Loader(); const renderer = new Renderer({ baseUrl: baseUrl // compatibility mode for legacy installations }); // check needed by compatibility mode for legacy installations if (renderer.getAssetManager) { renderer.getAssetManager().setData('baseUrl', baseUrl); } require([`json!${qtiJsonFile}`], function(itemData) { loader.loadItemData(itemData, function(item) { renderer.load(function() { //start right before rendering const start = window.performance.now(); //set renderer item.setRenderer(this); //render markup const $container = $('