Ejemplo n.º 1
0
    def build_desired_rates(ds_name, ds_desc, dv_name, dv_desc, obj):
        if not obj:
            last_bin_end = 0
            bins = dv_desc.bin_count * [{}]
        else:
            pool_rates = obj['pool_rates'][dv_name]
            desired_versions = obj['desired_versions'][dv_name]

            def get_total_pool_rate(t):
                n = int((pool_rates['last_bin_end'] - t) / dv_desc.bin_width)
                if n < 0 or n >= dv_desc.bin_count:
                    return None
                total = sum(x[0] for x in pool_rates['bins'][n].values())
                count = math.mean(x[1] for x in pool_rates['bins'][n].values())
                if count == 0:
                    return None
                return total / count

            last_bin_end = desired_versions['last_bin_end']
            bins = [
                dict((name,
                      (total *
                       get_total_pool_rate(last_bin_end -
                                           (i + 1 / 2) * dv_desc.bin_width),
                       count)) for name, (
                           total,
                           count) in desired_versions['bins'][i].iteritems())
                for i in xrange(dv_desc.bin_count)
            ]
        return graph.DataView(dv_desc, ds_desc, last_bin_end, bins)
Ejemplo n.º 2
0
 def build_pool_rates(ds_name, ds_desc, dv_name, dv_desc, obj):
     if not obj:
         last_bin_end = 0
         bins = dv_desc.bin_count*[{}]
     else:
         pool_rate = obj['pool_rate'][dv_name]
         pool_stale_rate = obj['pool_stale_rate'][dv_name]
         last_bin_end = max(pool_rate['last_bin_end'], pool_stale_rate['last_bin_end'])
         bins = dv_desc.bin_count*[{}]
         def get_value(obj, t):
             n = int((obj['last_bin_end'] - t)/dv_desc.bin_width)
             if n < 0 or n >= dv_desc.bin_count:
                 return None, 0
             total, count = obj['bins'][n].get('null', [0, 0])
             if count == 0:
                 return None, 0
             return total/count, count
         def get_bin(t):
             total, total_count = get_value(pool_rate, t)
             bad, bad_count = get_value(pool_stale_rate, t)
             if total is None or bad is None:
                 return {}
             count = int((total_count+bad_count)/2+1/2)
             return dict(good=[(total-bad)*count, count], bad=[bad*count, count], null=[0, count])
         bins = [get_bin(last_bin_end - (i+1/2)*dv_desc.bin_width) for i in xrange(dv_desc.bin_count)]
     return graph.DataView(dv_desc, ds_desc, last_bin_end, bins)