def users(): list_db = get_list_database() bottom_users = list_db.bottom_users() print "\nLowest-ranked users" print "karma\turl\tdisplay name\tmember since\tlast login" for user in bottom_users: if user.get_karma_score() < 0: print "%d\thttp://www.ned.com/user/%s/\t%s\t%s\t%s" % (user.get_karma_score(), user.get_user_id(), user.display_name(), str(user.member_since()), str(user.last_login))
def update_stats(): """Update the expensive site-wide stats.""" list_db = get_list_database() list_db.group_stats_force_update() transaction_commit(None, 'GroupStatsUpdate') list_db.user_stats_force_update() transaction_commit(None, 'UserStatsUpdate')
print 'userid' + '\t' + 'class' + '\t' + 'member since' + '\t' + '1st discussion post' + '\t' + '1st page edit' + '\t' + '1st page created' + '\t'\ + '1st personal news post' + '\t' + '1st comment post' + '\t' + '1st group created' + '\t' + 'num groups created' + '\t'\ + 'num discussion posts' + '\t' + 'num pages edited' + '\t' + 'num pages created' + '\t' + 'num personal news posts' + '\t'\ + 'num comments posted' + '\t' + 'num groups joined' + '\t' + 'num groups owned' + '\t' + 'page views' + '\t'\ + 'last login' + '\t' + 'last login in 30 days?' + '\t' + 'last login in 60 days?' + '\t' + 'last login in 90 days?' + '\t' + 'feedback' + '\t' + 'feedback bucket' + '\t'\ + 'bank' + '\t' + 'unique discussions commented on' + '\t' + 'unique pages edited' + '\t' + 'friends' + '\t'\ + 'pos fb spent' + '\t' + 'neg fb spent' + '\t' + 'comment fb' + '\t'\ + 'num groups created this month' + '\t' + 'num discussion posts this month' + '\t' + 'num pages edited this month' + '\t'\ + 'num pages created this month' + '\t' + 'num personal news posts this month' + '\t' + 'num comments posted this month' + '\t'\ + 'comments this month bucket' for u in sorted_users: pos, neg = get_list_database().karma_user_content_totals(u) # user class year = str(u.member_since().year) month = u.member_since().month if month < 10: month = "0" + str(month) else: month = str(month) user_class = year + "-" + month # feedback bucket - 2006-10-09 # 0 = 0 # 1 = 1 to 4 # 2 = 5 to 9 # 3 = 10 to 24
def user_data(self, login_bundle, atom_tag, fields): """Return struct containing requested fields for user atom_tag. Parameters: atom_tag: the atom tag of the user for which requesting data fields: array of zero or more of the following: 'name': currently-specified name to be displayed 'fscore': feedback score 'fbank': feedback bank 'fpos': positive feedback received 'fneg': negative feedback received 'fposgiv': positive feedback given 'fneggiv': negative feedback given 'fcom': net comment feedback received 'fcompos': positive comment feedback received 'fcomneg': negative comment feedback received 'membsince': member since date 'lastlogin': last login (may return 'never' or 'inactive') 'idletime': idle time or 'none' if not logged in 'posffrom': positive feedback from (array of user_ids) 'posffromnum': number of positive feedback givers 'negffrom': negative feedback from (if visible) 'neggfromnum': number of negative feedback givers 'emaildomain: domain portion of email 'groupown': groups owned by user 'groupmemb': groups user is a member of 'all': all of the above Returns struct containing one entry per requested field. """ user_db = get_user_database() group_db = get_group_database() cur_user = self._check_login(login_bundle) user = lookup_atom_id(atom_tag) if not user or not isinstance(user, qon.user.User): raise xmlrpclib.Fault(FAULT_INVALID_ITEM, 'Invalid user id') all = 'all' in fields result = {} if all or 'name' in fields: result['name'] = user.display_name() if all or 'fscore' in fields: result['fscore'] = user.get_karma_score() if all or 'fbank' in fields: result['fbank'] = user.get_karma_bank_balance() if all or 'fpos' in fields: result['fpos'] = user.karma_plus_received() if all or 'fneg' in fields: result['fneg'] = user.karma_minus_received() if all or 'fposgiv' in fields: result['fposgiv'] = user.karma_plus_given() if all or 'fneggiv' in fields: result['fneggiv'] = user.karma_minus_given() if all or ('fcom' in fields) or ('fcompos' in fields) or ('fcomneg' in fields): fcompos, fcomneg = get_list_database().karma_user_content_totals(user) if all or 'fcom' in fields: result['fcom'] = fcompos + fcomneg if all or 'fcompos' in fields: result['fcompos'] = fcompos if all or 'fcomneg' in fields: result['fcomneg'] = fcomneg if all or 'membsince' in fields: dt = user.get_user_data().member_since() result['membsince'] = _format_dt(dt) if all or 'lastlogin' in fields: result['lastlogin'] = _format_dt(getattr(user, 'last_login', None)) if all or 'idletime' in fields: if user.is_disabled(): sec = 'inactive' else: idle = user.idle_time() if idle: sec = idle.seconds else: sec = 'none' result['idletime'] = sec if all or 'posffrom' in fields: result['posffrom'] = [atom_id(user_db.get_user(uid)) \ for karma, uid in user.positive_karma_givers()] if all or 'posffromnum' in fields: result['posffromnum'] = len(user.positive_karma_givers()) if all or 'negffrom' in fields: result['negffrom'] = [atom_id(user_db.get_user(uid)) \ for karma, uid in user.negative_karma_givers()] if all or 'negffromnum' in fields: result['negffromnum'] = len(user.negative_karma_givers()) if all or 'emaildomain' in fields: e = user.get_primary_email() result['emaildomain'] = e[e.find('@')+1:] if all or 'groupown' in fields: result['groupown'] = [atom_id(g) \ for g in group_db.owned_groups(user)] if all or 'groupmemb' in fields: result['groupmemb'] = [atom_id(g) \ for g in group_db.member_groups(user)] return result
def publish_stats(): """Call after update_stats to publish to a wiki page.""" _stats_group = 'community-general' _stats_page = 'user_statistics' _stats_author = 'admin' from datetime import datetime from qon.ui.blocks.util import format_datetime_utc_ymd group_db = get_group_database() group = group_db.get_group(_stats_group) if group: wiki = group.get_wiki() try: page = wiki.pages[_stats_page] except KeyError: return # build new text to publish stats # date, num_users, num_groups, num_topics, num_comments, num_pages, num_revisions, # total_bank, total_user_pos, total_user_neg, total_topic_pos, total_topic_pos, # total_comment_pos, total_comment_neg, total_page_pos, total_page_neg # jimc: added: total PMs, group PMs, group PM recipients total increases from 15 to 18 # added total tags, total tagged items for 20 total fields stats_fmt = ['%d' for i in range(20)] # fields stats_fmt = ','.join(stats_fmt) # comma-separated # indent and date is first field stats_fmt = ' %s,' % format_datetime_utc_ymd(datetime.utcnow()) + stats_fmt + '\n' # fill in stats list_db = get_list_database() group_stats = list_db.group_stats(force=True, ignore_out_of_date=False) #group_stats = list_db.group_stats(ignore_out_of_date=True) tidb = get_tagged_item_database() tags_db = get_tags_database() total_items_tagged = len(tidb) total_tags = len(tags_db.tags) stats = stats_fmt % ( group_stats['users'], group_stats['groups'], group_stats['topics'], group_stats['comments'], group_stats['pages'], group_stats['revisions'], list_db.karma_total_bank(), list_db.karma_total_user()[0], list_db.karma_total_user()[1], list_db.karma_total_topic()[0], list_db.karma_total_topic()[1], list_db.karma_total_comment()[0], list_db.karma_total_comment()[1], list_db.karma_total_page()[0], list_db.karma_total_page()[1], # total pms, for groups, and number of group pm recipients list_db.total_users_pms(), group_stats['total_group_pms'], group_stats['total_group_pm_recipients'], total_tags, total_items_tagged, ) # author is admin user author = get_user_database().get_user(_stats_author) # get current revision raw = page.versions[-1].get_raw() # append stats line raw += stats # set new revision - will commit qon.api.wiki_edit_page(wiki, page, page.name, author, page.versions[-1].title, raw)
def update_stats(): get_list_database().karma_stats_force_update() transaction_commit(None, 'KarmaStatsUpdate')
def notify_new_item(self, item): """Notice that I created a new personal news item.""" get_list_database().notify_personal_news_added(item) self.get_activity().add_recent_personal_news(item)
def notify_contact_name_changed(self): get_list_database().notify_user_changed()
def notify_karma_changed(self): get_list_database().notify_user_changed()