Skip to content

Commit

Permalink
optimize and fix test(unrelated to this PR)
Browse files Browse the repository at this point in the history
  • Loading branch information
akremstudy committed Oct 13, 2023
1 parent d702141 commit cff1085
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/telliot_feeds/reporters/tips/listener/funded_feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async def filtered_funded_feeds(
)
# for list of previous values, filter out any that weren't eligible for a tip
historical_timestamps_list_filtered = self.filter_historical_submissions(
feeds=feeds_timestsamps_and_values_filtered, month_old=month_old_timestamp
feeds=feeds_timestsamps_and_values_filtered
)

# get claim status count for every query ids eligible timestamp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,7 @@ async def price_change(self, query_data: bytes, value_before: bytes) -> Optional

return _get_price_change(previous_val=value_before_decoded, current_val=self.prices[query_id])

def filter_historical_submissions(
self, feeds: list[QueryIdandFeedDetails], month_old: int
) -> list[QueryIdandFeedDetails]:
def filter_historical_submissions(self, feeds: list[QueryIdandFeedDetails]) -> list[QueryIdandFeedDetails]:
"""Check list of values for older submission would've been eligible for a tip
if so the timestamps will be checked later to see if a tip for them has been claimed
Expand All @@ -150,11 +148,6 @@ def filter_historical_submissions(
for current, previous in zip(
feed.queryid_timestamps_values_list[::-1], feed.queryid_timestamps_values_list[-2::-1]
):
# if current timestamp is before feed start or
# timestamp to check is older than a month then no need to check
if feed.params.startTime > current.timestamp or current.timestamp < month_old:
feed.queryid_timestamps_values_list.remove(current)
continue
in_eligibile_window = self.is_timestamp_first_in_window(
timestamp_before=previous.timestamp,
timestamp_to_check=current.timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ async def month_of_timestamps_and_values(
return None, error_status(note)
values = multiple_values_response[values_tup]
timestamps = multiple_values_response[timestamps_tup]
# remove old timestamps
if timestamps:
timestamps = [
timestamp for timestamp in timestamps if timestamp > max_age and timestamp >= feed.params.startTime
]
# short circuit the loop since None means failed response and can't calculate tip accurately
if values is None:
note = "getMultipleValuesBefore call failed"
Expand Down
2 changes: 1 addition & 1 deletion src/telliot_feeds/reporters/tips/tip_amount.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ async def fetch_feed_tip(
return tip_amount

# filter out query id timestamps not eligible for tip
feeds_with_timestamps_filtered = filtr.filter_historical_submissions(eligible_feeds, month_old)
feeds_with_timestamps_filtered = filtr.filter_historical_submissions(eligible_feeds)

unclaimed_count, status = await call.rewards_claimed_status_call(feeds_with_timestamps_filtered)

Expand Down
2 changes: 1 addition & 1 deletion tests/feeds/test_diva_usd_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ async def test_diva_usd_median_feed():
print(f"DIVA/USD Price: {v}")

# Get list of data sources from sources dict
source_prices = [source.latest[0] for source in diva_usd_median_feed]
source_prices = [source.latest[0] for source in diva_usd_median_feed.source.sources]
print(source_prices)

# Make sure error is less than decimal tolerance
Expand Down

0 comments on commit cff1085

Please sign in to comment.