@@ -175,14 +175,18 @@ function import_funscript_generator_json_result()
175175 if name and name == scriptNames [v .idx ] then
176176 if actions [k ] then
177177 script = ofs .Script (i )
178- delete_range (script , actions [k ][1 ][" at" ] / 1000.0 , actions [k ][# (actions [k ])][" at" ] / 1000.0 )
179- for _ , action in pairs (actions [k ]) do
180- local closest_action , _ = script :closestAction (action [" at" ])
181- local new_action = Action .new (action [" at" ]/ 1000.0 , action [" pos" ], true )
182- if filterSimilarTimestamps and closest_action and math.abs (closest_action .at - new_action .at ) <= frame_time then
183- filtered = filtered + 1
184- else
185- script .actions :add (new_action )
178+ if # (actions [k ]) < 2 then
179+ print (" not enough data available" )
180+ else
181+ delete_range (script , actions [k ][1 ][" at" ] / 1000.0 , actions [k ][# (actions [k ])][" at" ] / 1000.0 )
182+ for _ , action in pairs (actions [k ]) do
183+ local closest_action , _ = script :closestAction (action [" at" ])
184+ local new_action = Action .new (action [" at" ]/ 1000.0 , action [" pos" ], true )
185+ if filterSimilarTimestamps and closest_action and math.abs (closest_action .at - new_action .at ) <= frame_time then
186+ filtered = filtered + 1
187+ else
188+ script .actions :add (new_action )
189+ end
186190 end
187191 end
188192 script :commit ()
@@ -195,14 +199,18 @@ function import_funscript_generator_json_result()
195199 script = ofs .Script (scriptIdx )
196200 for metric , actions_metric in pairs (actions ) do
197201 print (' add ' , metric , ' to ' , ofs .ScriptName (scriptIdx ))
198- delete_range (script , actions_metric [1 ][" at" ] / 1000.0 , actions_metric [# actions_metric ][" at" ] / 1000.0 )
199- for _ , action in pairs (actions_metric ) do
200- local closest_action , _ = script :closestAction (action [" at" ]/ 1000.0 )
201- local new_action = Action .new (action [" at" ]/ 1000.0 , action [" pos" ], true )
202- if filterSimilarTimestamps and closest_action and math.abs (closest_action .at - new_action .at ) <= frame_time then
203- filtered = filtered + 1
204- else
205- script .actions :add (new_action )
202+ if # actions_metric < 2 then
203+ print (" not enough data available" )
204+ else
205+ delete_range (script , actions_metric [1 ][" at" ] / 1000.0 , actions_metric [# actions_metric ][" at" ] / 1000.0 )
206+ for _ , action in pairs (actions_metric ) do
207+ local closest_action , _ = script :closestAction (action [" at" ]/ 1000.0 )
208+ local new_action = Action .new (action [" at" ]/ 1000.0 , action [" pos" ], true )
209+ if filterSimilarTimestamps and closest_action and math.abs (closest_action .at - new_action .at ) <= frame_time then
210+ filtered = filtered + 1
211+ else
212+ script .actions :add (new_action )
213+ end
206214 end
207215 end
208216 end
0 commit comments