def get_validator_daily_stats( self, validator_index: int, from_ts: Optional[Timestamp] = None, to_ts: Optional[Timestamp] = None, ) -> List[ValidatorDailyStats]: """Gets all DB entries for daily staking stats of a validator""" cursor = self.db.conn.cursor() querystr = ('SELECT validator_index,' ' timestamp,' ' start_usd_price,' ' end_usd_price,' ' pnl,' ' start_amount,' ' end_amount,' ' missed_attestations,' ' orphaned_attestations,' ' proposed_blocks,' ' missed_blocks,' ' orphaned_blocks,' ' included_attester_slashings,' ' proposer_attester_slashings,' ' deposits_number,' ' amount_deposited ' ' FROM eth2_daily_staking_details ' ' WHERE validator_index = ? ') querystr, bindings = form_query_to_filter_timestamps( query=querystr, timestamp_attribute='timestamp', from_ts=from_ts, to_ts=to_ts, ) results = cursor.execute(querystr, (validator_index, *bindings)) return [ValidatorDailyStats.deserialize_from_db(x) for x in results]
def get_validator_daily_stats( self, filter_query: Eth2DailyStatsFilterQuery, ) -> List[ValidatorDailyStats]: """Gets all DB entries for validator daily stats according to the given filter""" cursor = self.db.conn.cursor() query, bindings = filter_query.prepare() query = 'SELECT * from eth2_daily_staking_details ' + query results = cursor.execute(query, bindings) daily_stats = [ValidatorDailyStats.deserialize_from_db(x) for x in results] # Take into account the proportion of the validator owned validators_ownership = { validator.index: validator.ownership_proportion for validator in self.get_validators() } for daily_stat in daily_stats: owned_proportion = validators_ownership.get(daily_stat.validator_index, ONE) if owned_proportion != ONE: daily_stat.pnl = daily_stat.pnl * owned_proportion return daily_stats