大家好,
我正在尝试获取机器能耗数据的统计结果(图形表示)。在机器的组件建模中,我定义了空闲、工作和关机功率,单位为千瓦。同时,我还有一个Python脚本来计算模拟过程中的总能耗。
(已附截图)
但当我从统计数据中插入图表时,图表显示为恒定值,并未展示模拟过程中动态变化的空闲、工作和关机功率。同时,它也没有计算总能耗值。
我不知道哪里出了问题。恳请大家分享想法,帮助我解决这个问题。
谢谢![]()
大家好,
我正在尝试获取机器能耗数据的统计结果(图形表示)。在机器的组件建模中,我定义了空闲、工作和关机功率,单位为千瓦。同时,我还有一个Python脚本来计算模拟过程中的总能耗。
(已附截图)
但当我从统计数据中插入图表时,图表显示为恒定值,并未展示模拟过程中动态变化的空闲、工作和关机功率。同时,它也没有计算总能耗值。
我不知道哪里出了问题。恳请大家分享想法,帮助我解决这个问题。
谢谢![]()
OnRun中没有包含循环,所以它只在模拟开始时计算并设置属性值一次。
通常,如果目标是以固定间隔运行循环,OnRun的使用方式如下:
def OnRun():
dt = 1.0 # 1 second
while True:
# your logic here
delay(dt)
既然你的脚本已经在读取属性当前值,并且已有变量 `lastTime` 用于计算距离上次调用的时间差,你可以使用 `OnSimulationUpdate` 来实现逻辑: 此方法会在每次场景更新时被调用。在 1 倍仿真速度且布局为空的情况下,它大约每 40 毫秒调用一次。某些组件可能会调用 `getSimulation().update()`,此时该方法会被更频繁地调用,且时间间隔不均匀。 附注:我将把此主题移至 Python 编程分类。 Raj 2026 年 1 月 8 日 下午 1:26 非常感谢您的回复。 但我仍然无法绘制在仿真过程中动态变化的“总能耗”图表。 KustiH 2026 年 1 月 8 日 下午 3:54 “EnergyConsumed” 属性的值是否在变化,但未在统计仪表板中显示?请检查主页选项卡中的统计间隔设置。该值是否非常大,例如 3600 秒?数据点会按照该间隔绘制,不会更频繁。 在采纳我的建议后,你的脚本现在是什么样子?
def OnSimulationUpdate(simtime):
global lastTime
dt = simtime - lastTime
lastTime = simtime
# your logic here
This method is called every time the scene is updated. With 1x simulation speed and empty layout it’s called every 40 milliseconds. Some components can call getSimulation().update(), and then the method would be called more frequently with uneven intervals.

Ps. I’ll move this topic to Python Programming.
Thank you so much for your reply.
But still, I am not able to plot the graph that changes dynamically during simulation for the “Total Energy Consumption.”
Does the EnergyConsumed property change value, but the value is not reflected in statistics dashboard? Check the statistics interval setting from Home tab. Is it a very large number, e.g. 3600 seconds? Data points are plotted following that interval, not any more often.
What does the script look like after implementing my tips?
您是本站第530966名访客 今日有0篇新文章/评论