Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance/add histogram sample #137

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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