ctl_itemex.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace refill;
  3. class ctl_itemex
  4. {
  5. const feed_threshold = 2;
  6. private $mName;
  7. private $mCardType;
  8. private $mAmount;
  9. private $mQuality;
  10. private $mMaxSpeed;
  11. private $mPrefix;
  12. private $mPriority;
  13. private $mStorge;
  14. private $mOpened;
  15. private $mPrice;
  16. private $mSpeed;
  17. private $mRatio;
  18. private $mRatioCommit;
  19. private $mNotifyTime;
  20. private $mMonitorCommit;
  21. public function __construct($chname, $card_type, $amount, $max_speed, $priority, $storge, $opened, $quality)
  22. {
  23. $this->mPrefix = "{$chname}-{$quality}-{$card_type}-{$amount}";
  24. $this->mName = $chname;
  25. $this->mCardType = $card_type;
  26. $this->mAmount = $amount;
  27. $this->mQuality = $quality;
  28. $this->mMaxSpeed = $max_speed;
  29. $this->mPriority = $priority;
  30. $this->mStorge = $storge;
  31. $this->mOpened = $opened;
  32. $this->mPrice = 0.0;
  33. $this->mSpeed = 0;
  34. $this->mRatio =0.0;
  35. $this->mRatioCommit = 0;
  36. $this->mNotifyTime = 0;
  37. $this->mMonitorCommit = 0;
  38. }
  39. public function name()
  40. {
  41. return $this->mName;
  42. }
  43. public function priority()
  44. {
  45. return $this->mPriority;
  46. }
  47. public function storge()
  48. {
  49. return $this->mStorge;
  50. }
  51. public function opened()
  52. {
  53. return $this->mOpened;
  54. }
  55. public function quality()
  56. {
  57. return $this->mQuality;
  58. }
  59. public function spec()
  60. {
  61. return $this->mAmount;
  62. }
  63. public function card_type()
  64. {
  65. return $this->mCardType;
  66. }
  67. public function set_price($price)
  68. {
  69. $this->mPrice = $price;
  70. }
  71. public function price()
  72. {
  73. return $this->mPrice;
  74. }
  75. public function prefix() {
  76. return $this->mPrefix;
  77. }
  78. public function update_params($parms)
  79. {
  80. [$this->mSpeed, $this->mRatio, $this->mRatioCommit, $this->mNotifyTime,$this->mMonitorCommit] = $parms;
  81. if($this->mNotifyTime == 0) {
  82. $this->mNotifyTime = 1;
  83. }
  84. }
  85. public function max_speed()
  86. {
  87. return $this->mMaxSpeed;
  88. }
  89. public function speed_overload(): bool
  90. {
  91. if ($this->mMaxSpeed < 0) {
  92. return false;
  93. } elseif ($this->mMaxSpeed == 0) {
  94. return true;
  95. } else {
  96. return $this->mSpeed >= $this->mMaxSpeed;
  97. }
  98. }
  99. public function cur_speed()
  100. {
  101. return $this->mSpeed;
  102. }
  103. public function notify_ratio() {
  104. return $this->mRatio;
  105. }
  106. public function submits() {
  107. return $this->mRatioCommit;
  108. }
  109. public function notify_time() {
  110. return $this->mNotifyTime;
  111. }
  112. public function need_feed()
  113. {
  114. if(self::feed_threshold >= $this->mMaxSpeed) {
  115. return $this->mMonitorCommit < $this->mMaxSpeed;
  116. } else {
  117. return $this->mMonitorCommit < self::feed_threshold;
  118. }
  119. }
  120. public function compile_val($profit_ratio)
  121. {
  122. $val = $this->mRatio * $profit_ratio * 100 / $this->mNotifyTime;
  123. return round($val,5);
  124. }
  125. }