import ibeis
ibs = ibeis.opendb(db=db)
ibeis.other.dbinfo.show_image_time_distributions(ibs, ibs.get_valid_gids())

_ = ibeis.other.dbinfo.get_dbinfo(ibs)

"""
Explanation: Database Information
End of explanation
"""


# Get a sample of images
gids = ibs.get_valid_gids()
aids = ibs.get_image_aids(gids)
nAids_list = list(map(len, aids))
gids_sorted = ut.sortedby(gids, nAids_list)[::-1]
samplex = list(range(5))
print(samplex)
gids_sample = ut.list_take(gids_sorted, samplex)

import ibeis.viz
for gid in ut.ProgressIter(gids_sample, lbl='drawing image'):
    ibeis.viz.show_image(ibs, gid)

"""
Explanation: Detection Summary
End of explanation
"""


a = ['unctrl', ctrl]
if db in ['WS_ALL', 'WS_Hard']:
    a = [ctrl]

test_result = ibeis.run_experiment(
    e='rank_cdf', 
    db=db, 
    a=a, 
    t=['baseline'])
#test_result.print_unique_annot_config_stats()
_ = test_result.draw_func()

"""
Explanation: Identification Summary
Identification Accuracy
The uncontrolled
The baseline pipeline configuration is:
End of explanation
"""


test_result = ibeis.run_experiment(
    e='timedelta_hist',
    db=db, 
    a=a,
    t=['baseline'],
    truepos=True)
test_result.draw_func()

"""
Explanation: Distribution of Correct Matches (True Positives) over timedelta categories
End of explanation
"""


# Baseline Timedeltas FP
test_result = ibeis.run_experiment(
    e='timedelta_hist',
    db=db, 
    a=a,
    t=['baseline'],
    falsepos=True)
test_result.draw_func()

"""
Explanation: Distribution of Incorrect Matches (False Positives) over timedelta categories
End of explanation
"""


test_result = ibeis.run_experiment(
    e='rank_cdf',
    db=db, 
    a=['ctrl'], 
    t=['invar4'])
test_result.draw_func()

"""
Explanation: Identification using different pipeline configuration
This test varies the feature invariance used in the identification algorithm
End of explanation
"""


a = a
t = ['best']

"""
Explanation: Score Separability Experiments
These plots show the distribution of identification scores for groundtrue (correct) and groundfalse (incorrect) matches
End of explanation
"""


test_result = ibeis.run_experiment(
    e='scores',
    db=db, 
    a=a, 
    t=t,
    f=[':fail=False,min_gf_timedelta=None'],
)
_ = test_result.draw_func()

"""
Explanation: Scores of Success Cases
End of explanation
"""


# Score Seperability with NO FILTERING
test_result = ibeis.run_experiment(
    e='scores',
    db=db, 
    a=a, 
    t=t,
    f=[':fail=None,min_gf_timedelta=None']
)
_ = test_result.draw_func()

"""
Explanation: Scores of All Cases
End of explanation
"""


t = ['best']
a = a
draw_case_kw = dict(show_in_notebook=True, annot_modes=[0, 1])

"""
Explanation: Individual Results

Higher scores are on the Left
Groundtrue matches have a green border
End of explanation
"""


test_result = ibeis.run_experiment(
    e='draw_cases',
    db=db, 
    a=a, 
    t=t,
    f=[':fail=False,min_gf_timedelta=12h,index=0:3,sortdsc=gtscore,without_gf_tag=Photobomb'],
    **draw_case_kw)
_ = test_result.draw_func()

"""
Explanation: Highest Scoring Success Cases
End of explanation
"""


test_result = ibeis.run_experiment(
    e='draw_cases',
    db=db, 
    a=a, 
    t=t,
    f=[':fail=True,min_gf_timedelta=12h,index=0:3,sortdsc=gtscore'],
    **draw_case_kw)
_ = test_result.draw_func()

"""
Explanation: Failure Cases (sorted by groundtrue score)
End of explanation
"""


test_result = ibeis.run_experiment(
    e='draw_cases',
    db=db, 
    a=a, 
    t=t,
    f=[':fail=True,min_gf_timedelta=12h,index=0:3,sortdsc=gfscore'],
    **draw_case_kw)
_ = test_result.draw_func()

"""
Explanation: Failure Cases (sorted by groundfalse score)
End of explanation
"""


