Skip to content

Commit

Permalink
Reduce data usage
Browse files Browse the repository at this point in the history
  • Loading branch information
RensHam committed Oct 20, 2019
1 parent fb05da6 commit 45a9825
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 99 deletions.
2 changes: 1 addition & 1 deletion src/components/BlockPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
const blocks = await this.resultService.update();
this.updateFields(blocks);
} catch (e) {
this.updateFields(this.resultService.getLastReggataData());
this.updateFields(this.resultService.getLastRegattaData());
return false;
}
} else {
Expand Down
59 changes: 0 additions & 59 deletions src/components/HelloWorld.vue

This file was deleted.

8 changes: 0 additions & 8 deletions src/router.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
import Vue from 'vue';
import Router from 'vue-router';
import Home from './views/Home.vue';

Vue.use(Router);

export default new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path: '/',
name: 'home',
component: Home,
},
],
});
43 changes: 35 additions & 8 deletions src/services/ResultService.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export class ResultService extends Service {
this.endCount = 0;
this.regatta = null;
this.lastReults = null;
this._fieldIndex = null;
this._blockIndex = null;
this.blocks = null;
}

/**
Expand All @@ -38,20 +41,40 @@ export class ResultService extends Service {
* @return {Promise<null|*|{}|props.regatta|regatta>}
*/
async update() {
if (this.regatta === null) {
const regatta = await this._initRegatta();
this.regatta = JSON.stringify(regatta.regatta);
this.blocks = JSON.parse(JSON.stringify(regatta.regatta));
this._blockIndex = 0;
this._fieldIndex = 0;
}
const data = await this._update();
this.regatta = JSON.stringify(data.regatta);
return data.regatta;
const regattaData = JSON.parse(this.regatta);
regattaData[this._blockIndex][this._fieldIndex].crews = data.field;
this.regatta = JSON.stringify(regattaData);
if (++this._fieldIndex === this.blocks[this._blockIndex].length) {
this._fieldIndex = 0;
if (++this._blockIndex === this.blocks.length) {
this._blockIndex = 0;
}
}
return regattaData;
}

getLastReggataData() {
getLastRegattaData() {
return JSON.parse(this.regatta);
}

_initRegatta() {
return this._fetch(`/beamer/getRegattaData/${this.regattaId}/${this.presetId}`);
}

/**
* @private
*/
_update() {
return this._fetch(`/beamer/getRegattaData/${this.regattaId}/${this.presetId}`);
const fieldCode = this.blocks[this._blockIndex][this._fieldIndex].fieldnameshort;
return this._fetch(`/beamer/getField/${this.regattaId}/${this.presetId}/${fieldCode.replace(/\+/g, '%2B')}`);
}

_updateLastResults() {
Expand All @@ -66,7 +89,11 @@ export class ResultService extends Service {
let fieldCount = 0;
blocks = blocks.map(block => {
block = block.map((field) => {
field.crewCount = field.crews.teams.length;
if (field.crews) {
field.crewCount = field.crews.teams.length;
} else {
field.crewCount = 0;
}
return field;
});
block.crewCount = block.reduce((sum, field) => {
Expand All @@ -88,18 +115,18 @@ export class ResultService extends Service {
field.crews.teams.length = 0;
}
}
if (count + field.crews.teams.length + fieldCount > this.endCount) {
if (count + field.crewCount + fieldCount > this.endCount) {
field.crews.teams.length = Math.max(0, this.endCount - count - 1 - fieldCount);
}

count += field.crewCount;
if (field.crews.teams.length) {
if (field.crewCount) {
fieldCount++;
}
});
this.endCount -= fieldCount;
this.fields[this.fields.length - 1] = this.fields[this.fields.length - 1].filter(field => {
return field.crews.teams.length > 0;
return field.crewCount;
});
} else {
count += block.crewCount;
Expand Down
5 changes: 0 additions & 5 deletions src/views/About.vue

This file was deleted.

18 changes: 0 additions & 18 deletions src/views/Home.vue

This file was deleted.

0 comments on commit 45a9825

Please sign in to comment.