|
|
@@ -225,6 +225,24 @@ function sleep(ms) {
|
|
|
return new Promise((r) => setTimeout(r, ms))
|
|
|
}
|
|
|
|
|
|
+/** 根据轨迹首尾 deviceTime 得到预计跑完全程的等待时长(与循环内 sleep 总和一致,不含网络请求) */
|
|
|
+function estimateRunWallClockMs(points) {
|
|
|
+ if (!Array.isArray(points) || points.length < 2) {
|
|
|
+ return 0
|
|
|
+ }
|
|
|
+ return Math.max(0, points[points.length - 1].deviceTime - points[0].deviceTime)
|
|
|
+}
|
|
|
+
|
|
|
+function formatMinutesSeconds(ms) {
|
|
|
+ const totalSec = Math.max(0, Math.round(ms / 1000))
|
|
|
+ const m = Math.floor(totalSec / 60)
|
|
|
+ const s = totalSec % 60
|
|
|
+ if (m <= 0) {
|
|
|
+ return `${s}秒`
|
|
|
+ }
|
|
|
+ return `${m}分${s}秒`
|
|
|
+}
|
|
|
+
|
|
|
function buildAxiosConfig(headers) {
|
|
|
const s = getJkesSettings()
|
|
|
const agent = new https.Agent({
|
|
|
@@ -342,7 +360,8 @@ async function runJkesRecord(opts) {
|
|
|
})
|
|
|
const recordId = startJson.data.info.id
|
|
|
const chunks = chunkPoints(points, firstBatchSize, batchSize)
|
|
|
- log(`已开始跑步 recordId=${recordId} 预计耗时${(CALC_INTERVAL_MS * chunks.length / 1000).toFixed(2)}秒`)
|
|
|
+ const estMs = estimateRunWallClockMs(points)
|
|
|
+ log(`已开始跑步 recordId=${recordId} 预计耗时${formatMinutesSeconds(estMs)}`)
|
|
|
|
|
|
const calcState = {
|
|
|
runStartMs,
|
|
|
@@ -389,7 +408,7 @@ async function runJkesRecord(opts) {
|
|
|
|
|
|
await postJson(`/health/runRecord/pause/${recordId}`, {})
|
|
|
const endJson = await postJson(`/health/runRecord/end/${recordId}`, {})
|
|
|
- log(`ID:{recordId} 跑步已结束`)
|
|
|
+ log(`ID:${recordId} 跑步已结束`)
|
|
|
return { recordId, endJson, runStartMs, uploadedPayloadPoints }
|
|
|
}
|
|
|
|