Logging erweitert

This commit is contained in:
2025-07-23 11:29:47 +02:00
parent 09cf3706e4
commit 5c4f419895
2 changed files with 37 additions and 1 deletions

10
app.py
View File

@@ -147,15 +147,23 @@ def stats():
log_path = os.path.join('log', 'pageviews.log') log_path = os.path.join('log', 'pageviews.log')
pageviews = 0 pageviews = 0
func_counts = {} func_counts = {}
impressions_per_day = {}
if os.path.exists(log_path): if os.path.exists(log_path):
with open(log_path, encoding='utf-8') as f: with open(log_path, encoding='utf-8') as f:
for line in f: for line in f:
if 'PAGEVIEW' in line: if 'PAGEVIEW' in line:
pageviews += 1 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: elif 'FUNC:' in line:
func = line.split('FUNC:')[1].strip() func = line.split('FUNC:')[1].strip()
func_counts[func] = func_counts.get(func, 0) + 1 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__': if __name__ == '__main__':

View File

@@ -21,12 +21,40 @@
<div class="stats-label">Gesamt-Pageviews:</div> <div class="stats-label">Gesamt-Pageviews:</div>
<div class="stats-value">{{ pageviews }}</div> <div class="stats-value">{{ pageviews }}</div>
</div> </div>
<div class="chart-container">
<canvas id="imprChart" width="400" height="180"></canvas>
</div>
<div class="chart-container"> <div class="chart-container">
<canvas id="funcChart" width="400" height="220"></canvas> <canvas id="funcChart" width="400" height="220"></canvas>
</div> </div>
<a href="/" style="color:#2563eb;">Zurück zur App</a> <a href="/" style="color:#2563eb;">Zurück zur App</a>
</div> </div>
<script> <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 funcCounts = {{ func_counts|tojson }};
const labels = Object.keys(funcCounts); const labels = Object.keys(funcCounts);
const data = Object.values(funcCounts); const data = Object.values(funcCounts);