|
17 | 17 | */
|
18 | 18 | $myrepo->getAllById('', '', $envId);
|
19 | 19 |
|
| 20 | +/** |
| 21 | + * Snapshot access stats |
| 22 | + */ |
| 23 | + |
20 | 24 | /**
|
21 | 25 | * If a filter has been selected for the main chart, the page is reloaded in the background by jquery and retrieves the chart data from the selected filter
|
22 | 26 | */
|
23 |
| -if (!empty($_GET['repo_access_chart_filter'])) { |
24 |
| - if (\Controllers\Common::validateData($_GET['repo_access_chart_filter']) == "1week") { |
25 |
| - $repo_access_chart_filter = "1week"; |
| 27 | +if (!empty($_GET['chartFilter'])) { |
| 28 | + if (\Controllers\Common::validateData($_GET['chartFilter']) == "1week") { |
| 29 | + $chartFilter = "1week"; |
26 | 30 | }
|
27 |
| - if (\Controllers\Common::validateData($_GET['repo_access_chart_filter']) == "1month") { |
28 |
| - $repo_access_chart_filter = "1month"; |
| 31 | + if (\Controllers\Common::validateData($_GET['chartFilter']) == "1month") { |
| 32 | + $chartFilter = "1month"; |
29 | 33 | }
|
30 |
| - if (\Controllers\Common::validateData($_GET['repo_access_chart_filter']) == "3months") { |
31 |
| - $repo_access_chart_filter = "3months"; |
| 34 | + if (\Controllers\Common::validateData($_GET['chartFilter']) == "3months") { |
| 35 | + $chartFilter = "3months"; |
32 | 36 | }
|
33 |
| - if (\Controllers\Common::validateData($_GET['repo_access_chart_filter']) == "6months") { |
34 |
| - $repo_access_chart_filter = "6months"; |
| 37 | + if (\Controllers\Common::validateData($_GET['chartFilter']) == "6months") { |
| 38 | + $chartFilter = "6months"; |
35 | 39 | }
|
36 |
| - if (\Controllers\Common::validateData($_GET['repo_access_chart_filter']) == "1year") { |
37 |
| - $repo_access_chart_filter = "1year"; |
| 40 | + if (\Controllers\Common::validateData($_GET['chartFilter']) == "1year") { |
| 41 | + $chartFilter = "1year"; |
38 | 42 | }
|
39 | 43 | }
|
| 44 | + |
| 45 | +/** |
| 46 | + * Retrieve last access logs from database |
| 47 | + */ |
| 48 | +if ($myrepo->getPackageType() == 'rpm') { |
| 49 | + $lastAccess = $mystats->getLastAccess($myrepo->getName(), '', '', $myrepo->getEnv()); |
| 50 | +} |
| 51 | +if ($myrepo->getPackageType() == 'deb') { |
| 52 | + $lastAccess = $mystats->getLastAccess($myrepo->getName(), $myrepo->getDist(), $myrepo->getSection(), $myrepo->getEnv()); |
| 53 | +} |
| 54 | + |
| 55 | +/** |
| 56 | + * Sort by date and time |
| 57 | + */ |
| 58 | +if (!empty($lastAccess)) { |
| 59 | + array_multisort(array_column($lastAccess, 'Date'), SORT_DESC, array_column($lastAccess, 'Time'), SORT_DESC, $lastAccess); |
| 60 | +} |
| 61 | + |
| 62 | +/** |
| 63 | + * Count repo size and packages count |
| 64 | + */ |
| 65 | +if ($myrepo->getPackageType() == 'rpm') { |
| 66 | + $repoSize = \Controllers\Filesystem\Directory::getSize(REPOS_DIR . '/' . $myrepo->getDateFormatted() . '_' . $myrepo->getName()); |
| 67 | + $packagesCount = count(\Controllers\Common::findRecursive(REPOS_DIR . '/' . $myrepo->getDateFormatted() . '_' . $myrepo->getName(), 'rpm')); |
| 68 | +} |
| 69 | +if ($myrepo->getPackageType() == 'deb') { |
| 70 | + $repoSize = \Controllers\Filesystem\Directory::getSize(REPOS_DIR . '/' . $myrepo->getName() . '/' . $myrepo->getDist() . '/' . $myrepo->getDateFormatted() . '_' . $myrepo->getSection()); |
| 71 | + $packagesCount = count(\Controllers\Common::findRecursive(REPOS_DIR . '/' . $myrepo->getName() . '/' . $myrepo->getDist() . '/' . $myrepo->getDateFormatted() . '_' . $myrepo->getSection(), 'deb')); |
| 72 | +} |
| 73 | + |
| 74 | +/** |
| 75 | + * Convert repo size in the most suitable byte format |
| 76 | + */ |
| 77 | +$repoSize = \Controllers\Common::sizeFormat($repoSize); |
| 78 | + |
| 79 | +/** |
| 80 | + * If no filter has been selected by the user then we set it to 1 week by default |
| 81 | + */ |
| 82 | +if (empty($chartFilter)) { |
| 83 | + $chartFilter = "1week"; |
| 84 | +} |
| 85 | + |
| 86 | +/** |
| 87 | + * Initialize the starting date of the chart, according to the selected filter |
| 88 | + */ |
| 89 | +if ($chartFilter == "1week") { |
| 90 | + // the beginning of the counter starts at the current date -1 week. |
| 91 | + $dateCounter = date('Y-m-d', strtotime('-1 week', strtotime(DATE_YMD))); |
| 92 | +} |
| 93 | +if ($chartFilter == "1month") { |
| 94 | + // the beginning of the counter starts at the current date -1 month. |
| 95 | + $dateCounter = date('Y-m-d', strtotime('-1 month', strtotime(DATE_YMD))); |
| 96 | +} |
| 97 | +if ($chartFilter == "3months") { |
| 98 | + // the beginning of the counter starts at the current date -3 months. |
| 99 | + $dateCounter = date('Y-m-d', strtotime('-3 months', strtotime(DATE_YMD))); |
| 100 | +} |
| 101 | +if ($chartFilter == "6months") { |
| 102 | + // the beginning of the counter starts at the current date -6 months. |
| 103 | + $dateCounter = date('Y-m-d', strtotime('-6 months', strtotime(DATE_YMD))); |
| 104 | +} |
| 105 | +if ($chartFilter == "1year") { |
| 106 | + // the beginning of the counter starts at the current date -1 year. |
| 107 | + $dateCounter = date('Y-m-d', strtotime('-1 year', strtotime(DATE_YMD))); |
| 108 | +} |
| 109 | + |
| 110 | +$repoAccessChartLabels = ''; |
| 111 | +$repoAccessChartData = ''; |
| 112 | + |
| 113 | +/** |
| 114 | + * Process all dates until the current date (which is also processed) |
| 115 | + */ |
| 116 | +while ($dateCounter != date('Y-m-d', strtotime('+1 day', strtotime(DATE_YMD)))) { |
| 117 | + if ($myrepo->getPackageType() == 'rpm') { |
| 118 | + $dateAccessCount = $mystats->getDailyAccessCount($myrepo->getName(), '', '', $myrepo->getEnv(), $dateCounter); |
| 119 | + } |
| 120 | + if ($myrepo->getPackageType() == 'deb') { |
| 121 | + $dateAccessCount = $mystats->getDailyAccessCount($myrepo->getName(), $myrepo->getDist(), $myrepo->getSection(), $myrepo->getEnv(), $dateCounter); |
| 122 | + } |
| 123 | + |
| 124 | + if (!empty($dateAccessCount)) { |
| 125 | + $repoAccessChartData .= $dateAccessCount . ', '; |
| 126 | + } else { |
| 127 | + $repoAccessChartData .= '0, '; |
| 128 | + } |
| 129 | + |
| 130 | + /** |
| 131 | + * Add the current date to the labels |
| 132 | + */ |
| 133 | + $repoAccessChartLabels .= "'$dateCounter', "; |
| 134 | + |
| 135 | + /** |
| 136 | + * Increment by 1 day to be able to process the next date |
| 137 | + */ |
| 138 | + $dateCounter = date('Y-m-d', strtotime('+1 day', strtotime($dateCounter))); |
| 139 | +} |
| 140 | + |
| 141 | +/** |
| 142 | + * Remove the last comma |
| 143 | + */ |
| 144 | +$repoAccessChartLabels = rtrim($repoAccessChartLabels, ', '); |
| 145 | +$repoAccessChartData = rtrim($repoAccessChartData, ', '); |
| 146 | + |
| 147 | +/** |
| 148 | + * Snapshot size stats |
| 149 | + */ |
| 150 | + |
| 151 | +/** |
| 152 | + * Get stats for the last 60 days |
| 153 | + */ |
| 154 | +$stats = $mystats->getAll($myrepo->getEnvId()); |
| 155 | +$envSizeStats = $mystats->getEnvSize($myrepo->getEnvId(), 60); |
| 156 | + |
| 157 | +if (!empty($envSizeStats)) { |
| 158 | + $sizeDateLabels = ''; |
| 159 | + $sizeData = ''; |
| 160 | + |
| 161 | + foreach ($envSizeStats as $stat) { |
| 162 | + $date = DateTime::createFromFormat('Y-m-d', $stat['Date'])->format('d-m-Y'); |
| 163 | + |
| 164 | + // Convert bytes to MB |
| 165 | + $size = round(round($stat['Size'] / 1024) / 1024); |
| 166 | + |
| 167 | + /** |
| 168 | + * Build data for chart |
| 169 | + */ |
| 170 | + $sizeDateLabels .= '"' . $date . '", '; |
| 171 | + $sizeData .= '"' . $size . '", '; |
| 172 | + } |
| 173 | + |
| 174 | + /** |
| 175 | + * Remove last comma |
| 176 | + */ |
| 177 | + $sizeDateLabels = rtrim($sizeDateLabels, ', '); |
| 178 | + $sizeData = rtrim($sizeData, ', '); |
| 179 | +} |
| 180 | + |
| 181 | +/** |
| 182 | + * Snapshot package count stats |
| 183 | + */ |
| 184 | + |
| 185 | +$pkgCountStats = $mystats->getPkgCount($myrepo->getEnvId(), 60); |
| 186 | + |
| 187 | +if (!empty($pkgCountStats)) { |
| 188 | + $countDateLabels = ''; |
| 189 | + $countData = ''; |
| 190 | + |
| 191 | + foreach ($pkgCountStats as $stat) { |
| 192 | + $date = DateTime::createFromFormat('Y-m-d', $stat['Date'])->format('d-m-Y'); |
| 193 | + $count = $stat['Packages_count']; |
| 194 | + |
| 195 | + /** |
| 196 | + * Build data for chart |
| 197 | + */ |
| 198 | + $countDateLabels .= '"' . $date . '", '; |
| 199 | + $countData .= '"' . $count . '", '; |
| 200 | + } |
| 201 | + |
| 202 | + /** |
| 203 | + * Remove last comma |
| 204 | + */ |
| 205 | + $countDateLabels = rtrim($countDateLabels, ', '); |
| 206 | + $countData = rtrim($countData, ', '); |
| 207 | +} |
0 commit comments