If a beatgrid contains skips forward or backwards (i. e. for notated repeats like above), the "length_in_measures" attribute in the JSON ends up having incorrect values: In the example, it would consider the yellow theme to end at measure 1, where the subtraction of start from end gives it a metrical length of 0 and the last orange unit one of -8.
The safer option would be to count the measures/beats that exist within the timespan, which would work as long as the beatgrid is complete.