Skill: shineniefei/test-online-analysis (version 1.0.0)

--- name: test-online-analysis description: Online (real-time) data analysis, rule extraction, and pattern recognition for testing scenarios. Activate when user mentions test online analysis, real-time data rule extraction, testing scenario pattern recognition, or log/stream data analysis for testing. --- # Test Online Analysis 测试实时分析技能 ## Overview This skill provides real-time data analysis capabilities, including rule extraction from online streaming data, pattern recognition for testing scenarios, log analysis, and anomaly detection. It helps automate the process of identifying business rules, testing patterns, and abnormal behaviors from live data streams or log files. ## Core Capabilities ### 1. Rule Extraction - Automatically extract business rules from online data streams - Identify implicit logic and constraints from real-time transaction data - Generate structured rule documentation for testing reference ### 2. Pattern Recognition - Recognize common testing scenarios from log data - Identify recurring patterns in user behavior and system responses - Classify data patterns to simplify test case design ### 3. Anomaly Detection - Real-time detection of abnormal data points and system behaviors - Compare current data against historical patterns to identify outliers - Generate anomaly reports with severity levels ### 4. Testing Scenario Generation - Automatically generate test cases based on extracted rules and patterns - Map real-world scenarios to test coverage requirements - Identify edge cases and boundary conditions from live data ## Workflow ### Step 1: Data Ingestion 1. Accept input data sources: log files, real-time API streams, database queries 2. Validate data format and structure 3. Preprocess data (cleaning, normalization, filtering) ### Step 2: Analysis Execution 1. Run rule extraction algorithm on processed data 2. Apply pattern recognition models to identify testing scenarios 3. Perform anomaly detection against baseline patterns ### Step 3: Result Generation 1. Generate structured rule documentation in markdown format 2. Create test case suggestions based on extracted patterns 3. Produce anomaly reports with actionable insights ### Step 4: Output Delivery 1. Present summary of key findings to user 2. Offer to export full analysis results to files 3. Suggest follow-up actions for testing optimization ## Usage Examples ### Example 1: Extract Rules from Transaction Logs **User Request:** "Analyze these transaction logs and extract business rules for testing" **Skill Action:** 1. Ingest and parse log files 2. Extract transaction validation rules, amount limits, and processing logic 3. Generate structured rule document with test case suggestions 4. Output summary of key rules and potential testing scenarios ### Example 2: Detect Anomalies in Real-time Data **User Request:** "Monitor this data stream and find anomalies" **Skill Action:** 1. Connect to real-time data source 2. Establish baseline pattern from historical data 3. Alert on anomalous data points as they appear 4. Generate anomaly report with severity assessment ## Resources ### scripts/ - `rule_extractor.py`: Core algorithm for extracting business rules from structured data - `pattern_recognizer.py`: Machine learning model for identifying testing scenarios - `anomaly_detector.py`: Real-time anomaly detection utility - `test_case_generator.py`: Automatically generate test cases from extracted rules ### references/ - `rule_extraction_standards.md`: Guidelines for consistent rule documentation - `pattern_catalog.md`: Catalog of common testing patterns and scenarios - `anomaly_severity_matrix.md`: Severity classification framework for anomalies ## Installation ### Local Installation 1. Clone or copy the `online-analysis` directory to your OpenClaw skills folder: ```bash # User workspace skills cp -r online-analysis ~/.openclaw/workspace/skills/ # Or global system skills cp -r online-analysis /usr/local/lib/node_modules/openclaw/skills/ ``` 2. Restart OpenClaw to load the new skill ### Dependencies ```bash pip install numpy ``` ## Usage ### Command Line ```bash # Extract rules from log files python scripts/rule_extractor.py transaction_logs.txt > extracted_rules.md # Detect anomalies in numeric data python scripts/anomaly_detector.py performance_metrics.json > anomaly_report.md ``` ### Skill Trigger The skill automatically activates when you mention: - "online analysis" - "rule extraction" - "real-time data analysis" - "log analysis for testing" - "anomaly detection" ## License MIT

path: _meta.json
content: {
  "slug": "test-online-analysis",
  "name": "Test Online Analysis",
  "version": "1.0.0",
  "description": "在线实时数据分析与测试规则提取技能，支持从日志/数据流自动提取业务规则、异常检测、测试场景生成",
  "author": "飞飞侠",
  "license": "MIT",
  "tags": ["testing", "analysis", "rule-extraction", "anomaly-detection"],
  "homepage": "https://clawhub.com/spclaudehome/test-online-analysis",
  "repository": "https://clawhub.com/spclaudehome/test-online-analysis.git",
  "dependencies": {
    "python": ">=3.8",
    "numpy": ">=1.21.0"
  },
  "compatibility": {
    "openclaw": ">=0.9.0"
  }
}


path: README.md
content: # OpenClaw Skill: Test Online Analysis

**测试专用在线实时数据分析与规则提取技能**

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![OpenClaw Compatible](https://img.shields.io/badge/OpenClaw-%3E%3D0.9.0-blue.svg)](https://openclaw.ai)

## 🚀 功能简介

专为测试场景设计的实时数据分析技能，能够自动从日志、数据流中提取业务规则，识别异常模式，生成测试用例，大幅提升测试效率。

## ✨ 核心特性

### 📊 规则自动提取
- 从交易日志、接口返回、业务数据流中自动识别业务规则
- 支持提取字段约束、校验逻辑、金额限制、状态流转等规则
- 自动生成结构化的规则文档，可直接用于测试设计

### 🚨 实时异常检测
- 基于统计模型的实时异常点检测
- 支持严重程度分级（高/中/低）
- 自动生成异常报告，包含预期值、偏差度等信息

### 🎯 测试场景生成
- 基于提取的规则自动生成测试用例建议
- 识别边界条件和边缘场景
- 映射到测试覆盖度要求

## 🛠️ 快速开始

### 安装依赖
```bash
pip install numpy
```

### 基础使用

#### 1. 从日志提取业务规则
```bash
# 分析文本日志
python scripts/rule_extractor.py transaction_logs.txt

# 分析JSON结构数据
python scripts/rule_extractor.py api_responses.json

# 导出规则到Markdown文件
python scripts/rule_extractor.py logs.txt > business_rules.md
```

#### 2. 检测数据异常
```bash
# 分析数值型数据
python scripts/anomaly_detector.py performance_metrics.json

# 生成异常报告
python scripts/anomaly_detector.py metrics.json > anomaly_report.md
```

## 📋 技能触发关键词

当你提到以下内容时，技能会自动激活：
- online分析 / 实时分析
- 规则提取 / 业务规则识别
- 日志分析 / 数据流分析
- 异常检测 / 问题定位
- 测试场景生成 / 用例设计

## 📁 目录结构
```
online-analysis/
├── SKILL.md              # 技能核心定义与详细文档
├── README.md             # 项目说明文档
├── scripts/              # 可执行脚本
│   ├── rule_extractor.py    # 规则提取工具
│   ├── anomaly_detector.py  # 异常检测工具
│   ├── pattern_recognizer.py # 模式识别工具
│   └── test_case_generator.py # 测试用例生成工具
└── references/           # 参考文档
    ├── rule_extraction_standards.md # 规则提取标准
    ├── pattern_catalog.md            # 测试模式目录
    └── anomaly_severity_matrix.md    # 异常严重度矩阵
```

## 🧪 示例输出

### 规则提取报告示例
```markdown
# Extracted Business Rules

Generated at: 2026-03-13 15:00:00

| Rule Type | Condition | Confidence |
|-----------|-----------|------------|
| amount_limit | transaction amount must be less than 10000 | 0.9 |
| field_type | status must be of type string | 1.0 |
| field_enum | status must be one of: pending, success, failed | 0.9 |
```

### 异常检测报告示例
```markdown
# Anomaly Detection Report

Generated at: 2026-03-13 15:00:00
Total data points processed: 200
Total anomalies detected: 2

## Anomalies

| Timestamp | Value | Expected Mean | Z-Score | Severity |
|-----------|-------|---------------|---------|----------|
| 2026-03-13T14:55:00 | 200 | 100.23 | 9.87 | high |
| 2026-03-13T14:56:00 | 50 | 100.23 | 4.92 | medium |
```

## 📝 开发说明

### 扩展功能
- 在 `scripts/` 目录下添加新的分析脚本
- 在 `references/` 目录下添加行业规则库和模式模板
- 支持自定义规则提取正则表达式

### 贡献
欢迎提交 Issue 和 Pull Request 来完善这个技能！

## 📄 许可证

MIT License

## 🔗 相关链接

- [OpenClaw 官方文档](https://docs.openclaw.ai)
- [ClawHub 技能市场](https://clawhub.com)


path: scripts/anomaly_detector.py
content: #!/usr/bin/env python3
"""
Anomaly Detector for Online Analysis Skill
Real-time anomaly detection from data streams
"""

import numpy as np
from typing import List, Dict, Any
from datetime import datetime
from collections import deque

class AnomalyDetector:
    def __init__(self, window_size: int = 100, threshold: float = 3.0):
        self.window_size = window_size
        self.threshold = threshold
        self.data_window = deque(maxlen=window_size)
        self.baseline_mean = None
        self.baseline_std = None
        self.anomalies = []
    
    def update_baseline(self) -> None:
        """Update baseline statistics from current window"""
        if len(self.data_window) < self.window_size // 2:
            return
        
        numeric_data = [x for x in self.data_window if isinstance(x, (int, float))]
        if numeric_data:
            self.baseline_mean = np.mean(numeric_data)
            self.baseline_std = np.std(numeric_data)
    
    def add_data_point(self, value: Any, metadata: Dict = None) -> Dict[str, Any]:
        """Add a single data point and check for anomalies"""
        self.data_window.append(value)
        self.update_baseline()
        
        anomaly = None
        if isinstance(value, (int, float)) and self.baseline_mean is not None and self.baseline_std > 0:
            z_score = abs((value - self.baseline_mean) / self.baseline_std)
            if z_score > self.threshold:
                anomaly = {
                    'timestamp': datetime.now().isoformat(),
                    'value': value,
                    'expected_mean': self.baseline_mean,
                    'expected_std': self.baseline_std,
                    'z_score': z_score,
                    'severity': 'high' if z_score > 5 else 'medium' if z_score > 4 else 'low',
                    'metadata': metadata or {}
                }
                self.anomalies.append(anomaly)
        
        return anomaly
    
    def analyze_batch(self, data: List[Any]) -> List[Dict[str, Any]]:
        """Analyze a batch of data points"""
        batch_anomalies = []
        for point in data:
            anomaly = self.add_data_point(point)
            if anomaly:
                batch_anomalies.append(anomaly)
        return batch_anomalies
    
    def get_anomalies(self, severity: str = None) -> List[Dict[str, Any]]:
        """Get all detected anomalies, optionally filtered by severity"""
        if severity:
            return [a for a in self.anomalies if a['severity'] == severity]
        return self.anomalies
    
    def generate_report(self) -> str:
        """Generate anomaly report in markdown format"""
        md = "# Anomaly Detection Report\n\n"
        md += f"Generated at: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n"
        md += f"Total data points processed: {len(self.data_window)}\n"
        md += f"Total anomalies detected: {len(self.anomalies)}\n\n"
        
        if self.anomalies:
            md += "## Anomalies\n\n"
            md += "| Timestamp | Value | Expected Mean | Z-Score | Severity |\n"
            md += "|-----------|-------|---------------|---------|----------|\n"
            
            for anomaly in sorted(self.anomalies, key=lambda x: x['z_score'], reverse=True):
                md += f"| {anomaly['timestamp']} | {anomaly['value']} | {anomaly['expected_mean']:.2f} | {anomaly['z_score']:.2f} | {anomaly['severity']} |\n"
        
        return md

if __name__ == "__main__":
    import sys
    import json
    
    detector = AnomalyDetector()
    
    if len(sys.argv) < 2:
        # Generate test data
        test_data = np.random.normal(100, 10, 200).tolist()
        test_data[50] = 200  # Anomaly
        test_data[150] = 50   # Anomaly
        
        anomalies = detector.analyze_batch(test_data)
        print(detector.generate_report())
    else:
        with open(sys.argv[1], 'r') as f:
            if sys.argv[1].endswith('.json'):
                data = json.load(f)
            else:
                data = [float(line.strip()) for line in f if line.strip()]
        
        anomalies = detector.analyze_batch(data)
        print(detector.generate_report())


path: scripts/rule_extractor.py
content: #!/usr/bin/env python3
"""
Rule Extractor for Online Analysis Skill
Extracts business rules and implicit logic from structured data streams
"""

import json
import re
from typing import List, Dict, Any
from datetime import datetime

class RuleExtractor:
    def __init__(self):
        self.rules = []
        self.patterns = {
            'amount_limit': r'amount.*(greater than|less than|equal to|exceeds|below)\s*(\d+\.?\d*)',
            'time_constraint': r'(before|after|between)\s*(\d{1,2}:\d{2})',
            'status_transition': r'(status|state).*from\s*(\w+)\s*to\s*(\w+)',
            'validation': r'(must|should|required|cannot|must not)\s*(\w+.*?)\.',
        }
    
    def extract_from_text(self, text: str) -> List[Dict[str, Any]]:
        """Extract rules from plain text/logs"""
        extracted = []
        
        for rule_type, pattern in self.patterns.items():
            matches = re.finditer(pattern, text, re.IGNORECASE)
            for match in matches:
                rule = {
                    'type': rule_type,
                    'condition': match.group(0),
                    'extracted_at': datetime.now().isoformat(),
                    'confidence': 0.8 if len(match.groups()) > 1 else 0.6
                }
                extracted.append(rule)
        
        self.rules.extend(extracted)
        return extracted
    
    def extract_from_json(self, data: List[Dict]) -> List[Dict[str, Any]]:
        """Extract rules from structured JSON data"""
        extracted = []
        
        # Field value range analysis
        fields = {}
        for entry in data:
            for key, value in entry.items():
                if key not in fields:
                    fields[key] = {'types': set(), 'values': set()}
                fields[key]['types'].add(type(value).__name__)
                if isinstance(value, (int, float, str)) and len(str(value)) < 100:
                    fields[key]['values'].add(value)
        
        # Generate rules from field analysis
        for field, stats in fields.items():
            if len(stats['types']) == 1:
                extracted.append({
                    'type': 'field_type',
                    'condition': f"{field} must be of type {stats['types'].pop()}",
                    'confidence': 1.0
                })
            
            if len(stats['values']) > 0 and len(stats['values']) < 10:
                extracted.append({
                    'type': 'field_enum',
                    'condition': f"{field} must be one of: {', '.join(map(str, stats['values']))}",
                    'confidence': 0.9
                })
        
        self.rules.extend(extracted)
        return extracted
    
    def get_rules(self) -> List[Dict[str, Any]]:
        """Get all extracted rules"""
        return sorted(self.rules, key=lambda x: x['confidence'], reverse=True)
    
    def export_markdown(self) -> str:
        """Export rules as markdown document"""
        md = "# Extracted Business Rules\n\n"
        md += f"Generated at: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n\n"
        md += "| Rule Type | Condition | Confidence |\n"
        md += "|-----------|-----------|------------|\n"
        
        for rule in self.get_rules():
            md += f"| {rule['type']} | {rule['condition']} | {rule['confidence']:.1f} |\n"
        
        return md

if __name__ == "__main__":
    import sys
    if len(sys.argv) < 2:
        print("Usage: python rule_extractor.py <input_file>")
        sys.exit(1)
    
    extractor = RuleExtractor()
    
    with open(sys.argv[1], 'r') as f:
        if sys.argv[1].endswith('.json'):
            data = json.load(f)
            rules = extractor.extract_from_json(data)
        else:
            text = f.read()
            rules = extractor.extract_from_text(text)
    
    print(extractor.export_markdown())


path: references/rule_extraction_standards.md
content: # Rule Extraction Standards

## Overview
This document defines the standards for extracting and documenting business rules from online data streams.

## Rule Classification

### 1. Business Rules
- **Definition:** Rules that enforce business logic and requirements
- **Examples:** Transaction limits, eligibility criteria, approval workflows
- **Confidence Level:** High (≥0.8) when extracted from multiple data points

### 2. Technical Rules
- **Definition:** Rules that enforce technical constraints and system behavior
- **Examples:** Data type constraints, format validations, API rate limits
- **Confidence Level:** Very High (≥0.9) when consistently observed

### 3. Implicit Rules
- **Definition:** Rules that are not explicitly documented but observed in practice
- **Examples:** Undocumented edge case handling, default behaviors
- **Confidence Level:** Medium (≥0.6) when pattern is consistent

## Rule Documentation Format

Each extracted rule must include:
1. **Rule ID:** Unique identifier (RULE-XXXX)
2. **Rule Type:** Business/Technical/Implicit
3. **Condition:** Clear statement of the rule condition
4. **Source:** Data source where the rule was observed
5. **Confidence:** 0.0-1.0 score indicating reliability
6. **Examples:** 1-2 concrete examples of the rule in action

## Quality Criteria

### High Confidence (≥0.8)
- Observed in ≥10 independent data points
- No counterexamples found
- Consistent across different time periods

### Medium Confidence (0.6-0.8)
- Observed in 3-10 data points
- No significant counterexamples
- Mostly consistent across scenarios

### Low Confidence (<0.6)
- Observed in <3 data points
- Potential counterexamples exist
- Pattern may be coincidental

## Validation Process

1. **Initial Extraction:** Automatic extraction from data
2. **Pattern Verification:** Check for consistency across multiple data points
3. **Counterexample Check:** Search for data points that violate the candidate rule
4. **Confidence Scoring:** Assign confidence level based on validation results
5. **Documentation:** Record rule in standard format


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: suspicious (HIGH)