注册 登录
发贴工具
查看: 4|回复: 0
打印 上一主题 下一主题

[24小时收录超级好的网站] AIWROK软件示例数组方法实战应用

[复制链接]

2540

主题

2588

帖子

1万

积分

积分
15414
跳转到指定楼层
楼主
AIWROK软件示例数组方法实战应用
AIWROK软件示例数组方法实战应用 群发软件发帖工具

  1. /**
  2. * AIWROK数组方法实战应用示例
  3. * 专为AIWROK安卓自动化环境设计的真实数组应用场景
  4. *
  5. * @功能特点
  6. * - UI控件数组的查找、筛选和批量操作
  7. * - 图像识别结果的数组处理和坐标计算
  8. * - 设备信息数组的管理和查询
  9. * - 任务队列数组的调度和执行
  10. *
  11. * @作者 AIWROK开发团队
  12. * @版本 3.0 - 实战版
  13. * @日期 2024
  14. */

  15. //===========================================
  16. // 基础兼容性设置
  17. //===========================================

  18. // AIWROK环境统一使用console.log输出日志

  19. //===========================================
  20. // 高级数组工具类 - 增强版
  21. //===========================================

  22. /**
  23. * AdvancedArrayUtils - 高级数组操作工具类
  24. * 提供链式调用、批量处理和性能优化功能
  25. */
  26. function AdvancedArrayUtils() {
  27.     this.version = "2.0.0";
  28.     this.performanceMetrics = {
  29.         operations: 0,
  30.         startTime: 0,
  31.         endTime: 0,
  32.         memoryUsage: 0
  33.     };
  34. }

  35. /**
  36. * 开始性能监控
  37. */
  38. AdvancedArrayUtils.prototype.startPerformanceMonitoring = function() {
  39.     this.performanceMetrics.startTime = new Date().getTime();
  40.     this.performanceMetrics.operations = 0;
  41.     return this;
  42. };

  43. /**
  44. * 结束性能监控并返回报告
  45. */
  46. AdvancedArrayUtils.prototype.endPerformanceMonitoring = function() {
  47.     this.performanceMetrics.endTime = new Date().getTime();
  48.     var duration = this.performanceMetrics.endTime - this.performanceMetrics.startTime;
  49.     return {
  50.         duration: duration,
  51.         operations: this.performanceMetrics.operations,
  52.         opsPerSecond: Math.round(this.performanceMetrics.operations / (duration / 1000)),
  53.         memoryUsage: this.performanceMetrics.memoryUsage
  54.     };
  55. };

  56. /**
  57. * 安全数组遍历 - 支持中断和异常处理
  58. * @param {Array} array - 要遍历的数组
  59. * @param {Function} callback - 回调函数,返回false可中断遍历
  60. * @param {Object} context - 回调函数上下文
  61. * @returns {AdvancedArrayUtils} 支持链式调用
  62. */
  63. AdvancedArrayUtils.prototype.forEachSafe = function(array, callback, context) {
  64.     if (!Array.isArray(array)) throw new Error('参数必须是数组');
  65.     if (typeof callback !== 'function') throw new Error('回调函数必须是函数');
  66.    
  67.     context = context || this;
  68.    
  69.     try {
  70.         for (var i = 0; i < array.length; i++) {
  71.             this.performanceMetrics.operations++;
  72.             var result = callback.call(context, array[i], i, array);
  73.             if (result === false) break; // 支持主动中断
  74.         }
  75.     } catch (e) {
  76.         console.log("数组遍历错误 at index " + i + ": " + (e.message || e));
  77.     }
  78.    
  79.     return this;
  80. };

  81. /**
  82. * 智能数组过滤 - 支持多条件和复杂逻辑
  83. * @param {Array} array - 源数组
  84. * @param {Array} conditions - 过滤条件数组
  85. * @returns {Array} 过滤后的数组
  86. *
  87. * @示例
  88. * var result = advancedArrayUtils.smartFilter(data, [
  89. *     { field: 'age', operator: '>', value: 18 },
  90. *     { field: 'name', operator: 'contains', value: '张' },
  91. *     { field: 'score', operator: 'between', value: [60, 100] }
  92. * ]);
  93. */
  94. AdvancedArrayUtils.prototype.smartFilter = function(array, conditions) {
  95.     if (!Array.isArray(array)) throw new Error('第一个参数必须是数组');
  96.     if (!Array.isArray(conditions)) throw new Error('条件参数必须是数组');
  97.    
  98.     var self = this;
  99.    
  100.     return array.filter(function(item) {
  101.         self.performanceMetrics.operations++;
  102.         
  103.         for (var i = 0; i < conditions.length; i++) {
  104.             var condition = conditions[i];
  105.             var fieldValue = self.getFieldValue(item, condition.field);
  106.             
  107.             if (!self.evaluateCondition(fieldValue, condition.operator, condition.value)) {
  108.                 return false;
  109.             }
  110.         }
  111.         
  112.         return true;
  113.     });
  114. };

  115. /**
  116. * 获取对象字段值 - 支持嵌套属性访问
  117. */
  118. AdvancedArrayUtils.prototype.getFieldValue = function(obj, field) {
  119.     if (!obj || !field) return undefined;
  120.    
  121.     var parts = field.split('.');
  122.     var result = obj;
  123.    
  124.     for (var i = 0; i < parts.length; i++) {
  125.         if (result === null || result === undefined) return undefined;
  126.         result = result[parts[i]];
  127.     }
  128.    
  129.     return result;
  130. };

  131. /**
  132. * 评估条件 - 支持多种操作符
  133. */
  134. AdvancedArrayUtils.prototype.evaluateCondition = function(fieldValue, operator, conditionValue) {
  135.     switch (operator) {
  136.         case '==': return fieldValue == conditionValue;
  137.         case '===': return fieldValue === conditionValue;
  138.         case '!=': return fieldValue != conditionValue;
  139.         case '!==': return fieldValue !== conditionValue;
  140.         case '>': return fieldValue > conditionValue;
  141.         case '>=': return fieldValue >= conditionValue;
  142.         case '<': return fieldValue < conditionValue;
  143.         case '<=': return fieldValue <= conditionValue;
  144.         case 'contains':
  145.             return String(fieldValue).indexOf(conditionValue) !== -1;
  146.         case 'startsWith':
  147.             return String(fieldValue).indexOf(conditionValue) === 0;
  148.         case 'endsWith':
  149.             var str = String(fieldValue);
  150.             return str.lastIndexOf(conditionValue) === str.length - conditionValue.length;
  151.         case 'between':
  152.             return fieldValue >= conditionValue[0] && fieldValue <= conditionValue[1];
  153.         case 'in':
  154.             return conditionValue.indexOf(fieldValue) !== -1;
  155.         case 'notIn':
  156.             return conditionValue.indexOf(fieldValue) === -1;
  157.         default:
  158.             return false;
  159.     }
  160. };

  161. /**
  162. * 数组数据聚合 - 支持多种聚合函数
  163. * @param {Array} array - 源数组
  164. * @param {Object} config - 聚合配置
  165. * @returns {Object} 聚合结果
  166. *
  167. * @示例
  168. * var stats = advancedArrayUtils.aggregate(salesData, {
  169. *     groupBy: 'category',
  170. *     metrics: {
  171. *         totalSales: { field: 'amount', operation: 'sum' },
  172. *         avgPrice: { field: 'price', operation: 'avg' },
  173. *         count: { operation: 'count' }
  174. *     }
  175. * });
  176. */
  177. AdvancedArrayUtils.prototype.aggregate = function(array, config) {
  178.     if (!Array.isArray(array)) throw new Error('参数必须是数组');
  179.    
  180.     var result = {};
  181.     var self = this;
  182.    
  183.     // 分组处理
  184.     if (config.groupBy) {
  185.         var groups = {};
  186.         
  187.         array.forEach(function(item) {
  188.             self.performanceMetrics.operations++;
  189.             var groupKey = self.getFieldValue(item, config.groupBy);
  190.             if (!groups[groupKey]) {
  191.                 groups[groupKey] = [];
  192.             }
  193.             groups[groupKey].push(item);
  194.         });
  195.         
  196.         // 对每个分组进行聚合
  197.         for (var groupKey in groups) {
  198.             if (groups.hasOwnProperty(groupKey)) {
  199.                 result[groupKey] = self.calculateMetrics(groups[groupKey], config.metrics);
  200.             }
  201.         }
  202.     } else {
  203.         // 不分组,直接聚合
  204.         result = this.calculateMetrics(array, config.metrics);
  205.     }
  206.    
  207.     return result;
  208. };

  209. /**
  210. * 计算指标 - 支持多种聚合操作
  211. */
  212. AdvancedArrayUtils.prototype.calculateMetrics = function(array, metrics) {
  213.     var result = {};
  214.     var self = this;
  215.    
  216.     for (var metricName in metrics) {
  217.         if (metrics.hasOwnProperty(metricName)) {
  218.             var metric = metrics[metricName];
  219.             result[metricName] = self.calculateMetric(array, metric);
  220.         }
  221.     }
  222.    
  223.     return result;
  224. };

  225. /**
  226. * 计算单个指标
  227. */
  228. AdvancedArrayUtils.prototype.calculateMetric = function(array, metric) {
  229.     var operation = metric.operation;
  230.     var field = metric.field;
  231.    
  232.     switch (operation) {
  233.         case 'count':
  234.             return array.length;
  235.             
  236.         case 'sum':
  237.             return array.reduce(function(sum, item) {
  238.                 return sum + (field ? this.getFieldValue(item, field) : item);
  239.             }.bind(this), 0);
  240.             
  241.         case 'avg':
  242.             var sum = array.reduce(function(sum, item) {
  243.                 return sum + (field ? this.getFieldValue(item, field) : item);
  244.             }.bind(this), 0);
  245.             return array.length > 0 ? sum / array.length : 0;
  246.             
  247.         case 'max':
  248.             return Math.max.apply(Math, array.map(function(item) {
  249.                 return field ? this.getFieldValue(item, field) : item;
  250.             }.bind(this)));
  251.             
  252.         case 'min':
  253.             return Math.min.apply(Math, array.map(function(item) {
  254.                 return field ? this.getFieldValue(item, field) : item;
  255.             }.bind(this)));
  256.             
  257.         default:
  258.             return 0;
  259.     }
  260. };

  261. /**
  262. * 数组分页处理 - 支持大数据集的分页显示
  263. * @param {Array} array - 源数组
  264. * @param {number} pageSize - 每页大小
  265. * @param {number} pageNumber - 页码(从1开始)
  266. * @returns {Object} 分页结果
  267. */
  268. AdvancedArrayUtils.prototype.paginate = function(array, pageSize, pageNumber) {
  269.     if (!Array.isArray(array)) throw new Error('参数必须是数组');
  270.    
  271.     pageSize = Math.max(1, pageSize || 10);
  272.     pageNumber = Math.max(1, pageNumber || 1);
  273.    
  274.     var totalItems = array.length;
  275.     var totalPages = Math.ceil(totalItems / pageSize);
  276.     var startIndex = (pageNumber - 1) * pageSize;
  277.     var endIndex = Math.min(startIndex + pageSize, totalItems);
  278.    
  279.     return {
  280.         items: array.slice(startIndex, endIndex),
  281.         pagination: {
  282.             pageNumber: pageNumber,
  283.             pageSize: pageSize,
  284.             totalItems: totalItems,
  285.             totalPages: totalPages,
  286.             hasPrevious: pageNumber > 1,
  287.             hasNext: pageNumber < totalPages,
  288.             startIndex: startIndex,
  289.             endIndex: endIndex - 1
  290.         }
  291.     };
  292. };

  293. /**
  294. * 数组去重 - 支持复杂对象的去重
  295. * @param {Array} array - 源数组
  296. * @param {string|Function} keySelector - 用于去重的键选择器
  297. * @returns {Array} 去重后的数组
  298. */
  299. AdvancedArrayUtils.prototype.distinct = function(array, keySelector) {
  300.     if (!Array.isArray(array)) throw new Error('参数必须是数组');
  301.    
  302.     var seen = {};
  303.     var result = [];
  304.     var self = this;
  305.    
  306.     array.forEach(function(item) {
  307.         self.performanceMetrics.operations++;
  308.         
  309.         var key;
  310.         if (typeof keySelector === 'function') {
  311.             key = keySelector(item);
  312.         } else if (typeof keySelector === 'string') {
  313.             key = self.getFieldValue(item, keySelector);
  314.         } else {
  315.             key = item;
  316.         }
  317.         
  318.         var keyString = String(key);
  319.         if (!seen.hasOwnProperty(keyString)) {
  320.             seen[keyString] = true;
  321.             result.push(item);
  322.         }
  323.     });
  324.    
  325.     return result;
  326. };

  327. //===========================================
  328. // AIWROK特定功能集成
  329. //===========================================

  330. /**
  331. * UI控件批量处理 - 结合AIWROK的UI操作
  332. * @param {Array} uiElements - UI元素数组
  333. * @param {Function} processor - 处理函数
  334. * @param {Object} options - 处理选项
  335. */
  336. AdvancedArrayUtils.prototype.batchUIProcess = function(uiElements, processor, options) {
  337.     options = options || {};
  338.     var batchSize = options.batchSize || 10;
  339.     var delay = options.delay || 100;
  340.     var self = this;
  341.    
  342.     console.log("开始批量处理 " + uiElements.length + " 个UI元素");
  343.    
  344.     var batches = [];
  345.     for (var i = 0; i < uiElements.length; i += batchSize) {
  346.         batches.push(uiElements.slice(i, i + batchSize));
  347.     }
  348.    
  349.     // 分批处理(AIWROK环境使用threads.sleep代替setTimeout)
  350.     for (var batchIndex = 0; batchIndex < batches.length; batchIndex++) {
  351.         var batch = batches[batchIndex];
  352.         console.log("处理第 " + (batchIndex + 1) + " 批,共 " + batch.length + " 个元素");
  353.         
  354.         batch.forEach(function(element, index) {
  355.             try {
  356.                 processor(element, index);
  357.                 self.performanceMetrics.operations++;
  358.             } catch (e) {
  359.                 console.log("处理UI元素失败: " + (e.message || e));
  360.             }
  361.         });
  362.         
  363.         // 批次间延时
  364.         if (batchIndex < batches.length - 1) {
  365.             sleep.second(delay / 1000);
  366.         }
  367.     }
  368.    
  369.     console.log("批量处理完成");
  370.    
  371.     return this;
  372. };

  373. /**
  374. * OCR结果智能筛选 - 结合AIWROK的OCR功能
  375. * @param {Array} ocrResults - OCR识别结果数组
  376. * @param {Object} filterOptions - 筛选选项
  377. * @returns {Array} 筛选后的结果
  378. */
  379. AdvancedArrayUtils.prototype.filterOCRResults = function(ocrResults, filterOptions) {
  380.     filterOptions = filterOptions || {};
  381.    
  382.     var conditions = [];
  383.    
  384.     // 文本长度过滤
  385.     if (filterOptions.minLength) {
  386.         conditions.push({
  387.             field: 'text',
  388.             operator: '>',
  389.             value: filterOptions.minLength
  390.         });
  391.     }
  392.    
  393.     // 置信度过滤
  394.     if (filterOptions.minConfidence) {
  395.         conditions.push({
  396.             field: 'confidence',
  397.             operator: '>=',
  398.             value: filterOptions.minConfidence
  399.         });
  400.     }
  401.    
  402.     // 文本内容过滤
  403.     if (filterOptions.contains) {
  404.         conditions.push({
  405.             field: 'text',
  406.             operator: 'contains',
  407.             value: filterOptions.contains
  408.         });
  409.     }
  410.    
  411.     // 位置过滤
  412.     if (filterOptions.minX !== undefined) {
  413.         conditions.push({
  414.             field: 'x',
  415.             operator: '>=',
  416.             value: filterOptions.minX
  417.         });
  418.     }
  419.    
  420.     return this.smartFilter(ocrResults, conditions);
  421. };

  422. /**
  423. * 日志数据聚合分析 - 结合AIWROK的日志功能
  424. * @param {Array} logEntries - 日志条目数组
  425. * @param {Object} analysisConfig - 分析配置
  426. * @returns {Object} 分析结果
  427. */
  428. AdvancedArrayUtils.prototype.analyzeLogs = function(logEntries, analysisConfig) {
  429.     analysisConfig = analysisConfig || {};
  430.    
  431.     var timeWindow = analysisConfig.timeWindow || 3600000; // 1小时
  432.     var logLevelWeights = analysisConfig.logLevelWeights || {
  433.         'ERROR': 10,
  434.         'WARN': 5,
  435.         'INFO': 1,
  436.         'DEBUG': 0.5
  437.     };
  438.    
  439.     var currentTime = new Date().getTime();
  440.     var recentLogs = logEntries.filter(function(log) {
  441.         return currentTime - log.timestamp <= timeWindow;
  442.     });
  443.    
  444.     var analysis = {
  445.         totalLogs: recentLogs.length,
  446.         levelDistribution: {},
  447.         errorRate: 0,
  448.         warningRate: 0,
  449.         healthScore: 100
  450.     };
  451.    
  452.     // 统计日志级别分布
  453.     recentLogs.forEach(function(log) {
  454.         var level = log.level || 'INFO';
  455.         analysis.levelDistribution[level] = (analysis.levelDistribution[level] || 0) + 1;
  456.     });
  457.    
  458.     // 计算错误率和警告率
  459.     var errorCount = analysis.levelDistribution['ERROR'] || 0;
  460.     var warnCount = analysis.levelDistribution['WARN'] || 0;
  461.    
  462.     analysis.errorRate = analysis.totalLogs > 0 ? (errorCount / analysis.totalLogs) * 100 : 0;
  463.     analysis.warningRate = analysis.totalLogs > 0 ? (warnCount / analysis.totalLogs) * 100 : 0;
  464.    
  465.     // 计算健康分数
  466.     var totalWeight = 0;
  467.     var weightedScore = 0;
  468.    
  469.     for (var level in analysis.levelDistribution) {
  470.         if (analysis.levelDistribution.hasOwnProperty(level)) {
  471.             var count = analysis.levelDistribution[level];
  472.             var weight = logLevelWeights[level] || 1;
  473.             totalWeight += count * weight;
  474.             weightedScore += count * weight;
  475.         }
  476.     }
  477.    
  478.     if (totalWeight > 0) {
  479.         analysis.healthScore = Math.max(0, 100 - (errorCount * 10) - (warnCount * 3));
  480.     }
  481.    
  482.     return analysis;
  483. };

  484. //===========================================
  485. // 使用示例和测试
  486. //===========================================

  487. function uiControlArrayExample() {
  488.     console.log("=== 示例1: UI控件数组操作 ===");
  489.    
  490.     // 模拟通过findControls获取的UI控件数组
  491.     var uiControls = [
  492.         { id: 'btn_login', type: 'Button', text: '登录', visible: true, enabled: true, x: 100, y: 200, width: 200, height: 80 },
  493.         { id: 'btn_register', type: 'Button', text: '注册', visible: true, enabled: true, x: 100, y: 300, width: 200, height: 80 },
  494.         { id: 'input_username', type: 'EditText', text: '', visible: true, enabled: true, x: 50, y: 100, width: 300, height: 60 },
  495.         { id: 'input_password', type: 'EditText', text: '', visible: true, enabled: true, x: 50, y: 170, width: 300, height: 60 },
  496.         { id: 'chk_remember', type: 'CheckBox', text: '记住密码', visible: true, enabled: true, x: 50, y: 250, width: 150, height: 40 },
  497.         { id: 'txt_forgot', type: 'TextView', text: '忘记密码?', visible: true, enabled: true, x: 250, y: 250, width: 120, height: 40 },
  498.         { id: 'btn_cancel', type: 'Button', text: '取消', visible: false, enabled: false, x: 100, y: 400, width: 200, height: 80 }
  499.     ];
  500.    
  501.     console.log("找到 " + uiControls.length + " 个UI控件");
  502.    
  503.     // 1. 筛选所有可见且可用的按钮
  504.     var clickableButtons = [];
  505.     for (var i = 0; i < uiControls.length; i++) {
  506.         var ctrl = uiControls[i];
  507.         if (ctrl.type === 'Button' && ctrl.visible && ctrl.enabled) {
  508.             clickableButtons.push(ctrl);
  509.         }
  510.     }
  511.    
  512.     console.log("可点击的按钮有 " + clickableButtons.length + " 个:");
  513.     for (var j = 0; j < clickableButtons.length; j++) {
  514.         console.log("  - " + clickableButtons[j].text + " (位置: " + clickableButtons[j].x + "," + clickableButtons[j].y + ")");
  515.     }
  516.    
  517.     // 2. 查找特定文本的控件
  518.     var loginButton = null;
  519.     for (var k = 0; k < uiControls.length; k++) {
  520.         if (uiControls[k].text === '登录') {
  521.             loginButton = uiControls[k];
  522.             break;
  523.         }
  524.     }
  525.    
  526.     if (loginButton) {
  527.         console.log("找到登录按钮:");
  528.         console.log("  ID: " + loginButton.id);
  529.         console.log("  类型: " + loginButton.type);
  530.         console.log("  位置: (" + loginButton.x + ", " + loginButton.y + ")");
  531.         console.log("  尺寸: " + loginButton.width + "x" + loginButton.height);
  532.         console.log("  中心点: (" + (loginButton.x + loginButton.width/2) + ", " + (loginButton.y + loginButton.height/2) + ")");
  533.     }
  534.    
  535.     // 3. 批量计算控件中心坐标(用于点击操作)
  536.     console.log("所有输入框的中心坐标:");
  537.     for (var m = 0; m < uiControls.length; m++) {
  538.         var control = uiControls[m];
  539.         if (control.type === 'EditText') {
  540.             var centerX = control.x + control.width / 2;
  541.             var centerY = control.y + control.height / 2;
  542.             console.log("  " + control.id + ": (" + centerX + ", " + centerY + ")");
  543.         }
  544.     }
  545.    
  546.     // 步骤间延时2秒
  547.     console.log("等待2秒...");
  548.     sleep.second(2);
  549. }

  550. /**
  551. * 图像识别结果数组处理示例
  552. */
  553. function imageRecognitionArrayExample() {
  554.     console.log("=== 示例2: 图像识别结果数组处理 ===");
  555.    
  556.     // 模拟通过findImage或shapeSearch返回的识别结果数组
  557.     var recognitionResults = [
  558.         { name: '登录按钮', confidence: 0.95, x: 150, y: 300, width: 180, height: 60, timestamp: new Date().getTime() },
  559.         { name: '登录按钮', confidence: 0.92, x: 152, y: 298, width: 178, height: 62, timestamp: new Date().getTime() + 100 },
  560.         { name: '提交按钮', confidence: 0.88, x: 200, y: 500, width: 160, height: 55, timestamp: new Date().getTime() + 200 },
  561.         { name: '验证码图片', confidence: 0.75, x: 100, y: 400, width: 200, height: 80, timestamp: new Date().getTime() + 300 },
  562.         { name: '登录按钮', confidence: 0.90, x: 148, y: 302, width: 182, height: 58, timestamp: new Date().getTime() + 400 }
  563.     ];
  564.    
  565.     console.log("识别到 " + recognitionResults.length + " 个目标");
  566.    
  567.     // 1. 筛选高置信度的结果(>0.85)
  568.     var highConfidenceResults = [];
  569.     for (var i = 0; i < recognitionResults.length; i++) {
  570.         if (recognitionResults[i].confidence > 0.85) {
  571.             highConfidenceResults.push(recognitionResults[i]);
  572.         }
  573.     }
  574.    
  575.     console.log("高置信度结果(>0.85)有 " + highConfidenceResults.length + " 个:");
  576.     for (var j = 0; j < highConfidenceResults.length; j++) {
  577.         var result = highConfidenceResults[j];
  578.         console.log("  - " + result.name + " (置信度: " + result.confidence + ", 位置: " + result.x + "," + result.y + ")");
  579.     }
  580.    
  581.     // 2. 按名称分组统计
  582.     var groupedByName = {};
  583.     for (var k = 0; k < recognitionResults.length; k++) {
  584.         var item = recognitionResults[k];
  585.         if (!groupedByName[item.name]) {
  586.             groupedByName[item.name] = [];
  587.         }
  588.         groupedByName[item.name].push(item);
  589.     }
  590.    
  591.     console.log("按名称分组统计:");
  592.     for (var name in groupedByName) {
  593.         if (groupedByName.hasOwnProperty(name)) {
  594.             var items = groupedByName[name];
  595.             console.log("  " + name + ": " + items.length + " 次匹配");
  596.             
  597.             // 计算平均置信度
  598.             var totalConfidence = 0;
  599.             for (var m = 0; m < items.length; m++) {
  600.                 totalConfidence += items[m].confidence;
  601.             }
  602.             var avgConfidence = totalConfidence / items.length;
  603.             console.log("    平均置信度: " + avgConfidence.toFixed(3));
  604.             
  605.             // 找到最佳匹配(最高置信度)
  606.             var bestMatch = items[0];
  607.             for (var n = 1; n < items.length; n++) {
  608.                 if (items[n].confidence > bestMatch.confidence) {
  609.                     bestMatch = items[n];
  610.                 }
  611.             }
  612.             console.log("    最佳匹配: (" + bestMatch.x + ", " + bestMatch.y + ") 置信度: " + bestMatch.confidence);
  613.         }
  614.     }
  615.    
  616.     // 3. 计算多个匹配点的中心位置(用于提高点击精度)
  617.     var loginButtons = groupedByName['登录按钮'];
  618.     if (loginButtons && loginButtons.length > 0) {
  619.         var sumX = 0, sumY = 0;
  620.         for (var p = 0; p < loginButtons.length; p++) {
  621.             sumX += loginButtons[p].x + loginButtons[p].width / 2;
  622.             sumY += loginButtons[p].y + loginButtons[p].height / 2;
  623.         }
  624.         var centerX = sumX / loginButtons.length;
  625.         var centerY = sumY / loginButtons.length;
  626.         
  627.         console.log("登录按钮的平均中心位置:");
  628.         console.log("  X: " + Math.round(centerX));
  629.         console.log("  Y: " + Math.round(centerY));
  630.         console.log("  建议点击坐标: (" + Math.round(centerX) + ", " + Math.round(centerY) + ")");
  631.     }
  632.    
  633.     // 步骤间延时2秒
  634.     console.log("等待2秒...");
  635.     sleep.second(2);
  636. }

  637. /**
  638. * 任务队列数组调度示例
  639. */
  640. function taskQueueArrayExample() {
  641.     console.log("=== 示例3: 任务队列数组调度 ===");
  642.    
  643.     // 模拟任务队列数组
  644.     var taskQueue = [
  645.         { id: 1, name: '打开应用', priority: 1, status: 'pending', duration: 2000 },
  646.         { id: 2, name: '等待首页加载', priority: 2, status: 'pending', duration: 3000 },
  647.         { id: 3, name: '点击登录按钮', priority: 3, status: 'pending', duration: 1000 },
  648.         { id: 4, name: '输入用户名', priority: 4, status: 'pending', duration: 1500 },
  649.         { id: 5, name: '输入密码', priority: 5, status: 'pending', duration: 1500 },
  650.         { id: 6, name: '点击提交', priority: 6, status: 'pending', duration: 1000 },
  651.         { id: 7, name: '验证登录结果', priority: 7, status: 'pending', duration: 2000 }
  652.     ];
  653.    
  654.     console.log("任务队列共有 " + taskQueue.length + " 个任务");
  655.    
  656.     // 1. 按优先级排序
  657.     taskQueue.sort(function(a, b) {
  658.         return a.priority - b.priority;
  659.     });
  660.    
  661.     console.log("按优先级排序后的任务列表:");
  662.     for (var i = 0; i < taskQueue.length; i++) {
  663.         var task = taskQueue[i];
  664.         console.log("  [" + task.priority + "] " + task.name + " (预计耗时: " + task.duration + "ms)");
  665.     }
  666.    
  667.     // 2. 模拟执行任务队列
  668.     console.log("开始执行任务队列:");
  669.     var completedTasks = [];
  670.     var failedTasks = [];
  671.    
  672.     for (var j = 0; j < taskQueue.length; j++) {
  673.         var currentTask = taskQueue[j];
  674.         console.log("  执行任务 #" + (j+1) + ": " + currentTask.name);
  675.         
  676.         // 模拟任务执行(成功率90%)
  677.         var success = Math.random() > 0.1;
  678.         
  679.         if (success) {
  680.             currentTask.status = 'completed';
  681.             completedTasks.push(currentTask);
  682.             console.log("    ✓ 完成");
  683.         } else {
  684.             currentTask.status = 'failed';
  685.             failedTasks.push(currentTask);
  686.             console.log("    ✗ 失败");
  687.         }
  688.         
  689.         // 任务间短暂延时
  690.         sleep.second(0.3);
  691.     }
  692.    
  693.     console.log("");
  694.     console.log("任务执行统计:");
  695.     console.log("  总任务数: " + taskQueue.length);
  696.     console.log("  成功: " + completedTasks.length);
  697.     console.log("  失败: " + failedTasks.length);
  698.     console.log("  成功率: " + (completedTasks.length / taskQueue.length * 100).toFixed(1) + "%");
  699.    
  700.     if (failedTasks.length > 0) {
  701.         console.log("");
  702.         console.log("失败的任务:");
  703.         for (var k = 0; k < failedTasks.length; k++) {
  704.             console.log("  - " + failedTasks[k].name);
  705.         }
  706.     }
  707.    
  708.     // 步骤间延时2秒
  709.     console.log("等待2秒...");
  710.     sleep.second(2);
  711. }

  712. /**
  713. * 设备信息数组管理示例
  714. */
  715. function deviceInfoArrayExample() {
  716.     console.log("=== 示例4: 设备信息数组管理 ===");
  717.    
  718.     // 模拟多设备信息数组
  719.     var devices = [
  720.         { deviceId: 'device_001', model: '小米11', androidVersion: '12', screenWidth: 1080, screenHeight: 2400, battery: 85, online: true },
  721.         { deviceId: 'device_002', model: '华为P40', androidVersion: '11', screenWidth: 1080, screenHeight: 2340, battery: 62, online: true },
  722.         { deviceId: 'device_003', model: 'OPPO Reno6', androidVersion: '11', screenWidth: 1080, screenHeight: 2400, battery: 45, online: false },
  723.         { deviceId: 'device_004', model: 'vivo X60', androidVersion: '12', screenWidth: 1080, screenHeight: 2376, battery: 90, online: true },
  724.         { deviceId: 'device_005', model: '三星S21', androidVersion: '13', screenWidth: 1080, screenHeight: 2400, battery: 30, online: true }
  725.     ];
  726.    
  727.     console.log("设备列表共有 " + devices.length + " 台设备");
  728.    
  729.     // 1. 筛选在线设备
  730.     var onlineDevices = [];
  731.     for (var i = 0; i < devices.length; i++) {
  732.         if (devices[i].online) {
  733.             onlineDevices.push(devices[i]);
  734.         }
  735.     }
  736.    
  737.     console.log("在线设备: " + onlineDevices.length + " 台");
  738.     for (var j = 0; j < onlineDevices.length; j++) {
  739.         var device = onlineDevices[j];
  740.         console.log("  - " + device.model + " (电量: " + device.battery + "%, Android " + device.androidVersion + ")");
  741.     }
  742.    
  743.     // 2. 查找低电量设备(<50%)
  744.     var lowBatteryDevices = [];
  745.     for (var k = 0; k < devices.length; k++) {
  746.         if (devices[k].battery < 50) {
  747.             lowBatteryDevices.push(devices[k]);
  748.         }
  749.     }
  750.    
  751.     if (lowBatteryDevices.length > 0) {
  752.         console.log("低电量设备警告 (<50%): " + lowBatteryDevices.length + " 台");
  753.         for (var m = 0; m < lowBatteryDevices.length; m++) {
  754.             var lowDevice = lowBatteryDevices[m];
  755.             console.log("  ⚠ " + lowDevice.model + " - 电量: " + lowDevice.battery + "%");
  756.         }
  757.     } else {
  758.         console.log("所有设备电量充足");
  759.     }
  760.    
  761.     // 3. 按Android版本分组
  762.     var versionGroups = {};
  763.     for (var n = 0; n < devices.length; n++) {
  764.         var dev = devices[n];
  765.         var version = 'Android ' + dev.androidVersion;
  766.         if (!versionGroups[version]) {
  767.             versionGroups[version] = [];
  768.         }
  769.         versionGroups[version].push(dev);
  770.     }
  771.    
  772.     console.log("按Android版本分组:");
  773.     for (var version in versionGroups) {
  774.         if (versionGroups.hasOwnProperty(version)) {
  775.             var group = versionGroups[version];
  776.             console.log("  " + version + ": " + group.length + " 台设备");
  777.             for (var p = 0; p < group.length; p++) {
  778.                 console.log("    - " + group[p].model);
  779.             }
  780.         }
  781.     }
  782.    
  783.     // 4. 计算平均电量
  784.     var totalBattery = 0;
  785.     for (var q = 0; q < devices.length; q++) {
  786.         totalBattery += devices[q].battery;
  787.     }
  788.     var avgBattery = totalBattery / devices.length;
  789.    
  790.     console.log("设备统计信息:");
  791.     console.log("  平均电量: " + avgBattery.toFixed(1) + "%");
  792.     console.log("  最高电量: " + Math.max.apply(Math, devices.map(function(d) { return d.battery; })) + "%");
  793.     console.log("  最低电量: " + Math.min.apply(Math, devices.map(function(d) { return d.battery; })) + "%");
  794.    
  795.     // 步骤间延时2秒
  796.     console.log("等待2秒...");
  797.     sleep.second(2);
  798. }

  799. //===========================================
  800. // 主函数和执行入口
  801. //===========================================

  802. /**
  803. * 运行所有示例
  804. */
  805. function runAllExamples() {
  806.     try {
  807.         uiControlArrayExample();
  808.         imageRecognitionArrayExample();
  809.         taskQueueArrayExample();
  810.         deviceInfoArrayExample();
  811.         console.log("=== 所有示例执行完成 ===");
  812.     } catch (e) {
  813.         console.log("执行示例时发生错误: " + (e.message || e));
  814.     }
  815. }

  816. // 执行所有示例
  817. runAllExamples();
复制代码



unto示例JavaScript的 try-catch-finally-throw用法nextnocontent
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关导读了
    采集亚马逊正版群发工具有没有?
    Apr.20旅行X心语今天来说说YYPOST新功能的一个灵活用法,采集亚马逊商品信息,并且获得排名的软件,亚马逊现在越来越多客户做,淘宝的水是越来越清了,以前做电商的客户,现在都转战到外国,最赚钱的要数一些客户往亚马逊里堆了吧,拿我这个YYPOST的客户,最多的是采集,分析排名,刷价格,刷数量,改价,刷访问量等等技术

    企业发展B2B网站有什么东东软件可以发呢
    标题企业发展网B2B软件,现在虽然B2B网站收录不错,可愁的是心急的人们,他们太想一口吃撑胖子了,发帖宣传虽然不能像佛系那样淡定,但也不能像跑火车那般急躁对待,自己内容不收录,完全是自己操作内容问题,可以参考一下别人的内容是怎么弄的,然后自己要试着转变,而且收录这个内容,常常会变化的,不是一种规则就吃到老

    搜房天下房聊软件哪一个好呢
    本帖最后由 发帖软件 于 2019-5-22 16:15 编辑 2搜房天下群发房聊信息软件,开始本来打算做58同城的,但发一个就要一次点触验证码,这就让人没有感觉到存在的价值了吧,都是卖二手房和新房的搜房天下倒是可以发即时聊天信息,也没有发现他这个网站有啥子限制,登陆一个搜房天下账号,然后采集回来分类列表的网址,然后就一

    大家坛有没有好用的群发工具下载呢
    当你的笑容给我礼貌的招呼,大家坛全自动发帖软件,宣传推广是一场持久战,总是有一些人把软件用了一天,或是几个小时,就觉得自己付出太多了,那加进来的粉丝,或是流量,应该是和宣传多少成正比的,其实没有这么便宜的事,就像很多阅读量超过一百万的视频,或是电影,真正会在屏幕打赏的人不会超过三千,真正大额打赏给主

    群发正版软件中国塑料网
    中国塑料网群发软件YYPOST脚本下载地址,这个网站会有一个很奇怪的问题就是你在首页登陆无半个验证码,但在登陆网址登陆就会有一个验证码,所以我们灵活一些,在首页登陆就不用输入验证码了哈。网站秒收录比较高,但发的都是五金和建筑行业,先前有很多人都是发土建工程的大公司操作的,现在这个网站专为那个行业诞生的吧。

    OpenStreetMap网站正版2019年发帖工具下载
    本帖最后由 发帖软件 于 2019-5-21 11:13 编辑 OpenStreetMap网站全自动群发,OpenStreetMapOpenStreetMap(简称OSM,中文是公开地图)是一个网上地图协作计划,目标是创造一个内容自由且能让所有人编辑的世界地图。有的人编辑地图然后等收录,有的人发日志等收录,我们这里也是利用地图日志做为宣传的目标,简单的脚本理

    搜房天下全自动收短信全自动识别验证码注册账号软件
    房天下自动注册机,这个脚本是前几天发房聊的脚本廷伸品种,这个脚本能做到自动注册账号,自动保存账号,自动发房聊的效果,不过今天我们主要说一说怎么注册账号写脚本吧,这个搜房天天下的账号,可以发提问,可以发房聊,发论坛,发博客,还有发个人中心页都是有秒收的效果的,这样就省去了去买号,去乱花钱的效果了吧,而

    企业邮箱安卓端有什么APP软件可以发的呢
    请输入标题企业邮箱安卓发发送邮箱脚本,这个脚本是利用企业邮箱进行群发的,全程是一种模拟手工操作的过程,所以封号是很少的,而且企业邮箱群发到普通QQ邮箱不容易进垃圾箱中的,所以这个脚本也是这样的原理,不过最好是利用一些多开器,登陆多点的QQ邮箱账号会比较流畅一些,然后用软件一个一个的切换APP进行群发邮件会

    头条留评论软件有没有好用的呢?
    今天整一个今日头条留言软件,对于留言YYPOST是优势是比较大的存在,因为他往往专注一些下拉定位的优点,像今日头条这样,还是需要一些特殊下拉定位的,因为他新闻有长有短,有图有视频的,所以综合起来定位是比较难的,如果用POST也不是很轻松可以破解他的加密参数。这个脚本也是有一个不好的地方就是换号会比较麻烦,您电

    单网页生成神器
    最近新技术,网页生成机占领了整个网络的半壁江山,效果很疯狂,虽然不知道能持续多久,作为开发软件的领头者,一直在找收录的方法,一直在努力创新着,一直被人模仿,却从没有被超越过,这个网页生成机,已经出来有一段时间了,一直没有拿出来分享,醉过醉过,它是利用的一些小小收录漏洞整的,您最好用一些老站域名,进行

关闭
快速回复 返回列表 返回顶部
本站自动发贴软件,是现在最流行的做脚本软件,这种发贴工具,不但发贴收录快,而且抢占好的先机,完全自由编辑,实现针对性群发模拟操作,软件可以顶贴,也可以发贴,可以兼容支持Discuz、PHPWind、Dvbbs三大主流论坛,有手机验证码收件,邮件收发的功能,支持验证码识别,注册问题识别,多线程任务,自动上传头像,自动激活注册邮件,兼容防注册插件,本站软件原创正版,更新效率最快的原创软件。 『网络推广软件』『自动发帖软件』『 自动发帖