From 2dc6cb41bbbb030ba7ed4eb339daa361641b2253 Mon Sep 17 00:00:00 2001 From: Timon G Date: Tue, 11 Feb 2020 23:12:31 +0100 Subject: [PATCH] Fix filament calculations with multiple tools (#418) * Add logging if error occurs * Calculate Length based on all tools * Should work now --- src/app/app.service.ts | 3 +- src/app/files.service.ts | 2 - src/app/job-status/job-status.component.html | 1 - src/app/job.service.ts | 55 ++++++++++++-------- 4 files changed, 35 insertions(+), 26 deletions(-) diff --git a/src/app/app.service.ts b/src/app/app.service.ts index a429259b5..ceeeabfed 100644 --- a/src/app/app.service.ts +++ b/src/app/app.service.ts @@ -195,9 +195,8 @@ export class AppService { public convertFilamentLengthToAmount(filamentLength: number): number { return Math.round((Math.PI * (this.configService.getFilamentThickness() / 2) * filamentLength) - * this.configService.getFilamentThickness() / 100) / 10; + * this.configService.getFilamentDensity() / 100) / 10; } - } interface VersionInformation { diff --git a/src/app/files.service.ts b/src/app/files.service.ts index ce5de8ce7..3d0ad9cb2 100644 --- a/src/app/files.service.ts +++ b/src/app/files.service.ts @@ -64,8 +64,6 @@ export class FilesService { printTime: this.service.convertSecondsToHours(fileOrFolder.gcodeAnalysis.estimatedPrintTime), filamentWeight: this.service.convertFilamentLengthToAmount(filamentLength), } as File); - } else if (fileOrFolder.typePath.includes('gcode') && fileOrFolder.origin === 'sdcard') { - // TODO } }); data = null; diff --git a/src/app/job-status/job-status.component.html b/src/app/job-status/job-status.component.html index 87bd4e5be..880c6f7b8 100644 --- a/src/app/job-status/job-status.component.html +++ b/src/app/job-status/job-status.component.html @@ -35,7 +35,6 @@ {{ job.filamentAmount }}g - filament will be used diff --git a/src/app/job.service.ts b/src/app/job.service.ts index 108f077d7..81b70c297 100644 --- a/src/app/job.service.ts +++ b/src/app/job.service.ts @@ -3,7 +3,7 @@ import { Observable, Observer, timer, Subscription } from 'rxjs'; import { ConfigService } from './config/config.service'; import { HttpClient, HttpErrorResponse } from '@angular/common/http'; import { shareReplay, publish } from 'rxjs/operators'; -import { OctoprintJobAPI, JobCommand } from './octoprint-api/jobAPI'; +import { OctoprintJobAPI, JobCommand, OctoprintFilament } from './octoprint-api/jobAPI'; import { NotificationService } from './notification/notification.service'; import { AppService } from './app.service'; @@ -11,7 +11,6 @@ import { AppService } from './app.service'; providedIn: 'root' }) export class JobService { - httpGETRequest: Subscription; httpPOSTRequest: Subscription; observable: Observable; @@ -34,25 +33,29 @@ export class JobService { let job: Job = null; if (data.job && data.job.file.name) { this.printing = ['Printing', 'Pausing', 'Paused', 'Cancelling'].includes(data.state); - job = { - status: data.state, - filename: data.job.file.display.replace('.gcode', ''), - progress: Math.round((data.progress.filepos / data.job.file.size) * 100), - filamentAmount: this.service.convertFilamentLengthToAmount(data.job.filament.tool0.length), - timeLeft: { - value: this.service.convertSecondsToHours(data.progress.printTimeLeft), - unit: 'h' - }, - timePrinted: { - value: this.service.convertSecondsToHours(data.progress.printTime), - unit: 'h' - }, - estimatedPrintTime: { - value: this.service.convertSecondsToHours(data.job.estimatedPrintTime), - unit: 'h' - }, - estimatedEndTime: this.calculateEndTime(data.job.estimatedPrintTime), - }; + try { + job = { + status: data.state, + filename: data.job.file.display.replace('.gcode', ''), + progress: Math.round((data.progress.filepos / data.job.file.size) * 100), + filamentAmount: this.service.convertFilamentLengthToAmount(this.getTotalAmountOfFilament(data.job.filament)), + timeLeft: { + value: this.service.convertSecondsToHours(data.progress.printTimeLeft), + unit: 'h' + }, + timePrinted: { + value: this.service.convertSecondsToHours(data.progress.printTime), + unit: 'h' + }, + estimatedPrintTime: { + value: this.service.convertSecondsToHours(data.job.estimatedPrintTime), + unit: 'h' + }, + estimatedEndTime: this.calculateEndTime(data.job.estimatedPrintTime), + }; + } catch (error) { + this.notificationService.setError('Can\'t retrieve Job Status', error); + } } observer.next(job); }, (error: HttpErrorResponse) => { @@ -65,6 +68,16 @@ export class JobService { this.observable.subscribe(); } + private getTotalAmountOfFilament(filamentAmount: OctoprintFilament): number { + let filamentLength = 0; + for (const property in filamentAmount) { + if (filamentAmount.hasOwnProperty(property) && filamentAmount[property].hasOwnProperty('length')) { + filamentLength += filamentAmount[property].length; + } + } + return filamentLength; + } + public deleteJobInformation(): void { this.observer.next(null); }