Skip to content

Commit

Permalink
enhance/add histogram sample (#137)
Browse files Browse the repository at this point in the history
  • Loading branch information
Superjomn authored Jan 14, 2018
1 parent 346b64e commit 971578c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions visualdl/server/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def get_histogram_tags(storage):
return get_tags(storage, 'histogram')


def get_histogram(storage, mode, tag):
def get_histogram(storage, mode, tag, num_samples=200):
with storage.mode(mode) as reader:
histogram = reader.histogram(tag)
res = []
Expand All @@ -171,7 +171,22 @@ def get_histogram(storage, mode, tag):
[instance.left(),
instance.right(),
instance.frequency()])
return res
if len(res) < num_samples:
return res

# sample some steps
span = float(len(res)) / (num_samples - 1)
span_offset = 0
data_idx = 0

sampled_data = []
data_size = len(res)
while data_idx < data_size:
sampled_data.append(res[data_size - data_idx - 1])
span_offset += 1
data_idx = int(span_offset * span)
sampled_data.append(res[0])
return sampled_data[::-1]


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

0 comments on commit 971578c

Please sign in to comment.