lib/pipeline/base.rb in tracksperanto-1.9.2 vs lib/pipeline/base.rb in tracksperanto-1.9.3

- old
+ new

@@ -66,11 +66,12 @@ endpoint = wrap_output_with_middlewares(mux) @converted_points, @converted_keyframes = run_export(read_data, importer, endpoint) end def report_progress(percent_complete, message) - @progress_block.call(percent_complete, message) if @progress_block + int_pct = percent_complete.to_f.floor # Prevent float overflow above 100 percent + @progress_block.call(int_pct, message) if @progress_block end def initialize_importer_with_path_and_options(from_input_file_path, options) d = Tracksperanto::FormatDetector.new(from_input_file_path) @@ -96,16 +97,16 @@ # Runs the export and returns the number of points and keyframes processed. # If a block is passed, the block will receive the percent complete and the last # status message that you can pass back to the UI def run_export(tracker_data_io, importer, exporter) points, keyframes, percent_complete = 0, 0, 0.0 - + report_progress(percent_complete, "Starting the parser") - + # Report progress from the parser importer.progress_block = lambda { | m | report_progress(percent_complete, m) } - + # Wrap the input in a progressive IO, setup a lambda that will spy on the reader and # update the percentage. We will only broadcast messages that come from the parser # though (complementing it with a percentage) io_with_progress = Tracksperanto::ProgressiveIO.new(tracker_data_io) do | offset, of_total | percent_complete = (50.0 / of_total) * offset @@ -133,12 +134,12 @@ report_progress(percent_complete += kf_weight, "Writing keyframe #{idx+1} of #{t.name.inspect}, #{trackers.length - tracker_idx} trackers to go") end exporter.end_tracker_segment end exporter.end_export - + report_progress(100.0, "Wrote #{points} points and #{keyframes} keyframes") - + [points, keyframes] ensure @ios.reject!{|e| e.close unless (!e.respond_to?(:closed?) || e.closed?) } if @ios end \ No newline at end of file