-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from mauricerenck/develop
Some more stats
- Loading branch information
Showing
17 changed files
with
346 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.