Skip to content

Commit

Permalink
Added chart for brew overviews for a special bean
Browse files Browse the repository at this point in the history
  • Loading branch information
graphefruit committed Mar 17, 2020
1 parent b57c345 commit e5b92e0
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@
<ion-list-header>
<ion-label>{{"PAGE_STATISTICS_FOR_NERDS" | translate}}</ion-label>
</ion-list-header>
<ion-item>{{"PAGE_BEAN_INFORMATION_GOOD_BREWS" | translate}}:&nbsp;{{countGoodBrews()}}</ion-item>
<ion-item>{{"PAGE_BEAN_INFORMATION_BAD_BREWS" | translate}}:&nbsp;{{countBadBrews()}}</ion-item>
<ion-item>{{"PAGE_BEAN_INFORMATION_COUNT_BREWS" | translate}}:&nbsp;{{countBrews()}}</ion-item>
</ion-list>

<ion-card>
<ion-card-content>
<canvas #beanChart></canvas>
</ion-card-content>
</ion-card>

</ion-content>
<ion-footer>
<ion-row>
Expand Down
111 changes: 109 additions & 2 deletions src/app/beans/beans-information/beans-information.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, Input, OnInit} from '@angular/core';
import {Component, Input, OnInit, ViewChild} from '@angular/core';
import {Bean} from '../../../classes/bean/bean';
import {ROASTS_ENUM} from '../../../enums/beans/roasts';
import {BEAN_MIX_ENUM} from '../../../enums/beans/mix';
Expand All @@ -10,6 +10,8 @@ import {UIHelper} from '../../../services/uiHelper';
import {UIAnalytics} from '../../../services/uiAnalytics';
import {UIBrewStorage} from '../../../services/uiBrewStorage';
import {Brew} from '../../../classes/brew/brew';
import {TranslateService} from '@ngx-translate/core';
import {Chart} from 'chart.js';

@Component({
selector: 'beans-information',
Expand All @@ -23,22 +25,37 @@ export class BeansInformationComponent implements OnInit {
public mixEnum = BEAN_MIX_ENUM;
@Input() private bean: IBean;

@ViewChild('beanChart', {static: false}) public beanChart;

constructor(private readonly navParams: NavParams,
private readonly modalController: ModalController,
private readonly uiBeanStorage: UIBeanStorage,
private readonly uiImage: UIImage,
private readonly uiHelper: UIHelper,
private readonly uiAnalytics: UIAnalytics,
private readonly uiBrewStorage: UIBrewStorage) {
private readonly uiBrewStorage: UIBrewStorage,
private readonly translate: TranslateService) {
this.data.roastingDate = new Date().toISOString();
}

public ionViewWillEnter(): void {
this.uiAnalytics.trackEvent('BEAN', 'INFORMATION');
// this.bean = this.navParams.get('BEAN');
this.data.initializeByObject(this.bean);
this.__loadBeanChart();
}

public countAwesomeBrews() {
let counter: number = 0;
const brews: Array<Brew> = this.__getAllBrewsForThisBean();
for (const brew of brews) {
if (brew.isAwesomeBrew()) {
counter++;
}
}

return counter;
}
public countGoodBrews() {
let counter: number = 0;
const brews: Array<Brew> = this.__getAllBrewsForThisBean();
Expand All @@ -63,6 +80,31 @@ export class BeansInformationComponent implements OnInit {
return counter;
}

public countNotRatedBrews() {
let counter: number = 0;
const brews: Array<Brew> = this.__getAllBrewsForThisBean();
for (const brew of brews) {
if (brew.isNotRatedBrew()) {
counter++;
}
}

return counter;
}

public countIsNormalBrew() {
let counter: number = 0;
const brews: Array<Brew> = this.__getAllBrewsForThisBean();
for (const brew of brews) {
if (brew.isNormalBrew()) {
counter++;
}
}

return counter;
}


public countBrews() {
let counter: number = 0;
const brews: Array<Brew> = this.__getAllBrewsForThisBean();
Expand Down Expand Up @@ -94,4 +136,69 @@ export class BeansInformationComponent implements OnInit {
return brewsForThisBean;
}

private __loadBeanChart(): void {


const drinkingData = {
labels: [],
datasets: [{
label: '',
data: [],
backgroundColor: []
}]
};


const countAwesome = this.countAwesomeBrews();
if (countAwesome > 0) {
drinkingData.labels.push(this.translate.instant('PAGE_BEAN_INFORMATION_AWESOME_BREWS'));
drinkingData.datasets[0].data.push(countAwesome);
drinkingData.datasets[0].backgroundColor.push('#aa8736');
}

const countGood = this.countGoodBrews();
if (countGood > 0) {
drinkingData.labels.push(this.translate.instant('PAGE_BEAN_INFORMATION_GOOD_BREWS'));
drinkingData.datasets[0].data.push(countGood);
drinkingData.datasets[0].backgroundColor.push('#009966');
}
const countNormal = this.countIsNormalBrew();
if (countNormal > 0) {
drinkingData.labels.push(this.translate.instant('PAGE_BEAN_INFORMATION_NORMAL_BREWS'));
drinkingData.datasets[0].data.push(countNormal);
drinkingData.datasets[0].backgroundColor.push('#89729e');
}

const countBad = this.countBadBrews();
if (countBad > 0) {
drinkingData.labels.push(this.translate.instant('PAGE_BEAN_INFORMATION_BAD_BREWS'));
drinkingData.datasets[0].data.push(countBad);
drinkingData.datasets[0].backgroundColor.push('#fe4164');
}


const countNotRated = this.countNotRatedBrews();
if (countNotRated > 0) {
drinkingData.labels.push(this.translate.instant('PAGE_BEAN_INFORMATION_NOT_RATED_BREWS'));
drinkingData.datasets[0].data.push(countNotRated);
drinkingData.datasets[0].backgroundColor.push('#cfd7e1');
}

const chartOptions = {
responsive: true,
title: {
display: true,
text: this.translate.instant('PAGE_BEAN_BREW_CHART_TITLE'),
}
};
this.beanChart = new Chart(this.beanChart.nativeElement, {
type: 'pie',
data: drinkingData,
options: chartOptions
});
}




}
9 changes: 9 additions & 0 deletions src/app/beans/beans.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@
<ion-card-content *ngIf="bean.note != ''">
<pre class="blockquote">{{bean.note}}</pre>
</ion-card-content>
<ion-row>

<ion-col col-12>
<ion-button (click)="informationBean(bean)" color="dark" fill="clear" size="small">
<ion-icon name="list-outline" slot="start"></ion-icon>
<span>{{"INFORMATION" | translate}}</span>
</ion-button>
</ion-col>
</ion-row>
<ion-row>
<ion-col col-4>
<ion-button (click)="repeatBean(bean)" color="dark" fill="clear" size="small">
Expand Down
4 changes: 4 additions & 0 deletions src/app/brew/brew.page.scss
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@
border-top: 5px #fe4164 solid;
}

ion-card.awesome-brew {
border-top: 5px #aa8736 solid;
}

ion-list-header {
--background: rgb(160, 176, 196);
--color: black;
Expand Down
4 changes: 3 additions & 1 deletion src/app/brew/brew.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ export class BrewPage implements OnInit {


public getBrewDisplayClass(_brew: Brew) {
if (_brew.isGoodBrew()) {
if (_brew.isAwesomeBrew()) {
return 'awesome-brew';
} else if (_brew.isGoodBrew()) {
return 'good-brew';
} else if (_brew.isNormalBrew()) {
return 'normal-brew';
Expand Down
10 changes: 7 additions & 3 deletions src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,12 @@
"ALLOW_ANALYTICS_DENIED_DESCRIPTION": "Falls du es dir dennoch anders überlegst, findest du in den Einstellungen die Möglichkeit dazu!",
"ALLOW_ANALYTICS_DENIED_TITLE": "Auch Ok!",
"PAGE_BEAN_INFORMATION": "Bohnen Information",
"PAGE_BEAN_INFORMATION_GOOD_BREWS": "Gute Brühungen",
"PAGE_BEAN_INFORMATION_BAD_BREWS": "Schlechte Brühungen",
"PAGE_BEAN_INFORMATION_GOOD_BREWS": "Gut",
"PAGE_BEAN_INFORMATION_BAD_BREWS": "Schlecht",
"PAGE_BEAN_INFORMATION_COUNT_BREWS": "Insgesamte Brühungen",
"INFORMATION": "Information"
"INFORMATION": "Information",
"PAGE_BEAN_BREW_CHART_TITLE": "Brühübersicht für diese Bohne",
"PAGE_BEAN_INFORMATION_AWESOME_BREWS": "Grandios",
"PAGE_BEAN_INFORMATION_NORMAL_BREWS": "Normal",
"PAGE_BEAN_INFORMATION_NOT_RATED_BREWS": "Nicht bewertet"
}
11 changes: 9 additions & 2 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@
"ALLOW_ANALYTICS_DESCRIPTION": "With your agreement I'd like to retrieve analytic information. No personal information will be saved, promise.",
"ALLOW_ANALYTICS_DENIED_DESCRIPTION": "If you change your mind, you can find it in the settings!",
"ALLOW_ANALYTICS_DENIED_TITLE": "It's okay!",
"PAGE_BEAN_INFORMATION": "Bean information",
"INFORMATION": "Information"
"PAGE_BEAN_INFORMATION": "Bohnen Information",
"PAGE_BEAN_INFORMATION_GOOD_BREWS": "Good",
"PAGE_BEAN_INFORMATION_BAD_BREWS": "Bad",
"PAGE_BEAN_INFORMATION_COUNT_BREWS": "Total brews",
"INFORMATION": "Information",
"PAGE_BEAN_BREW_CHART_TITLE": "Brew overview for this bean",
"PAGE_BEAN_INFORMATION_AWESOME_BREWS": "Awesome",
"PAGE_BEAN_INFORMATION_NORMAL_BREWS": "Normal",
"PAGE_BEAN_INFORMATION_NOT_RATED_BREWS": "Not rated"
}
8 changes: 6 additions & 2 deletions src/classes/brew/brew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,20 @@ export class Brew implements IBrew {

}

public isAwesomeBrew(): boolean {
return this.rating === 10;
}

public isGoodBrew(): boolean {
return this.rating > 8;
return this.rating > 8 && this.rating < 10;
}

public isNormalBrew(): boolean {
return this.rating > 5 && this.rating < 8;
}

public isBadBrew(): boolean {
return this.rating < 4 && this.rating > 0;
return this.rating < 5 && this.rating > 0;
}

public isNotRatedBrew(): boolean {
Expand Down

0 comments on commit e5b92e0

Please sign in to comment.