Skip to content

Commit

Permalink
Fix filament calculations with multiple tools (#418)
Browse files Browse the repository at this point in the history
* Add logging if error occurs

* Calculate Length based on all tools

* Should work now
  • Loading branch information
UnchartedBull committed Feb 11, 2020
1 parent c1061e9 commit 2dc6cb4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 26 deletions.
3 changes: 1 addition & 2 deletions src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions src/app/files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/app/job-status/job-status.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
{{ job.filamentAmount }}g
</span>
<span class="job-info__print-details-finish-state">
<!-- TODO Once Filament Manager is up and working either display costs here or filament left-->
filament will be used
</span>
</div>
Expand Down
55 changes: 34 additions & 21 deletions src/app/job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ 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';

@Injectable({
providedIn: 'root'
})
export class JobService {

httpGETRequest: Subscription;
httpPOSTRequest: Subscription;
observable: Observable<Job>;
Expand All @@ -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) => {
Expand All @@ -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);
}
Expand Down

0 comments on commit 2dc6cb4

Please sign in to comment.