Update routes/ds_pyc_hoan_thanh.py
Browse files- 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(
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
return {
|
| 34 |
-
"tong_so_hoan_thanh": len(
|
| 35 |
"khach_hang": {
|
| 36 |
khach: {
|
| 37 |
-
"
|
| 38 |
-
"
|
| 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 |
}
|