1@startuml
2title "Torflow measurements scaling with PID control (Per relay scaled bandwidth)."
3
4' Own previous bwfile
5:prev_votes = VoteSet();
6:tot_net_bw = 0;
7:;
8note right
9    for every measurement
10end note
11while (for n in nodes.itervalues()?)
12    partition "Intialize ratios and pid_error" {
13        ' Anything not set is initialized to 0 or None
14        :n.fbw_ratio = n.filt_bw/true_filt_avg[n.node_class()];
15        :n.sbw_ratio = n.strm_bw/true_strm_avg[n.node_class()];
16        :n.use_bw = n.desc_bw;
17        :n.pid_error = max(n.fbw_ratio, n.sbw_ratio) - 1;
18    }
19    if (n.idhex in prev_votes.vote_map \nand not newer measurement?) then (yes)
20        :self.new_bw = prev_vote.bw*1000
21        self.measured_at = vote.measured_at;
22    ' Not in previous bwfile, usually only with authoritites, possibly not in conensus?
23    else (no)
24        :n.new_bw = n.use_bw + n.use_bw * n.pid_error;
25    endif
26
27    ' For capping later
28    if (n.idhex in prev_consensus \nand prev_consensus[n.idhex].bandwidth != None) then (yes)
29        :prev_consensus[n.idhex].measured = True
30        tot_net_bw += n.new_bw;
31    endif
32endwhile
33while (for n in nodes.itervalues()?)
34    :cap...;
35endwhile
36stop
37
38@enduml
39