<s> """<STR_LIT>""" <EOL> import utilities <EOL> db = current . db <EOL> atable = db . auth_user <EOL> cftable = db . custom_friend <EOL> afields = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> users = db ( atable ) . select ( * afields ) <EOL> registered_users = [ ] <EOL> for user in users : <EOL> registered_users . append ( user ) <EOL> cfields = afields + [ "<STR_LIT>" ] <EOL> custom_users = db ( cftable ) . select ( * cfields ) <EOL> custom_friends = [ ] <EOL> for custom_user in custom_users : <EOL> custom_friends . append ( custom_user ) <EOL> solved_count = { } <EOL> sql = """<STR_LIT>""" <EOL> tmplist = db . executesql ( sql ) <EOL> for user in tmplist : <EOL> solved_count [ user [ <NUM_LIT:0> ] ] = user [ <NUM_LIT:1> ] <EOL> complete_dict = { } <EOL> friends_stopstalk_handles = [ ] <EOL> for x in registered_users : <EOL> friends_stopstalk_handles . append ( "<STR_LIT:'>" + x . stopstalk_handle + "<STR_LIT:'>" ) <EOL> complete_dict [ x . stopstalk_handle ] = [ ] <EOL> for custom_user in custom_users : <EOL> stopstalk_handle = custom_user . stopstalk_handle <EOL> if custom_user . duplicate_cu : <EOL> stopstalk_handle = cftable ( custom_user . duplicate_cu ) . stopstalk_handle <EOL> friends_stopstalk_handles . append ( "<STR_LIT:'>" + stopstalk_handle + "<STR_LIT:'>" ) <EOL> complete_dict [ stopstalk_handle ] = [ ] <EOL> if friends_stopstalk_handles == [ ] : <EOL> friends_stopstalk_handles = [ "<STR_LIT>" ] <EOL> sql_query = """<STR_LIT>""" % ( "<STR_LIT:U+002CU+0020>" . join ( friends_stopstalk_handles ) ) <EOL> user_rows = db . executesql ( sql_query ) <EOL> for user in user_rows : <EOL> if complete_dict [ user [ <NUM_LIT:0> ] ] != [ ] : <EOL> complete_dict [ user [ <NUM_LIT:0> ] ] . append ( ( user [ <NUM_LIT:1> ] , user [ <NUM_LIT:2> ] ) ) <EOL> else : <EOL> complete_dict [ user [ <NUM_LIT:0> ] ] = [ ( user [ <NUM_LIT:1> ] , user [ <NUM_LIT:2> ] ) ] <EOL> users = [ ] <EOL> for user in registered_users : <EOL> try : <EOL> solved = solved_count [ user . stopstalk_handle ] <EOL> except KeyError : <EOL> solved = <NUM_LIT:0> <EOL> tup = utilities . compute_row ( user , complete_dict , solved , update_flag = True ) <EOL> sql = sql . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> tmplist = db . executesql ( sql ) <EOL> for user in tmplist : <EOL> solved_count [ user [ <NUM_LIT:0> ] ] = user [ <NUM_LIT:1> ] <EOL> for user in custom_friends : <EOL> try : <EOL> if user . duplicate_cu : <EOL> orig_user = cftable ( user . duplicate_cu ) <EOL> solved = solved_count [ orig_user . stopstalk_handle ] <EOL> else : <EOL> solved = solved_count [ user . stopstalk_handle ] <EOL> except KeyError : <EOL> solved = <NUM_LIT:0> <EOL> tup = utilities . compute_row ( user , complete_dict , solved , custom = True , update_flag = True ) </s>
