def _generate_cache_sqls(cls, accounts, block_date=None): if not block_date: block_date = get_adapter().head_time() sqls = [] for account in get_adapter().get_accounts(accounts): values = { 'name': account['name'], 'proxy': account['proxy'], 'post_count': account['post_count'], 'reputation': rep_log10(account['reputation']), 'proxy_weight': amount(account['vesting_shares']), 'vote_weight': amount(account['vesting_shares']) + amount(account['received_vesting_shares']) - amount(account['delegated_vesting_shares']), 'kb_used': int(account['lifetime_bandwidth']) / 1e6 / 1024, 'active_at': account['last_bandwidth_update'], 'cached_at': block_date, **cls._safe_account_metadata(account) } update = ', '.join([k + " = :" + k for k in values.keys()][1:]) sql = "UPDATE hive_accounts SET %s WHERE name = :name" % (update) sqls.append([(sql, values)]) return sqls
def get_post_stats(cls,post): net_rshares_adj = 0 neg_rshares = 0 total_votes = 0 up_votes = 0 for vote in post['active_votes']: if vote['percent'] == 0: continue total_votes += 1 rshares = int(vote['rshares']) sign = 1 if vote['percent'] > 0 else -1 if sign > 0: up_votes += 1 if sign < 0: neg_rshares += rshares # For graying: sum rshares, but ignore neg rep users and dust downvotes neg_rep = str(vote['reputation'])[0] == '-' if not (neg_rep and sign < 0 and len(str(rshares)) < 11): net_rshares_adj += rshares # take negative rshares, divide by 2, truncate 10 digits (plus neg sign), # and count digits. creates a cheap log10, stake-based flag weight. # result: 1 = approx $400 of downvoting stake; 2 = $4,000; etc flag_weight = max((len(str(neg_rshares / 2)) - 11, 0)) allow_delete = post['children'] == 0 and int(post['net_rshares']) <= 0 has_pending_payout = amount(post['pending_payout_value']) >= 0.02 author_rep = rep_log10(post['author_reputation']) gray_threshold = -9999999999 low_value_post = net_rshares_adj < gray_threshold and author_rep < 65 gray = not has_pending_payout and (author_rep < 1 or low_value_post) hide = not has_pending_payout and (author_rep < 0) return { 'hide': hide, 'gray': gray, 'allow_delete': allow_delete, 'author_rep': author_rep, 'flag_weight': flag_weight, 'total_votes': total_votes, 'up_votes': up_votes }
def vote_csv_row(vote): return ','.join((vote['voter'], str(vote['rshares']), str(vote['percent']), str(rep_log10(vote['reputation']))))