71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
import subprocess, time, os, sys, glob, json
|
|
|
|
PORT = 17766
|
|
PROJ = r"C:\Users\25044\Desktop\Proj\天璇"
|
|
os.chdir(PROJ)
|
|
|
|
# 1. Start server
|
|
print("Starting server...")
|
|
server = subprocess.Popen(
|
|
[r"runtime\python\python.exe", "manage.py", "runserver", f"127.0.0.1:{PORT}", "--noreload"],
|
|
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
|
|
)
|
|
time.sleep(6)
|
|
|
|
import requests
|
|
|
|
# 2. Upload 50 files
|
|
print("Uploading 50 files...")
|
|
csvs = sorted(glob.glob("data/multi_upload/[0-9]*.csv"))[:50]
|
|
files = [("files", (os.path.basename(f), open(f, "rb"), "text/csv")) for f in csvs]
|
|
r = requests.post(f"http://127.0.0.1:{PORT}/upload/csv/", files=files, timeout=300)
|
|
data = r.json()
|
|
run_id = data["run_id"]
|
|
print(f"run_id={run_id}")
|
|
|
|
# 3. Poll until ready
|
|
for _ in range(180):
|
|
r = requests.get(f"http://127.0.0.1:{PORT}/runs/{run_id}/status/", timeout=10)
|
|
s = r.json()
|
|
st = s["status"]
|
|
if st in ("ready", "failed"):
|
|
break
|
|
time.sleep(2)
|
|
print(f"Upload status={st}, flows={s.get('total_flows')}, error={s.get('error_message','')[:300]}")
|
|
|
|
if st == "failed":
|
|
print(f"FAILED: {s.get('error_message','')}")
|
|
server.terminate(); sys.exit(1)
|
|
|
|
# 4. Run clustering
|
|
print("Running clustering...")
|
|
r = requests.post(f"http://127.0.0.1:{PORT}/analyze/run/",
|
|
json={"run_id": run_id, "algorithm": "hdbscan", "min_cluster_size": 5, "cluster_mode": "raw"},
|
|
timeout=30)
|
|
print(f"Cluster started: {r.json()}")
|
|
|
|
# 5. Poll until completed
|
|
for _ in range(120):
|
|
r = requests.get(f"http://127.0.0.1:{PORT}/runs/{run_id}/status/", timeout=10)
|
|
s = r.json()
|
|
st = s["status"]
|
|
if st in ("completed", "failed"):
|
|
break
|
|
time.sleep(5)
|
|
print(f"Cluster status={st}, entity_count={s.get('entity_count')}, cluster_count={s.get('cluster_count')}")
|
|
|
|
# 6. Verify globe
|
|
r = requests.get(f"http://127.0.0.1:{PORT}/globe/?runs={run_id}", timeout=10)
|
|
has_arcs = "arcCount" in r.text
|
|
print(f"Globe arcCount present: {has_arcs}")
|
|
|
|
# 7. Result
|
|
server.terminate()
|
|
server.wait()
|
|
if st == "completed" and s.get("cluster_count", 0) > 0:
|
|
print(f"E2E PASSED: {s['entity_count']} entities, {s['cluster_count']} clusters")
|
|
sys.exit(0)
|
|
else:
|
|
print(f"E2E FAILED")
|
|
sys.exit(1)
|