66 lines
3 KiB
Python
66 lines
3 KiB
Python
import importlib.util, json, re
|
||
from collections import defaultdict
|
||
|
||
spec = importlib.util.spec_from_file_location("ss", "/app/sync_server.py")
|
||
m = importlib.util.module_from_spec(spec)
|
||
spec.loader.exec_module(m)
|
||
|
||
# Read ghazal-contetnt FULL width (A1:R2000), get K/L/M columns
|
||
rows = []
|
||
for start in range(1, 2200, 100):
|
||
d = m.composio_execute("GOOGLESHEETS_VALUES_GET", {"spreadsheet_id": m.SHEET_ID, "range": f"'ghazal-contetnt'!A{start}:R{start+99}"})
|
||
v = d.get("values", [])
|
||
if not v: break
|
||
rows.extend(v)
|
||
if len(v) < 100: break
|
||
|
||
def parse_time(x):
|
||
if x is None: return 0.0
|
||
s = str(x).strip().replace(",", ".")
|
||
if not s: return 0.0
|
||
if ":" in s:
|
||
parts = s.split(":")
|
||
try:
|
||
if len(parts) == 2: return float(parts[0]) + float(parts[1])/60
|
||
if len(parts) == 3: return float(parts[0]) + float(parts[1])/60 + float(parts[2])/3600
|
||
except Exception: return 0.0
|
||
tr = {"۰":"0","۱":"1","۲":"2","۳":"3","۴":"4","۵":"5","۶":"6","۷":"7","۸":"8","۹":"9"}
|
||
try: return float("".join(tr.get(c,c) for c in s))
|
||
except Exception: return 0.0
|
||
|
||
clock_rows = []
|
||
for i, r in enumerate(rows):
|
||
if len(r) < 10: continue
|
||
task = str(r[1]).strip()
|
||
if not task or task.startswith("Task"): continue
|
||
cin = str(r[10]).strip() if len(r) > 10 else ""
|
||
cout = str(r[11]).strip() if len(r) > 11 else ""
|
||
wh = parse_time(r[12]) if len(r) > 12 else 0.0
|
||
act = parse_time(r[5]) if len(r) > 5 else 0.0
|
||
date_s = str(r[3]).strip() if len(r) > 3 else ""
|
||
status = str(r[6]).strip() if len(r) > 6 else ""
|
||
if cin or cout or wh or act:
|
||
clock_rows.append({"task": task[:40], "cin": cin, "cout": cout, "wh": wh, "act": act, "date": date_s, "status": status})
|
||
|
||
print("ghazal rows:", len(rows), "| with clock/act:", len(clock_rows))
|
||
for cr in clock_rows[:20]:
|
||
print(" ", cr["task"], "| in:", cr["cin"], "| out:", cr["cout"], "| wh:", cr["wh"], "| act:", cr["act"], "| date:", cr["date"], "| st:", cr["status"])
|
||
|
||
# aggregate workdays via clock-in pairs
|
||
pairs = defaultdict(list)
|
||
for cr in clock_rows:
|
||
if cr["cin"] and cr["cout"]:
|
||
pairs[(cr["cin"], cr["cout"])].append(cr)
|
||
print("\ndistinct clock pairs (workdays):", len(pairs))
|
||
tot_wh = sum(max(cr["wh"] for cr in v) if any(cr["wh"]>0 for cr in v) else 0 for v in pairs.values())
|
||
print("sum work_hours:", round(tot_wh, 1))
|
||
# fallback: rows with act only
|
||
act_rows = [cr for cr in clock_rows if cr["act"] > 0]
|
||
print("act rows:", len(act_rows), "sum act:", round(sum(cr["act"] for cr in act_rows), 1))
|
||
# rows with wh value
|
||
wh_rows = [cr for cr in clock_rows if cr["wh"] > 0]
|
||
print("wh rows:", len(wh_rows), "sum wh:", round(sum(cr["wh"] for cr in wh_rows), 1), "avg/row:", round(sum(cr["wh"] for cr in wh_rows)/max(len(wh_rows),1), 2))
|
||
print(">=8h:", sum(1 for cr in wh_rows if cr["wh"] >= 8), "<8h:", sum(1 for cr in wh_rows if 0 < cr["wh"] < 8))
|
||
# check dates on clock rows
|
||
dated = [cr for cr in clock_rows if "/" in cr["date"]]
|
||
print("clock rows with real date:", len(dated))
|