5001_get_dalao_relationship.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. from base_class import BaseVariableFunction
  2. from base_class import *
  3. baseclass = BaseVariableFunction(__file__)
  4. old_print = print
  5. def timestamped_print(*args, **kwargs):
  6. old_print(datetime.datetime.utcnow().replace(
  7. microsecond=0), *args, **kwargs)
  8. print = timestamped_print
  9. print('\n'*5)
  10. print(f"{'{:<6}'.format('ENTER')} {baseclass.scriptfilename} ----------------NOTE-----------NOTE---------------")
  11. # 获取输入节点相关的图
  12. def get_connected_edges(df, str_dalaoaddress, max_connections=6):
  13. # 初始化结果列表
  14. result = []
  15. # 初始化待检查的节点集合
  16. to_check = {str_dalaoaddress}
  17. # 初始化已检查的节点集合
  18. checked = set()
  19. # 初始化连接数字典
  20. connection_counts = {node: 0 for node in df['from_owner'].tolist() + df['to_owner'].tolist()}
  21. while to_check:
  22. # 取出一个节点
  23. node = to_check.pop()
  24. # 添加到已检查集合
  25. checked.add(node)
  26. # 如果节点连接数超过最大限制,则跳过
  27. if connection_counts[node] > max_connections:
  28. continue
  29. # 找到所有从这个节点出发的边
  30. from_edges = df[df['from_owner'] == node]
  31. # 找到所有进入这个节点的边
  32. to_edges = df[df['to_owner'] == node]
  33. # 更新连接数
  34. connection_counts[node] += len(from_edges) + len(to_edges)
  35. # 如果连接数超过最大限制,则跳过
  36. if connection_counts[node] > max_connections:
  37. continue
  38. # 将这些边添加到结果列表
  39. result.extend(from_edges.index.tolist())
  40. result.extend(to_edges.index.tolist())
  41. # 将所有连接的节点添加到待检查集合
  42. for edge in from_edges['to_owner'].tolist() + to_edges['from_owner'].tolist():
  43. if edge not in checked:
  44. to_check.add(edge)
  45. # 返回与起始节点连接的所有边的索引
  46. connected_edges_indices = result
  47. connected_df = df.loc[connected_edges_indices]
  48. connected_df=connected_df.drop_duplicates().reset_index(drop=True)
  49. return connected_df
  50. excutionid ='01JBXRQNBWHRQ0RT66W4AC1QFE'
  51. file_name = f"one_token_relation_graph_{excutionid}.csv"
  52. obj_excutionid_2_tokeninfo = None
  53. obj_tokeninfo = None
  54. with open(baseclass.dune_excution_path/"obj_excutionid_2_tokeninfo.json",mode='r',encoding='utf8') as f:
  55. obj_excutionid_2_tokeninfo = json.load(f)
  56. obj_tokeninfo = obj_excutionid_2_tokeninfo[excutionid]
  57. str_tokenaddress = obj_tokeninfo["tokenaddress"]
  58. str_tokenname = obj_tokeninfo["tokenname"]
  59. # df =pd.read_excel(baseclass.librarydata_path/"test.xlsx",dtype=object)
  60. df =pd.read_csv(baseclass.dune_excution_path/file_name , dtype=object)
  61. str_dalaoaddress ='EeS7DBots7zF7JA4iCPun1uA779aXCPCBhe4kGkuCuRA'
  62. df = get_connected_edges(df, str_dalaoaddress)
  63. df =df.astype(
  64. { "owner_count":int,
  65. }
  66. )
  67. # def makeurl( self,url,url_show):
  68. # return '=HYPERLINK("{}","{}")'.format(url, "url_"+url_show)
  69. df["gmgn_from"] = df.apply(lambda ser: baseclass.makeurl(
  70. f"https://gmgn.ai/sol/token/{str_tokenaddress}?maker={ser['from_owner']}" , f"gmgn_{ser['from_owner'][0:6]}" ), axis=1)
  71. df["gmgn_to"] = df.apply(lambda ser: baseclass.makeurl(
  72. f"https://gmgn.ai/sol/token/{str_tokenaddress}?maker={ser['to_owner']}" , f"gmgn_{ser['to_owner'][0:6]}" ), axis=1)
  73. df["url_from_ata"] = df.apply(lambda ser: baseclass.makeurl(
  74. f"https://solscan.io/account/{ser['from_token_account']}" , f"sol_{ser['from_token_account'][0:6]}" ), axis=1)
  75. df["url_to_ata"] = df.apply(lambda ser: baseclass.makeurl(
  76. f"https://solscan.io/account/{ser['to_token_account']}" , f"sol_{ser['to_token_account'][0:6]}" ), axis=1)
  77. df =df.sort_values(by=['from_owner']).reset_index(drop=True)
  78. baseclass.makedirpath(baseclass.dune_token_graph_path/ str_tokenaddress)
  79. df.to_excel(baseclass.dune_token_graph_path/ str_tokenaddress/f"{str_dalaoaddress}.xlsx",index=False)