Spaces:
Sleeping

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

Update routes/ds_pyc_hoan_thanh.py

Browse files
Files changed (1) hide show
  1. 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, hf_hub_download
5
- from openpyxl import load_workbook
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("/ds_pyc_hoan_thanh")
15
- def ds_pyc_hoan_thanh():
16
- all_files = list_repo_files(repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN)
17
-
18
- pyc_files = [
19
- f for f in all_files
20
- if f.startswith("Khach_hang/")
21
- and "/Phieu_yeu_cau/" in f
22
- and f.endswith(".xlsx")
23
- ]
24
-
25
- ds = []
26
- for file in pyc_files:
27
- try:
28
- local = hf_hub_download(repo_id=REPO_ID, repo_type="dataset", token=HF_TOKEN, filename=file, cache_dir="/tmp")
29
- wb = load_workbook(local, data_only=True)
30
- sheet = wb.active
31
-
32
- ma = sheet["BS3"].value
33
- thiet_bi = sheet["D24"].value
34
- ngay_ht = sheet["I19"].value
35
-
36
- if isinstance(ngay_ht, datetime):
37
- ngay = ngay_ht.strftime("%Y-%m-%d")
38
- else:
39
- ngay = str(ngay_ht)
40
-
41
- ds.append({
42
- "ma": ma or "Không rõ",
43
- "thiet_bi": thiet_bi or "Không rõ",
44
- "ngay_ht": ngay
45
- })
46
-
47
- except Exception as e:
48
- print(f"Lỗi đọc {file}: {e}")
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)}