Posts

LeoFinance witness - How many have earned more than 1000 LEO this month but haven't voted Leo as witness? -Python code + DATA and CHARTS

avatar of @amr008
25
@amr008
·
·
0 views
·
5 min read

Good evening to everyone , I hope you all are having a great day .

Onboarding

We all know how much LeoFinance team has done regarding onboarding of people . I am not here to talk about that , the thing I want to mention in this post is - how can we help LeoFinance team in this regard?

One obvious way is to delegate our HP to @leo.voter so that HP available in that account is used to delegate to new users .

I am here to talk about the second way , let's get LeoFinance in top 20 - that way the Block producer reward will keep on adding HP to LeoFinance more than what they are gaining right now at 30th position .

Note: For those who isn't interested in codes , skip to the end of post for results.

Proxy accounts are those which haven't directly voted for witness but have used proxy to vote for witnesses indirectly . Non-Proxy are those who have voted by themselves.

First , I gathered all the data from TxAccount table from HiveSQL and bifurcated the account with proxy and without proxy and stored it in CSV file .

The following data is used to retrieve the data from CSV and store it in DataFrame.

import pandas as pd 
from datetime import datetime as dt 
without_proxy = pd.read_csv('Without_proxy.csv') 

Table looks like this -

What we need to look for is - witness_votes column -

No Proxy account

witness_list=[] 
for j in range(0,len(without_proxy)): 
    list_generator= list(without_proxy['witness_votes'][j].split('\r\n'))  
    if list_generator: 
        for i in range(0,len(list_generator)): 
            list_generator[i]=''.join(e for e in list_generator[i] if e.isalnum()) 
        list_generator= list(filter(None, list_generator)) 
     
    witness_list.append([without_proxy['name'][j],list_generator]) 
     

What have I done above?

  • going through every row ( which contains details of who a particular user has voted for as witness)

  • it contains some unnecessary data like \r\n so I have cleansed it and stored it in pure username form

  • I have stored that in a list in the following format

    • Username : Witness votes

    • Ex :

    • Here 'hope777' is the account name and the next list is whom he has voted for as witness.

voted_for_leo_list=[] 
not_voted_list=[] 
for i in range(0,len(witness_list)): 
    if 'leofinance' in (witness_list[i][1]): 
        voted_for_leo_list.append(witness_list[i][0]) 
    else: 
        not_voted_list.append(witness_list[i][0]) 
     

In the above code

  • I have just checked if LeoFinance is one of the votes by the user .

  • If yes , I have stored his name in voted_for_leo_list

  • If no , I have stored his name in not_voted_list

That is it for ' No proxy account votes ' . Now let's jump to ' Proxy accounts '

with_proxy = pd.read_csv('With_proxy.csv') 
for i in range(0,len(with_proxy)): 
    proxy_name=with_proxy['proxy'][i] 
     
    if proxy_name in voted_for_leo_list: 
        voted_for_leo_list.append(with_proxy['name'][i]) 
    else: 
        not_voted_list.append(with_proxy['name'][i]) 

Steps

  • I have stored taken user and his proxy .

  • I have stored the proxy name in proxy_name .

  • I have checked if the proxy_name have voted for leofinance by referring to above voted_for_leo_list

  • If yes , I have appended the user name to voted_for_leo_list

  • If no , I have stored his name in not_voted_list .

Now I have used Hive-Engine API to gather the data of how much they have earned from Jan 1 to Jan 26.

import shelve 
s=shelve.open('Blocks\Blockchain') # Where I store all 2nd layer tx details 
df=pd.DataFrame.from_dict(s.items()) # Converting to DataFrame 
df.columns=['Blocks','Transactions'] # Renaming the columns  
 
 
import json 
leo_earned_list=[] 
for i in range(0,len(df)): 
    if(df['Transactions'][i]['Transaction']['action']=='issue'): 
        json_logs=json.loads(df['Transactions'][i]['Transaction']['logs']) 
        if 'events' in json_logs: 
            if(json_logs['events'][0]['data']['symbol']=='LEO'): 
                leo_earned_list.append([json_logs['events'][0]['data']['to'],json_logs['events'][0]['data']['quantity'],df['Transactions'][i]['Transaction']['sender']]) 
                 
         

Steps

  • I have filtered first by taking transactions which has action as 'issue'
  • I have taken logs and have stored the data for only LEO symbol .

The output looks like this -

Since we need all the LEO issued to particular user from Jan 1 to Jan 25 , I have used groupby username and sum() , this will give us -

df_total_leo_earned=df_leo_earned.groupby('to').sum().reset_index() 

output -

LEO earned in this month from Jan 1 to Jan 25

list_less_100=[] 
list_100_1000=[] 
list_more_1000=[] 
for i in range(0,len(df_total_leo_earned)): 
    if(df_total_leo_earned['quantity'][i]>100 and df_total_leo_earned['quantity'][i]<1000): 
        list_100_1000.append(df_total_leo_earned['to'][i]) 
    elif(df_total_leo_earned['quantity'][i]<=100): 
        list_less_100.append(df_total_leo_earned['to'][i]) 
    else: 
        list_more_1000.append(df_total_leo_earned['to'][i]) 

This is pretty simple , I have segregated accounts based on amount of LEO earned .

  • Those who have earned less than 100 , their names are stored in list_less_100 .
  • Those who have earned between 100 and 1000 , I have stored in list_100_1000 .
  • Those who have earned more than 1000 , I have stored in list_more_1000 .

If I count the number of users -

print('Less than 100 LEO earned = '+str(len(list_less_100))) 
print('Earned between 100 and 1000 = '+str(len(list_100_1000))) 
print('Leo Earned more than 1000 = '+str(len(list_more_1000))) 

Output -

Less than 100 LEO earned = 2421 Earned between 100 and 1000 = 152 Leo Earned more than 1000 = 45

Now comes the main part - How many users have voted to LeoFinance ?

count_less_100=0 
count_100_1000=0 
count_more_1000=0 
for i in list_less_100: 
    if i in voted_for_leo_list: 
        count_less_100+=1 
 
for i in list_100_1000: 
    if i in voted_for_leo_list: 
        count_100_1000 +=1 
 
for i in list_more_1000: 
    if i in voted_for_leo_list: 
        count_more_1000 +=1 
 

Steps

  • I have just taken users and seen if they have voted or not , that's it .

Data and Charts

So for all those people who just hated the above part and just want to know the final result -
this is it -

Total voted for Leofinance who have earned less than 100 :535
Total voted for Leofinance who have earned between 100 and 1000 :93
Total voted for Leofinance who have earned more than 1000 :19

Not voted for Leofinance but who have earned less than 100 :1886
Not voted for Leofinance but who have earned between 100 and 1000 :59
Not voted for Leofinance but who have earned more than 1000 :26

Those who have earned less than 100 LEO , witness votes proportion.

Those who have earned between 100 and 1000 LEO , witness votes proportion

Those who have earned more than 1000 LEO .

What do you think of the above ?

I also tried to see how much Vests resides in the accounts who have earned over 1000 LEO .

*Note: Only over 1000 LEO , not the other two , if we calculate the total VESTS - we get this '

sum_vests=0 
from beem.account import Account 
for i in final_list1: 
    account = Account(i) 
    sum_vests=sum_vests+(float(str(account.balances['total'][2]).split(' ')[0])) 
 
for i in final_list2: 
    account = Account(i) 
    sum_vests=sum_vests+(float(str(account.balances['total'][2]).split(' ')[0])) 
    
     
for i in final_list3: 
    account = Account(i) 
 
    sum_vests=sum_vests+(float(str(account.balances['total'][2]).split(' ')[0])) 
     
 
sum_vests  

Update : I have just updated for all 3 lists -
Output - 35242666163.46122 VESTS .

In HP - 18 M HP.

Posted Using LeoFinance Beta