@@ -756,49 +756,56 @@ def find_profiles(current_config, profiles):
756756 detected_profiles = []
757757 for profile_name , profile in profiles .items ():
758758 config = profile ["config" ]
759- matches = True
760- for name , output in config .items ():
761-
762- missing_output_names = []
763- fingerprint_mismatch = []
764- closeness_scores = []
765- profile_output_names = config .keys ()
759+ on = set ()
760+ missing_fingerprint = set ()
761+ missing_output_names = set ()
762+ fingerprint_mismatch = set ()
763+ closeness_scores = set ()
764+ profile_output_names = set (config .keys ())
766765
767766 for name in profile_output_names :
768767 output = config [name ]
769768
770769 if not output .fingerprint :
770+ missing_fingerprint .add (name )
771+ continue
772+ elif name not in current_config :
773+ missing_output_names .add (name )
771774 continue
772-
773- if name not in current_config :
774- missing_output_names .append (name )
775-
776775 elif not output .fingerprint_equals (current_config [name ]):
777- fingerprint_mismatch .append (name )
776+ fingerprint_mismatch .add (name )
777+ continue
778+ elif "off" in output .options :
779+ continue
778780
779- closeness = max (match_asterisk (output .edid , current_config [name ].edid ), match_asterisk (
780- current_config [name ].edid , output .edid ))
781+ on .add (name )
781782
782- closeness_scores .append (closeness )
783+ current_edid = current_config [name ].edid
784+ if output .edid is not None and current_edid is not None :
785+ closeness_scores .add (max (match_asterisk (output .edid , current_edid ), match_asterisk (current_edid , output .edid )))
786+ else :
787+ print (f'no edid match for output { name } in profile { profile_name } ; current={ current_edid } , output={ output .edid } ' )
788+ closeness_scores .append (0 )
783789
784790 if len (fingerprint_mismatch ) > 0 :
791+ print (f'have { len (fingerprint_mismatch )} ({ ", " .join (fingerprint_mismatch )} ) mismatching fingerprint(s) for profile { profile_name } ; omitting it.' )
785792 continue
786793 elif len (missing_output_names ) > 0 :
794+ print (f'have { len (missing_output_names )} missing output(s) ({ ", " .join (missing_output_names )} ) for profile { profile_name } ; omitting it.' )
787795 continue
788796
789797 current_output_names = [name for name in current_config .keys () if current_config [name ].fingerprint ]
790- possible_output_names = [name for name in current_output_names if name in profile_output_names ]
798+ possible_output_names = [name for name in current_output_names if name in on ]
791799
792800 percent_present_in_profile = len (possible_output_names ) / len (current_output_names )
793- percent_present_in_current_config = len (profile_output_names ) / len (possible_output_names )
801+ percent_present_in_current_config = len (on ) / len (possible_output_names )
794802
795- closeness = 1
796- for closeness_score in closeness_scores :
797- closeness *= closeness_score
803+ closeness = sum (closeness_scores ) / len (closeness_scores )
798804
799805 score = percent_present_in_profile * percent_present_in_current_config * closeness
800806
801807 detected_profiles .append ((score , profile_name ))
808+
802809 detected_profiles = [o [1 ] for o in sorted (detected_profiles , key = lambda x : - x [0 ])]
803810 return detected_profiles
804811
0 commit comments