|
|
AIWROKÊý×é·½·¨¸ß¼¶Ó¦Óð¸Àý
- /**
- * AIWROKÊý×é·½·¨¸ß¼¶Ó¦Óð¸Àý
- * רΪ°²×¿Rhino JavaScriptÒýÇæÓÅ»¯µÄÊý×é´¦Àí½â¾ö·½°¸
- * 🍎½»Á÷QQȺ711841924Ⱥһ£¬Æ»¹ûÄÚ²âȺ£¬528816639
- * @¹¦ÄÜÌØµã
- * - ÍêÈ«¼æÈÝES5Óï·¨ºÍRhinoÒýÇæ
- * - ÌṩÊý¾Ý¹ýÂË¡¢×ª»»¡¢¾ÛºÏµÈ¸ß¼¶²Ù×÷
- * - Ö§³ÖÅúÁ¿´¦ÀíºÍÒì²½²Ù×÷ģʽ
- * - ¼¯³ÉAIWROKÌØÓеÄÈÕÖ¾ºÍUIÏÔʾ¹¦ÄÜ
- * - °üº¬ÐÔÄÜÓÅ»¯ºÍÄÚ´æ¹ÜÀí
- *
- * @Ó¦Óó¡¾°
- * - UI¿Ø¼þÅúÁ¿²Ù×÷
- * - ÍøÂçÇëÇóÊý¾Ý´¦Àí
- * - ͼÏñʶ±ð½á¹ûɸѡ
- * - ÈÕÖ¾Êý¾Ý¾ÛºÏ·ÖÎö
- * - ¶àÏß³ÌÊý¾Ý´¦Àí
- *
- * @×÷Õß AIWROK¿ª·¢ÍŶÓ
- * @°æ±¾ 1.0 - Rhino¼æÈݰæ
- * @ÈÕÆÚ 2024
- */
- //===========================================
- // »ù´¡¼æÈÝÐÔÉèÖÃ
- //===========================================
- // È·±£printlº¯Êý¿ÉÓ㨼æÈÝRhino»·¾³£©
- if (typeof printl === 'undefined') {
- function printl(message) {
- try {
- if (typeof console !== 'undefined' && console.log) {
- console.log(message);
- } else if (typeof print !== 'undefined') {
- print(message);
- } else {
- java.lang.System.out.println(String(message));
- }
- } catch (e) {
- // ¾²Ä¬Ê§°Ü
- }
- }
- }
- //===========================================
- // ¸ß¼¶Êý×鹤¾ßÀà
- //===========================================
- /**
- * ArrayUtils - ¸ß¼¶Êý×é²Ù×÷¹¤¾ßÀà
- * ÌṩÁ´Ê½µ÷Óá¢ÅúÁ¿´¦ÀíºÍÐÔÄÜÓÅ»¯¹¦ÄÜ
- */
- function ArrayUtils() {
- this.version = "1.0.0";
- this.performanceMetrics = {
- operations: 0,
- startTime: 0,
- endTime: 0
- };
- }
- /**
- * ¿ªÊ¼ÐÔÄÜ¼à¿Ø
- */
- ArrayUtils.prototype.startPerformanceMonitoring = function() {
- this.performanceMetrics.startTime = new Date().getTime();
- this.performanceMetrics.operations = 0;
- return this;
- };
- /**
- * ½áÊøÐÔÄÜ¼à¿Ø²¢·µ»Ø±¨¸æ
- */
- ArrayUtils.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))
- };
- };
- /**
- * °²È«Êý×é±éÀú - Ö§³ÖÖжϺÍÒì³£´¦Àí
- * @param {Array} array - Òª±éÀúµÄÊý×é
- * @param {Function} callback - »Øµ÷º¯Êý£¬·µ»Øfalse¿ÉÖжϱéÀú
- * @param {Object} context - »Øµ÷º¯ÊýÉÏÏÂÎÄ
- * @returns {ArrayUtils} Ö§³ÖÁ´Ê½µ÷ÓÃ
- */
- ArrayUtils.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) {
- printl("Êý×é±éÀú´íÎó at index " + i + ": " + (e.message || e));
- }
-
- return this;
- };
- /**
- * ÖÇÄÜÊý×é¹ýÂË - Ö§³Ö¶àÌõ¼þºÍ¸´ÔÓÂß¼
- * @param {Array} array - Ô´Êý×é
- * @param {Array} conditions - ¹ýÂËÌõ¼þÊý×é
- * @returns {Array} ¹ýÂ˺óµÄÊý×é
- *
- * @ʾÀý
- * var result = arrayUtils.smartFilter(data, [
- * { field: 'age', operator: '>', value: 18 },
- * { field: 'name', operator: 'contains', value: 'ÕÅ' },
- * { field: 'score', operator: 'between', value: [60, 100] }
- * ]);
- */
- ArrayUtils.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;
- });
- };
- /**
- * »ñÈ¡¶ÔÏó×Ö¶ÎÖµ - Ö§³ÖǶÌ×ÊôÐÔ·ÃÎÊ
- */
- ArrayUtils.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;
- };
- /**
- * ÆÀ¹ÀÌõ¼þ - Ö§³Ö¶àÖÖ²Ù×÷·û
- */
- ArrayUtils.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 = arrayUtils.aggregate(salesData, {
- * groupBy: 'category',
- * metrics: {
- * totalSales: { field: 'amount', operation: 'sum' },
- * avgPrice: { field: 'price', operation: 'avg' },
- * count: { operation: 'count' }
- * }
- * });
- */
- ArrayUtils.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;
- };
- /**
- * ¼ÆËãÖ¸±ê - Ö§³Ö¶àÖ־ۺϲÙ×÷
- */
- ArrayUtils.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;
- };
- /**
- * ¼ÆËãµ¥¸öÖ¸±ê
- */
- ArrayUtils.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} ·ÖÒ³½á¹û
- */
- ArrayUtils.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} È¥ÖØºóµÄÊý×é
- */
- ArrayUtils.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 - ´¦ÀíÑ¡Ïî
- */
- ArrayUtils.prototype.batchUIProcess = function(uiElements, processor, options) {
- options = options || {};
- var batchSize = options.batchSize || 10;
- var delay = options.delay || 100;
- var self = this;
-
- printl("¿ªÊ¼ÅúÁ¿´¦Àí " + uiElements.length + " ¸öUIÔªËØ");
-
- var batches = [];
- for (var i = 0; i < uiElements.length; i += batchSize) {
- batches.push(uiElements.slice(i, i + batchSize));
- }
-
- // ·ÖÅú´¦Àí
- batches.forEach(function(batch, batchIndex) {
- setTimeout(function() {
- printl("´¦ÀíµÚ " + (batchIndex + 1) + " Åú£¬¹² " + batch.length + " ¸öÔªËØ");
-
- batch.forEach(function(element, index) {
- try {
- processor(element, index);
- self.performanceMetrics.operations++;
- } catch (e) {
- printl("´¦ÀíUIÔªËØÊ§°Ü: " + (e.message || e));
- }
- });
-
- if (batchIndex === batches.length - 1) {
- printl("ÅúÁ¿´¦ÀíÍê³É");
- }
- }, batchIndex * delay);
- });
-
- return this;
- };
- /**
- * OCR½á¹ûÖÇÄÜɸѡ - ½áºÏAIWROKµÄOCR¹¦ÄÜ
- * @param {Array} ocrResults - OCRʶ±ð½á¹ûÊý×é
- * @param {Object} filterOptions - ɸѡѡÏî
- * @returns {Array} ɸѡºóµÄ½á¹û
- */
- ArrayUtils.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} ·ÖÎö½á¹û
- */
- ArrayUtils.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 ecommerceDataProcessingExample() {
- printl("=== AIWROKÊý×é·½·¨¸ß¼¶Ó¦Óð¸Àý ===");
-
- // ´´½¨Êý×鹤¾ßʵÀý
- var arrayUtils = new ArrayUtils();
-
- // Ä£ÄâµçÉÌÊý¾Ý
- var products = [
- { id: 1, name: 'iPhone 13', category: 'ÊÖ»ú', price: 5999, stock: 50, sales: 120 },
- { id: 2, name: '»ªÎªP50', category: 'ÊÖ»ú', price: 4488, stock: 30, sales: 85 },
- { id: 3, name: 'MacBook Pro', category: 'µçÄÔ', price: 12999, stock: 20, sales: 45 },
- { id: 4, name: 'СÃ×µçÊÓ', category: '¼Òµç', price: 2999, stock: 15, sales: 200 },
- { id: 5, name: 'AirPods Pro', category: 'Åä¼þ', price: 1999, stock: 100, sales: 300 },
- { id: 6, name: '»ªÎªÊÖ±í', category: 'Åä¼þ', price: 2688, stock: 25, sales: 150 },
- { id: 7, name: 'iPad Air', category: 'ƽ°å', price: 4399, stock: 40, sales: 180 },
- { id: 8, name: '´÷¶ûÏÔʾÆ÷', category: 'µçÄÔ', price: 2199, stock: 35, sales: 95 }
- ];
-
- // ¿ªÊ¼ÐÔÄÜ¼à¿Ø
- arrayUtils.startPerformanceMonitoring();
-
- printl("ÔʼÊý¾Ý£º¹² " + products.length + " ¸öÉÌÆ·");
-
- // 1. ÖÇÄÜɸѡ£ºÕÒ³ö¼Û¸ñ´óÓÚ2000ÇÒÏúÁ¿´óÓÚ100µÄÉÌÆ·
- var hotProducts = arrayUtils.smartFilter(products, [
- { field: 'price', operator: '>', value: 2000 },
- { field: 'sales', operator: '>', value: 100 }
- ]);
-
- printl("ÈÈÃÅÉÌÆ·£º" + hotProducts.length + " ¸ö");
- hotProducts.forEach(function(product) {
- printl(" - " + product.name + " (¼Û¸ñ: ¥" + product.price + ", ÏúÁ¿: " + product.sales + ")");
- });
-
- // 2. Êý¾Ý¾ÛºÏ£º°´Àà±ðͳ¼Æ
- var categoryStats = arrayUtils.aggregate(products, {
- groupBy: 'category',
- metrics: {
- totalProducts: { operation: 'count' },
- avgPrice: { field: 'price', operation: 'avg' },
- totalSales: { field: 'sales', operation: 'sum' },
- totalValue: { field: 'stock', operation: 'sum' }
- }
- });
-
- printl("\nÀà±ðͳ¼Æ£º");
- for (var category in categoryStats) {
- if (categoryStats.hasOwnProperty(category)) {
- var stats = categoryStats[category];
- printl(" " + category + ": ");
- printl(" ÉÌÆ·ÊýÁ¿: " + stats.totalProducts);
- printl(" ƽ¾ù¼Û¸ñ: ¥" + Math.round(stats.avgPrice));
- printl(" ×ÜÏúÁ¿: " + stats.totalSales);
- printl(" ¿â´æ×ÜÁ¿: " + stats.totalValue);
- }
- }
-
- // 3. ·ÖÒ³ÏÔʾ£ºÃ¿Ò³ÏÔʾ3¸öÉÌÆ·
- var pageResult = arrayUtils.paginate(products, 3, 2);
-
- printl("\n·ÖÒ³ÏÔʾ£¨µÚ2Ò³£¬Ã¿Ò³3¸ö£©£º");
- pageResult.items.forEach(function(product) {
- printl(" " + product.name + " - " + product.category);
- });
-
- printl("·ÖÒ³ÐÅÏ¢£º");
- printl(" µ±Ç°Ò³: " + pageResult.pagination.pageNumber);
- printl(" ×ÜÒ³Êý: " + pageResult.pagination.totalPages);
- printl(" ×ÜÉÌÆ·Êý: " + pageResult.pagination.totalItems);
-
- // 4. ¸´ÔÓÊý¾Ý´¦ÀíʾÀý£ºÕÒ³ö¸÷Æ·ÀàÖÐ×ÏúµÄÉÌÆ·
- var topProductsByCategory = {};
- var categories = arrayUtils.distinct(products, 'category');
-
- categories.forEach(function(category) {
- var categoryProducts = arrayUtils.smartFilter(products, [
- { field: 'category', operator: '==', value: category }
- ]);
-
- // °´ÏúÁ¿ÅÅÐò£¬È¡ÏúÁ¿×î¸ßµÄ
- categoryProducts.sort(function(a, b) {
- return b.sales - a.sales;
- });
-
- // È·±£·ÖÀàÏÂÓÐÉÌÆ·ÔÙ¸³Öµ
- if (categoryProducts.length > 0) {
- topProductsByCategory[category] = categoryProducts[0];
- }
- });
-
- printl("\n¸÷Æ·Àà×ÏúÉÌÆ·£º");
- for (var cat in topProductsByCategory) {
- if (topProductsByCategory.hasOwnProperty(cat)) {
- var product = topProductsByCategory[cat];
- if (product) { // È·±£²úÆ·´æÔÚÔÙÊä³ö
- printl(" " + cat + ": " + product.name + " (ÏúÁ¿: " + product.sales + ")");
- }
- }
- }
-
- // 5. ÐÔÄÜ¼à¿Ø½á¹û
- var perfReport = arrayUtils.endPerformanceMonitoring();
- printl("\nÐÔÄܱ¨¸æ£º");
- printl(" Ö´ÐÐʱ¼ä: " + perfReport.duration + "ms");
- printl(" ²Ù×÷´ÎÊý: " + perfReport.operations);
- printl(" ´¦ÀíËÙ¶È: " + perfReport.opsPerSecond + " ops/sec");
- }
- /**
- * OCRʶ±ð½á¹û´¦ÀíʾÀý
- */
- function ocrResultProcessingExample() {
- printl("\n=== OCRʶ±ð½á¹û´¦ÀíʾÀý ===");
-
- var arrayUtils = new ArrayUtils();
-
- // Ä£ÄâOCRʶ±ð½á¹û
- var ocrResults = [
- { text: '怬', confidence: 0.95, x: 100, y: 200, width: 50, height: 30 },
- { text: 'Óû§Ãû', confidence: 0.87, x: 50, y: 300, width: 70, height: 25 },
- { text: 'ÃÜÂë', confidence: 0.92, x: 50, y: 350, width: 50, height: 25 },
- { text: '¼ÇסÎÒ', confidence: 0.78, x: 100, y: 400, width: 80, height: 20 },
- { text: 'Íü¼ÇÃÜÂë', confidence: 0.85, x: 200, y: 400, width: 90, height: 20 },
- { text: '×¢²á', confidence: 0.90, x: 300, y: 200, width: 50, height: 30 },
- { text: 'AIWROK', confidence: 0.98, x: 150, y: 100, width: 100, height: 40 },
- { text: '°ïÖú', confidence: 0.72, x: 300, y: 500, width: 50, height: 25 }
- ];
-
- // ɸѡ¸ßÖÃÐŶÈÎı¾
- var highConfidenceTexts = arrayUtils.filterOCRResults(ocrResults, {
- minConfidence: 0.85
- });
-
- printl("¸ßÖÃÐŶÈÎı¾ (" + highConfidenceTexts.length + " ¸ö):");
- highConfidenceTexts.forEach(function(result) {
- printl(" - " + result.text + " (ÖÃÐŶÈ: " + result.confidence + ")");
- });
-
- // ²éÕÒÌØ¶¨¹Ø¼ü´Ê
- var loginRelatedTexts = arrayUtils.filterOCRResults(ocrResults, {
- contains: '怬'
- });
-
- printl("\n°üº¬'µÇ¼'µÄÎı¾:");
- loginRelatedTexts.forEach(function(result) {
- printl(" - " + result.text);
- });
- }
- /**
- * ÈÕÖ¾·ÖÎöʾÀý
- */
- function logAnalysisExample() {
- printl("\n=== ÈÕÖ¾·ÖÎöʾÀý ===");
-
- var arrayUtils = new ArrayUtils();
-
- // Ä£ÄâÈÕÖ¾Êý¾Ý
- var logEntries = [
- { level: 'INFO', message: 'Ó¦ÓÃÆô¶¯', timestamp: new Date().getTime() - 3600000 },
- { level: 'DEBUG', message: '¼ÓÔØÅäÖÃÎļþ', timestamp: new Date().getTime() - 3590000 },
- { level: 'INFO', message: 'Óû§µÇ¼³É¹¦', timestamp: new Date().getTime() - 3500000 },
- { level: 'WARN', message: 'ÄÚ´æÊ¹ÓÃÂʹý¸ß', timestamp: new Date().getTime() - 3000000 },
- { level: 'ERROR', message: 'Êý¾Ý¿âÁ¬½Óʧ°Ü', timestamp: new Date().getTime() - 2500000 },
- { level: 'INFO', message: 'Êý¾Ý¿âÁ¬½Ó»Ö¸´', timestamp: new Date().getTime() - 2400000 },
- { level: 'ERROR', message: 'APIÇëÇó³¬Ê±', timestamp: new Date().getTime() - 2000000 },
- { level: 'WARN', message: 'APIÏìÓ¦»ºÂý', timestamp: new Date().getTime() - 1800000 },
- { level: 'INFO', message: 'Óû§Ö´ÐвÙ×÷', timestamp: new Date().getTime() - 1500000 },
- { level: 'DEBUG', message: '»º´æ¸üÐÂ', timestamp: new Date().getTime() - 1000000 }
- ];
-
- // ·ÖÎö×î½üһСʱµÄÈÕÖ¾
- var analysis = arrayUtils.analyzeLogs(logEntries, {
- timeWindow: 3600000, // 1Сʱ
- logLevelWeights: {
- 'ERROR': 10,
- 'WARN': 5,
- 'INFO': 1,
- 'DEBUG': 0.5
- }
- });
-
- printl("ÈÕÖ¾·ÖÎö½á¹û:");
- printl(" ×ÜÈÕÖ¾Êý: " + analysis.totalLogs);
- printl(" ´íÎóÂÊ: " + analysis.errorRate.toFixed(2) + "%");
- printl(" ¾¯¸æÂÊ: " + analysis.warningRate.toFixed(2) + "%");
- printl(" ϵͳ½¡¿µÆÀ·Ö: " + analysis.healthScore);
- printl(" ÈÕÖ¾¼¶±ð·Ö²¼:");
-
- for (var level in analysis.levelDistribution) {
- if (analysis.levelDistribution.hasOwnProperty(level)) {
- printl(" " + level + ": " + analysis.levelDistribution[level]);
- }
- }
- }
- /**
- * UIÔªËØÅúÁ¿´¦ÀíʾÀý
- */
- function uiElementBatchProcessingExample() {
- printl("\n=== UIÔªËØÅúÁ¿´¦ÀíʾÀý ===");
-
- var arrayUtils = new ArrayUtils();
-
- // Ä£ÄâUIÔªËØ
- var uiElements = [
- { id: 'btn1', type: 'button', text: 'Ìá½»', visible: true },
- { id: 'btn2', type: 'button', text: 'È¡Ïû', visible: true },
- { id: 'inp1', type: 'input', text: '', visible: true },
- { id: 'inp2', type: 'input', text: '', visible: false },
- { id: 'chk1', type: 'checkbox', text: 'ͬÒâÌõ¿î', visible: true },
- { id: 'lbl1', type: 'label', text: 'Óû§ÐÒé', visible: true },
- { id: 'img1', type: 'image', text: '', visible: true }
- ];
-
- // ´¦Àí¿É¼ûµÄ°´Å¥ÔªËØ
- var visibleButtons = arrayUtils.smartFilter(uiElements, [
- { field: 'visible', operator: '==', value: true },
- { field: 'type', operator: '==', value: 'button' }
- ]);
-
- printl("¿É¼û°´Å¥ÊýÁ¿: " + visibleButtons.length);
-
- // Ä£ÄâÅúÁ¿´¦Àí
- arrayUtils.batchUIProcess(visibleButtons, function(element, index) {
- try {
- printl(" ´¦Àí°´Å¥ #" + (index+1) + ": " + element.text + " (ID: " + element.id + ")");
- // ÕâÀï¿ÉÒÔÖ´ÐÐʵ¼ÊµÄUI²Ù×÷£¬Èçµã»÷¡¢ÐÞ¸ÄÊôÐÔµÈ
- } catch (e) {
- printl(" ´¦Àí°´Å¥Ê±³ö´í: " + e.message);
- }
- }, { batchSize: 2, delay: 500 });
- }
- //===========================================
- // Ö÷º¯ÊýºÍÖ´ÐÐÈë¿Ú
- //===========================================
- /**
- * ÔËÐÐËùÓÐʾÀý
- */
- function runAllExamples() {
- try {
- ecommerceDataProcessingExample();
- ocrResultProcessingExample();
- logAnalysisExample();
- uiElementBatchProcessingExample();
- printl("\n=== ËùÓÐʾÀýÖ´ÐÐÍê³É ===");
- } catch (e) {
- printl("Ö´ÐÐʾÀýʱ·¢Éú´íÎó: " + (e.message || e));
- }
- }
- // Èç¹ûÖ±½ÓÔËÐд˽ű¾£¬ÔòÖ´ÐÐËùÓÐʾÀý
- if (typeof module === 'undefined' || !module.exports) {
- runAllExamples();
- }
- // µ¼³öArrayUtilsÀ๩ÆäËûÄ£¿éʹÓÃ
- if (typeof module !== 'undefined' && module.exports) {
- module.exports = ArrayUtils;
- }
¸´ÖÆ´úÂë
|
|