def _ioam(p1, p2):
    """Computes intersection of two intervals over the armonic mean of their lengths.
    
    This is a better metric for peak matching than classic intersection over
    union: it still ranges from 0 to 1 but keeps higher values if one interval
    is much shorter than the other, specifically it cannot be lower than
    I/(2*min(L1,L2)).
    
    Args:
        p1 ((int,int)): First interval as (first ts, last ts)
        p2 ((int,int)): Second interval as (first ts, last ts)
        
    Returns:
        float: interval intersection over armonic mean of intervals' lengths.
    """
    i_start = max(p1[0],p2[0])
    i_end = min(p1[1],p2[1])
    i_len = max(0,i_end-i_start)
    l1 = p1[1]-p1[0]
    l2 = p2[1]-p2[0]
    am = 2*l1*l2/(l1+l2)
    return float(i_len)/am