Update routes/ds_pyc_hoan_thanh.py
Browse files- routes/ds_pyc_hoan_thanh.py +37 -42
routes/ds_pyc_hoan_thanh.py
CHANGED
|
@@ -1,9 +1,6 @@
|
|
| 1 |
-
|
| 2 |
-
# routes/ds_pyc_hoan_thanh.py
|
| 3 |
from fastapi import APIRouter
|
| 4 |
-
from huggingface_hub import list_repo_files
|
| 5 |
-
from
|
| 6 |
-
from datetime import datetime
|
| 7 |
import os
|
| 8 |
|
| 9 |
router = APIRouter()
|
|
@@ -11,40 +8,38 @@ router = APIRouter()
|
|
| 11 |
REPO_ID = "doluong6/Quatest1"
|
| 12 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 13 |
|
| 14 |
-
@router.get("/
|
| 15 |
-
def
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
return ds
|
|
|
|
|
|
|
|
|
|
| 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()
|
|
|
|
| 8 |
REPO_ID = "doluong6/Quatest1"
|
| 9 |
HF_TOKEN = os.environ.get("HF_TOKEN")
|
| 10 |
|
| 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 |
+
}
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
except Exception as e:
|
| 45 |
+
return {"error": str(e)}
|
|
|
|
|
|