Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 110 |
|
0.00% |
0 / 33 |
CRAP | |
0.00% |
0 / 1 |
| StoreStat | |
0.00% |
0 / 110 |
|
0.00% |
0 / 33 |
2162 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| createStoreStat | |
0.00% |
0 / 78 |
|
0.00% |
0 / 1 |
210 | |||
| getSecondsFromADifference | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setAvgDelay | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAvgDelay | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setAvgPerContainer | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAvgPerContainer | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setAvgTotal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAvgTotal | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setBuysStranded | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getBuysStranded | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setDate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setFirstBuy | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFirstBuy | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setLastBuy | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getLastBuy | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setNumBuys | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getNumBuys | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setNumContainers | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getNumContainers | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setUniqueCustomers | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUniqueCustomers | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getNumBuyers | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setNumBuyers | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getSortDelay | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setSortDelay | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getSortTime | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setSortTime | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTypeNum | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setTypeNum | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\Core; |
| 4 | |
| 5 | class StoreStat extends Store { |
| 6 | public $id; |
| 7 | public $date; |
| 8 | public $avgDelay; |
| 9 | public $sortDelay; |
| 10 | public $sortTime; |
| 11 | public $avgTotal; |
| 12 | public $avgPerContainer; |
| 13 | public $numBuys; |
| 14 | public $numContainers; |
| 15 | public $numBuyers; |
| 16 | public $firstBuy; |
| 17 | public $lastBuy; |
| 18 | public $buysStranded; |
| 19 | public $uniqueCustomers; |
| 20 | public $typeNum; |
| 21 | |
| 22 | public function __construct() { |
| 23 | parent::__construct(); |
| 24 | } |
| 25 | |
| 26 | public function createStoreStat($dailyStats) { |
| 27 | $totalSeconds = 0; |
| 28 | $sortSeconds = 0; |
| 29 | $sortDelay = 0; |
| 30 | $totalContainers = 0; |
| 31 | $totalBuys = count($dailyStats); |
| 32 | $totalDelaySeconds = 0; |
| 33 | $isFirst = true; |
| 34 | $count = 0; |
| 35 | $customersIDArray = array(); |
| 36 | $buyerIDArray = array(); |
| 37 | $totalContainers = 0; |
| 38 | $buysThatCount = 0; |
| 39 | |
| 40 | foreach ($dailyStats as $buy) { |
| 41 | $sorted = 0; |
| 42 | $timeStarted = new \DateTime($buy['timeStarted']); |
| 43 | $timeCompleted = new \DateTime($buy['timeCompleted']); |
| 44 | $timeEntered = new \DateTime($buy['timeEntered']); |
| 45 | $sortStarted = new \DateTime($buy['sortStarted']); |
| 46 | $sortCompleted = new \DateTime($buy['sortCompleted']); |
| 47 | |
| 48 | $dateRange = getDateRange($timeEntered->format("Y-m-d H:i:s")); |
| 49 | |
| 50 | |
| 51 | if($isFirst) { |
| 52 | $this->setFirstBuy($timeEntered); |
| 53 | $isFirst = false; |
| 54 | $dateStart = $dateRange['dateStart']; |
| 55 | } |
| 56 | if($count+1 == $totalBuys) { |
| 57 | $this->setLastBuy($timeEntered); |
| 58 | } |
| 59 | if($buy['timeCompleted'] == "0000-00-00 00:00:00") { |
| 60 | $this->buysStranded++; |
| 61 | } elseif($timeCompleted < $dateRange['dateEnd']) { |
| 62 | $buysThatCount++; |
| 63 | $diffStartedCompleted = $timeCompleted->diff($timeStarted); |
| 64 | //This buy was sorted so we have to change the stats accordingly. |
| 65 | if($buy['sortCompleted'] !== "0000-00-00 00:00:00") { |
| 66 | $sorted = 1; |
| 67 | $diffSorts = $sortCompleted->diff($sortStarted); |
| 68 | $diffEnteredStarted = $timeStarted->diff($sortCompleted); |
| 69 | $diffSortDelay= $sortStarted->diff($timeEntered); |
| 70 | if($buy['remainingContainers'] > 0) { |
| 71 | $totalContainers += (int)$buy['remainingContainers']; |
| 72 | } else { |
| 73 | $totalContainers += (int)$buy['numContainers']; |
| 74 | } |
| 75 | |
| 76 | |
| 77 | $sortDelay += $this->getSecondsFromADifference($diffSortDelay); |
| 78 | $sortSeconds += $this->getSecondsFromADifference($diffSorts); |
| 79 | $totalSeconds += $this->getSecondsFromADifference($diffStartedCompleted); |
| 80 | $totalDelaySeconds += $this->getSecondsFromADifference($diffEnteredStarted); |
| 81 | } else { |
| 82 | $totalContainers += (int)$buy['numContainers']; |
| 83 | //This buy was not sorted |
| 84 | $diffEnteredStarted = $timeStarted->diff($timeEntered); |
| 85 | $totalSeconds += $this->getSecondsFromADifference($diffStartedCompleted); |
| 86 | $totalDelaySeconds += $this->getSecondsFromADifference($diffEnteredStarted); |
| 87 | } |
| 88 | |
| 89 | if(!in_array($buy['buyerID'], $buyerIDArray)) { |
| 90 | $buyerIDArray[] = $buy['buyerID']; |
| 91 | } |
| 92 | } |
| 93 | if(!in_array($buy['customerID'], $customersIDArray)) { |
| 94 | $customersIDArray[] = $buy['customerID']; |
| 95 | } |
| 96 | |
| 97 | $count++; |
| 98 | } |
| 99 | if(isset($dateStart)) { |
| 100 | $this->setDate($dateStart); |
| 101 | } |
| 102 | if($buysThatCount > 0 && $totalContainers > 0) { |
| 103 | $avgDelay = floor($totalDelaySeconds / $buysThatCount); |
| 104 | $avgTotal = floor($totalSeconds / $buysThatCount); |
| 105 | $avgPerContainer = floor($totalSeconds / $totalContainers); |
| 106 | $uniqueCustomers = count($customersIDArray); |
| 107 | $avgSortTime = floor($sortSeconds / $buysThatCount); |
| 108 | $avgSortDelay = round($sortDelay / $buysThatCount); |
| 109 | } else { |
| 110 | $avgDelay = 0; |
| 111 | $avgTotal = 0; |
| 112 | $avgPerContainer = 0; |
| 113 | $uniqueCustomers = 0; |
| 114 | $avgSortTime = 0; |
| 115 | $avgSortDelay = 0; |
| 116 | } |
| 117 | if(!$this->buysStranded > 0) { |
| 118 | $this->buysStranded = 0; |
| 119 | } |
| 120 | |
| 121 | |
| 122 | $this->setAvgDelay($avgDelay); |
| 123 | $this->setAvgTotal($avgTotal); |
| 124 | $this->setSortDelay($avgSortDelay); |
| 125 | $this->setSortTime($avgSortTime); |
| 126 | $this->setAvgPerContainer($avgPerContainer); |
| 127 | $this->setNumBuys($buysThatCount); |
| 128 | $this->setNumContainers($totalContainers); |
| 129 | $this->setUniqueCustomers($uniqueCustomers); |
| 130 | $this->numBuyers = count($buyerIDArray); |
| 131 | |
| 132 | } |
| 133 | private function getSecondsFromADifference($diff) { |
| 134 | return ((int)$diff->format('%h') * 60 * 60) + ((int)$diff->format('%i') * 60) + ((int)$diff->format('%s')); |
| 135 | } |
| 136 | |
| 137 | |
| 138 | public function setAvgDelay($avgDelay) |
| 139 | { |
| 140 | $this->avgDelay = $avgDelay; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * @return mixed |
| 145 | */ |
| 146 | public function getAvgDelay() |
| 147 | { |
| 148 | return $this->avgDelay; |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * @param mixed $avgPerContainer |
| 153 | */ |
| 154 | public function setAvgPerContainer($avgPerContainer) |
| 155 | { |
| 156 | $this->avgPerContainer = $avgPerContainer; |
| 157 | } |
| 158 | |
| 159 | /** |
| 160 | * @return mixed |
| 161 | */ |
| 162 | public function getAvgPerContainer() |
| 163 | { |
| 164 | return $this->avgPerContainer; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * @param mixed $avgTotal |
| 169 | */ |
| 170 | public function setAvgTotal($avgTotal) |
| 171 | { |
| 172 | $this->avgTotal = $avgTotal; |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * @return mixed |
| 177 | */ |
| 178 | public function getAvgTotal() |
| 179 | { |
| 180 | return $this->avgTotal; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * @param mixed $buysStranded |
| 185 | */ |
| 186 | public function setBuysStranded($buysStranded) |
| 187 | { |
| 188 | $this->buysStranded = $buysStranded; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * @return mixed |
| 193 | */ |
| 194 | public function getBuysStranded() |
| 195 | { |
| 196 | return $this->buysStranded; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * @param mixed $date |
| 201 | */ |
| 202 | public function setDate($date) |
| 203 | { |
| 204 | $this->date = $date; |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * @return mixed |
| 209 | */ |
| 210 | public function getDate() |
| 211 | { |
| 212 | return $this->date; |
| 213 | } |
| 214 | |
| 215 | /** |
| 216 | * @param mixed $firstBuy |
| 217 | */ |
| 218 | public function setFirstBuy($firstBuy) |
| 219 | { |
| 220 | $this->firstBuy = $firstBuy; |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * @return mixed |
| 225 | */ |
| 226 | public function getFirstBuy() |
| 227 | { |
| 228 | return $this->firstBuy; |
| 229 | } |
| 230 | |
| 231 | /** |
| 232 | * @param mixed $id |
| 233 | */ |
| 234 | public function setId($id) |
| 235 | { |
| 236 | $this->id = $id; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * @return mixed |
| 241 | */ |
| 242 | public function getId() |
| 243 | { |
| 244 | return $this->id; |
| 245 | } |
| 246 | |
| 247 | /** |
| 248 | * @param mixed $lastBuy |
| 249 | */ |
| 250 | public function setLastBuy($lastBuy) |
| 251 | { |
| 252 | $this->lastBuy = $lastBuy; |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * @return mixed |
| 257 | */ |
| 258 | public function getLastBuy() |
| 259 | { |
| 260 | return $this->lastBuy; |
| 261 | } |
| 262 | |
| 263 | /** |
| 264 | * @param mixed $numBuys |
| 265 | */ |
| 266 | public function setNumBuys($numBuys) |
| 267 | { |
| 268 | $this->numBuys = $numBuys; |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * @return mixed |
| 273 | */ |
| 274 | public function getNumBuys() |
| 275 | { |
| 276 | return $this->numBuys; |
| 277 | } |
| 278 | |
| 279 | /** |
| 280 | * @param mixed $numContainers |
| 281 | */ |
| 282 | public function setNumContainers($numContainers) |
| 283 | { |
| 284 | $this->numContainers = $numContainers; |
| 285 | } |
| 286 | |
| 287 | /** |
| 288 | * @return mixed |
| 289 | */ |
| 290 | public function getNumContainers() |
| 291 | { |
| 292 | return $this->numContainers; |
| 293 | } |
| 294 | |
| 295 | /** |
| 296 | * @param mixed $uniqueCustomers |
| 297 | */ |
| 298 | public function setUniqueCustomers($uniqueCustomers) |
| 299 | { |
| 300 | $this->uniqueCustomers = $uniqueCustomers; |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * @return mixed |
| 305 | */ |
| 306 | public function getUniqueCustomers() |
| 307 | { |
| 308 | return $this->uniqueCustomers; |
| 309 | } |
| 310 | |
| 311 | /** |
| 312 | * @return mixed |
| 313 | */ |
| 314 | public function getNumBuyers() |
| 315 | { |
| 316 | return $this->numBuyers; |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * @param mixed $numBuyers |
| 321 | */ |
| 322 | public function setNumBuyers($numBuyers) |
| 323 | { |
| 324 | $this->numBuyers = $numBuyers; |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * @return mixed |
| 329 | */ |
| 330 | public function getSortDelay() |
| 331 | { |
| 332 | return $this->sortDelay; |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * @param mixed $sortDelay |
| 337 | */ |
| 338 | public function setSortDelay($sortDelay) |
| 339 | { |
| 340 | $this->sortDelay = $sortDelay; |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * @return mixed |
| 345 | */ |
| 346 | public function getSortTime() |
| 347 | { |
| 348 | return $this->sortTime; |
| 349 | } |
| 350 | |
| 351 | /** |
| 352 | * @param mixed $sortTime |
| 353 | */ |
| 354 | public function setSortTime($sortTime) |
| 355 | { |
| 356 | $this->sortTime = $sortTime; |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * @return mixed |
| 361 | */ |
| 362 | public function getTypeNum() |
| 363 | { |
| 364 | return $this->typeNum; |
| 365 | } |
| 366 | |
| 367 | /** |
| 368 | * @param mixed $typeNum |
| 369 | */ |
| 370 | public function setTypeNum($typeNum) |
| 371 | { |
| 372 | $this->typeNum = $typeNum; |
| 373 | } |
| 374 | |
| 375 | |
| 376 | } |