Utilitaire pour indexer des informations de la blockchain et dessiner des Plots. Focalisé sur la toile de confiance. http://datajune.coinduf.eu/
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.

120 lines
4.7 KiB

module DataPlotter
using ..StatsExporter: api
using ..Config, ..WotHistory
using Plots, Dates, Serialization, Logging, DataFrames, CSV
"write plot to file in given format"
function print_output(path, p, format)
savefig(p, joinpath(PLOTS_PATH, path*"."*format))
end
"plot : membres"
function plot_member_count(format, dates, members, was_member)
p = plot(size=(1200,720), thickness_scaling=1.4, legend=:topleft)
plot!(dates, members, label="membres actifs")
plot!(dates, was_member - members, label="anciens membres")
plot!(dates, was_member, label="total")
title!("Évolution du nombre de membres de la ğ1")
xaxis!("date")
yaxis!("nombre de membres")
print_output("members", p, format)
@debug "printed member count ($format)"
end
"plot : referent"
function plot_member_referent(format, dates, members, referent)
p = plot(size=(1200,720), thickness_scaling=1.4, legend=:topleft)
plot!(dates, members, label="number of members")
plot!(dates, referent, label="number of referent members")
axis = twinx(p)
green = palette(:auto).colors.colors[3]
plot!(axis, dates, referent./members, label="proportion of referent members", color=green, legend=:bottomright)
xaxis!("date")
yaxis!("...")
print_output("referent", p, format)
@debug "printed referent member count ($format)"
end
"plot : proportion de référents atteints"
function plot_average_pr(format, dates, avg_pr)
p = plot(size=(1200,720), thickness_scaling=1.4, legend=:bottomright)
plot!(dates, avg_pr, label=["distance 1" "distance 2" "distance 3" "distance 4" "distance 5"])
title!("Évolution de la proportion de membres référents atteints pour différentes distances (moyenne des membres de la ğ1)")
xaxis!("date")
yaxis!("qualité moyenne")
print_output("average_pr", p, format)
@debug "printed average pr ($format)"
end
"plot : proportion de référents atteints à distance 5"
function plot_average_pr5(format, dates, avg_pr)
p = plot(size=(1200,720), thickness_scaling=1.4, legend=:bottomright)
plot!(dates, avg_pr[:,5], label="distance 5")
title!("Évolution de la proportion de membres référents atteints à distance 5 (moyenne des membres de la ğ1)")
xaxis!("date")
yaxis!("qualité moyenne")
print_output("average_pr5", p, format)
@debug "printed average pr5 ($format)"
end
"plot : respect de la règle de distance"
function plot_distance_rule_compliance(format, dates, distance_rule_compliance)
p = plot(size=(1200,720), thickness_scaling=1.4, legend=:bottomright)
plot!(dates, distance_rule_compliance, label="dist rule compliance")
title!("Évolution de la proportion de membres atteignant >= 80% de membres référents")
xaxis!("date")
yaxis!("proportion de membres")
print_output("distance_rule_compliance", p, format)
@debug "printed distance rule compliance ($format)"
end
"plot : membres de la ğ1 / membres forums"
function plot_forums_vs_members()
members = CSV.read(joinpath(API_PATH, "members+distrule.csv"), DataFrame)
forum_ml = CSV.read(joinpath(API_PATH, "forum.monnaie-libre.fr_signups.csv"), DataFrame)
forum_duniter = CSV.read(joinpath(API_PATH, "forum.duniter.org_signups.csv"), DataFrame)
p = plot(size=(1200,720), thickness_scaling=1.4, legend=:topleft)
title!("comparaison entre les forums et le nombre de membres en blockchain")
xaxis!("date")
yaxis!("nombre de membres")
plot!(members.Dates, members.IdCount, label="membres ğ1 total", linewidth=2)
plot!(forum_ml.Jour, cumsum(forum_ml.Nombre), label="forum ml", linewidth=2)
plot!(forum_duniter.Jour, cumsum(forum_duniter.Nombre), label="forum duniter", linewidth=2)
print_output("forms_vs_members", p, "png")
end
"commande tous les plots au format donné"
function all_plots(format)
# load data
@info "loading data"
w = WotSnapshot()
ws = deserialize(WOTSTATS_CACHE_FILE)
dates = Date.(unix2datetime.(w.intervals))
if format == "html"
plotlyjs() # plotlyjs can export interactive plots in html
elseif format == "svg"
gr() # pyplot has better svg export but requires additional dependancies
else # gr is the quickest renderer and is perfect for pngs
gr()
end
@info "plotting data"
plot_member_count(format, dates, ws.members, ws.was_member)
plot_member_referent(format, dates, ws.members, ws.total_referent)
plot_average_pr(format, dates, ws.avg_pr)
plot_average_pr5(format, dates, ws.avg_pr)
plot_distance_rule_compliance(format, dates, ws.member_prop_over80percent)
end
"commande tous les plots pour tous les formats"
function all_plots_all_formats()
all_plots("png")
all_plots("html")
all_plots("svg")
end
end