def CombinePlaces(places, time_resolution):
 sorted_places = sorted([{'locality': GetPlace(p['placemark']), 'timestamp': p['timestamp'], 'opacity': 1.0, 'num_combined': 1, 'total_count': p['total_count']} for p in places], key=itemgetter('timestamp'))
 place_list = []
 def _GetAvgTimestamp(p):
  return (p['timestamp'] / p['num_combined'])
 def _MaybeCombinePlace(p):
  if place_list:
   last_place = place_list[(-1)]
   if ((p['locality'] == last_place['locality']) and (abs((p['timestamp'] - _GetAvgTimestamp(last_place))) < time_resolution)):
    for attr in ['timestamp', 'total_count', 'num_combined']:
     last_place[attr] += p[attr]
    return
  place_list.append(p)
 for p in sorted_places:
  _MaybeCombinePlace(p)
 for p in place_list:
  p['timestamp'] = _GetAvgTimestamp(p)
 return place_list

def CombinePlaces ( places , time_resolution ) : sorted_places = sorted ( [ { 'locality' : GetPlace ( p [ 'placemark' ] ) , 'timestamp' : p [ 'timestamp' ] , 'opacity' : 1.0 , 'num_combined' : 1 , 'total_count' : p [ 'total_count' ] } for p in places ] , key = itemgetter ( 'timestamp' ) ) place_list = [ ] def _GetAvgTimestamp ( p ) : return ( p [ 'timestamp' ] / p [ 'num_combined' ] ) def _MaybeCombinePlace ( p ) : if place_list : last_place = place_list [ ( - 1 ) ] if ( ( p [ 'locality' ] == last_place [ 'locality' ] ) and ( abs ( ( p [ 'timestamp' ] - _GetAvgTimestamp ( last_place ) ) ) < time_resolution ) ) : for attr in [ 'timestamp' , 'total_count' , 'num_combined' ] : last_place [ attr ] += p [ attr ] return place_list . append ( p ) for p in sorted_places : _MaybeCombinePlace ( p ) for p in place_list : p [ 'timestamp' ] = _GetAvgTimestamp ( p ) return place_list
try to combine consecutive viewpoints into a meta-viewpoints by locality .