def calculate_group_scores(messages, user_email):
 now = datetime.datetime.now()
 message_ids_to_scores = {}
 molecules_dict = defaultdict(set)
 def get_message_list_weight(message_ids):
  return sum([message_ids_to_scores[m_id] for m_id in message_ids])
 for msg in messages:
  participants = _get_participants(msg, [user_email])
  if (len(participants) >= MIN_GROUP_SIZE):
   molecules_dict[tuple(participants)].add(msg.id)
   message_ids_to_scores[msg.id] = _get_message_weight(now, msg.date)
 if (len(molecules_dict) > SOCIAL_MOLECULE_LIMIT):
  return {}
 if (len(molecules_dict) < SOCIAL_MOLECULE_EXPANSION_LIMIT):
  _expand_molecule_pool(molecules_dict)
 molecules_list = [(set(emails), set(msgs)) for (emails, msgs) in molecules_dict.iteritems() if (get_message_list_weight(msgs) >= MIN_MESSAGE_COUNT)]
 molecules_list = _subsume_molecules(molecules_list, get_message_list_weight)
 molecules_list = _combine_similar_molecules(molecules_list)
 return {', '.join(sorted(g)): get_message_list_weight(m) for (g, m) in molecules_list}

def calculate_group_scores ( messages , user_email ) : now = datetime . datetime . now ( ) message_ids_to_scores = { } molecules_dict = defaultdict ( set ) def get_message_list_weight ( message_ids ) : return sum ( [ message_ids_to_scores [ m_id ] for m_id in message_ids ] ) for msg in messages : participants = _get_participants ( msg , [ user_email ] ) if ( len ( participants ) >= MIN_GROUP_SIZE ) : molecules_dict [ tuple ( participants ) ] . add ( msg . id ) message_ids_to_scores [ msg . id ] = _get_message_weight ( now , msg . date ) if ( len ( molecules_dict ) > SOCIAL_MOLECULE_LIMIT ) : return { } if ( len ( molecules_dict ) < SOCIAL_MOLECULE_EXPANSION_LIMIT ) : _expand_molecule_pool ( molecules_dict ) molecules_list = [ ( set ( emails ) , set ( msgs ) ) for ( emails , msgs ) in molecules_dict . iteritems ( ) if ( get_message_list_weight ( msgs ) >= MIN_MESSAGE_COUNT ) ] molecules_list = _subsume_molecules ( molecules_list , get_message_list_weight ) molecules_list = _combine_similar_molecules ( molecules_list ) return { ', ' . join ( sorted ( g ) ) : get_message_list_weight ( m ) for ( g , m ) in molecules_list }
this is a implementation of the algorithm described in this paper: URL messages must have the following properties: to_addr - [ .