
# 将油猴脚本获取的top trader
from base_class import BaseVariableFunction
from base_class import *
baseclass = BaseVariableFunction(__file__)

old_print = print


def timestamped_print(*args, **kwargs):
    old_print(datetime.datetime.utcnow().replace(
        microsecond=0), *args, **kwargs)


print = timestamped_print
print('\n'*5)
print(f"{'{:<6}'.format('ENTER')} {baseclass.scriptfilename} ----------------NOTE-----------NOTE---------------")


def makescreenurl(urlname, urlparam):
    # pairAddress = series[address_str]
    urlname = urlname + urlparam
    return '=HYPERLINK("{}","{}")'.format(urlname, urlname)


def filter_simple_dalao():

    df = baseclass.readcsvfiles_2df(baseclass.topdalao_from_dexscreener_path)
    df["Amountper"] = df["Amountper"].astype(float)
    df["Buymoney"] = df["Buymoney"].astype(float)
    df["Earnper"] = df["Earnper"].astype(float)
    df["Buycount"] = df["Buycount"].astype(int)
    df["Sellcount"] = df["Sellcount"].astype(int)
    df["Earnper"] = df['Earnper'].round(2)
    df["Amountper"] = df['Amountper'].round(2)
    df.insert(11, 'isNormal', -1)

    filter_mask = (
        (df["Amountper"] <= 1.3)
        & (df["Earnper"] >= 1.1)
        & (df["Buymoney"] > 3)
        & ~((df["Buycount"] >= 5) & (df["Sellcount"] >= 5))
    )

    df = df[filter_mask].reset_index(drop=True)

    # 示例 获取结果如下https://dexscreener.com/solana/9s9sgqskfyzbygm45qblje4rt6calfa2dbhjrevlszrc?maker=47TwqZwwMGHc9CkJJxvVgFNGLDqBuSPy95KwUSTcLSti

    df['DexScreenURL'] = df.apply(lambda ser: makescreenurl(
        "https://dexscreener.com/solana/", f"{ser['TokenAddress']}?maker={ser['Maker']}"), axis=1)

    df.to_excel(baseclass.dalao_merge_path /
                "un_onhand_dalao.xlsx", index=False)

    return


filter_simple_dalao()


print(f"{'{:<6}'.format('END')} {baseclass.scriptfilename} ----------------NOTE-----------NOTE---------------")
