Spaces:
Sleeping

doluong6 commited on
Commit
8b8a90b
·
verified ·
1 Parent(s): 2bfa8ac

Update routes/ds_pyc_hoan_thanh.py

Browse files
Files changed (1) hide show
  1. routes/ds_pyc_hoan_thanh.py +30 -21
routes/ds_pyc_hoan_thanh.py CHANGED
@@ -11,31 +11,40 @@ HF_TOKEN = os.environ.get("HF_TOKEN")
11
  @router.get("/dem_pyc_hoan_thanh")
12
  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
- hoan_thanh_paths = set()
17
- thong_ke = defaultdict(list)
18
-
19
- for f in all_files:
20
- if (
21
- f.startswith("Khach_hang/")
22
- and "/Scan/" in f
23
- and "GCN" in os.path.basename(f).upper()
24
- ):
25
- parts = f.split("/")
26
- if len(parts) >= 4:
27
- ten_khach = parts[1]
28
- ten_pyc = parts[2]
29
- thu_muc = f"Khach_hang/{ten_khach}/{ten_pyc}"
30
- hoan_thanh_paths.add(thu_muc)
31
- thong_ke[ten_khach].append(thu_muc)
 
 
 
 
 
 
 
 
 
32
 
33
  return {
34
- "tong_so_hoan_thanh": len(hoan_thanh_paths),
35
  "khach_hang": {
36
  khach: {
37
- "so_hoan_thanh": len(set(paths)), # loại trùng thư mục
38
- "danh_sach": list(set(paths))
39
  }
40
  for khach, paths in thong_ke.items()
41
  }
 
11
  @router.get("/dem_pyc_hoan_thanh")
12
  def dem_pyc_hoan_thanh():
13
  try:
14
+ all_files = list_repo_files(
15
+ repo_id=REPO_ID,
16
+ repo_type="dataset",
17
+ token=HF_TOKEN
18
+ )
19
+
20
+ # Chỉ lấy các file GCN hợp lệ trong thư mục Scan
21
+ gcn_files = [
22
+ f for f in all_files
23
+ if f.startswith("Khach_hang/")
24
+ and "/Scan/" in f
25
+ and "GCN" in os.path.basename(f).upper()
26
+ and f.lower().endswith((".pdf", ".jpg", ".jpeg", ".png"))
27
+ ]
28
+
29
+ # Thống kê theo thư mục PYC
30
+ pyc_dirs = set()
31
+ thong_ke = defaultdict(set)
32
+
33
+ for f in gcn_files:
34
+ parts = f.split("/")
35
+ if len(parts) >= 4:
36
+ ten_khach = parts[1]
37
+ ten_pyc = parts[2]
38
+ thu_muc = f"Khach_hang/{ten_khach}/{ten_pyc}"
39
+ pyc_dirs.add(thu_muc)
40
+ thong_ke[ten_khach].add(thu_muc)
41
 
42
  return {
43
+ "tong_so_hoan_thanh": len(pyc_dirs),
44
  "khach_hang": {
45
  khach: {
46
+ "so_pyc_hoan_thanh": len(paths),
47
+ "danh_sach_pyc": list(paths)
48
  }
49
  for khach, paths in thong_ke.items()
50
  }