Skip to content

Commit

Permalink
tweak logs, fix lru_cache bug
Browse files Browse the repository at this point in the history
  • Loading branch information
smk762 committed Oct 15, 2024
1 parent 8047e68 commit 2d3ddf7
Show file tree
Hide file tree
Showing 11 changed files with 177 additions and 110 deletions.
1 change: 0 additions & 1 deletion code/kmd_ntx_api/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,6 @@ def get_notary_epoch_scores_table(request, notary=None):
epoch_id = epoch.split("_")[1]
else:
epoch_id = epoch
logger.calc(f"{server} {epoch} {coin}")
row = {
"notary": notary,
"season": season.replace("_", " "),
Expand Down
2 changes: 1 addition & 1 deletion code/scripts/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
TELEGRAM_CHAT_ID = os.getenv('TELEGRAM_CHAT_ID')

def send_telegram(msg):
t = datetime.now(timezone.utc).timestamp().strftime('%Y-%m-%d %H:%M:%S')
t = datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S')
payload = {
'chat_id': TELEGRAM_CHAT_ID,
'text': f"{t}: {msg}"
Expand Down
1 change: 0 additions & 1 deletion code/scripts/const_seasons.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ def epochs(self):
}
)
epoch_coins = self.coins_between(season, server, time_breaks[i], time_breaks[i + 1] - 1)
logger.calc(f"{season} {server} {epoch}")
season_epochs_dict[server][epoch].update(
{
"coins": epoch_coins,
Expand Down
2 changes: 1 addition & 1 deletion code/scripts/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ def wrapper_print_runtime(*args, **kwargs):
start = time.perf_counter()
x = func(*args, **kwargs)
end = time.perf_counter()
logger.info(f">>> {end-start:.3f} sec to complete {func.__name__!r}")
logger.calc(f">>> {end-start:.3f} sec to complete {func.__name__!r}")
return x
return wrapper_print_runtime
13 changes: 12 additions & 1 deletion code/scripts/lib_helper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python3.12
from functools import lru_cache
from lib_const import *
from const_seasons import SEASONS
from lib_urls import *
Expand All @@ -13,11 +14,13 @@ def safe_div(x,y):
return float(x/y)


@lru_cache(maxsize=None)
def handle_translate_coins(coin):
if coin in TRANSLATE_COINS:
return TRANSLATE_COINS[coin]
return coin

@lru_cache(maxsize=None)
def handle_translate_coins_reverse(coin):
if coin in REVERSE_TRANSLATE_COINS:
return REVERSE_TRANSLATE_COINS[coin]
Expand All @@ -30,6 +33,7 @@ def get_dpow_coin_src(src):
return src


@lru_cache(maxsize=None)
def get_nn_region_split(notary):
x = notary.split("_")
region = x[-1]
Expand All @@ -44,6 +48,7 @@ def get_results_or_none(cursor):
return ()


@lru_cache(maxsize=None)
def translate_dpow_server(server):
if server.lower() == "dpow-3p":
return "Third_Party"
Expand Down Expand Up @@ -86,6 +91,7 @@ def get_notary_address_lists(vin):
return notary_list, address_list


@lru_cache(maxsize=None)
def is_notary_ltc_address(addr):
if addr in ALL_SEASON_NOTARY_LTC_ADDRESSES:
return True
Expand Down Expand Up @@ -128,13 +134,15 @@ def is_postseason(timestamp=None, block=None):
return False


@lru_cache(maxsize=None)
def get_pubkeys(season, server):
if season in NOTARY_PUBKEYS:
if server in NOTARY_PUBKEYS[season]:
return NOTARY_PUBKEYS[season][server]
return []


@lru_cache(maxsize=None)
def get_address_from_notary(season, notary, coin):
if season in SEASONS.INFO:
for server in SEASONS.INFO[season]["servers"]:
Expand All @@ -157,14 +165,15 @@ def has_season_started(season, by_block=False):
return False


@lru_cache(maxsize=None)
def get_season_notaries(season):
if season in SEASONS.INFO:
notaries = SEASONS.INFO[season]["notaries"]
notaries.sort()
return notaries
return []


@lru_cache(maxsize=None)
def get_season_coins(season=None, server=None, epoch=None):
coins = []
if not season:
Expand All @@ -184,6 +193,7 @@ def get_season_coins(season=None, server=None, epoch=None):
return coins


@lru_cache(maxsize=None)
def get_season_servers(season):
if season in SEASONS.INFO:
servers = list(SEASONS.INFO[season]["servers"].keys())
Expand All @@ -192,6 +202,7 @@ def get_season_servers(season):
return []


@lru_cache(maxsize=None)
def get_season_server_epochs(season, server):
if season in SEASONS.INFO:
if server in SEASONS.INFO[season]["servers"]:
Expand Down
240 changes: 143 additions & 97 deletions code/scripts/lib_ntx.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion code/scripts/lib_rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def def_credentials(coin):
logger.info("Unable to set RPC proxy, please confirm rpcuser, rpcpassword and rpcport are set in "+coin_config_file)

def get_ntx_txids(start, end):
logger.calc(f"Getting nxt txids from blocks {start}-{end}")
logger.info(f"Getting nxt txids from blocks {start}-{end}")
return RPC["KMD"].getaddresstxids({"addresses": [lib_const.NTX_ADDR], "start":start, "end":end})


Expand Down
1 change: 0 additions & 1 deletion code/scripts/lib_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ def get_coin_epoch_score_at(season, server, coin, timestamp, testnet=False):


def calc_epoch_score(server, num_coins):
logger.info(f"[calc_epoch_score] {server} {num_coins}")
if num_coins == 0:
return 0
if server == "Main":
Expand Down
9 changes: 6 additions & 3 deletions code/scripts/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,16 @@ def addLoggingLevel(levelName, levelNum, methodName=None):
methodName = methodName or levelName.lower()
if hasattr(logging, levelName) or hasattr(logging.getLoggerClass(), methodName):
raise AttributeError(f"{levelName} or {methodName} already defined")

if levelName.lower() in ["info", "debug", "warning", "error"]:
stacklevel = 1
else:
stacklevel = 2
def logForLevel(self, message, *args, **kwargs):
if self.isEnabledFor(levelNum):
self._log(levelNum, message, args, **kwargs)
self._log(levelNum, message, args, **kwargs, stacklevel=stacklevel)

def logToRoot(message, *args, **kwargs):
logging.log(levelNum, message, *args, **kwargs)
logging.log(levelNum, message, *args, **kwargs, stacklevel=stacklevel)

logging.addLevelName(levelNum, levelName)
setattr(logging.getLoggerClass(), methodName, logForLevel)
Expand Down
4 changes: 1 addition & 3 deletions code/scripts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,7 @@ def update(self):
self.coin_ntx_pct, self.timestamp, self.season,
self.notarised_date)
if self.validated():
logger.info(f"Updating [notarised_count_daily] {self.notarised_date} {self.notary}")
if self.notary == "dragonhound_DEV":
logger.info(f"Updating [notarised_count_daily] {row_data}")
logger.debug(f"Updating [notarised_count_daily] {self.notarised_date} {self.notary}")
update_daily_notarised_count_row(row_data)
else:
logger.warning(f"[notarised_count_daily_row] Row data invalid!")
Expand Down
12 changes: 12 additions & 0 deletions code/scripts/test_season_ntx_dict.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import json

with open("season_ntx_dict_notaries.json", "r") as f:
notaries_data = json.load(f)

with open("season_ntx_dict_servers.json", "r") as f:
servers_data = json.load(f)

with open("season_ntx_dict_coins.json", "r") as f:
coins_data = json.load(f)


0 comments on commit 2d3ddf7

Please sign in to comment.