Skip to content

Commit

Permalink
Update metrics collector timeframe
Browse files Browse the repository at this point in the history
  • Loading branch information
dmytrotkk committed Nov 4, 2024
1 parent ec820b7 commit 72e8f97
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions metrics/src/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import logging
import asyncio
import aiohttp
from datetime import datetime, timedelta
from datetime import datetime, date, timedelta
from typing import Tuple, Optional, Dict, List
from aiohttp import ClientError, ClientSession

Expand Down Expand Up @@ -62,7 +62,7 @@ def get_empty_address_counter() -> AddressCounter:
'token_transfers_count': '0',
'transactions_count': '0',
'validations_count': '0',
'transactions_last_day': 0,
'transactions_today': 0,
'transactions_last_7_days': 0,
'transactions_last_30_days': 0,
}
Expand All @@ -81,30 +81,30 @@ async def fetch_address_data(
response.raise_for_status()

current_data: Dict = await response.json()
logger.debug(f'Explorer response for {address}: {json.dumps(current_data, indent=2)}')

await update_transaction_counts(chain_name, app_name, address, current_data)

today = datetime.now().date()
yesterday = today - timedelta(days=1)
today = date.today()
week_ago = today - timedelta(days=7)
month_ago = today - timedelta(days=30)

transactions_last_day = await get_address_transaction_counts(
chain_name, app_name, address, yesterday, yesterday
transactions_today = await get_address_transaction_counts(
chain_name, app_name, address, today, today
)
transactions_last_7_days = await get_address_transaction_counts(
chain_name, app_name, address, week_ago, yesterday
chain_name, app_name, address, week_ago, today
)
transactions_last_30_days = await get_address_transaction_counts(
chain_name, app_name, address, month_ago, yesterday
chain_name, app_name, address, month_ago, today
)

result: AddressCounter = {
'gas_usage_count': str(current_data.get('gas_usage_count', '0')),
'token_transfers_count': str(current_data.get('token_transfers_count', '0')),
'transactions_count': str(current_data.get('transactions_count', '0')),
'validations_count': str(current_data.get('validations_count', '0')),
'transactions_last_day': transactions_last_day,
'transactions_today': transactions_today,
'transactions_last_7_days': transactions_last_7_days,
'transactions_last_30_days': transactions_last_30_days,
}
Expand Down
2 changes: 1 addition & 1 deletion metrics/src/metrics_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AddressCounter(TypedDict):
token_transfers_count: str
transactions_count: str
validations_count: str
transactions_last_day: int
transactions_today: int
transactions_last_7_days: int
transactions_last_30_days: int

Expand Down

0 comments on commit 72e8f97

Please sign in to comment.