Regen CSV and summary
This commit is contained in:
parent
4af0648aa8
commit
0bd3c00e31
4 changed files with 92 additions and 4 deletions
67
regen.py
Normal file
67
regen.py
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Quick regen CSV + summary from ledger JSON, then git commit and push."""
|
||||||
|
import json, csv, subprocess
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parent
|
||||||
|
LEDGER = ROOT / 'truck_freight_ledger.json'
|
||||||
|
CSV = ROOT / 'truck_freight_ledger.csv'
|
||||||
|
SUMMARY = ROOT / 'truck_freight_summary.md'
|
||||||
|
|
||||||
|
ledger = json.loads(LEDGER.read_text())
|
||||||
|
records = ledger['records']
|
||||||
|
|
||||||
|
FIELDNAMES = ['id','date','status','vehicle','from','via','to','shipper','load_type','item','deliveries','freight_charged','advance_received','paid_to_driver','commission','driver_freight','pending_from_shipper','pending_to_driver','notes']
|
||||||
|
|
||||||
|
def jl(v):
|
||||||
|
if v is None: return ''
|
||||||
|
if isinstance(v, list): return ' | '.join(str(x) for x in v)
|
||||||
|
return str(v)
|
||||||
|
|
||||||
|
with CSV.open('w', newline='') as f:
|
||||||
|
writer = csv.DictWriter(f, fieldnames=FIELDNAMES)
|
||||||
|
writer.writeheader()
|
||||||
|
for r in records:
|
||||||
|
row = {k: '' for k in FIELDNAMES}
|
||||||
|
for k in ['id','date','status','vehicle','from','to','shipper','load_type','item','freight_charged','advance_received','paid_to_driver','commission','driver_freight','pending_from_shipper','pending_to_driver','notes']:
|
||||||
|
row[k] = r.get(k, '') if r.get(k, '') is not None else ''
|
||||||
|
row['via'] = jl(r.get('via'))
|
||||||
|
row['deliveries'] = jl(r.get('deliveries'))
|
||||||
|
writer.writerow(row)
|
||||||
|
|
||||||
|
def total(key):
|
||||||
|
return sum(r[key] for r in records if isinstance(r.get(key), (int, float)))
|
||||||
|
|
||||||
|
nr = len(records)
|
||||||
|
st = sum(1 for r in records if r.get('status') == 'settled')
|
||||||
|
|
||||||
|
lines = [
|
||||||
|
'# Truck Freight Ledger Summary', '',
|
||||||
|
'Overview',
|
||||||
|
f'- Records: {nr}',
|
||||||
|
f'- Settled loads: {st}',
|
||||||
|
'',
|
||||||
|
'Totals',
|
||||||
|
f'- Freight charged: {total("freight_charged")}',
|
||||||
|
f'- Advance received: {total("advance_received")}',
|
||||||
|
f'- Paid to driver: {total("paid_to_driver")}',
|
||||||
|
f'- Commission: {total("commission")}',
|
||||||
|
f'- Pending from shipper: {total("pending_from_shipper")}',
|
||||||
|
f'- Pending to driver: {total("pending_to_driver")}',
|
||||||
|
'',
|
||||||
|
'Record snapshot',
|
||||||
|
'| Date | Vehicle | Shipper | Route | Freight | Advance | Paid driver | Commission | Pending shipper | Status |',
|
||||||
|
'|---|---|---|---|---:|---:|---:|---:|---:|---|',
|
||||||
|
]
|
||||||
|
for r in sorted(records, key=lambda x: (x.get('date') or '', x.get('vehicle') or '', x.get('id') or '')):
|
||||||
|
route = ' → '.join([p for p in [r.get('from'), r.get('to')] if p])
|
||||||
|
if r.get('via'): route = f"{r.get('from')} via {jl(r.get('via'))} → {r.get('to')}"
|
||||||
|
lines.append(f"| {r.get('date','')} | {r.get('vehicle','') or '-'} | {r.get('shipper','') or '-'} | {route or '-'} | {r.get('freight_charged','') if r.get('freight_charged') is not None else '-'} | {r.get('advance_received','') if r.get('advance_received') is not None else '-'} | {r.get('paid_to_driver','') if r.get('paid_to_driver') is not None else '-'} | {r.get('commission','') if r.get('commission') is not None else '-'} | {r.get('pending_from_shipper','') if r.get('pending_from_shipper') is not None else '-'} | {r.get('status','') or '-'} |")
|
||||||
|
|
||||||
|
SUMMARY.write_text('\n'.join(lines) + '\n')
|
||||||
|
|
||||||
|
# Git commit and push
|
||||||
|
subprocess.run(['git', 'add', '-A'], check=True, cwd=ROOT)
|
||||||
|
subprocess.run(['git', 'commit', '-m', 'Regen CSV and summary'], check=True, cwd=ROOT)
|
||||||
|
subprocess.run(['git', 'push'], check=True, cwd=ROOT)
|
||||||
|
print(f'Done. Total records: {nr}')
|
||||||
|
|
@ -74,6 +74,7 @@ pending-sahara-packers-thiruvananthapuram-palakkad-household,2026-05-20,pending
|
||||||
2026-06-01-vehicle-mh02gh3248-tvpm-parking,2026-06-01,available vehicle,MH02GH3248,Thiruvananthapuram,,,Vehicle available / looking for load,10 ft open,,,,,,,,,,"Vehicle lead: MH02GH3248, 10ft open, in TVPM parking, contact 9284187529. Looking for load."
|
2026-06-01-vehicle-mh02gh3248-tvpm-parking,2026-06-01,available vehicle,MH02GH3248,Thiruvananthapuram,,,Vehicle available / looking for load,10 ft open,,,,,,,,,,"Vehicle lead: MH02GH3248, 10ft open, in TVPM parking, contact 9284187529. Looking for load."
|
||||||
2026-06-01-vehicle-tn30cw9849-tvpm-parking,2026-06-01,available vehicle,TN30CW9849,Thiruvananthapuram,,,Vehicle available / looking for load,9 ft open,,,,,,,,,,"Vehicle lead: TN30CW9849, 9ft open, in TVPM parking, contact 9944266246. Looking for load."
|
2026-06-01-vehicle-tn30cw9849-tvpm-parking,2026-06-01,available vehicle,TN30CW9849,Thiruvananthapuram,,,Vehicle available / looking for load,9 ft open,,,,,,,,,,"Vehicle lead: TN30CW9849, 9ft open, in TVPM parking, contact 9944266246. Looking for load."
|
||||||
2026-06-01-vehicle-tn66am1928-tvpm-parking,2026-06-01,available vehicle,TN66AM1928,Thiruvananthapuram,,,Vehicle available / looking for load,10 ft open,,,,,,,,,,"Vehicle lead: TN66AM1928, 10ft open, in TVPM parking, contact 9600028862. Looking for load."
|
2026-06-01-vehicle-tn66am1928-tvpm-parking,2026-06-01,available vehicle,TN66AM1928,Thiruvananthapuram,,,Vehicle available / looking for load,10 ft open,,,,,,,,,,"Vehicle lead: TN66AM1928, 10ft open, in TVPM parking, contact 9600028862. Looking for load."
|
||||||
|
2026-06-01-ktc-thiruvananthapuram-tirur-tn66am3928,2026-06-01,assigned vehicle,TN66AM3928,Thiruvananthapuram,,Tirur,KTC,,,,7500,,,500,7000,,,"KTC load from Thiruvananthapuram to Tirur. Vehicle TN66AM3928 assigned, contact 9600028862. Freight: 7500. Driver freight: 7000. Expected commission: 500. Vehicle assigned, awaiting loading and payment details."
|
||||||
2026-06-01-mohamed-anas-thiruvananthapuram-madurai-tn77f3427,2026-06-01,assigned vehicle,TN77F3427,Thiruvananthapuram,,Madurai,Mohamed Anas,,,,12000,,,,,,,"Mohamed Anas load from Thiruvananthapuram to Madurai. Vehicle TN77F3427 assigned, contact 9488151108. Freight: 12000. Vehicle assigned, awaiting loading and payment details."
|
2026-06-01-mohamed-anas-thiruvananthapuram-madurai-tn77f3427,2026-06-01,assigned vehicle,TN77F3427,Thiruvananthapuram,,Madurai,Mohamed Anas,,,,12000,,,,,,,"Mohamed Anas load from Thiruvananthapuram to Madurai. Vehicle TN77F3427 assigned, contact 9488151108. Freight: 12000. Vehicle assigned, awaiting loading and payment details."
|
||||||
2026-06-01-vehicle-tn93e6166-tvpm-parking,2026-06-01,available vehicle,TN93E6166,Thiruvananthapuram,,,Vehicle available / looking for load,"24 ft open, 12 ton capacity",,,,,,,,,,"Vehicle lead: TN93E6166, 24ft open, 12 ton capacity, in TVPM parking, contact 8848672650. Looking for load."
|
2026-06-01-vehicle-tn93e6166-tvpm-parking,2026-06-01,available vehicle,TN93E6166,Thiruvananthapuram,,,Vehicle available / looking for load,"24 ft open, 12 ton capacity",,,,,,,,,,"Vehicle lead: TN93E6166, 24ft open, 12 ton capacity, in TVPM parking, contact 8848672650. Looking for load."
|
||||||
2026-06-01-mohamed-anas-thiruvananthapuram-chennai-tn99ac1128,2026-06-01,assigned vehicle,TN99AC1128,Thiruvananthapuram,,Chennai,Mohamed Anas,,,,13000,,,,,,,"Mohamed Anas load from Thiruvananthapuram to Chennai. Vehicle TN99AC1128 assigned, contact 9344685852. Freight: 13000. Vehicle assigned, awaiting loading and payment details."
|
2026-06-01-mohamed-anas-thiruvananthapuram-chennai-tn99ac1128,2026-06-01,assigned vehicle,TN99AC1128,Thiruvananthapuram,,Chennai,Mohamed Anas,,,,13000,,,,,,,"Mohamed Anas load from Thiruvananthapuram to Chennai. Vehicle TN99AC1128 assigned, contact 9344685852. Freight: 13000. Vehicle assigned, awaiting loading and payment details."
|
||||||
|
|
|
||||||
|
|
|
@ -1463,6 +1463,26 @@
|
||||||
"status": "available vehicle",
|
"status": "available vehicle",
|
||||||
"notes": "Vehicle lead: TN66AM1928, 10ft open, in TVPM parking, contact 9600028862. Looking for load."
|
"notes": "Vehicle lead: TN66AM1928, 10ft open, in TVPM parking, contact 9600028862. Looking for load."
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"id": "2026-06-01-ktc-thiruvananthapuram-tirur-tn66am3928",
|
||||||
|
"date": "2026-06-01",
|
||||||
|
"vehicle": "TN66AM3928",
|
||||||
|
"from": "Thiruvananthapuram",
|
||||||
|
"to": "Tirur",
|
||||||
|
"via": null,
|
||||||
|
"shipper": "KTC",
|
||||||
|
"load_type": null,
|
||||||
|
"item": null,
|
||||||
|
"freight_charged": 7500,
|
||||||
|
"advance_received": null,
|
||||||
|
"paid_to_driver": null,
|
||||||
|
"commission": 500,
|
||||||
|
"driver_freight": 7000,
|
||||||
|
"pending_from_shipper": null,
|
||||||
|
"pending_to_driver": null,
|
||||||
|
"status": "assigned vehicle",
|
||||||
|
"notes": "KTC load from Thiruvananthapuram to Tirur. Vehicle TN66AM3928 assigned, contact 9600028862. Freight: 7500. Driver freight: 7000. Expected commission: 500. Vehicle assigned, awaiting loading and payment details."
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": "2026-06-01-mohamed-anas-thiruvananthapuram-madurai-tn77f3427",
|
"id": "2026-06-01-mohamed-anas-thiruvananthapuram-madurai-tn77f3427",
|
||||||
"date": "2026-06-01",
|
"date": "2026-06-01",
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
# Truck Freight Ledger Summary
|
# Truck Freight Ledger Summary
|
||||||
|
|
||||||
Overview
|
Overview
|
||||||
- Records: 78
|
- Records: 79
|
||||||
- Settled loads: 20
|
- Settled loads: 20
|
||||||
- Pending/partial/assigned/commission loads: 24
|
|
||||||
|
|
||||||
Totals
|
Totals
|
||||||
- Freight charged: 1031000
|
- Freight charged: 1038500
|
||||||
- Advance received: 508300
|
- Advance received: 508300
|
||||||
- Paid to driver: 635525
|
- Paid to driver: 635525
|
||||||
- Commission: 41415
|
- Commission: 41915
|
||||||
- Pending from shipper: 23700
|
- Pending from shipper: 23700
|
||||||
- Pending to driver: 5500
|
- Pending to driver: 5500
|
||||||
|
|
||||||
|
|
@ -91,6 +90,7 @@ Record snapshot
|
||||||
| 2026-06-01 | MH02GH3248 | Vehicle available / looking for load | Thiruvananthapuram | - | - | - | - | - | available vehicle |
|
| 2026-06-01 | MH02GH3248 | Vehicle available / looking for load | Thiruvananthapuram | - | - | - | - | - | available vehicle |
|
||||||
| 2026-06-01 | TN30CW9849 | Vehicle available / looking for load | Thiruvananthapuram | - | - | - | - | - | available vehicle |
|
| 2026-06-01 | TN30CW9849 | Vehicle available / looking for load | Thiruvananthapuram | - | - | - | - | - | available vehicle |
|
||||||
| 2026-06-01 | TN66AM1928 | Vehicle available / looking for load | Thiruvananthapuram | - | - | - | - | - | available vehicle |
|
| 2026-06-01 | TN66AM1928 | Vehicle available / looking for load | Thiruvananthapuram | - | - | - | - | - | available vehicle |
|
||||||
|
| 2026-06-01 | TN66AM3928 | KTC | Thiruvananthapuram → Tirur | 7500 | - | - | 500 | - | assigned vehicle |
|
||||||
| 2026-06-01 | TN77F3427 | Mohamed Anas | Thiruvananthapuram → Madurai | 12000 | - | - | - | - | assigned vehicle |
|
| 2026-06-01 | TN77F3427 | Mohamed Anas | Thiruvananthapuram → Madurai | 12000 | - | - | - | - | assigned vehicle |
|
||||||
| 2026-06-01 | TN93E6166 | Vehicle available / looking for load | Thiruvananthapuram | - | - | - | - | - | available vehicle |
|
| 2026-06-01 | TN93E6166 | Vehicle available / looking for load | Thiruvananthapuram | - | - | - | - | - | available vehicle |
|
||||||
| 2026-06-01 | TN99AC1128 | Mohamed Anas | Thiruvananthapuram → Chennai | 13000 | - | - | - | - | assigned vehicle |
|
| 2026-06-01 | TN99AC1128 | Mohamed Anas | Thiruvananthapuram → Chennai | 13000 | - | - | - | - | assigned vehicle |
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue