
from base_class import BaseVariableFunction
from base_class import *
baseclass = BaseVariableFunction(__file__)

baseclass.makedirpath(baseclass.dalao_ori_pnl_gmgn_path)

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):
    _url = urlname + urlparam
    return '=HYPERLINK("{}","{}")'.format(_url, _url)


def check_ispump(arr_str_dalaoaddress):
        for str_dalaoaddress in arr_str_dalaoaddress:
        
                if not (baseclass.dalao_ori_pnl_gmgn_path / f"ori_gmgn_pnl_{str_dalaoaddress}.csv").exists():
                        continue
                
                print(f"check_ispump str_dalaoaddress= {str_dalaoaddress}")
                dalao_df = pd.read_csv(baseclass.dalao_ori_pnl_gmgn_path /
                        f"ori_gmgn_pnl_{str_dalaoaddress }.csv", dtype= object)
        
                
                
                dalao_df['30d_txns_buy'] = dalao_df['30d_txns_buy'].str.replace("K", '000', regex=True)
                dalao_df['30d_txns_sell'] = dalao_df['30d_txns_sell'].str.replace("K", '000', regex=True)
                
                dalao_df['30d_txns_buy'] = dalao_df['30d_txns_buy'].str.replace(r'[,\.]', '', regex=True)

                dalao_df['30d_txns_sell'] = dalao_df['30d_txns_sell'].str.replace(r'[,\.]', '', regex=True)
                
                dalao_df =dalao_df.astype({
                
                        "buy_sol":float,
                        "profit_sol":float,
                        "30d_txns_buy":int,
                        "30d_txns_sell":int,
                        
                })

                dalao_df["profit_percent"] =     dalao_df["profit_sol"] /   dalao_df["buy_sol"]
                dalao_df["profit_percent"] =        dalao_df["profit_percent"].round(2)
                dalao_df["ispump"] = 0
                dalao_df["isnengen"] = -1
                
                dalao_df["beizhu"] = -1
        
                dalao_df["dexurl"] = dalao_df.apply(lambda ser: makescreenurl( f"https://dexscreener.com/solana/",f"{ser['tokenaddress']}?maker={str_dalaoaddress}")  , axis=1)
                dalao_df["definedurl"] = dalao_df.apply(lambda ser: makescreenurl("https://www.defined.fi/sol/" ,ser['tokenaddress'] )  , axis=1)

    
        
                
                pump_mask =  dalao_df['tokenaddress'].str.endswith('pump')
                dalao_df.loc[pump_mask,"ispump"] =1

                dalao_df.to_excel(baseclass.dalao_ori_pnl_gmgn_path /
                        f"ori_gmgn_pnl_{str_dalaoaddress}.xlsx", index=False )

        
        

arr_file =os.listdir(baseclass.dalao_ori_pnl_gmgn_path )


df =  pd.read_excel( baseclass.dalao_merge_defined_path / f"merge_defined.xlsx", dtype=object)
arr_str_dalaoaddress = df['dalaoaddress'].drop_duplicates().tolist()

check_ispump(arr_str_dalaoaddress=arr_str_dalaoaddress)
print(f"{'{:<6}'.format('END')}  ----------------NOTE-----------NOTE---------------")
