Skip to content

Commit

Permalink
Merge pull request #25 from mauricerenck/develop
Browse files Browse the repository at this point in the history
Some more stats
  • Loading branch information
mauricerenck authored Jun 11, 2019
2 parents 9531640 + 1b57e2e commit 86f8eeb
Show file tree
Hide file tree
Showing 17 changed files with 346 additions and 38 deletions.
6 changes: 5 additions & 1 deletion blueprints/pages/podcasterfeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ tabs:
columns:
- width: 2/3
sections:
podstatsy:
podstatsyearly:
type: podcasterYearlyGraph
podstatsTop:
type: podcasterTopTen
podstatsFeed:
type: podcasterFeedStats
- width: 1/3
sections:
podstatsEpisodic:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mauricerenck/podcaster",
"version": "1.1.0",
"version": "1.1.1",
"description": "A podcast plugin for Kirby 3",
"type": "kirby-plugin",
"license": "MIT",
Expand Down
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion index.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion index.js

Large diffs are not rendered by default.

36 changes: 33 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@
return $headline;
}
]
],
'podcasterTopTen' => [
'props' => [
'headline' => function ($headline = 'Top 10 Episodes') {
return $headline;
}
]
],
'podcasterFeedStats' => [
'props' => [
'headline' => function ($headline = 'Feed Downloads') {
return $headline;
}
]
]
],
'snippets' => [
Expand Down Expand Up @@ -165,16 +179,32 @@
}
],
[
'pattern' => 'podcaster/stats/(:any)/yearly-downloads/(:any)',
'action' => function ($podcast, $year) {
'pattern' => 'podcaster/stats/(:any)/(:any)/yearly-downloads/(:any)',
'action' => function ($podcast, $type, $year) {

if(option('mauricerenck.podcaster.statsInternal') === false || option('mauricerenck.podcaster.statsType') === 'file') {
$errorMessage = ['error' => 'cannot use stats on file method, use mysql version instead'];
echo new Response(json_encode($errorMessage), 'application/json', 501);
}

$podcasterStats = new PodcasterStats();
$stats = $podcasterStats->getDownloadsOfYear($podcast, $year, $type);
return [
'stats' => $stats
];
}
],
[
'pattern' => 'podcaster/stats/(:any)/top/(:num)',
'action' => function ($podcast, $limit) {

if(option('mauricerenck.podcaster.statsInternal') === false || option('mauricerenck.podcaster.statsType') === 'file') {
$errorMessage = ['error' => 'cannot use stats on file method, use mysql version instead'];
echo new Response(json_encode($errorMessage), 'application/json', 501);
}

$podcasterStats = new PodcasterStats();
$stats = $podcasterStats->getDownloadsOfYear($podcast, $year);
$stats = $podcasterStats->getTopDownloads($podcast, $limit);
return [
'stats' => $stats
];
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "podcaster",
"version": "1.1.0",
"version": "1.1.1",
"description": "Theme",
"main": "index.js",
"author": "Maurice Renck",
Expand Down
112 changes: 112 additions & 0 deletions src/components/FeedStats.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<template>
<div>
{{error}}
<div id="feedChart"></div>
</div>
</template>
<script>
import getYear from 'date-fns/getYear'
import { Chart } from 'frappe-charts/dist/frappe-charts.esm.js'
import 'frappe-charts/dist/frappe-charts.min.css'
import sanitizeTitle from '../utils'
export default {
components: { Chart },
data() {
return {
podcasterSlug: null,
currentDate: new Date(),
currentYear: null,
yearlyStats: [0],
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
datasets: [],
},
}
},
computed: {
id() {
return this.$store.state.form.current
},
pageValues() {
return this.$store.getters['form/values'](this.id)
},
},
mounted() {
const year = getYear(this.currentDate)
this.podcasterSlug = sanitizeTitle(this.pageValues.podcastertitle)
this.getStats(year)
},
methods: {
getStats(year) {
fetch('/api/podcaster/stats/' + this.podcasterSlug + '/feed/yearly-downloads/' + year + '+' + (year - 1), {
method: 'GET',
headers: {
'X-CSRF': panel.csrf,
},
})
.then(response => {
if (response.status !== 200) {
throw 'You are tracking your downloads, using the file method. Stats are currently available only when using mysql'
}
return response
})
.then(response => response.json())
.then(response => {
this.addChartData(response.stats, year)
})
.catch(error => {
this.error = error
})
},
addChartData(stats, year) {
const chartData = {
current: {
name: year,
values: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
},
past: {
name: year - 1,
values: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
},
}
stats.map(function(entry) {
if (entry.year === year) {
chartData.current.values[entry.month - 1] = entry.downloaded
} else {
chartData.past.values[entry.month - 1] = entry.downloaded
}
})
this.data.datasets = [chartData.current, chartData.past]
this.drawChart()
},
drawChart() {
const chart = new Chart('#feedChart', {
title: 'Monthly Feed Downloads',
data: this.data,
type: 'line', // or 'bar', 'line', 'scatter', 'pie', 'percentage'
height: 350,
colors: ['blue', 'dark-grey'],
lineOptions: {
hideLine: 0,
regionFill: 1,
hideDots: 0,
},
barOptions: {
spaceRatio: 0.25,
},
})
},
},
}
</script>

<style lang="scss">
.line-graph-path {
stroke-width: 2px !important;
}
</style>
113 changes: 113 additions & 0 deletions src/components/TopTen.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<template>
<section class="k-modified-section">
<k-text>{{ error }}</k-text>
<k-headline>{{ headline }}</k-headline>
<table id="topTen">
<tr v-for="episode in topEpisodes">
<td>{{ episode.downloads }}</td>
<td>{{ episode.title }}</td>
</tr>
</table>

</section>
</template>

<script>
import sanitizeTitle from '../utils'
export default {
data: function() {
return {
limit: 10,
headline: null,
topEpisodes: [],
error: null,
podcasterSlug: null
}
},
mounted() {
this.podcasterSlug = sanitizeTitle(this.pageValues.podcastertitle)
this.getStats()
},
created: function() {
this.load().then(response => {
this.headline = response.headline;
});
},
computed: {
id() {
return this.$store.state.form.current
},
pageValues() {
return this.$store.getters['form/values'](this.id)
},
},
methods: {
getStats() {
fetch('/api/podcaster/stats/'+ this.podcasterSlug + '/top/' + this.limit, {
method: 'GET',
headers: {
'X-CSRF': panel.csrf,
},
})
.then(response => {
if(response.status !== 200) {
throw 'You are tracking your downloads, using the file method. Stats are currently available only when using mysql'
}
return response
})
.then(response => response.json())
.then(response => {
this.topEpisodes = this.computeStats(response.stats)
})
.catch(error => {
this.error = error
})
},
computeStats(stats) {
const episodeStats = stats.map(function(episode) {
return { title: episode.episode.replace(/-/g, ' '), downloads: episode.downloaded }
})
return episodeStats
},
},
}
</script>

<style lang="scss">
.k-section-name-podstatsTop {
table {
width: 100%;
border: 1px solid #ccc;
background: #fff;
margin-top: 0.5em;
}
td {
border-bottom: 1px solid #ccc;
line-height: 2;
padding: 0 10px;
}
td:first-child {
text-align: right;
}
.podcaster-prev-next {
display: inline;
text-align: right;
color: #666;
}
.k-headline {
display: inline;
}
.k-text {
color: red;
}
}
</style>
Loading

0 comments on commit 86f8eeb

Please sign in to comment.