Skip to content

Commit

Permalink
#899 - Supporting CO2e (kg) per kg roasted coffee
Browse files Browse the repository at this point in the history
  • Loading branch information
graphefruit committed Feb 1, 2025
1 parent 39d9cc6 commit 94201b5
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,15 @@ <h2>{{"BEAN_DATA_EAN" | translate}}</h2>
</div>
</ion-checkbox>
</ion-item>
<ion-item tappable>
<ion-checkbox label-placement='start' (ngModelChange)='triggerChanges($event)'
[(ngModel)]='data.bean_manage_parameters.co2e_kg'>
<div class='ion-label'>
<h2>{{"BEAN_DATA_CO2E_KG" | translate}}</h2>
<p>{{"BEAN_DATA_CO2E_KG_TOOLTIP" | translate}}</p>
</div>
</ion-checkbox>
</ion-item>
<ion-item tappable>
<ion-checkbox label-placement='start' (ngModelChange)='triggerChanges($event)'
[(ngModel)]='data.bean_manage_parameters.note'>
Expand Down
20 changes: 10 additions & 10 deletions src/app/beans/beans-add/beans-add.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class BeansAddComponent implements OnInit {
private readonly uiAlert: UIAlert,
private readonly platform: Platform,
public readonly uiBeanHelper: UIBeanHelper,
private readonly uiSettingsStorage: UISettingsStorage
private readonly uiSettingsStorage: UISettingsStorage,
) {}

public ngOnInit() {
Expand All @@ -59,7 +59,7 @@ export class BeansAddComponent implements OnInit {
(_processNextHandler) => {
// Don't do anything.
this.confirmDismiss();
}
},
);
}
}
Expand Down Expand Up @@ -114,7 +114,7 @@ export class BeansAddComponent implements OnInit {
const yes = await this.uiAlert.showConfirm(
'BEAN_POPUP_YOU_DONT_SEE_EVERYTHING_DESCRIPTION',
'INFORMATION',
true
true,
);
this.settings.bean_manage_parameters.bean_information = true;
await this.uiSettingsStorage.update(this.settings);
Expand Down Expand Up @@ -198,7 +198,7 @@ export class BeansAddComponent implements OnInit {
},
() => {
// No
}
},
);
} else {
this.dismiss();
Expand All @@ -212,7 +212,7 @@ export class BeansAddComponent implements OnInit {
await this.uiBeanStorage.add(this.data);
this.uiAnalytics.trackEvent(
BEAN_TRACKING.TITLE,
BEAN_TRACKING.ACTIONS.ADD_FINISH
BEAN_TRACKING.ACTIONS.ADD_FINISH,
);
this.dismiss();
if (!this.hide_toast_message) {
Expand All @@ -231,7 +231,7 @@ export class BeansAddComponent implements OnInit {
dismissed: true,
},
undefined,
BeansAddComponent.COMPONENT_ID
BeansAddComponent.COMPONENT_ID,
);
}

Expand All @@ -253,19 +253,19 @@ export class BeansAddComponent implements OnInit {
this.data.decaffeinated = _bean.decaffeinated;
this.data.url = _bean.url;
this.data.ean_article_number = _bean.ean_article_number;
this.data.co2e_kg = _bean.co2e_kg;

this.data.bean_information = this.uiHelper.cloneData(
_bean.bean_information
_bean.bean_information,
);
this.data.cupping_points = _bean.cupping_points;
this.data.roast_range = _bean.roast_range;

const copyAttachments = [];
for (const attachment of _bean.attachments) {
try {
const newPath: string = await this.uiFileHelper.duplicateInternalFile(
attachment
);
const newPath: string =
await this.uiFileHelper.duplicateInternalFile(attachment);
copyAttachments.push(newPath);
} catch (ex) {}
}
Expand Down
6 changes: 6 additions & 0 deletions src/app/beans/beans-detail/beans-detail.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,12 @@ <h2>{{"BEAN_DATA_EAN" | translate}}:</h2>
<h3>{{data.ean_article_number}}</h3>
</ion-label>
</ion-item>
<ion-item *ngIf="(settings | beanFieldVisiblePipe: [settings.bean_manage_parameters.co2e_kg])">
<ion-label>
<h2>{{"BEAN_DATA_CO2E_KG" | translate}}:</h2>
<h3>{{data.co2e_kg}}</h3>
</ion-label>
</ion-item>
<ion-item>
<ion-checkbox justify="start" label-placement="start" [(ngModel)]="data.finished" disabled="true">{{"FINISHED" | translate}}?:</ion-checkbox>
</ion-item>
Expand Down
6 changes: 4 additions & 2 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1417,5 +1417,7 @@
"SMART_SCALE_ACAIA_CONNECTION_MODE_TITLE": "Acaia connection mode",
"SMART_SCALE_ACAIA_CONNECTION_MODE_DESCRIPTION": "If your scale keeps connecting and disconnecting, try setting the mode to V1 and adjusting the heartbeat and command timer. This will switch to the old connection routine.",
"SMART_SCALE_ACAIA_CONNECTION_MODE_V2": "V2 - New connection mode",
"SMART_SCALE_ACAIA_CONNECTION_MODE_V1": "V1 - Old connection mode"
}
"SMART_SCALE_ACAIA_CONNECTION_MODE_V1": "V1 - Old connection mode",
"BEAN_DATA_CO2E_KG": "CO2e (kg) per kg roasted coffee",
"BEAN_DATA_CO2E_KG_TOOLTIP": "The released CO2e (kg) released per kg roasted coffee"
}
10 changes: 7 additions & 3 deletions src/classes/bean/bean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export class Bean implements IBean {
public bestDate: string;
public openDate: string;

public co2e_kg: number;

constructor() {
this.name = '';
this.buyDate = '';
Expand Down Expand Up @@ -134,6 +136,8 @@ export class Bean implements IBean {

this.bestDate = '';
this.openDate = '';

this.co2e_kg = 0;
}

public getRoastName(): string {
Expand Down Expand Up @@ -176,7 +180,7 @@ export class Bean implements IBean {
this.bean_roast_information = new BeanRoastInformation();
Object.assign(
this.bean_roast_information,
beanObj.bean_roast_information
beanObj.bean_roast_information,
);
}
}
Expand All @@ -188,7 +192,7 @@ export class Bean implements IBean {
this.bean_roast_information = new BeanRoastInformation();
Object.assign(
this.bean_roast_information,
beanObj.bean_roast_information
beanObj.bean_roast_information,
);
}

Expand Down Expand Up @@ -342,7 +346,7 @@ export class Bean implements IBean {
public getRoastingMachine(): RoastingMachine {
const iRoastingMachine: IRoastingMachine =
this.getRoastingMachineStorage().getByUUID(
this.bean_roast_information.roaster_machine
this.bean_roast_information.roaster_machine,
) as IRoastingMachine;
const roastingMachine: RoastingMachine = new RoastingMachine();
roastingMachine.initializeByObject(iRoastingMachine);
Expand Down
3 changes: 3 additions & 0 deletions src/classes/parameter/beanListViewParameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class BeanListViewParameter implements IBeanParameter {

public bestDate: boolean;
public openDate: boolean;
public co2e_kg: boolean;

constructor() {
this.name = true;
Expand Down Expand Up @@ -76,6 +77,7 @@ export class BeanListViewParameter implements IBeanParameter {

this.bestDate = false;
this.openDate = false;
this.co2e_kg = false;
}

public activateAll() {
Expand Down Expand Up @@ -113,5 +115,6 @@ export class BeanListViewParameter implements IBeanParameter {
this.fob_price = true;
this.bestDate = true;
this.openDate = true;
this.co2e_kg = true;
}
}
3 changes: 3 additions & 0 deletions src/classes/parameter/beanManageParameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class BeanManageParameter implements IBeanParameter {

public bestDate: boolean;
public openDate: boolean;
public co2e_kg: boolean;

constructor() {
this.name = true;
Expand Down Expand Up @@ -76,6 +77,7 @@ export class BeanManageParameter implements IBeanParameter {

this.bestDate = false;
this.openDate = false;
this.co2e_kg = false;
}

public activateAll() {
Expand Down Expand Up @@ -114,5 +116,6 @@ export class BeanManageParameter implements IBeanParameter {

this.bestDate = true;
this.openDate = true;
this.co2e_kg = true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,13 @@
spellcheck="false" type="text">
</ion-input>
</ion-item>
<ion-item *ngIf="(settings | beanFieldVisiblePipe: [settings.bean_manage_parameters.co2e_kg])">
<ion-input label-placement="stacked" label='{{"BEAN_DATA_CO2E_KG" | translate}}' #co2e_kg="ngModel" [(ngModel)]="data.co2e_kg" autocapitalize="off" inputmode="decimal"
name="cupping_points"
prevent-characters remove-empty-number spellcheck="false"
type="text">
</ion-input>
</ion-item>
<ion-item *ngIf="data?.config.uuid !== ''" style='margin-bottom:5px;'>

<ion-checkbox justify="start" label-placement="start" [(ngModel)]="data.finished">{{"FINISHED"|translate}}?</ion-checkbox>
Expand Down
5 changes: 5 additions & 0 deletions src/interfaces/bean/iBean.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ export interface IBean {

bestDate: string;
openDate: string;

/**
* kg CO2e /kg for emission data.
*/
co2e_kg: number;
}
2 changes: 2 additions & 0 deletions src/interfaces/parameter/iBeanParameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ export interface IBeanParameter {

bestDate: boolean;
openDate: boolean;
/** Emission data **/
co2e_kg: boolean;
}
82 changes: 41 additions & 41 deletions src/mapper/bean/beanMapper.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import {ServerBean} from '../../models/bean/serverBean';
import {Bean} from '../../classes/bean/bean';
import {BEAN_MIX_ENUM} from '../../enums/beans/mix';
import {BEAN_ROASTING_TYPE_ENUM} from '../../enums/beans/beanRoastingType';
import {IBeanInformation} from '../../interfaces/bean/iBeanInformation';
import {UIFileHelper} from '../../services/uiFileHelper';
import {IAttachment} from '../../interfaces/server/iAttachment';
import {ROASTS_ENUM} from '../../enums/beans/roasts';
import { ServerBean } from '../../models/bean/serverBean';
import { Bean } from '../../classes/bean/bean';
import { BEAN_MIX_ENUM } from '../../enums/beans/mix';
import { BEAN_ROASTING_TYPE_ENUM } from '../../enums/beans/beanRoastingType';
import { IBeanInformation } from '../../interfaces/bean/iBeanInformation';
import { UIFileHelper } from '../../services/uiFileHelper';
import { IAttachment } from '../../interfaces/server/iAttachment';
import { ROASTS_ENUM } from '../../enums/beans/roasts';

export class BeanMapper {
constructor() {}

constructor() {

}

public async mapSharedUserBean(_userSharedBean: any): Promise<Bean> {
public async mapSharedUserBean(_userSharedBean: any): Promise<Bean> {
return new Promise<Bean>(async (resolve, reject) => {
try {
const newBean: Bean = new Bean();
Expand All @@ -29,20 +26,22 @@ export class BeanMapper {
newBean.decaffeinated = _userSharedBean.decaffeinated;
newBean.ean_article_number = _userSharedBean.ean_article_number;
newBean.note = _userSharedBean.note;
if ( _userSharedBean.roastingDate !== null && _userSharedBean.roastingDate !== ''){
if (
_userSharedBean.roastingDate !== null &&
_userSharedBean.roastingDate !== ''
) {
newBean.roastingDate = _userSharedBean.roastingDate;
}
newBean.url = _userSharedBean.url;

newBean.beanMix = _userSharedBean.beanMix;
newBean.beanMix = _userSharedBean.beanMix;
newBean.roast = _userSharedBean.roast;

if (newBean.roast === 'CUSTOM_ROAST' as ROASTS_ENUM.CUSTOM_ROAST) {
if (newBean.roast === ('CUSTOM_ROAST' as ROASTS_ENUM.CUSTOM_ROAST)) {
newBean.roast_custom = _userSharedBean.roast_custom;
}


newBean.bean_roasting_type = _userSharedBean.bean_roasting_type;
newBean.bean_roasting_type = _userSharedBean.bean_roasting_type;

for (const information of _userSharedBean.bean_information) {
const iInformation = {} as IBeanInformation;
Expand All @@ -63,18 +62,15 @@ export class BeanMapper {

newBean.shared = true;
resolve(newBean);

}
catch(ex) {
} catch (ex) {
resolve(null);
}

});
}



public async mapServerToClientBean(_serverResponse: ServerBean): Promise<Bean> {
public async mapServerToClientBean(
_serverResponse: ServerBean,
): Promise<Bean> {
return new Promise<Bean>(async (resolve, reject) => {
try {
const newBean: Bean = new Bean();
Expand All @@ -90,7 +86,14 @@ export class BeanMapper {
newBean.decaffeinated = _serverResponse.decaffeinated;
newBean.ean_article_number = _serverResponse.ean_article_number;
newBean.note = _serverResponse.note;
if ( _serverResponse.roastingDate !== null && _serverResponse.roastingDate !== ''){

if ('co2e_kg' in _serverResponse) {
newBean.co2e_kg = _serverResponse.co2e_kg;
}
if (
_serverResponse.roastingDate !== null &&
_serverResponse.roastingDate !== ''
) {
newBean.roastingDate = _serverResponse.roastingDate;
}
newBean.url = _serverResponse.url;
Expand All @@ -101,9 +104,8 @@ export class BeanMapper {
2: 'BLEND' as BEAN_MIX_ENUM,
}[_serverResponse.beanMix];


newBean.roast = {
0:'UNKNOWN' as ROASTS_ENUM,
0: 'UNKNOWN' as ROASTS_ENUM,
1: 'CINNAMON_ROAST' as ROASTS_ENUM,
2: 'AMERICAN_ROAST' as ROASTS_ENUM,
3: 'NEW_ENGLAND_ROAST' as ROASTS_ENUM,
Expand All @@ -123,7 +125,6 @@ export class BeanMapper {
newBean.roast_custom = _serverResponse.roast_custom;
}


newBean.bean_roasting_type = {
0: 'FILTER' as BEAN_ROASTING_TYPE_ENUM,
1: 'ESPRESSO' as BEAN_ROASTING_TYPE_ENUM,
Expand All @@ -149,27 +150,26 @@ export class BeanMapper {
}

resolve(newBean);

}
catch(ex) {
} catch (ex) {
resolve(null);
}

});
}

public async downloadAndAttachAttachments(_bean: Bean, attachments: Array<IAttachment>) {
public async downloadAndAttachAttachments(
_bean: Bean,
attachments: Array<IAttachment>,
) {
try {
const uiFileHelper: UIFileHelper = UIFileHelper.getInstance();
for (const attachment of attachments) {

const entry: string = await uiFileHelper.downloadExternalFile(attachment.uri, undefined, attachment.extension);
const entry: string = await uiFileHelper.downloadExternalFile(
attachment.uri,
undefined,
attachment.extension,
);
_bean.attachments.push(entry);

}
}
catch(ex) {

}
} catch (ex) {}
}
}
Loading

0 comments on commit 94201b5

Please sign in to comment.