#Remove the "left" steps from the path and segment the template based on the events point
#TODO: Problem here in the warping (some beats does not include the ending of the template, especially with low levels), check why !!!! With only 10 beats the effect is not visible
# RESULTS: ALL THE TEMPLATES POINTS ARE IN THE LAST POINT OF THE WARP!!
print(f"\tOld templates kept, representative of new clusters (but already present): {new_templates_substituted}/{len(old_templates)}")
print(f"\tOld templates removed for old clusters (with new defined params): {len(old_templates) - (old_templates_kept+old_templates_substituted+new_templates_substituted)}/{len(old_templates)}")
print(f"\tOld templates removed for new clusters: {old_templates_substituted}/{len(old_templates)}")
print(f"\tNew templates kept, representative of old clusters (with new params): {len(lbls_new_templates) - (new_templates_kept+new_templates_substituted)}/{len(lbls_new_templates)}")
print(f"\tNew templates removed for old clusters: {new_templates_substituted}/{len(lbls_new_templates)}")
print(f"\n\tFinal lenght of the new tempalte set: {len(new_template_set)}")
else:
new_template_set=old_templates
print("\tNo new template found, keeping the previously computed ones")
all_templates_collection,prd_id_coupling,initial_templates,time_info,beats_used=reconstruct_beats(data_orig,lvl,init_templates=initial_templates,start_after=SEC_FOR_INITIAL_TEMPLATES,resample_type=interpolation_type,num_beats_analyzed=NUM_BEAT_ANALYZED,verbose=True,log_dir=log_dir_this_lvl)#resample_type = flat vs linear
#TODO: problem here: /!\ level 3- spline does not with many samples, maybe a random beats trigger a condition that breake ecgpwuave (not halting)
# IT IS SOLVED BY TERMINATING (CTRL-C ing) ONCE WE USE THE LEVEL 3 --> arresting ecgpuwave stop only the delineator and everything else works
# TO ANALYZE BY NOT DELETING LEVELS AND TEST FROM TERMINAL --> there are annotations where level 3 fails to have any reconizable peak around the given annotation !