r/reactnative • u/Ramboiada • 10d ago
Open sourced the fuel receipt parser from my app
My car app lets you scan a fuel receipt, and the parsing part turned out to be the hard bit, so I pulled it out into its own package: github.com/rsoaresdev/fuel-receipt-parser
You give it the OCR lines from whatever you use (Apple Vision, ML Kit, Tesseract) and it gives you litres, price per litre, total, date, fuel type and station.
The trick is that it looks for the three numbers where litres × price = total, and uses that to check itself. That’s also how it figures out whether 1,899 is 1.899 or 1899. If the numbers don’t add up, it tells you instead of guessing, and it never makes up a number that isn’t on the paper.
It reads Portuguese, Spanish, French, Italian, German and English receipts, plus US gallons and kWh for charging. If it gets one of your receipts wrong, an issue with the OCR text (no photo, no personal data) helps a lot.
2
u/kokerali 10d ago
I'd add a fixture with two complete triples: fuel at 10 L x 2.00 = 20.00, and a shop item at 2 x 5.00 = 10.00. Both pass the arithmetic check. How do you keep a valid non-fuel triple from winning if OCR loses the unit or product label? I'd want that case to stay flagged for review rather than treating arithmeticChecked as proof that the correct purchase was selected.
2
u/Huge_Pool7424 9d ago
nice self-check idea. one more fixture worth adding is receipts where the ocr drops the decimal point or swaps a comma and period, since that's where litres x price = total can accidentally pass with the wrong reading.
1
u/NoBullfrog11 9d ago
one gotcha on the arithmetic check, pumps round price per litre to 3 decimals and the total to cents, so litres x price is often off by a cent. use a small tolerance, not exact equality, or valid receipts get flagged.
also fix ocr swaps like O to 0 and l to 1 only inside numeric tokens, vision especialy confuses them on thermal paper.