Repository navigation
Expand file tree
/
Copy pathstatistics.php
More file actions
101 lines (89 loc) · 3.32 KB
/
Copy pathstatistics.php
File metadata and controls
101 lines (89 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
require_once 'includes/database.php';
require_once 'includes/header.php';
require_once 'classes/TeaAnalyzer.class.php';
$current_year = (int) date('Y');
$year = isset($_GET['year']) ? (int) $_GET['year'] : $current_year;
if ($year < 2000 || $year > $current_year + 1)
$year = $current_year;
$result = $mysqli->query("SELECT * FROM teas WHERE YEAR(drink_date) = $year ORDER BY drink_date");
$teas_data = [];
while ($row = $result->fetch_assoc()) {
$teas_data[] = $row;
}
$analyzer = new TeaAnalyzer($teas_data, $year);
$averages = $analyzer->getDailyAverages();
$most_popular = $analyzer->getMostPopularDay();
$monthly_stats = $analyzer->getMonthlyStats();
$top_brands = $analyzer->getTopBrands(5);
$flavor_stats = $analyzer->getFlavorStats();
?>
<h2>Tea Statistics</h2>
<div class="cal-year-nav">
<a href="statistics.php?year=<?php echo $year - 1; ?>" class="cal-year-btn">« <?php echo $year - 1; ?></a>
<span class="cal-year-current"><?php echo $year; ?></span>
<a href="statistics.php?year=<?php echo $year + 1; ?>" class="cal-year-btn"><?php echo $year + 1; ?> »</a>
</div>
<h3>Overall — <?php echo $year; ?></h3>
<p>Total teas: <?php echo $averages['total_teas']; ?></p>
<p>Days with tea: <?php echo $averages['total_days']; ?></p>
<p>Average teas per tea day: <?php echo $averages['avg_per_day']; ?></p>
<?php if ($most_popular): ?>
<p>Most teas in one day: <?php echo $most_popular['count']; ?> on <?php echo htmlspecialchars($most_popular['date']); ?>
</p>
<?php endif; ?>
<?php if (empty($teas_data)): ?>
<p><em>No tea data found for <?php echo $year; ?>.</em></p>
<?php else: ?>
<div class="stats-grid">
<div>
<h3>Top 5 Brands</h3>
<table>
<tr>
<th>Brand</th>
<th>Teas</th>
</tr>
<?php foreach ($top_brands as $brand => $count): ?>
<tr>
<td><?php echo htmlspecialchars($brand); ?></td>
<td><?php echo $count; ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
<div>
<h3>Monthly Distribution</h3>
<table>
<tr>
<th>Month</th>
<th>Teas</th>
</tr>
<?php for ($month = 1; $month <= 12; $month++): ?>
<tr>
<td><?php echo date('F', mktime(0, 0, 0, $month, 1)); ?></td>
<td><?php echo $monthly_stats[$month]; ?></td>
</tr>
<?php endfor; ?>
</table>
</div>
<div>
<h3>Top 10 Flavors</h3>
<table>
<tr>
<th>Flavor</th>
<th>Count</th>
</tr>
<?php $counter = 0;
foreach ($flavor_stats as $flavor => $count):
if ($counter++ >= 10)
break; ?>
<tr>
<td><?php echo htmlspecialchars($flavor); ?></td>
<td><?php echo $count; ?></td>
</tr>
<?php endforeach; ?>
</table>
</div>
</div>
<?php endif; ?>
<?php require_once 'includes/footer.php'; ?>