|
|
AIWROKÈí¼þʾÀýÊý×é·½·¨ÊµÕ½Ó¦ÓÃ
- /**
- * AIWROKÊý×é·½·¨ÊµÕ½Ó¦ÓÃʾÀý
- * רΪAIWROK°²×¿×Ô¶¯»¯»·¾³Éè¼ÆµÄÕæÊµÊý×éÓ¦Óó¡¾°
- *
- * @¹¦ÄÜÌØµã
- * - UI¿Ø¼þÊý×éµÄ²éÕÒ¡¢É¸Ñ¡ºÍÅúÁ¿²Ù×÷
- * - ͼÏñʶ±ð½á¹ûµÄÊý×é´¦ÀíºÍ×ø±ê¼ÆËã
- * - É豸ÐÅÏ¢Êý×éµÄ¹ÜÀíºÍ²éѯ
- * - ÈÎÎñ¶ÓÁÐÊý×éµÄµ÷¶ÈºÍÖ´ÐÐ
- *
- * @×÷Õß AIWROK¿ª·¢ÍŶÓ
- * @°æ±¾ 3.0 - ʵս°æ
- * @ÈÕÆÚ 2024
- */
- //===========================================
- // »ù´¡¼æÈÝÐÔÉèÖÃ
- //===========================================
- // AIWROK»·¾³Í³Ò»Ê¹ÓÃconsole.logÊä³öÈÕÖ¾
- //===========================================
- // ¸ß¼¶Êý×鹤¾ßÀà - ÔöÇ¿°æ
- //===========================================
- /**
- * AdvancedArrayUtils - ¸ß¼¶Êý×é²Ù×÷¹¤¾ßÀà
- * ÌṩÁ´Ê½µ÷Óá¢ÅúÁ¿´¦ÀíºÍÐÔÄÜÓÅ»¯¹¦ÄÜ
- */
- function AdvancedArrayUtils() {
- this.version = "2.0.0";
- this.performanceMetrics = {
- operations: 0,
- startTime: 0,
- endTime: 0,
- memoryUsage: 0
- };
- }
- /**
- * ¿ªÊ¼ÐÔÄÜ¼à¿Ø
- */
- AdvancedArrayUtils.prototype.startPerformanceMonitoring = function() {
- this.performanceMetrics.startTime = new Date().getTime();
- this.performanceMetrics.operations = 0;
- return this;
- };
- /**
- * ½áÊøÐÔÄÜ¼à¿Ø²¢·µ»Ø±¨¸æ
- */
- AdvancedArrayUtils.prototype.endPerformanceMonitoring = function() {
- this.performanceMetrics.endTime = new Date().getTime();
- var duration = this.performanceMetrics.endTime - this.performanceMetrics.startTime;
- return {
- duration: duration,
- operations: this.performanceMetrics.operations,
- opsPerSecond: Math.round(this.performanceMetrics.operations / (duration / 1000)),
- memoryUsage: this.performanceMetrics.memoryUsage
- };
- };
- /**
- * °²È«Êý×é±éÀú - Ö§³ÖÖжϺÍÒì³£´¦Àí
- * @param {Array} array - Òª±éÀúµÄÊý×é
- * @param {Function} callback - »Øµ÷º¯Êý£¬·µ»Øfalse¿ÉÖжϱéÀú
- * @param {Object} context - »Øµ÷º¯ÊýÉÏÏÂÎÄ
- * @returns {AdvancedArrayUtils} Ö§³ÖÁ´Ê½µ÷ÓÃ
- */
- AdvancedArrayUtils.prototype.forEachSafe = function(array, callback, context) {
- if (!Array.isArray(array)) throw new Error('²ÎÊý±ØÐëÊÇÊý×é');
- if (typeof callback !== 'function') throw new Error('»Øµ÷º¯Êý±ØÐëÊǺ¯Êý');
-
- context = context || this;
-
- try {
- for (var i = 0; i < array.length; i++) {
- this.performanceMetrics.operations++;
- var result = callback.call(context, array[i], i, array);
- if (result === false) break; // Ö§³ÖÖ÷¶¯ÖжÏ
- }
- } catch (e) {
- console.log("Êý×é±éÀú´íÎó at index " + i + ": " + (e.message || e));
- }
-
- return this;
- };
- /**
- * ÖÇÄÜÊý×é¹ýÂË - Ö§³Ö¶àÌõ¼þºÍ¸´ÔÓÂß¼
- * @param {Array} array - Ô´Êý×é
- * @param {Array} conditions - ¹ýÂËÌõ¼þÊý×é
- * @returns {Array} ¹ýÂ˺óµÄÊý×é
- *
- * @ʾÀý
- * var result = advancedArrayUtils.smartFilter(data, [
- * { field: 'age', operator: '>', value: 18 },
- * { field: 'name', operator: 'contains', value: 'ÕÅ' },
- * { field: 'score', operator: 'between', value: [60, 100] }
- * ]);
- */
- AdvancedArrayUtils.prototype.smartFilter = function(array, conditions) {
- if (!Array.isArray(array)) throw new Error('µÚÒ»¸ö²ÎÊý±ØÐëÊÇÊý×é');
- if (!Array.isArray(conditions)) throw new Error('Ìõ¼þ²ÎÊý±ØÐëÊÇÊý×é');
-
- var self = this;
-
- return array.filter(function(item) {
- self.performanceMetrics.operations++;
-
- for (var i = 0; i < conditions.length; i++) {
- var condition = conditions[i];
- var fieldValue = self.getFieldValue(item, condition.field);
-
- if (!self.evaluateCondition(fieldValue, condition.operator, condition.value)) {
- return false;
- }
- }
-
- return true;
- });
- };
- /**
- * »ñÈ¡¶ÔÏó×Ö¶ÎÖµ - Ö§³ÖǶÌ×ÊôÐÔ·ÃÎÊ
- */
- AdvancedArrayUtils.prototype.getFieldValue = function(obj, field) {
- if (!obj || !field) return undefined;
-
- var parts = field.split('.');
- var result = obj;
-
- for (var i = 0; i < parts.length; i++) {
- if (result === null || result === undefined) return undefined;
- result = result[parts[i]];
- }
-
- return result;
- };
- /**
- * ÆÀ¹ÀÌõ¼þ - Ö§³Ö¶àÖÖ²Ù×÷·û
- */
- AdvancedArrayUtils.prototype.evaluateCondition = function(fieldValue, operator, conditionValue) {
- switch (operator) {
- case '==': return fieldValue == conditionValue;
- case '===': return fieldValue === conditionValue;
- case '!=': return fieldValue != conditionValue;
- case '!==': return fieldValue !== conditionValue;
- case '>': return fieldValue > conditionValue;
- case '>=': return fieldValue >= conditionValue;
- case '<': return fieldValue < conditionValue;
- case '<=': return fieldValue <= conditionValue;
- case 'contains':
- return String(fieldValue).indexOf(conditionValue) !== -1;
- case 'startsWith':
- return String(fieldValue).indexOf(conditionValue) === 0;
- case 'endsWith':
- var str = String(fieldValue);
- return str.lastIndexOf(conditionValue) === str.length - conditionValue.length;
- case 'between':
- return fieldValue >= conditionValue[0] && fieldValue <= conditionValue[1];
- case 'in':
- return conditionValue.indexOf(fieldValue) !== -1;
- case 'notIn':
- return conditionValue.indexOf(fieldValue) === -1;
- default:
- return false;
- }
- };
- /**
- * Êý×éÊý¾Ý¾ÛºÏ - Ö§³Ö¶àÖ־ۺϺ¯Êý
- * @param {Array} array - Ô´Êý×é
- * @param {Object} config - ¾ÛºÏÅäÖÃ
- * @returns {Object} ¾ÛºÏ½á¹û
- *
- * @ʾÀý
- * var stats = advancedArrayUtils.aggregate(salesData, {
- * groupBy: 'category',
- * metrics: {
- * totalSales: { field: 'amount', operation: 'sum' },
- * avgPrice: { field: 'price', operation: 'avg' },
- * count: { operation: 'count' }
- * }
- * });
- */
- AdvancedArrayUtils.prototype.aggregate = function(array, config) {
- if (!Array.isArray(array)) throw new Error('²ÎÊý±ØÐëÊÇÊý×é');
-
- var result = {};
- var self = this;
-
- // ·Ö×é´¦Àí
- if (config.groupBy) {
- var groups = {};
-
- array.forEach(function(item) {
- self.performanceMetrics.operations++;
- var groupKey = self.getFieldValue(item, config.groupBy);
- if (!groups[groupKey]) {
- groups[groupKey] = [];
- }
- groups[groupKey].push(item);
- });
-
- // ¶Ôÿ¸ö·Ö×é½øÐоۺÏ
- for (var groupKey in groups) {
- if (groups.hasOwnProperty(groupKey)) {
- result[groupKey] = self.calculateMetrics(groups[groupKey], config.metrics);
- }
- }
- } else {
- // ²»·Ö×飬ֱ½Ó¾ÛºÏ
- result = this.calculateMetrics(array, config.metrics);
- }
-
- return result;
- };
- /**
- * ¼ÆËãÖ¸±ê - Ö§³Ö¶àÖ־ۺϲÙ×÷
- */
- AdvancedArrayUtils.prototype.calculateMetrics = function(array, metrics) {
- var result = {};
- var self = this;
-
- for (var metricName in metrics) {
- if (metrics.hasOwnProperty(metricName)) {
- var metric = metrics[metricName];
- result[metricName] = self.calculateMetric(array, metric);
- }
- }
-
- return result;
- };
- /**
- * ¼ÆËãµ¥¸öÖ¸±ê
- */
- AdvancedArrayUtils.prototype.calculateMetric = function(array, metric) {
- var operation = metric.operation;
- var field = metric.field;
-
- switch (operation) {
- case 'count':
- return array.length;
-
- case 'sum':
- return array.reduce(function(sum, item) {
- return sum + (field ? this.getFieldValue(item, field) : item);
- }.bind(this), 0);
-
- case 'avg':
- var sum = array.reduce(function(sum, item) {
- return sum + (field ? this.getFieldValue(item, field) : item);
- }.bind(this), 0);
- return array.length > 0 ? sum / array.length : 0;
-
- case 'max':
- return Math.max.apply(Math, array.map(function(item) {
- return field ? this.getFieldValue(item, field) : item;
- }.bind(this)));
-
- case 'min':
- return Math.min.apply(Math, array.map(function(item) {
- return field ? this.getFieldValue(item, field) : item;
- }.bind(this)));
-
- default:
- return 0;
- }
- };
- /**
- * Êý×é·ÖÒ³´¦Àí - Ö§³Ö´óÊý¾Ý¼¯µÄ·ÖÒ³ÏÔʾ
- * @param {Array} array - Ô´Êý×é
- * @param {number} pageSize - ÿҳ´óС
- * @param {number} pageNumber - Ò³Â루´Ó1¿ªÊ¼£©
- * @returns {Object} ·ÖÒ³½á¹û
- */
- AdvancedArrayUtils.prototype.paginate = function(array, pageSize, pageNumber) {
- if (!Array.isArray(array)) throw new Error('²ÎÊý±ØÐëÊÇÊý×é');
-
- pageSize = Math.max(1, pageSize || 10);
- pageNumber = Math.max(1, pageNumber || 1);
-
- var totalItems = array.length;
- var totalPages = Math.ceil(totalItems / pageSize);
- var startIndex = (pageNumber - 1) * pageSize;
- var endIndex = Math.min(startIndex + pageSize, totalItems);
-
- return {
- items: array.slice(startIndex, endIndex),
- pagination: {
- pageNumber: pageNumber,
- pageSize: pageSize,
- totalItems: totalItems,
- totalPages: totalPages,
- hasPrevious: pageNumber > 1,
- hasNext: pageNumber < totalPages,
- startIndex: startIndex,
- endIndex: endIndex - 1
- }
- };
- };
- /**
- * Êý×éÈ¥ÖØ - Ö§³Ö¸´ÔÓ¶ÔÏóµÄÈ¥ÖØ
- * @param {Array} array - Ô´Êý×é
- * @param {string|Function} keySelector - ÓÃÓÚÈ¥ÖØµÄ¼üÑ¡ÔñÆ÷
- * @returns {Array} È¥ÖØºóµÄÊý×é
- */
- AdvancedArrayUtils.prototype.distinct = function(array, keySelector) {
- if (!Array.isArray(array)) throw new Error('²ÎÊý±ØÐëÊÇÊý×é');
-
- var seen = {};
- var result = [];
- var self = this;
-
- array.forEach(function(item) {
- self.performanceMetrics.operations++;
-
- var key;
- if (typeof keySelector === 'function') {
- key = keySelector(item);
- } else if (typeof keySelector === 'string') {
- key = self.getFieldValue(item, keySelector);
- } else {
- key = item;
- }
-
- var keyString = String(key);
- if (!seen.hasOwnProperty(keyString)) {
- seen[keyString] = true;
- result.push(item);
- }
- });
-
- return result;
- };
- //===========================================
- // AIWROKÌØ¶¨¹¦Äܼ¯³É
- //===========================================
- /**
- * UI¿Ø¼þÅúÁ¿´¦Àí - ½áºÏAIWROKµÄUI²Ù×÷
- * @param {Array} uiElements - UIÔªËØÊý×é
- * @param {Function} processor - ´¦Àíº¯Êý
- * @param {Object} options - ´¦ÀíÑ¡Ïî
- */
- AdvancedArrayUtils.prototype.batchUIProcess = function(uiElements, processor, options) {
- options = options || {};
- var batchSize = options.batchSize || 10;
- var delay = options.delay || 100;
- var self = this;
-
- console.log("¿ªÊ¼ÅúÁ¿´¦Àí " + uiElements.length + " ¸öUIÔªËØ");
-
- var batches = [];
- for (var i = 0; i < uiElements.length; i += batchSize) {
- batches.push(uiElements.slice(i, i + batchSize));
- }
-
- // ·ÖÅú´¦Àí£¨AIWROK»·¾³Ê¹ÓÃthreads.sleep´úÌæsetTimeout£©
- for (var batchIndex = 0; batchIndex < batches.length; batchIndex++) {
- var batch = batches[batchIndex];
- console.log("´¦ÀíµÚ " + (batchIndex + 1) + " Åú£¬¹² " + batch.length + " ¸öÔªËØ");
-
- batch.forEach(function(element, index) {
- try {
- processor(element, index);
- self.performanceMetrics.operations++;
- } catch (e) {
- console.log("´¦ÀíUIÔªËØÊ§°Ü: " + (e.message || e));
- }
- });
-
- // Åú´Î¼äÑÓʱ
- if (batchIndex < batches.length - 1) {
- sleep.second(delay / 1000);
- }
- }
-
- console.log("ÅúÁ¿´¦ÀíÍê³É");
-
- return this;
- };
- /**
- * OCR½á¹ûÖÇÄÜɸѡ - ½áºÏAIWROKµÄOCR¹¦ÄÜ
- * @param {Array} ocrResults - OCRʶ±ð½á¹ûÊý×é
- * @param {Object} filterOptions - ɸѡѡÏî
- * @returns {Array} ɸѡºóµÄ½á¹û
- */
- AdvancedArrayUtils.prototype.filterOCRResults = function(ocrResults, filterOptions) {
- filterOptions = filterOptions || {};
-
- var conditions = [];
-
- // Îı¾³¤¶È¹ýÂË
- if (filterOptions.minLength) {
- conditions.push({
- field: 'text',
- operator: '>',
- value: filterOptions.minLength
- });
- }
-
- // ÖÃÐŶȹýÂË
- if (filterOptions.minConfidence) {
- conditions.push({
- field: 'confidence',
- operator: '>=',
- value: filterOptions.minConfidence
- });
- }
-
- // Îı¾ÄÚÈݹýÂË
- if (filterOptions.contains) {
- conditions.push({
- field: 'text',
- operator: 'contains',
- value: filterOptions.contains
- });
- }
-
- // λÖùýÂË
- if (filterOptions.minX !== undefined) {
- conditions.push({
- field: 'x',
- operator: '>=',
- value: filterOptions.minX
- });
- }
-
- return this.smartFilter(ocrResults, conditions);
- };
- /**
- * ÈÕÖ¾Êý¾Ý¾ÛºÏ·ÖÎö - ½áºÏAIWROKµÄÈÕÖ¾¹¦ÄÜ
- * @param {Array} logEntries - ÈÕÖ¾ÌõÄ¿Êý×é
- * @param {Object} analysisConfig - ·ÖÎöÅäÖÃ
- * @returns {Object} ·ÖÎö½á¹û
- */
- AdvancedArrayUtils.prototype.analyzeLogs = function(logEntries, analysisConfig) {
- analysisConfig = analysisConfig || {};
-
- var timeWindow = analysisConfig.timeWindow || 3600000; // 1Сʱ
- var logLevelWeights = analysisConfig.logLevelWeights || {
- 'ERROR': 10,
- 'WARN': 5,
- 'INFO': 1,
- 'DEBUG': 0.5
- };
-
- var currentTime = new Date().getTime();
- var recentLogs = logEntries.filter(function(log) {
- return currentTime - log.timestamp <= timeWindow;
- });
-
- var analysis = {
- totalLogs: recentLogs.length,
- levelDistribution: {},
- errorRate: 0,
- warningRate: 0,
- healthScore: 100
- };
-
- // ͳ¼ÆÈÕÖ¾¼¶±ð·Ö²¼
- recentLogs.forEach(function(log) {
- var level = log.level || 'INFO';
- analysis.levelDistribution[level] = (analysis.levelDistribution[level] || 0) + 1;
- });
-
- // ¼ÆËã´íÎóÂʺ;¯¸æÂÊ
- var errorCount = analysis.levelDistribution['ERROR'] || 0;
- var warnCount = analysis.levelDistribution['WARN'] || 0;
-
- analysis.errorRate = analysis.totalLogs > 0 ? (errorCount / analysis.totalLogs) * 100 : 0;
- analysis.warningRate = analysis.totalLogs > 0 ? (warnCount / analysis.totalLogs) * 100 : 0;
-
- // ¼ÆË㽡¿µ·ÖÊý
- var totalWeight = 0;
- var weightedScore = 0;
-
- for (var level in analysis.levelDistribution) {
- if (analysis.levelDistribution.hasOwnProperty(level)) {
- var count = analysis.levelDistribution[level];
- var weight = logLevelWeights[level] || 1;
- totalWeight += count * weight;
- weightedScore += count * weight;
- }
- }
-
- if (totalWeight > 0) {
- analysis.healthScore = Math.max(0, 100 - (errorCount * 10) - (warnCount * 3));
- }
-
- return analysis;
- };
- //===========================================
- // ʹÓÃʾÀýºÍ²âÊÔ
- //===========================================
- function uiControlArrayExample() {
- console.log("=== ʾÀý1: UI¿Ø¼þÊý×é²Ù×÷ ===");
-
- // Ä£Äâͨ¹ýfindControls»ñÈ¡µÄUI¿Ø¼þÊý×é
- var uiControls = [
- { id: 'btn_login', type: 'Button', text: '怬', visible: true, enabled: true, x: 100, y: 200, width: 200, height: 80 },
- { id: 'btn_register', type: 'Button', text: '×¢²á', visible: true, enabled: true, x: 100, y: 300, width: 200, height: 80 },
- { id: 'input_username', type: 'EditText', text: '', visible: true, enabled: true, x: 50, y: 100, width: 300, height: 60 },
- { id: 'input_password', type: 'EditText', text: '', visible: true, enabled: true, x: 50, y: 170, width: 300, height: 60 },
- { id: 'chk_remember', type: 'CheckBox', text: '¼ÇסÃÜÂë', visible: true, enabled: true, x: 50, y: 250, width: 150, height: 40 },
- { id: 'txt_forgot', type: 'TextView', text: 'Íü¼ÇÃÜÂ룿', visible: true, enabled: true, x: 250, y: 250, width: 120, height: 40 },
- { id: 'btn_cancel', type: 'Button', text: 'È¡Ïû', visible: false, enabled: false, x: 100, y: 400, width: 200, height: 80 }
- ];
-
- console.log("ÕÒµ½ " + uiControls.length + " ¸öUI¿Ø¼þ");
-
- // 1. ɸѡËùÓпɼûÇÒ¿ÉÓõİ´Å¥
- var clickableButtons = [];
- for (var i = 0; i < uiControls.length; i++) {
- var ctrl = uiControls[i];
- if (ctrl.type === 'Button' && ctrl.visible && ctrl.enabled) {
- clickableButtons.push(ctrl);
- }
- }
-
- console.log("¿Éµã»÷µÄ°´Å¥ÓÐ " + clickableButtons.length + " ¸ö:");
- for (var j = 0; j < clickableButtons.length; j++) {
- console.log(" - " + clickableButtons[j].text + " (λÖÃ: " + clickableButtons[j].x + "," + clickableButtons[j].y + ")");
- }
-
- // 2. ²éÕÒÌØ¶¨Îı¾µÄ¿Ø¼þ
- var loginButton = null;
- for (var k = 0; k < uiControls.length; k++) {
- if (uiControls[k].text === '怬') {
- loginButton = uiControls[k];
- break;
- }
- }
-
- if (loginButton) {
- console.log("ÕÒµ½µÇ¼°´Å¥:");
- console.log(" ID: " + loginButton.id);
- console.log(" ÀàÐÍ: " + loginButton.type);
- console.log(" λÖÃ: (" + loginButton.x + ", " + loginButton.y + ")");
- console.log(" ³ß´ç: " + loginButton.width + "x" + loginButton.height);
- console.log(" ÖÐÐĵã: (" + (loginButton.x + loginButton.width/2) + ", " + (loginButton.y + loginButton.height/2) + ")");
- }
-
- // 3. ÅúÁ¿¼ÆËã¿Ø¼þÖÐÐÄ×ø±ê£¨ÓÃÓÚµã»÷²Ù×÷£©
- console.log("ËùÓÐÊäÈë¿òµÄÖÐÐÄ×ø±ê:");
- for (var m = 0; m < uiControls.length; m++) {
- var control = uiControls[m];
- if (control.type === 'EditText') {
- var centerX = control.x + control.width / 2;
- var centerY = control.y + control.height / 2;
- console.log(" " + control.id + ": (" + centerX + ", " + centerY + ")");
- }
- }
-
- // ²½Öè¼äÑÓʱ2Ãë
- console.log("µÈ´ý2Ãë...");
- sleep.second(2);
- }
- /**
- * ͼÏñʶ±ð½á¹ûÊý×é´¦ÀíʾÀý
- */
- function imageRecognitionArrayExample() {
- console.log("=== ʾÀý2: ͼÏñʶ±ð½á¹ûÊý×é´¦Àí ===");
-
- // Ä£Äâͨ¹ýfindImage»òshapeSearch·µ»ØµÄʶ±ð½á¹ûÊý×é
- var recognitionResults = [
- { name: 'µÇ¼°´Å¥', confidence: 0.95, x: 150, y: 300, width: 180, height: 60, timestamp: new Date().getTime() },
- { name: 'µÇ¼°´Å¥', confidence: 0.92, x: 152, y: 298, width: 178, height: 62, timestamp: new Date().getTime() + 100 },
- { name: 'Ìá½»°´Å¥', confidence: 0.88, x: 200, y: 500, width: 160, height: 55, timestamp: new Date().getTime() + 200 },
- { name: 'ÑéÖ¤ÂëͼƬ', confidence: 0.75, x: 100, y: 400, width: 200, height: 80, timestamp: new Date().getTime() + 300 },
- { name: 'µÇ¼°´Å¥', confidence: 0.90, x: 148, y: 302, width: 182, height: 58, timestamp: new Date().getTime() + 400 }
- ];
-
- console.log("ʶ±ðµ½ " + recognitionResults.length + " ¸öÄ¿±ê");
-
- // 1. ɸѡ¸ßÖÃÐŶȵĽá¹û£¨>0.85£©
- var highConfidenceResults = [];
- for (var i = 0; i < recognitionResults.length; i++) {
- if (recognitionResults[i].confidence > 0.85) {
- highConfidenceResults.push(recognitionResults[i]);
- }
- }
-
- console.log("¸ßÖÃÐŶȽá¹û£¨>0.85£©ÓÐ " + highConfidenceResults.length + " ¸ö:");
- for (var j = 0; j < highConfidenceResults.length; j++) {
- var result = highConfidenceResults[j];
- console.log(" - " + result.name + " (ÖÃÐŶÈ: " + result.confidence + ", λÖÃ: " + result.x + "," + result.y + ")");
- }
-
- // 2. °´Ãû³Æ·Ö×éͳ¼Æ
- var groupedByName = {};
- for (var k = 0; k < recognitionResults.length; k++) {
- var item = recognitionResults[k];
- if (!groupedByName[item.name]) {
- groupedByName[item.name] = [];
- }
- groupedByName[item.name].push(item);
- }
-
- console.log("°´Ãû³Æ·Ö×éͳ¼Æ:");
- for (var name in groupedByName) {
- if (groupedByName.hasOwnProperty(name)) {
- var items = groupedByName[name];
- console.log(" " + name + ": " + items.length + " ´ÎÆ¥Åä");
-
- // ¼ÆËãÆ½¾ùÖÃÐŶÈ
- var totalConfidence = 0;
- for (var m = 0; m < items.length; m++) {
- totalConfidence += items[m].confidence;
- }
- var avgConfidence = totalConfidence / items.length;
- console.log(" ƽ¾ùÖÃÐŶÈ: " + avgConfidence.toFixed(3));
-
- // ÕÒµ½×î¼ÑÆ¥Å䣨×î¸ßÖÃÐŶȣ©
- var bestMatch = items[0];
- for (var n = 1; n < items.length; n++) {
- if (items[n].confidence > bestMatch.confidence) {
- bestMatch = items[n];
- }
- }
- console.log(" ×î¼ÑÆ¥Åä: (" + bestMatch.x + ", " + bestMatch.y + ") ÖÃÐŶÈ: " + bestMatch.confidence);
- }
- }
-
- // 3. ¼ÆËã¶à¸öÆ¥ÅäµãµÄÖÐÐÄλÖã¨ÓÃÓÚÌá¸ßµã»÷¾«¶È£©
- var loginButtons = groupedByName['µÇ¼°´Å¥'];
- if (loginButtons && loginButtons.length > 0) {
- var sumX = 0, sumY = 0;
- for (var p = 0; p < loginButtons.length; p++) {
- sumX += loginButtons[p].x + loginButtons[p].width / 2;
- sumY += loginButtons[p].y + loginButtons[p].height / 2;
- }
- var centerX = sumX / loginButtons.length;
- var centerY = sumY / loginButtons.length;
-
- console.log("µÇ¼°´Å¥µÄƽ¾ùÖÐÐÄλÖÃ:");
- console.log(" X: " + Math.round(centerX));
- console.log(" Y: " + Math.round(centerY));
- console.log(" ½¨Òéµã»÷×ø±ê: (" + Math.round(centerX) + ", " + Math.round(centerY) + ")");
- }
-
- // ²½Öè¼äÑÓʱ2Ãë
- console.log("µÈ´ý2Ãë...");
- sleep.second(2);
- }
- /**
- * ÈÎÎñ¶ÓÁÐÊý×éµ÷¶ÈʾÀý
- */
- function taskQueueArrayExample() {
- console.log("=== ʾÀý3: ÈÎÎñ¶ÓÁÐÊý×éµ÷¶È ===");
-
- // Ä£ÄâÈÎÎñ¶ÓÁÐÊý×é
- var taskQueue = [
- { id: 1, name: '´ò¿ªÓ¦ÓÃ', priority: 1, status: 'pending', duration: 2000 },
- { id: 2, name: 'µÈ´ýÊ×Ò³¼ÓÔØ', priority: 2, status: 'pending', duration: 3000 },
- { id: 3, name: 'µã»÷µÇ¼°´Å¥', priority: 3, status: 'pending', duration: 1000 },
- { id: 4, name: 'ÊäÈëÓû§Ãû', priority: 4, status: 'pending', duration: 1500 },
- { id: 5, name: 'ÊäÈëÃÜÂë', priority: 5, status: 'pending', duration: 1500 },
- { id: 6, name: 'µã»÷Ìá½»', priority: 6, status: 'pending', duration: 1000 },
- { id: 7, name: 'ÑéÖ¤µÇ¼½á¹û', priority: 7, status: 'pending', duration: 2000 }
- ];
-
- console.log("ÈÎÎñ¶ÓÁй²ÓÐ " + taskQueue.length + " ¸öÈÎÎñ");
-
- // 1. °´ÓÅÏȼ¶ÅÅÐò
- taskQueue.sort(function(a, b) {
- return a.priority - b.priority;
- });
-
- console.log("°´ÓÅÏȼ¶ÅÅÐòºóµÄÈÎÎñÁбí:");
- for (var i = 0; i < taskQueue.length; i++) {
- var task = taskQueue[i];
- console.log(" [" + task.priority + "] " + task.name + " (Ô¤¼ÆºÄʱ: " + task.duration + "ms)");
- }
-
- // 2. Ä£ÄâÖ´ÐÐÈÎÎñ¶ÓÁÐ
- console.log("¿ªÊ¼Ö´ÐÐÈÎÎñ¶ÓÁÐ:");
- var completedTasks = [];
- var failedTasks = [];
-
- for (var j = 0; j < taskQueue.length; j++) {
- var currentTask = taskQueue[j];
- console.log(" Ö´ÐÐÈÎÎñ #" + (j+1) + ": " + currentTask.name);
-
- // Ä£ÄâÈÎÎñÖ´ÐУ¨³É¹¦ÂÊ90%£©
- var success = Math.random() > 0.1;
-
- if (success) {
- currentTask.status = 'completed';
- completedTasks.push(currentTask);
- console.log(" ✓ Íê³É");
- } else {
- currentTask.status = 'failed';
- failedTasks.push(currentTask);
- console.log(" ✗ ʧ°Ü");
- }
-
- // ÈÎÎñ¼ä¶ÌÔÝÑÓʱ
- sleep.second(0.3);
- }
-
- console.log("");
- console.log("ÈÎÎñÖ´ÐÐͳ¼Æ:");
- console.log(" ×ÜÈÎÎñÊý: " + taskQueue.length);
- console.log(" ³É¹¦: " + completedTasks.length);
- console.log(" ʧ°Ü: " + failedTasks.length);
- console.log(" ³É¹¦ÂÊ: " + (completedTasks.length / taskQueue.length * 100).toFixed(1) + "%");
-
- if (failedTasks.length > 0) {
- console.log("");
- console.log("ʧ°ÜµÄÈÎÎñ:");
- for (var k = 0; k < failedTasks.length; k++) {
- console.log(" - " + failedTasks[k].name);
- }
- }
-
- // ²½Öè¼äÑÓʱ2Ãë
- console.log("µÈ´ý2Ãë...");
- sleep.second(2);
- }
- /**
- * É豸ÐÅÏ¢Êý×é¹ÜÀíʾÀý
- */
- function deviceInfoArrayExample() {
- console.log("=== ʾÀý4: É豸ÐÅÏ¢Êý×é¹ÜÀí ===");
-
- // Ä£Äâ¶àÉ豸ÐÅÏ¢Êý×é
- var devices = [
- { deviceId: 'device_001', model: 'СÃ×11', androidVersion: '12', screenWidth: 1080, screenHeight: 2400, battery: 85, online: true },
- { deviceId: 'device_002', model: '»ªÎªP40', androidVersion: '11', screenWidth: 1080, screenHeight: 2340, battery: 62, online: true },
- { deviceId: 'device_003', model: 'OPPO Reno6', androidVersion: '11', screenWidth: 1080, screenHeight: 2400, battery: 45, online: false },
- { deviceId: 'device_004', model: 'vivo X60', androidVersion: '12', screenWidth: 1080, screenHeight: 2376, battery: 90, online: true },
- { deviceId: 'device_005', model: 'ÈýÐÇS21', androidVersion: '13', screenWidth: 1080, screenHeight: 2400, battery: 30, online: true }
- ];
-
- console.log("É豸ÁÐ±í¹²ÓÐ " + devices.length + " ̨É豸");
-
- // 1. ɸѡÔÚÏßÉ豸
- var onlineDevices = [];
- for (var i = 0; i < devices.length; i++) {
- if (devices[i].online) {
- onlineDevices.push(devices[i]);
- }
- }
-
- console.log("ÔÚÏßÉ豸: " + onlineDevices.length + " ̨");
- for (var j = 0; j < onlineDevices.length; j++) {
- var device = onlineDevices[j];
- console.log(" - " + device.model + " (µçÁ¿: " + device.battery + "%, Android " + device.androidVersion + ")");
- }
-
- // 2. ²éÕҵ͵çÁ¿É豸£¨<50%£©
- var lowBatteryDevices = [];
- for (var k = 0; k < devices.length; k++) {
- if (devices[k].battery < 50) {
- lowBatteryDevices.push(devices[k]);
- }
- }
-
- if (lowBatteryDevices.length > 0) {
- console.log("µÍµçÁ¿É豸¾¯¸æ (<50%): " + lowBatteryDevices.length + " ̨");
- for (var m = 0; m < lowBatteryDevices.length; m++) {
- var lowDevice = lowBatteryDevices[m];
- console.log(" ⚠ " + lowDevice.model + " - µçÁ¿: " + lowDevice.battery + "%");
- }
- } else {
- console.log("ËùÓÐÉ豸µçÁ¿³ä×ã");
- }
-
- // 3. °´Android°æ±¾·Ö×é
- var versionGroups = {};
- for (var n = 0; n < devices.length; n++) {
- var dev = devices[n];
- var version = 'Android ' + dev.androidVersion;
- if (!versionGroups[version]) {
- versionGroups[version] = [];
- }
- versionGroups[version].push(dev);
- }
-
- console.log("°´Android°æ±¾·Ö×é:");
- for (var version in versionGroups) {
- if (versionGroups.hasOwnProperty(version)) {
- var group = versionGroups[version];
- console.log(" " + version + ": " + group.length + " ̨É豸");
- for (var p = 0; p < group.length; p++) {
- console.log(" - " + group[p].model);
- }
- }
- }
-
- // 4. ¼ÆËãÆ½¾ùµçÁ¿
- var totalBattery = 0;
- for (var q = 0; q < devices.length; q++) {
- totalBattery += devices[q].battery;
- }
- var avgBattery = totalBattery / devices.length;
-
- console.log("É豸ͳ¼ÆÐÅÏ¢:");
- console.log(" ƽ¾ùµçÁ¿: " + avgBattery.toFixed(1) + "%");
- console.log(" ×î¸ßµçÁ¿: " + Math.max.apply(Math, devices.map(function(d) { return d.battery; })) + "%");
- console.log(" ×îµÍµçÁ¿: " + Math.min.apply(Math, devices.map(function(d) { return d.battery; })) + "%");
-
- // ²½Öè¼äÑÓʱ2Ãë
- console.log("µÈ´ý2Ãë...");
- sleep.second(2);
- }
- //===========================================
- // Ö÷º¯ÊýºÍÖ´ÐÐÈë¿Ú
- //===========================================
- /**
- * ÔËÐÐËùÓÐʾÀý
- */
- function runAllExamples() {
- try {
- uiControlArrayExample();
- imageRecognitionArrayExample();
- taskQueueArrayExample();
- deviceInfoArrayExample();
- console.log("=== ËùÓÐʾÀýÖ´ÐÐÍê³É ===");
- } catch (e) {
- console.log("Ö´ÐÐʾÀýʱ·¢Éú´íÎó: " + (e.message || e));
- }
- }
- // Ö´ÐÐËùÓÐʾÀý
- runAllExamples();
¸´ÖÆ´úÂë
|
|