man muste in twig etwas ändern und genau davon ist und war das statistig teil bestroffen.
ich msute auch einen abend programieren und debuggen bis das ging. das wird einige mehr betreffen das nutzen echt einige.
hier mein code überarbeitet in den zeilen mit {# Diagramm für Unterstützt durch #} ist hard codirt da die namen fest eingegeben werden und dann eine zahlenwert.
{% set sum = 0 %}
{% set count = 0 %}
{% set episodes_with_downloads = [] %}
{# Berechnung der Summe und Anzahl der Episoden #}
{% for episode in podcast.episodes %}
{% if episode.duration is defined and episode.duration.totalMilliseconds is defined %}
{% set sum = sum + episode.duration.totalMilliseconds %}
{% set count = count + 1 %}
{% endif %}
{% if episode.total_downloads|default(0) > 0 %}
{% set episodes_with_downloads = episodes_with_downloads|merge([episode]) %}
{% endif %}
{% endfor %}
<div class="podcast-summary">
<p>Bisher haben wir <span class="highlight">{{ count }}</span> Folgen veröffentlicht, die <span class="highlight">{{ (sum / count / 1000 / 60)|round(0, 'floor') }} Minuten</span> im Durchschnitt lang sind. Insgesamt haben wir schon <span class="highlight">{{ (sum / 1000 / 60)|round(0, 'floor') }} Minuten</span> gepodcastet, das sind <span class="highlight">{{ (sum / 1000 / 60 / 60)|round(2) }} Stunden</span>.</p>
</div>
<h2 class="podcast-heading">Aktuelle Folge</h2>
{% set latest = podcast.episodes[0] %}
<p class="podcast-text">Unsere aktuelle Folge (<a href="{{ latest.url }}"><b>{{ latest.title }}</b></a>) hat bisher <span class="highlight">{{ latest.total_downloads }} Downloads</span>. {% if not latest.meta('_podlove_downloads_2d') is empty %} In den ersten 48 Stunden waren es <b>{{ latest.meta('_podlove_downloads_2d') }} Abrufe</b>.{% endif %}</p>
<script src="https://unpkg.com/chartkick@4.0.4/dist/chartkick.js"></script>
<script src="https://unpkg.com/chart.js@3.3.2/dist/chart.js"></script>
<script src="https://unpkg.com/chartjs-adapter-date-fns@2.0.0/dist/chartjs-adapter-date-fns.bundle.js"></script>
<div id="all-episodes" class="chart-container"></div>
<script>
new Chartkick.ColumnChart("all-episodes", [
{% for episode in episodes_with_downloads|slice(-50,50) %}
["{{ episode.title|escape('js') }}", {{ episode.total_downloads|default(0) }}],
{% endfor %}
], {
colors: ["#4caf50"],
xtitle: "Episoden",
ytitle: "Downloads",
maxBarThickness: 50
});
</script>
<p class="podcast-text">Downloads der letzten 50 Folgen.</p>
<h3 class="podcast-heading">Beliebteste Folgen</h3>
<ul class="podcast-list">
{% for episode in episodes_with_downloads|sort((b, a) => a.total_downloads <=> b.total_downloads)|slice(0,5) %}
<li>
<a href="{{ episode.url }}"><b>{{ episode.title }}</b></a> – <span class="highlight">{{ episode.total_downloads }} Downloads</span>
</li>
{% endfor %}
</ul>
<h3 class="podcast-heading">Folgen mit Potential</h3>
<ul class="podcast-list">
{% for episode in episodes_with_downloads|sort((a, b) => a.total_downloads <=> b.total_downloads)|slice(0,5) %}
<li>
<a href="{{ episode.url }}"><b>{{ episode.title }}</b></a> – <span class="highlight">{{ episode.total_downloads }} Downloads</span>
</li>
{% endfor %}
</ul>
<h2 class="podcast-heading">Folgenlänge</h2>
<div id="episode-length" class="chart-container"></div>
<script>
new Chartkick.ColumnChart("episode-length", [
{% for episode in episodes_with_downloads|slice(-50,50) %}
["{{ episode.title|escape('js') }}", {{ (episode.duration.totalMilliseconds / 1000 / 60)|round(0, 'floor') }}],
{% endfor %}
], {
colors: ["#ff9800"],
xtitle: "Episoden",
ytitle: "Dauer (Minuten)",
maxBarThickness: 50
});
</script>
<p class="podcast-text">Folgenlänge der letzten 50 Folgen.</p>
<h3 class="podcast-heading">Längste Folgen</h3>
<ul class="podcast-list">
{% for episode in episodes_with_downloads|sort((b, a) => a.duration.totalMilliseconds <=> b.duration.totalMilliseconds)|slice(0,5) %}
<li>
<a href="{{ episode.url }}"><b>{{ episode.title }}</b></a> – <span class="highlight">{{ episode.duration.hours }}h {{ episode.duration.minutes }}m</span>
</li>
{% endfor %}
</ul>
<h3 class="podcast-heading">Kürzeste Folgen</h3>
<ul class="podcast-list">
{% for episode in episodes_with_downloads|sort((a, b) => a.duration.totalMilliseconds <=> b.duration.totalMilliseconds)|slice(0,5) %}
<li>
<a href="{{ episode.url }}"><b>{{ episode.title }}</b></a> – <span class="highlight">{{ episode.duration.hours }}h {{ episode.duration.minutes }}m</span>
</li>
{% endfor %}
</ul>
<h2 class="podcast-heading">Meist Diskutierte Folgen</h2>
<ul class="podcast-list">
{% for episode in podcast.episodes|sort((b, a) => a.post.comment_count <=> b.post.comment_count)|slice(0,5) %}
<li>
<a href="{{ episode.url }}#comments"><b>{{ episode.title }}</b></a> – <span class="highlight">{{ episode.post.comment_count }} Kommentare</span>
</li>
{% endfor %}
</ul>
{% set contributorCounts = {'Sascha': 0, 'Sarah': 0, 'Emtycee': 0, 'Notstrom': 0, 'Tobi': 0} %}
{% for episode in podcast.episodes %}
{% for contributor in episode.contributors %}
{% if contributor.name in contributorCounts|keys %}
{% set contributorCounts = contributorCounts|merge({ (contributor.name): (contributorCounts[contributor.name] + 1) }) %}
{% endif %}
{% endfor %}
{% endfor %}
<h2 class="podcast-heading">Beitragsanzahl der Moderatoren</h2>
{# Ausgabe der Zahlenwerte für Beitragsanzahl der Moderatoren #}
<ul class="podcast-list">
{% for name, count in contributorCounts %}
<li>{{ name }}: <span class="highlight">{{ count }}</span> Beiträge</li>
{% endfor %}
</ul>
{# Diagramm für Beitragsanzahl der Moderatoren #}
<div id="contributor-chart" class="chart-container"></div>
<script>
new Chartkick.PieChart("contributor-chart", [
{% for name, count in contributorCounts %}
["{{ name }}", {{ count }}],
{% endfor %}
], {
colors: [
"#2196f3", // Blau
"#e91e63", // Rosa
"#ffc107", // Gelb
"#4caf50", // Grün
"#9c27b0", // Lila
"#ff5722", // Orange
"#03a9f4", // Hellblau
"#8bc34a", // Hellgrün
"#ffeb3b", // Hellgelb
"#795548" // Braun
],
title: "Beiträge der Moderatoren"
});
</script>
<h2 class="podcast-heading">Unterstützt durch</h2>
{# Diagramm für Unterstützt durch #}
<div id="support" class="chart-container"></div>
<script>
new Chartkick.PieChart("support", [
["Sascha", 4], ["Wikipedia", 2], ["Community", 2], ["Werbung", 1]
], {
colors: [
"#2196f3", // Blau
"#e91e63", // Rosa
"#ffc107", // Gelb
"#4caf50", // Grün
"#9c27b0", // Lila
"#ff5722", // Orange
"#03a9f4", // Hellblau
"#8bc34a", // Hellgrün
"#ffeb3b", // Hellgelb
"#795548" // Braun
],
title: "Unterstützt durch"
});
</script>
<p class="podcast-text">Ihr wollt die Statistik auch für euren Podlove-Podcast? Das <a href="https://github.com/poschi3/podlove-publisher-templates">Template findet ihr auf Github</a>.</p>
<style>
.podcast-summary, .podcast-summary p {
font-size: 1.1rem;
line-height: 1.7;
margin: 20px 0;
padding: 20px;
background-color: #f0f0f0;
border-left: 5px solid #2196f3;
}
.podcast-summary .highlight {
color: #ff5722;
font-weight: bold;
}
.podcast-heading {
font-size: 1.6rem;
color: #333;
margin-top: 40px;
margin-bottom: 10px;
}
.podcast-list {
list-style: none;
padding: 0;
}
.podcast-list li {
margin: 10px 0;
font-size: 1.1rem;
}
.podcast-list li a {
text-decoration: none;
color: #2196f3;
}
.podcast-list li a:hover {
text-decoration: underline;
}
.podcast-list .highlight {
color: #4caf50;
font-weight: bold;
}
.podcast-text {
font-size: 1.1rem;
color: #555;
}
.chart-container {
height: 400px;
margin: 30px 0;
}
</style>