Logging erweitert
This commit is contained in:
10
app.py
10
app.py
@@ -147,15 +147,23 @@ def stats():
|
||||
log_path = os.path.join('log', 'pageviews.log')
|
||||
pageviews = 0
|
||||
func_counts = {}
|
||||
impressions_per_day = {}
|
||||
if os.path.exists(log_path):
|
||||
with open(log_path, encoding='utf-8') as f:
|
||||
for line in f:
|
||||
if 'PAGEVIEW' in line:
|
||||
pageviews += 1
|
||||
# Datum extrahieren (YYYY-MM-DD)
|
||||
try:
|
||||
date = line[:10]
|
||||
if len(date) == 10 and date[4] == '-' and date[7] == '-':
|
||||
impressions_per_day[date] = impressions_per_day.get(date, 0) + 1
|
||||
except Exception:
|
||||
pass
|
||||
elif 'FUNC:' in line:
|
||||
func = line.split('FUNC:')[1].strip()
|
||||
func_counts[func] = func_counts.get(func, 0) + 1
|
||||
return render_template('stats_dashboard.html', pageviews=pageviews, func_counts=func_counts)
|
||||
return render_template('stats_dashboard.html', pageviews=pageviews, func_counts=func_counts, impressions_per_day=impressions_per_day)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@@ -21,12 +21,40 @@
|
||||
<div class="stats-label">Gesamt-Pageviews:</div>
|
||||
<div class="stats-value">{{ pageviews }}</div>
|
||||
</div>
|
||||
<div class="chart-container">
|
||||
<canvas id="imprChart" width="400" height="180"></canvas>
|
||||
</div>
|
||||
<div class="chart-container">
|
||||
<canvas id="funcChart" width="400" height="220"></canvas>
|
||||
</div>
|
||||
<a href="/" style="color:#2563eb;">Zurück zur App</a>
|
||||
</div>
|
||||
<script>
|
||||
// Impressions pro Tag
|
||||
const imprData = {{ impressions_per_day|tojson }};
|
||||
const imprLabels = Object.keys(imprData);
|
||||
const imprCounts = Object.values(imprData);
|
||||
new Chart(document.getElementById('imprChart').getContext('2d'), {
|
||||
type: 'line',
|
||||
data: {
|
||||
labels: imprLabels,
|
||||
datasets: [{
|
||||
label: 'Impressions/Tag',
|
||||
data: imprCounts,
|
||||
borderColor: '#059669',
|
||||
backgroundColor: 'rgba(5,150,105,0.1)',
|
||||
tension: 0.2,
|
||||
fill: true
|
||||
}]
|
||||
},
|
||||
options: {
|
||||
plugins: { legend: { display: true } },
|
||||
scales: {
|
||||
y: { beginAtZero: true, ticks: { stepSize: 1 } }
|
||||
}
|
||||
}
|
||||
});
|
||||
// Funktionsaufrufe
|
||||
const funcCounts = {{ func_counts|tojson }};
|
||||
const labels = Object.keys(funcCounts);
|
||||
const data = Object.values(funcCounts);
|
||||
|
Reference in New Issue
Block a user