Skip to content

Commit

Permalink
feat: add finish time selection from slicer or file (#1378)
Browse files Browse the repository at this point in the history
Signed-off-by: Made Baruna <[email protected]>
Signed-off-by: Pedro Lamas <[email protected]>
Co-authored-by: Pedro Lamas <[email protected]>
  • Loading branch information
MadeBaruna and pedrolamas authored Mar 2, 2024
1 parent 3aa7269 commit 04abea4
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 34 deletions.
122 changes: 97 additions & 25 deletions src/components/settings/GeneralSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@

<v-divider />

<app-setting
:title="$t('app.setting.label.confirm_on_estop')"
>
<app-setting :title="$t('app.setting.label.confirm_on_estop')">
<v-switch
v-model="confirmOnEstop"
hide-details
Expand All @@ -79,9 +77,7 @@

<v-divider />

<app-setting
:title="$t('app.setting.label.show_upload_and_print')"
>
<app-setting :title="$t('app.setting.label.show_upload_and_print')">
<v-switch
v-model="showUploadAndPrint"
hide-details
Expand All @@ -92,9 +88,7 @@

<v-divider />

<app-setting
:title="$t('app.setting.label.power_toggle_in_top_nav')"
>
<app-setting :title="$t('app.setting.label.power_toggle_in_top_nav')">
<v-select
v-model="topNavPowerToggle"
filled
Expand All @@ -107,9 +101,7 @@

<v-divider />

<app-setting
:title="$t('app.setting.label.confirm_on_power_device_change')"
>
<app-setting :title="$t('app.setting.label.confirm_on_power_device_change')">
<v-switch
v-model="confirmOnPowerDeviceChange"
hide-details
Expand All @@ -120,9 +112,7 @@

<v-divider />

<app-setting
:title="$t('app.setting.label.show_save_config_and_restart')"
>
<app-setting :title="$t('app.setting.label.show_save_config_and_restart')">
<v-switch
v-model="showSaveConfigAndRestart"
hide-details
Expand All @@ -134,9 +124,7 @@
<template v-if="showSaveConfigAndRestart">
<v-divider />

<app-setting
:title="$t('app.setting.label.confirm_on_save_config_and_restart')"
>
<app-setting :title="$t('app.setting.label.confirm_on_save_config_and_restart')">
<v-switch
v-model="confirmOnSaveConfigAndRestart"
hide-details
Expand All @@ -149,9 +137,7 @@
<template v-if="showSaveConfigAndRestart && confirmOnSaveConfigAndRestart">
<v-divider />

<app-setting
:title="$t('app.setting.label.sections_to_ignore_pending_configuration_changes')"
>
<app-setting :title="$t('app.setting.label.sections_to_ignore_pending_configuration_changes')">
<v-combobox
v-model="sectionsToIgnorePendingConfigurationChanges"
:items="['bed_mesh default', 'bed_tilt']"
Expand All @@ -169,9 +155,7 @@

<v-divider />

<app-setting
:title="$t('app.setting.label.print_in_progress_layout')"
>
<app-setting :title="$t('app.setting.label.print_in_progress_layout')">
<v-select
v-model="printInProgressLayout"
filled
Expand All @@ -183,6 +167,44 @@

<v-divider />

<app-setting
:title="$t('app.setting.label.print_progress_calculation')"
:sub-title="$t('app.setting.tooltip.average_calculation')"
>
<v-select
v-model="printProgressCalculation"
multiple
filled
dense
hide-details="auto"
:rules="[
$rules.lengthGreaterThanOrEqual(1),
]"
:items="availablePrintProgressCalculation"
/>
</app-setting>

<v-divider />

<app-setting
:title="$t('app.setting.label.print_eta_calculation')"
:sub-title="$t('app.setting.tooltip.average_calculation')"
>
<v-select
v-model="printEtaCalculation"
multiple
filled
dense
hide-details="auto"
:rules="[
$rules.lengthGreaterThanOrEqual(1),
]"
:items="availablePrintEtaCalculation"
/>
</app-setting>

<v-divider />

<app-setting
:title="$t('app.setting.label.enable_diagnostics')"
:sub-title="$t('app.setting.tooltip.diagnostics_performance')"
Expand All @@ -204,7 +226,7 @@ import type { VInput } from '@/types'
import { SupportedLocales, DateFormats, TimeFormats } from '@/globals'
import type { OutputPin } from '@/store/printer/types'
import type { Device } from '@/store/power/types'
import type { PrintInProgressLayout } from '@/store/config/types'
import type { PrintEtaCalculation, PrintInProgressLayout, PrintProgressCalculation } from '@/store/config/types'
@Component({
components: {}
Expand Down Expand Up @@ -412,6 +434,56 @@ export default class GeneralSettings extends Mixins(StateMixin) {
]
}
get availablePrintProgressCalculation () {
return [
{
value: 'file',
text: this.$t('app.setting.timer_options.file')
},
{
value: 'slicer',
text: this.$t('app.setting.timer_options.slicer_m73')
}
]
}
get printProgressCalculation () {
return this.$store.state.config.uiSettings.general.printProgressCalculation as PrintProgressCalculation
}
set printProgressCalculation (value: string) {
this.$store.dispatch('config/saveByPath', {
path: 'uiSettings.general.printProgressCalculation',
value,
server: true
})
}
get availablePrintEtaCalculation () {
return [
{
value: 'file',
text: this.$t('app.setting.timer_options.file')
},
{
value: 'slicer',
text: this.$t('app.setting.timer_options.slicer')
}
]
}
get printEtaCalculation () {
return this.$store.state.config.uiSettings.general.printEtaCalculation as PrintEtaCalculation[]
}
set printEtaCalculation (value: PrintEtaCalculation[]) {
this.$store.dispatch('config/saveByPath', {
path: 'uiSettings.general.printEtaCalculation',
value,
server: true
})
}
get enableDiagnostics () {
return this.$store.state.config.uiSettings.general.enableDiagnostics
}
Expand Down
4 changes: 4 additions & 0 deletions src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,9 @@ app:
optional: Optional
power_toggle_in_top_nav: Power toggle in top navigation
primary_color: Primary color
print_eta_calculation: Print ETA calculation
print_in_progress_layout: Print in Progress layout
print_progress_calculation: Print Progress calculation
printer_name: Printer Name
reset: Reset settings
retraction_icon_size: Retraction Icon Size
Expand Down Expand Up @@ -631,6 +633,7 @@ app:
filament: Filament Estimation
file: File Estimation
slicer: Slicer
slicer_m73: Slicer (M73)
title:
authentication: Authentication
console: Console
Expand All @@ -644,6 +647,7 @@ app:
thermal_presets: Thermal Presets
tool: Tool
tooltip:
average_calculation: If more than one option is select, an average will be calculated
diagnostics_performance: '[BETA] Logging diagnostics info may impact performance'
gcode_coords: Use GCode position instead of toolhead position on dashboard
show_manual_probe_dialog_automatically: Automatically shows helper dialog if running a Manual Probe tool
Expand Down
2 changes: 2 additions & 0 deletions src/store/config/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export const defaultState = (): ConfigState => {
showScrewsTiltAdjustDialogAutomatically: true,
forceMoveToggleWarning: true,
printInProgressLayout: 'default',
printProgressCalculation: ['file'],
printEtaCalculation: ['file'],
enableDiagnostics: false,
thumbnailSize: 32,
colorPickerValueRange: 'absolute'
Expand Down
6 changes: 6 additions & 0 deletions src/store/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export interface GeneralConfig {
showScrewsTiltAdjustDialogAutomatically: boolean;
forceMoveToggleWarning: boolean;
printInProgressLayout: PrintInProgressLayout;
printProgressCalculation: PrintProgressCalculation[];
printEtaCalculation: PrintEtaCalculation[];
enableDiagnostics: boolean;
thumbnailSize: number;
colorPickerValueRange: ColorPickerValueRange;
Expand All @@ -112,6 +114,10 @@ export type PrintInProgressLayout = 'default' | 'compact'

export type ColorPickerValueRange = 'absolute' | 'percentage'

export type PrintProgressCalculation = 'file' | 'slicer'

export type PrintEtaCalculation = 'file' | 'slicer'

// Config stored in moonraker db
export interface ThemeConfig {
color: string;
Expand Down
67 changes: 58 additions & 9 deletions src/store/printer/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const getters: GetterTree<PrinterState, RootState> = {
}
},

getPrintProgress: (state): number => {
getFilePrintProgress: (state): number => {
const { gcode_start_byte, gcode_end_byte, path, filename } = state.printer.current_file ?? {}
const { file_position } = state.printer.virtual_sdcard ?? {}

Expand All @@ -121,6 +121,34 @@ export const getters: GetterTree<PrinterState, RootState> = {
return state.printer.display_status.progress || 0
},

getSlicerPrintProgress: (state): number => {
return state.printer.display_status.progress || 0
},

getPrintProgress: (state, getters, rootState): number => {
const printProgressCalculation = rootState.config.uiSettings.general.printProgressCalculation

const printProgressCalculationResults = printProgressCalculation
.map(type => {
switch (type) {
case 'file':
return getters.getFilePrintProgress

case 'slicer':
return getters.getSlicerPrintProgress

default:
return 0
}
})
.filter(result => result > 0)

const printProgress = printProgressCalculationResults
.reduce((a, b) => a + b, 0) / printProgressCalculationResults.length

return printProgress
},

getPrintLayers: (state): number => {
const layersFromPrintStats = state.printer.print_stats.info?.total_layer
if (typeof layersFromPrintStats === 'number') {
Expand Down Expand Up @@ -163,14 +191,15 @@ export const getters: GetterTree<PrinterState, RootState> = {
return 0
},

getTimeEstimates: (state, getters): TimeEstimates => {
getTimeEstimates: (state, getters, rootGetters): TimeEstimates => {
const progress = getters.getPrintProgress as number
const fileProgress = getters.getFilePrintProgress as number

const totalDuration = state.printer.print_stats?.total_duration as number | undefined ?? 0
const printDuration = state.printer.print_stats?.print_duration as number | undefined ?? 0

const fileLeft = printDuration > 0 && progress > 0
? printDuration / progress - printDuration
const fileLeft = printDuration > 0 && fileProgress > 0
? printDuration / fileProgress - printDuration
: 0

const currentFileStatus = state.printer.current_file?.history?.status as string | undefined
Expand All @@ -186,11 +215,31 @@ export const getters: GetterTree<PrinterState, RootState> = {
? slicerTotal - printDuration
: 0

const eta = Date.now() + (
actualLeft > 0
? actualLeft
: fileLeft
) * 1000
const printEtaCalculation = rootGetters.config.uiSettings.general.printEtaCalculation

const printEtaCalculationResults = printEtaCalculation
.map(type => {
switch (type) {
case 'file':
return (
actualLeft > 0
? actualLeft
: fileLeft
)

case 'slicer':
return slicerLeft

default:
return 0
}
})
.filter(result => result > 0)

const etaLeft = printEtaCalculationResults
.reduce((a, b) => a + b, 0) / printEtaCalculationResults.length

const eta = Date.now() + etaLeft * 1000

return {
progress: Math.floor(progress * 100),
Expand Down

0 comments on commit 04abea4

Please sign in to comment.