PropertyReport.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /**
  2. * Tencent is pleased to support the open source community by making Tars available.
  3. *
  4. * Copyright (C) 2016THL A29 Limited, a Tencent company. All rights reserved.
  5. *
  6. * Licensed under the BSD 3-Clause License (the "License"); you may not use this file except
  7. * in compliance with the License. You may obtain a copy of the License at
  8. *
  9. * https://opensource.org/licenses/BSD-3-Clause
  10. *
  11. * Unless required by applicable law or agreed to in writing, software distributed
  12. * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
  13. * CONDITIONS OF ANY KIND, either express or implied. See the License for the
  14. * specific language governing permissions and limitations under the License.
  15. */
  16. #include "servant/PropertyReport.h"
  17. #include "util/tc_common.h"
  18. namespace tars
  19. {
  20. string PropertyReport::sum::get()
  21. {
  22. string s = TC_Common::tostr(_d);
  23. clear();
  24. return s;
  25. }
  26. string PropertyReport::avg::get()
  27. {
  28. if(_count == 0)
  29. {
  30. return "0";
  31. }
  32. string s = TC_Common::tostr(static_cast<double>(_sum)/_count);
  33. clear();
  34. return s;
  35. }
  36. PropertyReport::distr::distr(const vector<int>& range)
  37. {
  38. _range = range;
  39. std::sort(_range.begin(), _range.end());
  40. _range.erase(unique(_range.begin(), _range.end()),_range.end());
  41. _result.resize(_range.size());
  42. }
  43. void PropertyReport::distr::set(int o)
  44. {
  45. vector<int>::iterator it = std::upper_bound(_range.begin(), _range.end(), o);
  46. if (it != _range.end())
  47. {
  48. size_t n = it - _range.begin();
  49. ++_result[n];
  50. }
  51. }
  52. string PropertyReport::distr::get()
  53. {
  54. string s = "";
  55. for(unsigned i = 0; i < _range.size(); ++i)
  56. {
  57. if (i != 0)
  58. {
  59. s += ",";
  60. }
  61. s = s + TC_Common::tostr(_range[i]) + "|" + TC_Common::tostr(_result[i]);
  62. }
  63. for(unsigned i = 0; i < _result.size(); ++i)
  64. {
  65. _result[i] = 0;
  66. }
  67. return s;
  68. }
  69. string PropertyReport::max::get()
  70. {
  71. string s = TC_Common::tostr(_d);
  72. clear();
  73. return s;
  74. }
  75. string PropertyReport::min::get()
  76. {
  77. string s = TC_Common::tostr(_d);
  78. clear();
  79. return s;
  80. }
  81. void PropertyReport::min::set(int o)
  82. {
  83. //非0最小值
  84. if(_d == 0 ||(_d > o && o != 0))
  85. {
  86. _d = o;
  87. }
  88. }
  89. string PropertyReport::count::get()
  90. {
  91. string s = TC_Common::tostr(_d);
  92. clear();
  93. return s;
  94. }
  95. ///////////////////////////////////////////////
  96. }