Spaces:
Sleeping

doluong6 commited on
Commit
3cc5e69
·
verified ·
1 Parent(s): 3d9744f

Update routes/dem_pyc_hoan_thanh.py

Browse files
Files changed (1) hide show
  1. routes/dem_pyc_hoan_thanh.py +13 -23
routes/dem_pyc_hoan_thanh.py CHANGED
@@ -1,40 +1,30 @@
1
- from fastapi import APIRouter
2
- from huggingface_hub import list_repo_files
3
- from collections import defaultdict
4
- import os
5
-
6
- router = APIRouter()
7
-
8
- REPO_ID = "doluong6/Quatest1"
9
- HF_TOKEN = os.environ.get("HF_TOKEN")
10
-
11
- @router.get("/dem_pyc_hoan_thanh")
12
- async def dem_pyc_hoan_thanh():
13
  try:
14
  all_files = list_repo_files(repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN)
15
 
16
- # Tìm tất cả file trong thư mục Scan
17
- scan_files = [
18
  f for f in all_files
19
- if f.startswith("Khach_hang/") and "/Scan/" in f
 
 
20
  ]
21
 
22
- hoan_thanh_theo_khach = defaultdict(list)
23
-
24
- for f in scan_files:
25
  parts = f.split("/")
26
  if len(parts) >= 3:
27
  ten_khach = parts[1]
28
- hoan_thanh_theo_khach[ten_khach].append(f)
29
 
30
  return {
31
- "tong_so_hoan_thanh": len(scan_files),
32
  "khach_hang": {
33
  khach: {
34
- "so_pyc_hoan_thanh": len(files),
35
- "danh_sach_file": files
36
  }
37
- for khach, files in hoan_thanh_theo_khach.items()
38
  }
39
  }
40
 
 
1
+ @app.get("/dem_pyc_hoan_thanh")
2
+ def dem_pyc_hoan_thanh():
 
 
 
 
 
 
 
 
 
 
3
  try:
4
  all_files = list_repo_files(repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN)
5
 
6
+ hoan_thanh_files = [
 
7
  f for f in all_files
8
+ if f.startswith("Khach_hang/")
9
+ and "/Scan/" in f
10
+ and "GCN" in f.upper() # ✅ chỉ tính file chứa "GCN" (không phân biệt hoa/thường)
11
  ]
12
 
13
+ thong_ke = defaultdict(list)
14
+ for f in hoan_thanh_files:
 
15
  parts = f.split("/")
16
  if len(parts) >= 3:
17
  ten_khach = parts[1]
18
+ thong_ke[ten_khach].append(f)
19
 
20
  return {
21
+ "tong_so_hoan_thanh": len(hoan_thanh_files),
22
  "khach_hang": {
23
  khach: {
24
+ "so_hoan_thanh": len(files),
25
+ "danh_sach": files
26
  }
27
+ for khach, files in thong_ke.items()
28
  }
29
  }
30