Script pour obtenir une animation de la toile de confiance duniter. [dépôt archivé] le code a été intégré à DataJune (https://git.42l.fr/HugoTrentesaux/DataJune.jl)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 

67 lines
2.8 KiB

# Utility functions converting text files extracted by blockchain_browser.py
# into ligthgraph format
module LightGraphExporter
using LightGraphs
using CSV, TOML, JLD2
using ProgressMeter
# transform txt cert files to lg files for step of time (seconds)
function txt2lg(folder, step)
mkpath(joinpath(folder, "cert.lg")) # create lg directory
pseudo = readlines(joinpath(folder,"pseudo")) # load all pseudo
joiners = CSV.File(joinpath(folder, "joiners"); header=["time","number"]) # load all joiners
leavers = CSV.File(joinpath(folder, "leavers"); header=["time","number"]) # load all leavers
cert_in = CSV.File(joinpath(folder, "cert_in"); header=["time","source","target"]) # load all certs
cert_out = CSV.File(joinpath(folder, "cert_out"); header=["time","source","target"]) # load all certs expiration
start = joiners[1][:time] # time of first joiner
stop = joiners[end][:time] # time of last joiner
npseudo = size(pseudo, 1) # number of pseudos
nstep = Int(floor((stop-start)/step)) # number of steps
g = SimpleDiGraph(npseudo) # empty graph with one node per pseudo
active_nodes = falses(npseudo,nstep) # boolean of node activity
i = 1 # step number
cur_stop = start # stop point of current iteration
crtinptr = 1 # pointer on cert_in
crtexptr = 1 # pointer on cert_out
joinptr = 1 # pointer on joiners
leavptr = 1 # pointer on leavers
@showprogress "Converting files..." for i in 1:nstep
cur_stop += step # increase time limit of current step
# take into account joiners and leavers (due to distance rule, revocation, membership...)
while joiners[joinptr][:time] < cur_stop
t, n = joiners[joinptr]
active_nodes[n,i:end] .= true # tell that id joined
joinptr += 1
end
while leavptr < size(leavers,1) && leavers[leavptr][:time] < cur_stop
t, n = leavers[leavptr]
active_nodes[n,i:end] .= false # tell that id leaved
leavptr += 1
end
# take certifications into account
while cert_in[crtinptr][:time] < cur_stop
t, source, target = cert_in[crtinptr]
add_edge!(g, source, target) # add new certifications
crtinptr += 1
end
while cert_out[crtexptr][:time] < cur_stop
t, source, target = cert_out[crtexptr]
rem_edge!(g, source, target) # remove expired certification
crtexptr += 1
end
savegraph(joinpath(folder, "cert.lg", lpad(i,4,'0')*".lg"), g) # save graph
f = open(joinpath(folder, "info"), "w")
TOML.print(f, Dict("start"=>start,"step"=>step,"nstep"=>nstep,"npseudo"=>npseudo)) # prints some info
end
@save joinpath(folder, "active") active_nodes
end
end