def _sql(cls, account, cached_at): """Prepare a SQL query from a steemd account.""" vests = vests_amount(account['vesting_shares']) vote_weight = (vests + vests_amount(account['received_vesting_shares']) - vests_amount(account['delegated_vesting_shares'])) proxy_weight = 0 if account['proxy'] else float(vests) for satoshis in account['proxied_vsf_votes']: proxy_weight += float(satoshis) / 1e6 # remove empty keys useless = ['transfer_history', 'market_history', 'post_history', 'vote_history', 'other_history', 'tags_usage', 'guest_bloggers'] for key in useless: del account[key] # pull out valid profile md and delete the key profile = safe_profile_metadata(account) del account['json_metadata'] del account['posting_json_metadata'] active_at = max(account['created'], account['last_account_update'], account['last_post'], account['last_root_post'], account['last_vote_time']) values = { 'name': account['name'], 'created_at': account['created'], 'proxy': account['proxy'], 'post_count': account['post_count'], 'reputation': rep_log10(account['reputation']), 'proxy_weight': proxy_weight, 'vote_weight': vote_weight, 'active_at': active_at, 'cached_at': cached_at, 'display_name': profile['name'], 'about': profile['about'], 'location': profile['location'], 'website': profile['website'], 'profile_image': profile['profile_image'], 'cover_image': profile['cover_image'], 'raw_json': json.dumps(account)} # update rank field, if present _id = cls.get_id(account['name']) if _id in cls._ranks: values['rank'] = cls._ranks[_id] bind = ', '.join([k+" = :"+k for k in list(values.keys())][1:]) return ("UPDATE hive_accounts SET %s WHERE name = :name" % bind, values)
def _generate_cache_sqls(cls, accounts): """Prepare a SQL query from a steemd account.""" cached_at = datetime.now().strftime('%Y-%m-%dT%H:%M:%S') sqls = [] for account in SteemClient.instance().get_accounts(accounts): vote_weight = (vests_amount(account['vesting_shares']) + vests_amount(account['received_vesting_shares']) - vests_amount(account['delegated_vesting_shares'])) # remove empty keys useless = [ 'transfer_history', 'market_history', 'post_history', 'vote_history', 'other_history', 'tags_usage', 'guest_bloggers' ] for key in useless: del account[key] # pull out valid profile md and delete the key profile = safe_profile_metadata(account) del account['json_metadata'] values = { 'name': account['name'], 'proxy': account['proxy'], 'post_count': account['post_count'], 'reputation': rep_log10(account['reputation']), 'proxy_weight': vests_amount(account['vesting_shares']), 'vote_weight': vote_weight, 'kb_used': int(account['lifetime_bandwidth']) / 1e6 / 1024, 'active_at': account['last_bandwidth_update'], 'cached_at': cached_at, 'display_name': profile['name'], 'about': profile['about'], 'location': profile['location'], 'website': profile['website'], 'profile_image': profile['profile_image'], 'cover_image': profile['cover_image'], 'raw_json': json.dumps(account) } update = ', '.join([k + " = :" + k for k in list(values.keys())][1:]) sql = "UPDATE hive_accounts SET %s WHERE name = :name" % (update) sqls.append((sql, values)) return sqls
def _sql(cls, account, cached_at): """Prepare a SQL query from a steemd account.""" vote_weight = (vests_amount(account['vesting_shares']) + vests_amount(account['received_vesting_shares']) - vests_amount(account['delegated_vesting_shares'])) # remove empty keys useless = [ 'transfer_history', 'market_history', 'post_history', 'vote_history', 'other_history', 'tags_usage', 'guest_bloggers' ] for key in useless: del account[key] # pull out valid profile md and delete the key profile = safe_profile_metadata(account) del account['json_metadata'] active_at = max(account['created'], account['last_post'], account['last_vote_time']) values = { 'name': account['name'], 'created_at': account['created'], 'proxy': account['proxy'], 'post_count': account['post_count'], 'reputation': rep_log10(account['reputation']), 'proxy_weight': vests_amount(account['vesting_shares']), 'vote_weight': vote_weight, 'active_at': active_at, 'cached_at': cached_at, 'display_name': profile['name'], 'about': profile['about'], 'location': profile['location'], 'website': profile['website'], 'profile_image': profile['profile_image'], 'cover_image': profile['cover_image'], 'raw_json': json.dumps(account) } bind = ', '.join([k + " = :" + k for k in list(values.keys())][1:]) return ("UPDATE hive_accounts SET %s WHERE name = :name" % bind, values)
def _get_steem_per_mvest(dgpo): steem = steem_amount(dgpo['total_vesting_fund_steem']) mvests = vests_amount(dgpo['total_vesting_shares']) / Decimal(1e6) return "%.6f" % (steem / mvests)
def test_vests_amount(): assert vests_amount('4.549292 VESTS') == Decimal('4.549292')
def _get_dpay_per_mvest(dgpo): dpay = dpay_amount(dgpo['total_vesting_fund_dpay']) mvests = vests_amount(dgpo['total_vesting_shares']) / Decimal(1e6) return "%.6f" % (dpay / mvests)