-
Notifications
You must be signed in to change notification settings - Fork 58
add cluster balance indicator #214
Changes from 22 commits
b2b4490
973df4a
190d1a1
372e1d6
b69aeef
1ab0319
09104fa
deca2c8
1c66447
23c3362
35c0843
3b7de8e
66b9e81
3149f39
35129b3
c36258e
10d3e28
4817720
937abc4
6174b5f
53e43fb
938ac9c
bc0ecd8
bf4ae85
27ca053
07399c2
6156c6f
6e90087
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) 2017, Xiaomi, Inc. All rights reserved. | ||
// This source code is licensed under the Apache License Version 2.0, which | ||
// can be found in the LICENSE file in the root directory of this source tree. | ||
|
||
#pragma once | ||
|
||
#include <vector> | ||
|
||
namespace dsn { | ||
namespace utils { | ||
|
||
double mean_stddev(const std::vector<unsigned> &result_set, bool partial_sample); | ||
|
||
} // namespace utils | ||
} // namespace dsn |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) 2017, Xiaomi, Inc. All rights reserved. | ||
// This source code is licensed under the Apache License Version 2.0, which | ||
// can be found in the LICENSE file in the root directory of this source tree. | ||
|
||
#include <numeric> | ||
#include <algorithm> | ||
#include <math.h> | ||
#include <dsn/utility/math.h> | ||
|
||
namespace dsn { | ||
namespace utils { | ||
|
||
double mean_stddev(const std::vector<unsigned> &result_set, bool partial_sample) | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可以加个 |
||
double sum = std::accumulate(result_set.begin(), result_set.end(), 0.0); | ||
double mean = sum / result_set.size(); | ||
|
||
double accum = 0.0; | ||
std::for_each(result_set.begin(), result_set.end(), [&](const double d) { | ||
accum += (d - mean) * (d - mean); | ||
}); | ||
|
||
double stddev; | ||
if (partial_sample) | ||
stddev = sqrt(accum / (result_set.size() - 1)); | ||
else | ||
stddev = sqrt(accum / (result_set.size())); | ||
|
||
stddev = ((double)((int)((stddev + 0.005) * 100))) / 100; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里只是为了做四舍五入吗? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 四舍五入保留小数点后两位 |
||
return stddev; | ||
} | ||
|
||
} // namespace utils | ||
} // namespace dsn |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,5 +183,13 @@ std::string string_md5(const char *buffer, unsigned length) | |
|
||
return result; | ||
} | ||
|
||
std::string to_string_with_precision(const double double_val, const int precision) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 用 fmtlib,这个函数没必要写,http://fmtlib.net/latest/syntax.html |
||
{ | ||
std::ostringstream out; | ||
out.precision(precision); | ||
out << std::fixed << double_val; | ||
return out.str(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个函数没有一点注释?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个应该还好吧,函数名一看就明白,公式也很简单
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unsigned 要改成 uint32_t(当然你提前要 include )这是 cpplint 标准写法。