Create doanh_thu_noi_bo.py
Browse files- routes/doanh_thu_noi_bo.py +42 -0
routes/doanh_thu_noi_bo.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter
|
| 2 |
+
from huggingface_hub import hf_hub_download
|
| 3 |
+
import pandas as pd
|
| 4 |
+
|
| 5 |
+
router = APIRouter()
|
| 6 |
+
|
| 7 |
+
@router.get("/doanh_thu_noi_bo")
|
| 8 |
+
def doanh_thu_noi_bo():
|
| 9 |
+
# Tải file từ dataset
|
| 10 |
+
file_path = hf_hub_download(
|
| 11 |
+
repo_id="doluong6/Quatest1",
|
| 12 |
+
filename="Theo doi DTNB & DT 2025.xlsx",
|
| 13 |
+
repo_type="dataset"
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
df = pd.read_excel(file_path, sheet_name="Nội bộ", header=None)
|
| 17 |
+
|
| 18 |
+
data = []
|
| 19 |
+
tong_chuyen_den = 0
|
| 20 |
+
tong_chuyen_di = 0
|
| 21 |
+
|
| 22 |
+
for row in df.itertuples(index=False):
|
| 23 |
+
phong = str(row[1]).strip() if len(row) > 6 else None # Cột B
|
| 24 |
+
chuyen_den = row[5] if isinstance(row[5], (int, float)) else 0 # Cột F
|
| 25 |
+
chuyen_di = row[6] if isinstance(row[6], (int, float)) else 0 # Cột G
|
| 26 |
+
|
| 27 |
+
if phong and phong != "None" and row[0] >= 4:
|
| 28 |
+
data.append({
|
| 29 |
+
"Phòng": phong,
|
| 30 |
+
"Chuyển đến": chuyen_den,
|
| 31 |
+
"Chuyển đi": chuyen_di
|
| 32 |
+
})
|
| 33 |
+
tong_chuyen_den += chuyen_den
|
| 34 |
+
tong_chuyen_di += chuyen_di
|
| 35 |
+
|
| 36 |
+
return {
|
| 37 |
+
"data": data,
|
| 38 |
+
"tong": {
|
| 39 |
+
"Tổng chuyển đến": tong_chuyen_den,
|
| 40 |
+
"Tổng chuyển đi": tong_chuyen_di
|
| 41 |
+
}
|
| 42 |
+
}
|