Enhance simulation preparation process and frontend display for improved user experience
- Added synchronous retrieval of entity count before starting background tasks in simulation.py, allowing immediate access to expected agent totals for the frontend. - Updated the simulation state to include expected entity count and types, enhancing the information available during preparation. - Modified Step2EnvSetup.vue to display a pending status when the simulation is in progress and adjusted the simulation rounds configuration to dynamically reflect calculated values. - Improved the slider for custom rounds to ensure it adapts to the auto-generated maximum rounds, enhancing usability and clarity.
This commit is contained in:
@@ -427,6 +427,7 @@
|
||||
</div>
|
||||
<div class="step-status">
|
||||
<span v-if="phase >= 4" class="badge processing">进行中</span>
|
||||
<span v-else class="badge pending">等待</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -434,8 +435,8 @@
|
||||
<p class="api-note">POST /api/simulation/start</p>
|
||||
<p class="description">模拟环境已准备完成,可以开始运行模拟</p>
|
||||
|
||||
<!-- 模拟轮数配置 -->
|
||||
<div class="rounds-config-section">
|
||||
<!-- 模拟轮数配置 - 只有在配置生成完成且轮数计算出来后才显示 -->
|
||||
<div v-if="simulationConfig && autoGeneratedRounds" class="rounds-config-section">
|
||||
<div class="rounds-header">
|
||||
<div class="header-left">
|
||||
<span class="section-title">模拟轮数设定</span>
|
||||
@@ -465,10 +466,10 @@
|
||||
type="range"
|
||||
v-model.number="customMaxRounds"
|
||||
min="10"
|
||||
max="120"
|
||||
:max="autoGeneratedRounds"
|
||||
step="5"
|
||||
class="minimal-slider"
|
||||
:style="{ '--percent': ((customMaxRounds - 10) / (120 - 10)) * 100 + '%' }"
|
||||
:style="{ '--percent': ((customMaxRounds - 10) / (autoGeneratedRounds - 10)) * 100 + '%' }"
|
||||
/>
|
||||
<div class="range-marks">
|
||||
<span>10</span>
|
||||
@@ -476,9 +477,9 @@
|
||||
class="mark-recommend"
|
||||
:class="{ active: customMaxRounds === 40 }"
|
||||
@click="customMaxRounds = 40"
|
||||
:style="{ position: 'absolute', left: 'calc(27.27% - 30px)' }"
|
||||
:style="{ position: 'absolute', left: `calc(${(40 - 10) / (autoGeneratedRounds - 10) * 100}% - 30px)` }"
|
||||
>40 (推荐)</span>
|
||||
<span>120</span>
|
||||
<span>{{ autoGeneratedRounds }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -665,7 +666,6 @@ const showProfilesDetail = ref(true)
|
||||
// 模拟轮数配置
|
||||
const useCustomRounds = ref(false) // 默认使用自动配置轮数
|
||||
const customMaxRounds = ref(40) // 默认推荐40轮
|
||||
const autoGeneratedRounds = ref(120) // 自动生成的轮数(从配置中读取)
|
||||
|
||||
// Watch stage to update phase
|
||||
watch(currentStage, (newStage) => {
|
||||
@@ -683,15 +683,20 @@ watch(currentStage, (newStage) => {
|
||||
}
|
||||
})
|
||||
|
||||
// Watch simulationConfig to update autoGeneratedRounds
|
||||
watch(simulationConfig, (newConfig) => {
|
||||
if (newConfig?.time_config) {
|
||||
const totalHours = newConfig.time_config.total_simulation_hours || 120
|
||||
const minutesPerRound = newConfig.time_config.minutes_per_round || 60
|
||||
const calculatedRounds = Math.floor((totalHours * 60) / minutesPerRound)
|
||||
autoGeneratedRounds.value = calculatedRounds || 120
|
||||
// 从配置中计算自动生成的轮数(不使用硬编码默认值)
|
||||
const autoGeneratedRounds = computed(() => {
|
||||
if (!simulationConfig.value?.time_config) {
|
||||
return null // 配置未生成时返回 null
|
||||
}
|
||||
}, { immediate: true })
|
||||
const totalHours = simulationConfig.value.time_config.total_simulation_hours
|
||||
const minutesPerRound = simulationConfig.value.time_config.minutes_per_round
|
||||
if (!totalHours || !minutesPerRound) {
|
||||
return null // 配置数据不完整时返回 null
|
||||
}
|
||||
const calculatedRounds = Math.floor((totalHours * 60) / minutesPerRound)
|
||||
// 确保最大轮数不小于40(推荐值),避免滑动条范围异常
|
||||
return Math.max(calculatedRounds, 40)
|
||||
})
|
||||
|
||||
// Polling timer
|
||||
let pollTimer = null
|
||||
@@ -786,6 +791,12 @@ const startPrepareSimulation = async () => {
|
||||
taskId.value = res.data.task_id
|
||||
addLog(`准备任务已启动: ${res.data.task_id}`)
|
||||
|
||||
// 立即设置预期Agent总数(从prepare接口返回值获取)
|
||||
if (res.data.expected_entities_count) {
|
||||
expectedTotal.value = res.data.expected_entities_count
|
||||
addLog(`预期Agent总数: ${res.data.expected_entities_count}`)
|
||||
}
|
||||
|
||||
// 开始轮询进度
|
||||
startPolling()
|
||||
// 开始实时获取 Profiles
|
||||
|
||||
Reference in New Issue
Block a user