def LoadData(d, m, y, Offset): """ This function load the composit graph data by calling getGraph function (built by the graph team) to build the COMPOSITE graph. It creates CSV file that represents the graph of transactions and addresses. """ code = None dd = d mm = m yy = y dOffset = Offset graphType = 'COMPOSITE' code, x = getGraph(dd, mm, yy, dOffset, graphType) while code == None and x == None: time.sleep(30) data = x.edges() data = list(data) return data
def getFeatures(day, month, year, feature): df = pd.DataFrame() try: result, networkxObj = getGraph(day, month, year, 1, "COMPOSITE") if result == 'Success': if feature == 'LEVEL_OF_ACTIVITY': result, df = levelOfActivity(networkxObj) df.index = np.arange(1, len(df) + 1) elif feature == 'TOTAL_BTC_RECEIVED': result, df = amountToAddress(networkxObj) df.index = np.arange(1, len(df) + 1) elif feature == 'TOTAL_BTC_SENT': result, df = BitcoinSent(networkxObj) elif feature == 'CURRENT_BALANCE': result, df = CurrentBalance(networkxObj) else: return 'Fail', 'Incorrect node feature' else: return 'Fail', networkxObj except Exception as e: return 'Fail', e return 'Success', df
def CurrentBalanceAnalysis(year, month, day): """To get the Current Balance of each address in the Bitcoin system at the end of each day""" try: dfObj = pd.DataFrame(columns=["Date", "Number of addresses with Current balance [0,1)", "Number of addresses with Current balance [1,10)", "Number of addresses with Current balance [10,100)", "Number of addresses with Current balance [100,1000)", "Number of addresses with Current balance [1000,10000)", "Number of addresses with Current balance [10000,50000)", "Number of addresses with Current balance greater than equal to 50000"]) d0 = date(2009, 1, 9) d1 = date(year, month, day) delta = d1 - d0 diff = delta.days print(diff) d = 9 m = 1 g = nx.MultiDiGraph() while diff >= 0: result, dfobject = getGraph(d, m, year, 1, "COMPOSITE") g = nx.compose(g, dfobject) lt1 = lt10 = lt100 = lt1000 = lt10000 = lt50000 = gt50000 = 0 outdegree = dict(g.out_degree(weight='weight')) indegree = dict(g.in_degree(weight='weight')) # print(outdegree) for ele, inval in indegree.items(): if len(ele) != 64: current = (inval - outdegree[ele]) / 100000000 if current < 1: lt1 += 1 elif current < 10: lt10 += 1 elif current < 100: lt100 += 1 elif current < 1000: lt1000 += 1 elif current < 10000: lt10000 += 1 elif current < 50000: lt50000 += 1 # print(ele,current) else: gt50000 += 1 dfObj = dfObj.append({"Date": str(year) + "-" + str(m) + "-" + str(d), "Number of addresses with Current balance [0,1)": lt1, "Number of addresses with Current balance [1,10)": lt10, "Number of addresses with Current balance [10,100)": lt100, "Number of addresses with Current balance [100,1000)": lt1000, "Number of addresses with Current balance [1000,10000)": lt10000, "Number of addresses with Current balance [10000,50000)": lt50000, "Number of addresses with Current balance greater than equal to 50000": gt50000 }, ignore_index=True) x = str(year) + "-" + str(m) + "-" + str(d) res = (datetime.strptime(x, '%Y-%m-%d') + timedelta(days=1)).strftime('%Y-%m-%d') res = datetime.strptime(res, '%Y-%m-%d') d = res.day m = res.month diff -= 1 except Exception as e: return 'Fail', e return "Success", dfObj
def getAnalysisResults(startyear, startmonth, startday, endyear, endmonth, endday): """Get all the graph analytics results on daily basis within the start and end date""" try: # dataFrame for address distribution dfAddDist = pd.DataFrame( columns=["Date", "Total Addresses", "Receive-only Address %", "Send/receive Address %"]) # dataFrame for Total BTC received dfTotRec = pd.DataFrame(columns=["Date", "Number of addresses with Total BTC received [0,1)", "Number of addresses with Total BTC received [1,10)", "Number of addresses with Total BTC received [10,100)", "Number of addresses with Total BTC received [100,1000)", "Number of addresses with Total BTC received [1000,10000)", "Number of addresses with Total BTC received [10000,50000)", "Number of addresses with Total BTC received greater than equal to 50000"]) # dataFrame for Level of activity dfLOActivity = pd.DataFrame(columns=["Date", "Number of addresses with Level of activity [1,2)", "Number of addresses with Level of activity [2,5)", "Number of addresses with Level of activity [5,10)", "Number of addresses with Level of activity [10,100)", "Number of addresses with Level of activity [100,1000)", "Number of addresses with Level of activity [1000,5000)", "Number of addresses with Level of activity greater than equal to 5000"]) # dataFrame for Strongly connected components dfSCC = pd.DataFrame(columns=["Date", "Number of Strongly connected components"]) # dataFrame for Weakly connected components dfWCC = pd.DataFrame(columns=["Date", "Number of Weakly connected components"]) # dataFrame for Transaction size dfTranSize = pd.DataFrame(columns=["Date", "Number of transaction of size [0,1)", "Number of transaction of size [1,10)", "Number of transaction of size [10,100)", "Number of transaction of size [100,5000)", "Number of transaction of size [5000,20000)", "Number of transaction of size [20000,50000)", "Number of transaction of size greater than equal to 50000"]) # dataframe for Assortativity coefficient dfAssortCo = pd.DataFrame(columns=["Date", "Assortativity coefficient"]) # dataframe for Bitcoin Circulation dfBTCCir = pd.DataFrame( columns=["Date", "Total Bitcoin", "Circulating Bitcoins %", "Not Circulating Bitcoins %"]) # dataframe for Clustering coefficient dfClustering = pd.DataFrame(columns=["Date", "Clustering coefficient"]) # dataframe for Pearson coefficient dfPearson = pd.DataFrame(columns=["Date", "Pearson coefficient"]) # dataframe for Active Entity dfMostActive = pd.DataFrame(columns=["Date", "Node", "Total Number of Transaction"]) # dataframe for Occurrence of different Chainlets dfChainletsOcc = pd.DataFrame(columns=["Date", "Occurrence of Split Chainlets", "Occurrence of Merge Chainlets", "Occurrence of Transition Chainlets"]) # dataframe for Amount of different Chainlets dfChainletsAocc = pd.DataFrame(columns=["Date", "Amount of split Chainlets", "Amount of merge Chainlets", "Amount of transition Chainlets"]) d0 = date(startyear, startmonth, startday) d1 = date(endyear, endmonth, endday) delta = d1 - d0 diff = delta.days print(diff) d = startday m = startmonth y = startyear while diff >= 0: result, ntObj = getGraph(d, m, y, 1, "COMPOSITE") curDate = str(y) + "-" + str(m) + "-" + str(d) # call Sarada's functions: res1, dfTotRec = TotalBTCreceived(curDate, ntObj, dfTotRec) if res1 == 'Fail': return dfTotRec res1, dfLOActivity = LevelOfActivity(curDate, ntObj, dfLOActivity) if res1 == 'Fail': return dfLOActivity res1, dfSCC = StronglyConnectedComponents(curDate, ntObj, dfSCC) if res1 == 'Fail': return dfSCC res1, dfWCC = WeaklyConnectedComponents(curDate, ntObj, dfWCC) if res1 == 'Fail': return dfWCC res1, dfChainletsOcc = diffChainlets(curDate, ntObj, dfChainletsOcc) if res1 == 'Fail': return dfChainletsOcc res1, dfChainletsAocc = diffChainletsAmount(curDate, ntObj, dfChainletsAocc) if res1 == 'Fail': return dfChainletsAocc occMat, AmtOccMat = diffChainletMatrix(curDate, ntObj) #call Saumya's functions: res2,dfBTCCir= BTCirculation(curDate,ntObj,dfBTCCir) if res2 == 'Fail': return dfBTCCir res2,dfMostActive = MostActiveEntity(curDate,ntObj,dfMostActive) if res2 == 'Fail': return dfMostActive res2, dfClustering = clusteringCoefficientonGraph(curDate, ntObj, dfClustering) if res2 == 'Fail': return dfClustering res2, dfPearson = PearsonCoefficient(curDate, ntObj, dfPearson) if res2 == 'Fail': return dfPearson # calling Srija's analysis functions res7, dfAddDist = AddressDistAnalysis(curDate, ntObj, dfAddDist) if res7 == 'Fail': return dfAddDist res8, dfTranSize = TransactionSizeAnalysis(curDate, ntObj, dfTranSize) if res8 == 'Fail': return dfTranSize res9, dfAssortCo = assortativityCoefficientAnalysis(curDate, ntObj, dfAssortCo) if res9 == 'Fail': return dfAssortCo res = (datetime.strptime(curDate, '%Y-%m-%d') + timedelta(days=1)).strftime('%Y-%m-%d') res = datetime.strptime(res, '%Y-%m-%d') d = res.day m = res.month y = res.year diff -= 1 except Exception as e: return e return "Success"
from graph.getGraph.getAPIData import getGraph from graph.getGraph.ethereumGraph.getAPIData import getEthereumgraph from graph.getGraph.graphanalysisSrija import CurrentBalanceAnalysis from graph.getGraph.mainAnalysis import getAnalysisResults from graph.getGraph.addressFeatures import getFeatures # to get Bitcoin graph object res1, graphobj = getGraph(9, 1, 2009, 1, 'COMPOSITE') # to get Ethereum graph object res2, ethergraphobj = getEthereumgraph(24, 4, 2018, 1, "zrx") # to evaluate current balance metric and store it in cummulative manner res3, currBal = CurrentBalanceAnalysis(2009, 1, 9) # evaluate all graph metrics and store it in daily basis from start and to date res4 = getAnalysisResults(2009, 2, 1, 2009, 2, 28) # get address feature for the specified date res5, feat = getFeatures(2, 2, 2009, 'LEVEL_OF_ACTIVITY')