Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieuy committed Oct 29, 2018
2 parents 151274e + 631a46e commit f5e0a99
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 32 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "feedseries",
"desktopName": "FeedSeries",
"productName": "FeedSeries",
"version": "1.2.1",
"version": "1.2.2",
"author": {
"name": "Matthieu YK",
"email": "matthieuy+git@riseup.net"
Expand Down
102 changes: 95 additions & 7 deletions src/renderer/components/Statistics.vue
Expand Up @@ -20,6 +20,12 @@
<span v-show="iteration">aujourd'hui</span>
</span>

<span class="binfo">
<i class="fa fa-clock" style="color: #b1b400;"></i>
{{ sum.t|duration_tv }}
<span v-show="iteration">aujourd'hui</span>
</span>

<span class="binfo" v-show="sum.d">
<i class="fa fa-download"></i>
<span v-show="sum.d > 0">{{ sum.d|plurialize('épisode récupéré', 'épisodes récupérés') }}</span>
Expand Down Expand Up @@ -69,12 +75,18 @@
<div class="clearfix"></div>
</div>

<div style="width: 90%; margin: auto;">
<div id="graphtime" class="graph-stats"></div>
<div class="clearfix"></div>
</div>

<div style="width: 90%; margin: auto;">
<div id="graphshow" class="graph-stats"></div>
</div>

<div style="width: 90%; margin: auto;">
<div id="graphweek" class="graph-stats"></div>
<div id="graphweek" class="graph-stats fleft" style="width: 350px;margin-right: 20px;"></div>
<div id="graphweektime" class="graph-stats fleft" style="width: 350px;"></div>
</div>
</div>
</div>
Expand Down Expand Up @@ -130,9 +142,10 @@
graphs
.setStartDate(this.period)
.setLabelFormat(this.labelFormat, 'episodes')
.setLabelFormat(this.labelFormat, 'times')
.setLabelFormat(this.labelFormat, 'shows')
.setStats(stats)
console.log('[GRAPH] Update')
console.log('[GRAPH] Update', stats)
},
/**
* Calculate sums for a period
Expand All @@ -152,6 +165,9 @@
return sums
},
/**
* Draw the graphs
*/
drawGraph () {
// Episodes
graphs
Expand All @@ -172,10 +188,46 @@
},
},
})
.addSerie('vus', 'v', { color: '#0a67ac' })
.addSerie('vus', 'v', {
color: '#0a67ac',
convertDataPoints: (dataPoints) => {
for (let i = 0; i < dataPoints.length; i++) {
if (!dataPoints[i].y) {
dataPoints[i].color = '#FF0000'
}
}
return dataPoints
},
})
.addSerie('récupérés', 'd', { color: '#885dbb' })
.addSerie('sous-titres', 's', { color: '#91bb2b' })
// Time
graphs
.addGraph('times', 'graphtime', 'Temps passé', {
axisY: {
suffix: 'h',
},
toolTip: {
contentFormatter: (e) => {
let point = e.entries[0].dataPoint
let duration = (point.y) ? this.$options.filters.duration_tv(point.y * 60) : 'aucun épisode vu'
return `<span>${point.label}</span><br><span style="color:${e.entries[0].dataSeries.color}">${duration}</span>`
},
},
})
.addSerie('Durée', 't', {
color: '#b1b400',
showInLegend: false,
convertDataPoints: (dataPoints) => {
for (let i = 0; i < dataPoints.length; i++) {
dataPoints[i].duration = this.$options.filters.duration_tv(dataPoints[i].y)
dataPoints[i].y /= 60
}
return dataPoints
},
})
// Shows
graphs
.addGraph('shows', 'graphshow', 'Séries', {
Expand All @@ -192,7 +244,7 @@
// Week
graphs
.addGraph('week', 'graphweek', 'Répartition', {
.addGraph('week', 'graphweek', 'Répartition (nombre)', {
width: 350,
toolTip: {
content: `<span style='"'color: {color};'"'>{y} épisodes vus le {label}</span> (#percent%)`,
Expand All @@ -201,6 +253,42 @@
.addSerie('Vus', 'v', {
type: 'doughnut',
showInLegend: false,
addEmptyPoint: false,
convertDataPoints: (dataPoints) => {
let colorSet = ['#369EAD', '#C24642', '#7F6084', '#86B402', '#C8B631', '#948e91', '#FFA500']
dataPoints = dataPoints.sort((a, b) => moment(a.date).format('e') - moment(b.date).format('e'))
for (let i = 0; i < dataPoints.length; i++) {
let day = moment(dataPoints[i].date).format('e')
dataPoints[i].color = colorSet[day]
dataPoints[i].indexLabelFontColor = colorSet[day]
}
return dataPoints
},
})
.setLabelFormat('dddd')
graphs
.addGraph('weektime', 'graphweektime', 'Répartition (temps)', {
width: 350,
toolTip: {
content: `<span style='"'color: {color};'"'>Temps passé le {label} : {duration}</span> (#percent%)`,
},
})
.addSerie('Durée', 't', {
type: 'doughnut',
showInLegend: false,
addEmptyPoint: false,
convertDataPoints: (dataPoints) => {
let colorSet = ['#369EAD', '#C24642', '#7F6084', '#86B402', '#C8B631', '#948e91', '#FFA500']
dataPoints = dataPoints.sort((a, b) => moment(a.date).format('e') - moment(b.date).format('e'))
for (let i = 0; i < dataPoints.length; i++) {
let day = moment(dataPoints[i].date).format('e')
dataPoints[i].color = colorSet[day]
dataPoints[i].indexLabelFontColor = colorSet[day]
dataPoints[i].duration = this.$options.filters.duration_tv(dataPoints[i].y)
}
return dataPoints
},
})
.setLabelFormat('dddd')
console.log('[GRAPH] Create')
Expand Down Expand Up @@ -228,7 +316,7 @@
let period = moment().startOf('day')
switch (value) {
case '1d': // Today
this.period = moment().startOf('day')
this.period = period
break
case '7d': // 1 week
this.period = period.subtract(7, 'days').add('10', 'seconds')
Expand All @@ -247,7 +335,7 @@
this.labelFormat = 'MMM YYYY'
break
}
console.log('[Stats] >=', this.period.format('DD/MM/YYYY'))
console.log('[Stats] >=', this.period.format('DD/MM/YYYY HH:mm'))
// Save and update graph
if (value !== localStore.get(localStore.key.STATS.PERIOD, '7d')) {
Expand Down Expand Up @@ -292,7 +380,7 @@
.graph-stats {
min-height: 300px;
margin-bottom: 25px;
width: 95%;
/*width: 95%;*/
.canvasjs-chart-container {
/*width: 600px;*/
margin: auto;
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/db/models/Stat.js
Expand Up @@ -73,6 +73,10 @@ class Stat extends Document {
* @param {Integer} value
*/
static incrementValue (type, increment, value) {
if (!value) {
return Promise.resolve()
}

return new Promise((resolve, reject) => {
this.findOne({
ts: this._getCurrentTs(),
Expand Down
54 changes: 30 additions & 24 deletions src/renderer/tools/StatsGraph.js
Expand Up @@ -69,7 +69,6 @@ class StatsGraph {
text: title,
},
axisX: {
margin: 0,
labelAutoFit: true,
labelWrap: true,
labelAngle: -45,
Expand Down Expand Up @@ -121,6 +120,7 @@ class StatsGraph {
showInLegend: true,
dataPoints: [],
statType: statType,
addEmptyPoint: true,
}

let options = (typeof opts !== 'undefined') ? jQuery.extend(true, {}, optionsDefault, opts) : optionsDefault
Expand Down Expand Up @@ -160,30 +160,36 @@ class StatsGraph {
}
}
})
this._data[name] = this._data[name].filter((a) => a.dataPoints.length)

// if (this._graphs[name].options.hasOwnProperty('addNullPoint') && this._graphs[name].options.addNullPoint) {
// for (let i = 0; i < this._data[name].length; i++) {
// let dateCurrent = moment(this._startDate.toDate())
// do {
// let label = dateCurrent.format(this._labelFormat[name])
// console.log('Test', label)
// let index = this._data[name][i].dataPoints.findIndex((a) => a.label === label)
// if (index === -1) {
// this._data[name][i].dataPoints.push({
// label: label,
// y: 0,
// date: dateCurrent.toDate(),
// })
// console.log('Add', label)
// }
// dateCurrent = dateCurrent.add(1, 'days')
// } while (dateCurrent.isBefore(moment.now()))
// this._data[name][i].dataPoints = this._data[name][i].dataPoints.sort((a, b) => a.date - b.date)
// console.log(this._data[name][i].dataPoints)
// }
// }

for (let i = 0; i < this._data[name].length; i++) {
// Hide graph if empty
this._data[name][i].visible = (this._data[name][i].dataPoints.length > 0)

// Add empty points
if (this._data[name][i].addEmptyPoint) {
let dateCurrent = moment(this._startDate.toDate())
do {
let label = dateCurrent.format(this._labelFormat[name])
let index = this._data[name][i].dataPoints.findIndex((a) => a.label === label)
if (index === -1 && !dateCurrent.seconds()) {
this._data[name][i].dataPoints.push({
label: label,
y: 0,
date: dateCurrent.toDate(),
})
}
dateCurrent = dateCurrent.add(1, 'days').startOf('day')
} while (dateCurrent.isBefore(moment.now()))
this._data[name][i].dataPoints = this._data[name][i].dataPoints.sort((a, b) => a.date - b.date)
}

// Edit dataPoint with callback
if (this._data[name][i].hasOwnProperty('convertDataPoints')) {
this._data[name][i].dataPoints = this._data[name][i].convertDataPoints(this._data[name][i].dataPoints)
}
}

console.log(name, this._data[name])
this.render(name)
}
}
Expand Down

0 comments on commit f5e0a99

Please sign in to comment.