mirror of
https://github.com/AstrBotDevs/AstrBot.git
synced 2026-10-29 17:24:47 +08:00
🐞 fix: 显示运行时长国际化
This commit is contained in:
@@ -41,10 +41,15 @@ class StatRoute(Route):
|
|||||||
await self.core_lifecycle.restart()
|
await self.core_lifecycle.restart()
|
||||||
return Response().ok().__dict__
|
return Response().ok().__dict__
|
||||||
|
|
||||||
def format_sec(self, sec: int):
|
def _get_running_time_components(self, total_seconds: int):
|
||||||
m, s = divmod(sec, 60)
|
"""将总秒数转换为时分秒组件"""
|
||||||
h, m = divmod(m, 60)
|
minutes, seconds = divmod(total_seconds, 60)
|
||||||
return f"{h}小时{m}分{s}秒"
|
hours, minutes = divmod(minutes, 60)
|
||||||
|
return {
|
||||||
|
"hours": hours,
|
||||||
|
"minutes": minutes,
|
||||||
|
"seconds": seconds
|
||||||
|
}
|
||||||
|
|
||||||
def is_default_cred(self):
|
def is_default_cred(self):
|
||||||
username = self.config["dashboard"]["username"]
|
username = self.config["dashboard"]["username"]
|
||||||
@@ -107,6 +112,11 @@ class StatRoute(Route):
|
|||||||
}
|
}
|
||||||
plugin_info.append(info)
|
plugin_info.append(info)
|
||||||
|
|
||||||
|
# 计算运行时长组件
|
||||||
|
running_time = self._get_running_time_components(
|
||||||
|
int(time.time()) - self.core_lifecycle.start_time
|
||||||
|
)
|
||||||
|
|
||||||
stat_dict.update(
|
stat_dict.update(
|
||||||
{
|
{
|
||||||
"platform": self.db_helper.get_grouped_base_stats(
|
"platform": self.db_helper.get_grouped_base_stats(
|
||||||
@@ -119,9 +129,7 @@ class StatRoute(Route):
|
|||||||
"plugin_count": len(plugins),
|
"plugin_count": len(plugins),
|
||||||
"plugins": plugin_info,
|
"plugins": plugin_info,
|
||||||
"message_time_series": message_time_based_stats,
|
"message_time_series": message_time_based_stats,
|
||||||
"running": self.format_sec(
|
"running": running_time, # 现在返回时间组件而不是格式化的字符串
|
||||||
int(time.time()) - self.core_lifecycle.start_time
|
|
||||||
),
|
|
||||||
"memory": {
|
"memory": {
|
||||||
"process": psutil.Process().memory_info().rss >> 20,
|
"process": psutil.Process().memory_info().rss >> 20,
|
||||||
"system": psutil.virtual_memory().total >> 20,
|
"system": psutil.virtual_memory().total >> 20,
|
||||||
|
|||||||
@@ -21,7 +21,8 @@
|
|||||||
},
|
},
|
||||||
"runningTime": {
|
"runningTime": {
|
||||||
"title": "Uptime",
|
"title": "Uptime",
|
||||||
"subtitle": "System uptime duration"
|
"subtitle": "System uptime duration",
|
||||||
|
"format": "{hours}h {minutes}m {seconds}s"
|
||||||
},
|
},
|
||||||
"memoryUsage": {
|
"memoryUsage": {
|
||||||
"title": "Memory Usage",
|
"title": "Memory Usage",
|
||||||
|
|||||||
@@ -21,7 +21,8 @@
|
|||||||
},
|
},
|
||||||
"runningTime": {
|
"runningTime": {
|
||||||
"title": "运行时间",
|
"title": "运行时间",
|
||||||
"subtitle": "系统已运行时长"
|
"subtitle": "系统已运行时长",
|
||||||
|
"format": "{hours}小时{minutes}分{seconds}秒"
|
||||||
},
|
},
|
||||||
"memoryUsage": {
|
"memoryUsage": {
|
||||||
"title": "内存占用",
|
"title": "内存占用",
|
||||||
|
|||||||
@@ -30,7 +30,16 @@ export default {
|
|||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
formattedTime() {
|
formattedTime() {
|
||||||
return this.stat?.running || this.t('status.loading');
|
if (!this.stat?.running) {
|
||||||
|
return this.t('status.loading');
|
||||||
|
}
|
||||||
|
|
||||||
|
const { hours, minutes, seconds } = this.stat.running;
|
||||||
|
return this.t('stats.runningTime.format', {
|
||||||
|
hours,
|
||||||
|
minutes,
|
||||||
|
seconds
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user