def disaggregate(statistic, data):
 new_statistic = {}
 for (loc, details) in data.items():
  new_statistic[loc] = {}
  prev_value = 0
  for key in sorted(details.keys()):
   new_value = details[key][0]
   if (prev_value != new_value):
    if (new_value is None):
     if prev_value:
      rejected_data[loc] = [key, 'None value', statistic, new_value, prev_value]
      continue
     else:
      new_value = 0
    if ((new_value < prev_value) and (statistic not in ('Suspected cases', 'Probable cases'))):
     suspect_data[loc] = [key, 'Value went down', statistic, new_value, prev_value]
    details[key][0] = (new_value - prev_value)
    prev_value = new_value
    new_statistic[loc][key] = details[key]
 return new_statistic

def disaggregate ( statistic , data ) : new_statistic = { } for ( loc , details ) in data . items ( ) : new_statistic [ loc ] = { } prev_value = 0 for key in sorted ( details . keys ( ) ) : new_value = details [ key ] [ 0 ] if ( prev_value != new_value ) : if ( new_value is None ) : if prev_value : rejected_data [ loc ] = [ key , 'None value' , statistic , new_value , prev_value ] continue else : new_value = 0 if ( ( new_value < prev_value ) and ( statistic not in ( 'Suspected cases' , 'Probable cases' ) ) ) : suspect_data [ loc ] = [ key , 'Value went down' , statistic , new_value , prev_value ] details [ key ] [ 0 ] = ( new_value - prev_value ) prev_value = new_value new_statistic [ loc ] [ key ] = details [ key ] return new_statistic
dis-aggregate the running total for each statistic .