65 lines
2.6 KiB
Python
65 lines
2.6 KiB
Python
"""Test all functionality under Chinese directory path"""
|
|
import sys, os
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'tianxuan.settings'
|
|
import django; django.setup()
|
|
|
|
print('1. Django import:', 'OK')
|
|
from analysis.data_loader import load_csv_directory
|
|
from analysis.entity_detector import detect_entity_column
|
|
from analysis.entity_aggregator import aggregate_by_entity
|
|
from analysis.session_store import SessionStore
|
|
print('2. All modules imported:', 'OK')
|
|
|
|
import asyncio
|
|
from analysis.tool_registry import handle_call
|
|
|
|
store = SessionStore()
|
|
store.drop_all()
|
|
|
|
# Load from Chinese path
|
|
csv = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'data', '复杂测试.csv')
|
|
print(f'Loading: {csv}')
|
|
lf, schema, rc, fc, mem = load_csv_directory(csv)
|
|
store.store_dataset('ds', lf, schema=schema, metadata={'row_count': rc, 'csv_glob': csv})
|
|
print(f'3. Loaded {rc} rows from Chinese path CSV:', 'OK')
|
|
|
|
# Profile
|
|
prof = asyncio.run(handle_call('profile_data', {'dataset_id': 'ds'}))
|
|
print(f'4. Profile: {len(prof.get("column_stats",{}))} columns profiled:', 'OK' if 'error' not in prof else 'FAIL')
|
|
|
|
# Entity detection (direct call)
|
|
from analysis.entity_detector import detect_entity_column
|
|
detect_result = detect_entity_column('ds')
|
|
entity_col = detect_result.get('recommended', '')
|
|
print(f'5. Entity detection: {entity_col}:', 'OK' if entity_col else 'FAIL')
|
|
|
|
# Aggregate
|
|
agg_lf, features = aggregate_by_entity(lf, entity_col, schema)
|
|
df_agg = agg_lf.collect()
|
|
store.store_dataset('entity', agg_lf, schema=dict(zip(features, ['']*len(features))),
|
|
metadata={'row_count': len(df_agg), 'csv_glob': csv})
|
|
print(f'6. Aggregation: {len(df_agg)} entities, {len(features)} features:', 'OK')
|
|
|
|
# Cluster
|
|
clust = asyncio.run(handle_call('run_clustering', {
|
|
'dataset_id': 'entity',
|
|
'cluster_columns': [c for c in features if not c.startswith('_')][:8],
|
|
'algorithm': 'hdbscan',
|
|
'params': {'min_cluster_size': 5},
|
|
'random_state': 42,
|
|
}))
|
|
print(f'7. Clustering: {clust.get("n_clusters")} clusters:', 'OK' if 'error' not in clust else f'FAIL: {clust.get("error")}')
|
|
|
|
# Extract features
|
|
cid = clust.get('cluster_result_id', '')
|
|
if cid and 'error' not in clust:
|
|
feats = asyncio.run(handle_call('extract_features', {
|
|
'dataset_id': 'entity',
|
|
'cluster_result_id': cid,
|
|
'top_k': 10, 'method': 'zscore', 'save_to_db': True,
|
|
}))
|
|
print(f'8. Feature extraction: {feats.get("n_features")} features db_saved={feats.get("db_saved")}:', 'OK' if feats.get('db_saved') else 'FAIL')
|
|
|
|
print('\n=== ALL TESTS PASSED UNDER CHINESE PATH ===')
|