Skip to content

Commit 971578c

Browse files
authored
enhance/add histogram sample (#137)
1 parent 346b64e commit 971578c

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

visualdl/server/lib.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def get_histogram_tags(storage):
146146
return get_tags(storage, 'histogram')
147147

148148

149-
def get_histogram(storage, mode, tag):
149+
def get_histogram(storage, mode, tag, num_samples=200):
150150
with storage.mode(mode) as reader:
151151
histogram = reader.histogram(tag)
152152
res = []
@@ -171,7 +171,22 @@ def get_histogram(storage, mode, tag):
171171
[instance.left(),
172172
instance.right(),
173173
instance.frequency()])
174-
return res
174+
if len(res) < num_samples:
175+
return res
176+
177+
# sample some steps
178+
span = float(len(res)) / (num_samples - 1)
179+
span_offset = 0
180+
data_idx = 0
181+
182+
sampled_data = []
183+
data_size = len(res)
184+
while data_idx < data_size:
185+
sampled_data.append(res[data_size - data_idx - 1])
186+
span_offset += 1
187+
data_idx = int(span_offset * span)
188+
sampled_data.append(res[0])
189+
return sampled_data[::-1]
175190

176191

177192
def retry(ntimes, function, time2sleep, *args, **kwargs):

0 commit comments

Comments
 (0)