diff --git a/src/app/beans/beans-information/beans-information.component.html b/src/app/beans/beans-information/beans-information.component.html index be8efdb6b..173a472af 100644 --- a/src/app/beans/beans-information/beans-information.component.html +++ b/src/app/beans/beans-information/beans-information.component.html @@ -14,11 +14,15 @@ {{"PAGE_STATISTICS_FOR_NERDS" | translate}} - {{"PAGE_BEAN_INFORMATION_GOOD_BREWS" | translate}}: {{countGoodBrews()}} - {{"PAGE_BEAN_INFORMATION_BAD_BREWS" | translate}}: {{countBadBrews()}} {{"PAGE_BEAN_INFORMATION_COUNT_BREWS" | translate}}: {{countBrews()}} + + + + + + diff --git a/src/app/beans/beans-information/beans-information.component.ts b/src/app/beans/beans-information/beans-information.component.ts index 72af78142..8f4191f62 100644 --- a/src/app/beans/beans-information/beans-information.component.ts +++ b/src/app/beans/beans-information/beans-information.component.ts @@ -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'; @@ -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', @@ -23,13 +25,16 @@ 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(); } @@ -37,8 +42,20 @@ export class BeansInformationComponent implements OnInit { 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 = this.__getAllBrewsForThisBean(); + for (const brew of brews) { + if (brew.isAwesomeBrew()) { + counter++; + } + } + + return counter; + } public countGoodBrews() { let counter: number = 0; const brews: Array = this.__getAllBrewsForThisBean(); @@ -63,6 +80,31 @@ export class BeansInformationComponent implements OnInit { return counter; } + public countNotRatedBrews() { + let counter: number = 0; + const brews: Array = this.__getAllBrewsForThisBean(); + for (const brew of brews) { + if (brew.isNotRatedBrew()) { + counter++; + } + } + + return counter; + } + + public countIsNormalBrew() { + let counter: number = 0; + const brews: Array = this.__getAllBrewsForThisBean(); + for (const brew of brews) { + if (brew.isNormalBrew()) { + counter++; + } + } + + return counter; + } + + public countBrews() { let counter: number = 0; const brews: Array = this.__getAllBrewsForThisBean(); @@ -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 + }); + } + + + + } diff --git a/src/app/beans/beans.page.html b/src/app/beans/beans.page.html index 7a9fc5f9d..b53d02aa9 100644 --- a/src/app/beans/beans.page.html +++ b/src/app/beans/beans.page.html @@ -163,6 +163,15 @@
{{bean.note}}
+ + + + + + {{"INFORMATION" | translate}} + + + diff --git a/src/app/brew/brew.page.scss b/src/app/brew/brew.page.scss index 3be26d1ed..ab192706f 100644 --- a/src/app/brew/brew.page.scss +++ b/src/app/brew/brew.page.scss @@ -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; diff --git a/src/app/brew/brew.page.ts b/src/app/brew/brew.page.ts index 947344b3d..27c699dad 100644 --- a/src/app/brew/brew.page.ts +++ b/src/app/brew/brew.page.ts @@ -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'; diff --git a/src/assets/i18n/de.json b/src/assets/i18n/de.json index eb6e3f256..4c9d763ff 100644 --- a/src/assets/i18n/de.json +++ b/src/assets/i18n/de.json @@ -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" } diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index c55b16172..f5a17751f 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -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" } diff --git a/src/classes/brew/brew.ts b/src/classes/brew/brew.ts index a6f506fd5..704a0f2d0 100755 --- a/src/classes/brew/brew.ts +++ b/src/classes/brew/brew.ts @@ -152,8 +152,12 @@ 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 { @@ -161,7 +165,7 @@ export class Brew implements IBrew { } public isBadBrew(): boolean { - return this.rating < 4 && this.rating > 0; + return this.rating < 5 && this.rating > 0; } public isNotRatedBrew(): boolean {