Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate filament weight based on length #1082

Merged
merged 1 commit into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/app/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,13 @@ export class AppService {
return roundedHours + ':' + ('0' + roundedMinutes).slice(-2);
}

public convertFilamentVolumeToWeight(filamentVolume: number): number {
public convertFilamentLengthToWeight(filamentLength: number): number {
return this.convertFilamentVolumeToWeight(
(filamentLength * Math.PI * Math.pow(this.configService.getFilamentThickness() / 2, 2)) / 1000,
);
}

private convertFilamentVolumeToWeight(filamentVolume: number): number {
return Math.round(filamentVolume * this.configService.getFilamentDensity() * 10) / 10;
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/app/files.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class FilesService {
let filamentLength = 0;
if (fileOrFolder.gcodeAnalysis) {
_.forEach(fileOrFolder.gcodeAnalysis.filament, (tool): void => {
filamentLength += tool.volume;
filamentLength += tool.length;
});
}

Expand All @@ -88,7 +88,7 @@ export class FilesService {
...(fileOrFolder.gcodeAnalysis
? {
printTime: this.service.convertSecondsToHours(fileOrFolder.gcodeAnalysis.estimatedPrintTime),
filamentWeight: this.service.convertFilamentVolumeToWeight(filamentLength),
filamentWeight: this.service.convertFilamentLengthToWeight(filamentLength),
}
: {}),
} as unknown) as File);
Expand Down Expand Up @@ -148,7 +148,7 @@ export class FilesService {
let filamentLength = 0;
if (data.gcodeAnalysis) {
_.forEach(data.gcodeAnalysis.filament, (tool): void => {
filamentLength += tool.volume;
filamentLength += tool.length;
});
}
const file = ({
Expand All @@ -160,7 +160,7 @@ export class FilesService {
? {
date: this.service.convertDateToString(new Date(data.date * 1000)),
printTime: this.service.convertSecondsToHours(data.gcodeAnalysis.estimatedPrintTime),
filamentWeight: this.service.convertFilamentVolumeToWeight(filamentLength),
filamentWeight: this.service.convertFilamentLengthToWeight(filamentLength),
}
: {}),
thumbnail: data.thumbnail
Expand Down
6 changes: 3 additions & 3 deletions src/app/job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class JobService {
progress: Math.round((data.progress.filepos / data.job.file.size) * 100),
...(data.job.filament !== null
? {
filamentAmount: this.service.convertFilamentVolumeToWeight(
filamentAmount: this.service.convertFilamentLengthToWeight(
this.getTotalAmountOfFilament(data.job.filament),
),
}
Expand Down Expand Up @@ -103,9 +103,9 @@ export class JobService {
for (const property in filamentAmount) {
if (
Object.prototype.hasOwnProperty.call(filamentAmount, property) &&
Object.prototype.hasOwnProperty.call(filamentAmount[property], 'volume')
Object.prototype.hasOwnProperty.call(filamentAmount[property], 'length')
) {
filamentLength += filamentAmount[property].volume;
filamentLength += filamentAmount[property].length;
}
}
return filamentLength;
Expand Down
3 changes: 0 additions & 3 deletions src/app/plugin-service/enclosure.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ export class EnclosureService {
if (this.httpPOSTRequest) {
this.httpPOSTRequest.unsubscribe();
}
console.log(colorBody);
console.log(identifier);
this.httpPOSTRequest = this.http
.patch(
this.configService.getURL('plugin/enclosure/neopixel/' + identifier).replace('/api', ''),
Expand All @@ -79,7 +77,6 @@ export class EnclosureService {
.subscribe(
(): void => resolve(),
(error: HttpErrorResponse): void => {
console.log(error.message);
this.notificationService.setError("Can't set LED color!", error.message);
reject();
},
Expand Down