Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 115 |
|
0.00% |
0 / 24 |
CRAP | |
0.00% |
0 / 1 |
| BuyReport | |
0.00% |
0 / 115 |
|
0.00% |
0 / 24 |
1560 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| setDates | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getAllDays | |
0.00% |
0 / 38 |
|
0.00% |
0 / 1 |
72 | |||
| getBuyTimesByDay | |
0.00% |
0 / 37 |
|
0.00% |
0 / 1 |
42 | |||
| getAvgBuysPerHour | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| getMinMaxTime | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| getEndDate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setEndDate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFriday | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setFriday | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getMonday | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setMonday | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getSaturday | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setSaturday | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getStartDate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setStartDate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getSunday | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setSunday | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getThursday | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setThursday | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTuesday | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setTuesday | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getWednesday | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setWednesday | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\Core; |
| 4 | |
| 5 | class BuyReport extends Store { |
| 6 | |
| 7 | public $dateStart; |
| 8 | public $dateEnd; |
| 9 | private $db; |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | public function __construct($typeNum) { |
| 15 | parent::__construct(); |
| 16 | $this->createStore($typeNum); |
| 17 | $this->db = dbConnectByName($this->getDbName()); |
| 18 | } |
| 19 | public function setDates($dateStart, $dateEnd) { |
| 20 | $this->setStartDate(getDateRange($dateStart)); |
| 21 | $this->setEndDate(getDateRange($dateEnd)); |
| 22 | } |
| 23 | |
| 24 | public function getAllDays() |
| 25 | { |
| 26 | //Get an array that contains each day of the weeks total amount and the percent of the week it contains |
| 27 | $query = $this->db->query("SELECT timeEntered, buyID FROM buyQueue WHERE timeEntered BETWEEN '".$this->getStartDate()['dateStart']->format("Y-m-d H:i:s")."' AND '".$this->getEndDate()['dateEnd']->format("Y-m-d H:i:s")."'"); |
| 28 | $timesArray = [ |
| 29 | "Mon" => array(0,0,0), |
| 30 | "Tue" => array(0,0,0), |
| 31 | "Wed" => array(0,0,0), |
| 32 | "Thu" => array(0,0,0), |
| 33 | "Fri" => array(0,0,0), |
| 34 | "Sat" => array(0,0,0), |
| 35 | "Sun" => array(0,0,0) |
| 36 | ]; |
| 37 | $daysArray = [ |
| 38 | "Mon" => 0, |
| 39 | "Tue" => 0, |
| 40 | "Wed" => 0, |
| 41 | "Thu" => 0, |
| 42 | "Fri" => 0, |
| 43 | "Sat" => 0, |
| 44 | "Sun" => 0, |
| 45 | ]; |
| 46 | $currentDay = ""; |
| 47 | $totalBuys =0; |
| 48 | while($row = $query->fetch(\PDO::FETCH_ASSOC)) { |
| 49 | $timeEntered = new \DateTime($row['timeEntered'], new \DateTimeZone('utc')); |
| 50 | $timeEntered->setTimezone(new \DateTimeZone($this->getTimeZone())); |
| 51 | $thisDay = $timeEntered->format("D"); |
| 52 | if($currentDay == "" || $currentDay !== $thisDay) { |
| 53 | if($currentDay !== "") { |
| 54 | $daysArray[$currentDay]++; |
| 55 | } |
| 56 | $currentDay = $thisDay; |
| 57 | } |
| 58 | $timesArray[$thisDay][0]++; |
| 59 | $totalBuys++; |
| 60 | } |
| 61 | foreach($timesArray as $key => $day) { |
| 62 | if($totalBuys > 0 && $daysArray[$key] > 0) { |
| 63 | $timesArray[$key][1] = round(($timesArray[$key][0] / $totalBuys) * 100); |
| 64 | $timesArray[$key][2] = round($timesArray[$key][0] / $daysArray[$key]); |
| 65 | } else { |
| 66 | $timesArray[$key][1] = 0; |
| 67 | $timesArray[$key][2] = 0; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | return array($timesArray); |
| 72 | } |
| 73 | public function getBuyTimesByDay() { |
| 74 | $daysArray = [ |
| 75 | "Mon" => array(), |
| 76 | "Tue" => array(), |
| 77 | "Wed" => array(), |
| 78 | "Thu" => array(), |
| 79 | "Fri" => array(), |
| 80 | "Sat" => array(), |
| 81 | "Sun" => array() |
| 82 | ]; |
| 83 | $daysTotalArray = [ |
| 84 | "Mon" => 0, |
| 85 | "Tue" => 0, |
| 86 | "Wed" => 0, |
| 87 | "Thu" => 0, |
| 88 | "Fri" => 0, |
| 89 | "Sat" => 0, |
| 90 | "Sun" => 0 |
| 91 | ]; |
| 92 | $diff = $this->getStartDate()['dateStart']->diff($this->getEndDate()['dateEnd']); |
| 93 | $numDays = (int)$diff->format("%a"); |
| 94 | |
| 95 | //Build our array with the first time being our minimum time and max time being the maximum time there was a buy in any given day in this period |
| 96 | $minMax = $this->getMinMaxTime(); |
| 97 | foreach($daysArray as $key=>$day) { |
| 98 | for($i = (int)$minMax['min']; $i <= (int)$minMax['max']; $i++) { |
| 99 | $daysArray[$key][$i] = 0; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | $query = $this->db->query("SELECT timeEntered, buyID FROM buyQueue WHERE timeEntered BETWEEN '".$this->getStartDate()['dateStart']->format("Y-m-d H:i:s")."' AND '".$this->getEndDate()['dateEnd']->format("Y-m-d H:i:s")."'"); |
| 104 | $currentDay = ""; |
| 105 | while($row = $query->fetch(\PDO::FETCH_ASSOC)) { |
| 106 | $timeEntered = new \DateTime($row['timeEntered'], new \DateTimeZone('utc')); |
| 107 | $timeEntered->setTimezone(new \DateTimeZone($this->getTimeZone())); |
| 108 | $thisHour = (int)$timeEntered->format("H"); |
| 109 | $thisDay = $timeEntered->format("D"); |
| 110 | if($currentDay == "" || $thisDay !== $currentDay) { |
| 111 | $daysTotalArray[$thisDay]++; |
| 112 | $currentDay = $thisDay; |
| 113 | } |
| 114 | |
| 115 | $daysArray[$thisDay][$thisHour]++; |
| 116 | } |
| 117 | $daysArray = $this->getAvgBuysPerHour($daysArray, $daysTotalArray); |
| 118 | |
| 119 | |
| 120 | return $daysArray; |
| 121 | } |
| 122 | public function getAvgBuysPerHour($daysArray, $daysTotalArray) { |
| 123 | $log = new \KLogger($_ENV['LOG_DIR']."dev_log.txt",\KLogger::DEBUG); |
| 124 | foreach($daysArray as $dayKey => $day) { |
| 125 | $daySum = array_sum($day); |
| 126 | $log->LogDebug("Array Sum for (".$dayKey.") - ".$daySum); |
| 127 | foreach($day as $timeKey => $time) { |
| 128 | if($time > 0) { |
| 129 | //$log->LogDebug("Time Sum: ".$daysTotalArray[$dayKey]); |
| 130 | $daysArray[$dayKey][$timeKey] = round($time/$daysTotalArray[$dayKey]); |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | return $daysArray; |
| 135 | } |
| 136 | public function getMinMaxTime() { |
| 137 | $minMax = []; |
| 138 | $query = $this->db->query(" SELECT MIN( DATE_FORMAT( timeEntered, '%H' ) ) AS minTime, MAX( DATE_FORMAT( timeEntered, '%H' ) ) AS maxTime |
| 139 | FROM buyQueue |
| 140 | WHERE timeEntered |
| 141 | BETWEEN '".$this->getStartDate()['dateStart']->format("Y-m-d H:i:s")."' |
| 142 | AND '".$this->getEndDate()['dateEnd']->format("Y-m-d H:i:s")."' |
| 143 | "); |
| 144 | |
| 145 | $row = $query->fetch(\PDO::FETCH_ASSOC); |
| 146 | |
| 147 | $minMax['min'] = 0; |
| 148 | $minMax['max'] = 23; |
| 149 | |
| 150 | return $minMax; |
| 151 | } |
| 152 | /** |
| 153 | * @return mixed |
| 154 | */ |
| 155 | public function getEndDate() |
| 156 | { |
| 157 | return $this->endDate; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * @param mixed $endDate |
| 162 | */ |
| 163 | public function setEndDate($endDate) |
| 164 | { |
| 165 | $this->endDate = $endDate; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * @return mixed |
| 170 | */ |
| 171 | public function getFriday() |
| 172 | { |
| 173 | return $this->friday; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * @param mixed $friday |
| 178 | */ |
| 179 | public function setFriday($friday) |
| 180 | { |
| 181 | $this->friday = $friday; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * @return mixed |
| 186 | */ |
| 187 | public function getMonday() |
| 188 | { |
| 189 | return $this->monday; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * @param mixed $monday |
| 194 | */ |
| 195 | public function setMonday($monday) |
| 196 | { |
| 197 | $this->monday = $monday; |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * @return mixed |
| 202 | */ |
| 203 | public function getSaturday() |
| 204 | { |
| 205 | return $this->saturday; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * @param mixed $saturday |
| 210 | */ |
| 211 | public function setSaturday($saturday) |
| 212 | { |
| 213 | $this->saturday = $saturday; |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * @return mixed |
| 218 | */ |
| 219 | public function getStartDate() |
| 220 | { |
| 221 | return $this->startDate; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * @param mixed $startDate |
| 226 | */ |
| 227 | public function setStartDate($startDate) |
| 228 | { |
| 229 | $this->startDate = $startDate; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * @return mixed |
| 234 | */ |
| 235 | public function getSunday() |
| 236 | { |
| 237 | return $this->sunday; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * @param mixed $sunday |
| 242 | */ |
| 243 | public function setSunday($sunday) |
| 244 | { |
| 245 | $this->sunday = $sunday; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * @return mixed |
| 250 | */ |
| 251 | public function getThursday() |
| 252 | { |
| 253 | return $this->thursday; |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * @param mixed $thursday |
| 258 | */ |
| 259 | public function setThursday($thursday) |
| 260 | { |
| 261 | $this->thursday = $thursday; |
| 262 | } |
| 263 | |
| 264 | /** |
| 265 | * @return mixed |
| 266 | */ |
| 267 | public function getTuesday() |
| 268 | { |
| 269 | return $this->tuesday; |
| 270 | } |
| 271 | |
| 272 | /** |
| 273 | * @param mixed $tuesday |
| 274 | */ |
| 275 | public function setTuesday($tuesday) |
| 276 | { |
| 277 | $this->tuesday = $tuesday; |
| 278 | } |
| 279 | |
| 280 | /** |
| 281 | * @return mixed |
| 282 | */ |
| 283 | public function getWednesday() |
| 284 | { |
| 285 | return $this->wednesday; |
| 286 | } |
| 287 | |
| 288 | /** |
| 289 | * @param mixed $wednesday |
| 290 | */ |
| 291 | public function setWednesday($wednesday) |
| 292 | { |
| 293 | $this->wednesday = $wednesday; |
| 294 | } |
| 295 | |
| 296 | |
| 297 | |
| 298 | } |