Thanks. One question -- If I throw away the retractions, then won't I end up overcounting the amount of filament extruded? Doesn't each retraction need to be balanced by a corresponding move in the positive direction, before we get back to the point where filament will be extruded again?
ETA: Hmm, looking at some gcode, I think I understand what you're saying:
G1 X123.891 Y87.419 E-0.09241
G1 X123.689 Y86.591 E-0.19668
G1 X124.271 Y86.587 E-0.13434
G1 X124.245 Y85.130 E-0.33657
G1 E-0.04000 F2100.00000
G1 Z0.800 F10800.000
G1 X125.647 Y78.831
G1 E0.80000 F2100.00000
Your code is only considering movements that have X or Y, and E. So you're missing that final E0.80000 that undid all of those previous negative E moves. So you have to throw away the negative moves.
Would it work out the same then to count all E moves, including negative ones and ones where X | Y didn't change? Seems a little simpler for my purpose.