ratio.php 1015 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace refill;
  3. class ratio
  4. {
  5. private $mCommitSucc;
  6. private $mCommitFail;
  7. private $mNotifySucc;
  8. private $mNotifyFail;
  9. public function __construct()
  10. {
  11. $this->mCommitSucc = 0;
  12. $this->mCommitFail = 0;
  13. $this->mNotifySucc = 0;
  14. $this->mNotifyFail = 0;
  15. }
  16. public function update(array $data)
  17. {
  18. $this->mCommitSucc = $data[0];
  19. $this->mCommitFail = $data[1];
  20. $this->mNotifySucc = $data[2];
  21. $this->mNotifyFail = $data[3];
  22. }
  23. public function commit_ratio()
  24. {
  25. $count = $this->mCommitSucc + $this->mCommitFail;
  26. if($count > 0) {
  27. return [true,$this->mCommitSucc / $count];
  28. } else {
  29. return [false,0];
  30. }
  31. }
  32. public function notify_ratio()
  33. {
  34. $count = $this->mNotifySucc + $this->mNotifyFail;
  35. if($count > 0) {
  36. return [true,$this->mCommitSucc / $count];
  37. } else {
  38. return [false,0];
  39. }
  40. }
  41. }