Skip to content

Commit

Permalink
Allow removal of individual results from Backtest memory
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Jul 26, 2023
1 parent 1fdbee1 commit b151d1f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/components/ftbot/BacktestResultSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
@click="setBacktestResult(key)"
>
{{ key }} {{ strat.total_trades }} {{ formatPercent(strat.profit_total) }}
<b-button
class="ms-1"
size="sm"
title="Delete this Result."
@click.stop="emit('removeResult', key)"
>
<i-mdi-delete />
</b-button>
</b-list-group-item>
</b-list-group>
</div>
Expand All @@ -27,8 +35,12 @@ defineProps({
},
selectedBacktestResultKey: { required: false, default: '', type: String },
});
const emit = defineEmits(['selectionChange']);
const setBacktestResult = (key) => {
const emit = defineEmits<{
selectionChange: [value: string];
removeResult: [value: string];
}>();
const setBacktestResult = (key: string) => {
emit('selectionChange', key);
};
</script>
Expand Down
11 changes: 11 additions & 0 deletions src/stores/ftbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,17 @@ export function createBotSubStore(botId: string, botName: string) {
setBacktestResultKey(key: string) {
this.selectedBacktestResultKey = key;
},
removeBacktestResultFromMemory(key: string) {
if (this.selectedBacktestResultKey === key) {
// Get first key from backtestHistory that is not the key to be deleted
const keys = Object.keys(this.backtestHistory);
const index = keys.findIndex((k) => k !== key);
if (index !== -1) {
this.selectedBacktestResultKey = keys[index];
}
}
delete this.backtestHistory[key];
},
async getSysInfo() {
try {
const { data } = await api.get<SysInfoResponse>('/sysinfo');
Expand Down
1 change: 1 addition & 0 deletions src/views/BacktestingView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
:backtest-history="botStore.activeBot.backtestHistory"
:selected-backtest-result-key="botStore.activeBot.selectedBacktestResultKey"
@selection-change="botStore.activeBot.setBacktestResultKey"
@remove-result="botStore.activeBot.removeBacktestResultFromMemory"
/>
</transition>
</div>
Expand Down

0 comments on commit b151d1f

Please sign in to comment.