Spaces:
Running
Running
Andre
deploy: snapshot c96b9ab -- Inventory Journals (Lagerforandringsjournal) na Contabilidade (v1.3.61)
77db408 Download backend/scripts/verify_lines_sum.py from inwave-gateway/hub: direct link, hf CLI and curl.
- Browser
- Download file 1.85 kB
-
https://huggingface.co/spaces/inwave-gateway/hub/resolve/main/backend/scripts/verify_lines_sum.py
- Command line
-
hf download hf://spaces/inwave-gateway/hub/backend/scripts/verify_lines_sum.py
-
curl -L -o verify_lines_sum.py https://huggingface.co/spaces/inwave-gateway/hub/resolve/main/backend/scripts/verify_lines_sum.py
1.85 kB
| import csv | |
| import io | |
| import sys | |
| import os | |
| # Force UTF-8 for stdout | |
| if sys.stdout.encoding != 'utf-8': | |
| sys.stdout.reconfigure(encoding='utf-8') | |
| def verify_lines(filepath): | |
| if not os.path.exists(filepath): | |
| print(f"File {filepath} not found.") | |
| return | |
| total_rev = 0.0 | |
| count_2024 = 0 | |
| total_rows = 0 | |
| with open(filepath, 'rb') as f: | |
| content = f.read().decode('utf-8-sig') | |
| reader = csv.DictReader(io.StringIO(content), delimiter=';') | |
| for row in reader: | |
| total_rows += 1 | |
| date = row.get('Invoice_Date', '') | |
| if date >= '2024-01-01': | |
| count_2024 += 1 | |
| # Robust price parsing from our _safe_float logic | |
| raw_val = row.get('Revenue_SEK_Final', '0') | |
| s = raw_val.replace("\xa0", "").strip() | |
| if not s: continue | |
| # Normalize decimal separator | |
| if "," in s: | |
| if "." not in s or s.rfind(",") > s.rfind("."): | |
| s = s.replace(".", "").replace(" ", "").replace(",", ".") | |
| else: | |
| s = s.replace(",", "").replace(" ", "") | |
| else: | |
| if s.count(".") > 1: | |
| s = s.replace(".", "").replace(" ", "") | |
| else: | |
| s = s.replace(" ", "") | |
| try: | |
| total_rev += float(s) | |
| except: | |
| pass | |
| print(f"File: {filepath}") | |
| print(f"Total Rows in CSV: {total_rows}") | |
| print(f"Rows with Date >= 2024-01-01: {count_2024}") | |
| print(f"Sum of Revenue_SEK_Final (2024+): {total_rev:,.2f}") | |
| if __name__ == "__main__": | |
| verify_lines("assets/fact_invoice_lines.csv") | |