jam.py how to find the last item of a field and compute a running sum?

I am new with JAM.py and I am trying to create a maintenance database for aircraft.

On the form used to enter the data, I am entering the tachymeter time in (tach_in, beginning of the flight), and out (tach_out, end of the flight).

The computation of the flight duration is easy. Some pictures of the current state:

frontend form

variable names

I am struggling with the following:

a) Each time I am creating a new entry using the form, how can I automatically populate the new tach_in as equal to the previous (or last) tack_out? For example:

Flight N-2 tach_in = 100 tach_out = 101
FLight N-1 tach_in = 101 tach_out = 102

Flight N is the flight I am currently entering using the form: I would like to have the new tach_in = 102 (ie: the value of the previous/last tach_out, and I only have to enter the NEW tach_out)

Any idea on how to do that?

b) How can I perform a running sum of the flight time, to show the new total time (flight_total) after each entry?

Flight N-2 tach_in = 100 tach_out = 101 flight_duration = 1 flight_total = 1
FLight N-1 tach_in = 101 tach_out = 102 flight_duration = 1 flight_total = 2
Flight N   tach_in = 102 tach_out = 103 flight_duration = 1 flight_total = 3

Thank you for your help!