converts trail duration to seconds
This commit is contained in:
@@ -274,7 +274,7 @@ func createTrailFromTour(app core.App, k *KomootApi, detailedTour *DetailedKomoo
|
|||||||
"distance": detailedTour.Distance,
|
"distance": detailedTour.Distance,
|
||||||
"elevation_gain": detailedTour.ElevationUp,
|
"elevation_gain": detailedTour.ElevationUp,
|
||||||
"elevation_loss": detailedTour.ElevationDown,
|
"elevation_loss": detailedTour.ElevationDown,
|
||||||
"duration": detailedTour.Duration / 60,
|
"duration": detailedTour.Duration,
|
||||||
"date": detailedTour.Date,
|
"date": detailedTour.Date,
|
||||||
"external_provider": "komoot",
|
"external_provider": "komoot",
|
||||||
"external_id": strconv.Itoa(detailedTour.ID),
|
"external_id": strconv.Itoa(detailedTour.ID),
|
||||||
|
|||||||
@@ -342,7 +342,7 @@ func createTrailFromRoute(app core.App, route StravaRoute, gpx *filesystem.File,
|
|||||||
"public": !route.Private,
|
"public": !route.Private,
|
||||||
"distance": route.Distance,
|
"distance": route.Distance,
|
||||||
"elevation_gain": route.ElevationGain,
|
"elevation_gain": route.ElevationGain,
|
||||||
"duration": route.EstimatedMovingTime / 60,
|
"duration": route.EstimatedMovingTime,
|
||||||
"date": time.Unix(int64(route.Timestamp), 0),
|
"date": time.Unix(int64(route.Timestamp), 0),
|
||||||
"external_provider": "strava",
|
"external_provider": "strava",
|
||||||
"external_id": route.IDStr,
|
"external_id": route.IDStr,
|
||||||
@@ -523,7 +523,7 @@ func createTrailFromActivity(app core.App, activity *DetailedStravaActivity, gpx
|
|||||||
"public": !activity.Private,
|
"public": !activity.Private,
|
||||||
"distance": activity.Distance,
|
"distance": activity.Distance,
|
||||||
"elevation_gain": activity.TotalElevationGain,
|
"elevation_gain": activity.TotalElevationGain,
|
||||||
"duration": activity.ElapsedTime / 60,
|
"duration": activity.ElapsedTime,
|
||||||
"date": activity.StartDate,
|
"date": activity.StartDate,
|
||||||
"external_provider": "strava",
|
"external_provider": "strava",
|
||||||
"external_id": activity.ID,
|
"external_id": activity.ID,
|
||||||
|
|||||||
42
db/migrations/1750859597_trail_duration_seconds.go
Normal file
42
db/migrations/1750859597_trail_duration_seconds.go
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package migrations
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/pocketbase/pocketbase/core"
|
||||||
|
m "github.com/pocketbase/pocketbase/migrations"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
m.Register(func(app core.App) error {
|
||||||
|
trails, err := app.FindAllRecords("trails")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, t := range trails {
|
||||||
|
duration := t.GetFloat("duration")
|
||||||
|
t.Set("duration", duration*60)
|
||||||
|
err = app.Save(t)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}, func(app core.App) error {
|
||||||
|
trails, err := app.FindAllRecords("trails")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, t := range trails {
|
||||||
|
duration := t.GetFloat("duration")
|
||||||
|
t.Set("duration", duration/60)
|
||||||
|
err = app.Save(t)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -120,7 +120,7 @@
|
|||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
><i class="fa fa-clock mr-2"></i>{formatTimeHHMM(
|
><i class="fa fa-clock mr-2"></i>{formatTimeHHMM(
|
||||||
log.duration ? log.duration / 60 : undefined,
|
log.duration ? log.duration : undefined,
|
||||||
)}</span
|
)}</span
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
|
|||||||
@@ -155,7 +155,7 @@
|
|||||||
{formatElevation(log.elevation_loss)}
|
{formatElevation(log.elevation_loss)}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{formatTimeHHMM(log.duration ? log.duration / 60 : undefined)}
|
{formatTimeHHMM(log.duration ? log.duration : undefined)}
|
||||||
</td>
|
</td>
|
||||||
{#if showCategory}
|
{#if showCategory}
|
||||||
<td>
|
<td>
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
import { browser } from "$app/environment";
|
import { browser } from "$app/environment";
|
||||||
import { page } from "$app/state";
|
import { page } from "$app/state";
|
||||||
import { get } from "svelte/store";
|
|
||||||
|
|
||||||
export function formatTimeHHMM(minutes?: number) {
|
export function formatTimeHHMM(seconds?: number) {
|
||||||
if (!minutes) {
|
if (seconds == null || isNaN(seconds)) {
|
||||||
return "-";
|
return "-";
|
||||||
}
|
}
|
||||||
const m = minutes % 60;
|
|
||||||
|
|
||||||
const h = (minutes - m) / 60;
|
const totalMinutes = Math.floor(seconds / 60);
|
||||||
|
const m = totalMinutes % 60;
|
||||||
|
const h = Math.floor(totalMinutes / 60);
|
||||||
|
|
||||||
return (h < 10 ? "0" : "") + h.toString() + "h " + (Math.round(m) < 10 ? "0" : "") + Math.round(m).toString() + "m";
|
return (h < 10 ? "0" : "") + h.toString() + "h " + (m < 10 ? "0" : "") + m.toString() + "m";
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formatDistance(meters?: number) {
|
export function formatDistance(meters?: number) {
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export async function gpx2trail(gpxString: string, fallbackName?: string, f: (ur
|
|||||||
.substring(0, 10);
|
.substring(0, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
trail.duration = totals.duration / 1000 / 60
|
trail.duration = totals.duration / 1000
|
||||||
trail.elevation_gain = totals.elevationGain;
|
trail.elevation_gain = totals.elevationGain;
|
||||||
trail.elevation_loss = totals.elevationLoss;
|
trail.elevation_loss = totals.elevationLoss;
|
||||||
trail.distance = totals.distance
|
trail.distance = totals.distance
|
||||||
|
|||||||
@@ -959,7 +959,7 @@ export class ElevationProfile {
|
|||||||
|
|
||||||
if (time) {
|
if (time) {
|
||||||
const timePrevious = this.times[i - 1];
|
const timePrevious = this.times[i - 1];
|
||||||
const timeDelta = (time.getTime() - timePrevious.getTime()) / (1000 * 60);
|
const timeDelta = (time.getTime() - timePrevious.getTime()) / (1000);
|
||||||
cumulatedTime += timeDelta;
|
cumulatedTime += timeDelta;
|
||||||
this.cumulatedTime.push(cumulatedTime)
|
this.cumulatedTime.push(cumulatedTime)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -316,7 +316,7 @@
|
|||||||
><i class="fa fa-clock mr-3"></i>{$_("duration")}</span
|
><i class="fa fa-clock mr-3"></i>{$_("duration")}</span
|
||||||
>
|
>
|
||||||
<p class="text-3xl font-bold">
|
<p class="text-3xl font-bold">
|
||||||
{formatTimeHHMM(totalDuration / 60)}
|
{formatTimeHHMM(totalDuration)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -858,7 +858,7 @@
|
|||||||
overwriteGPX = true;
|
overwriteGPX = true;
|
||||||
const totals = route.features;
|
const totals = route.features;
|
||||||
$formData.distance = totals.distance;
|
$formData.distance = totals.distance;
|
||||||
$formData.duration = totals.duration / 1000 / 60;
|
$formData.duration = totals.duration / 1000;
|
||||||
$formData.elevation_gain = totals.elevationGain;
|
$formData.elevation_gain = totals.elevationGain;
|
||||||
$formData.elevation_loss = totals.elevationLoss;
|
$formData.elevation_loss = totals.elevationLoss;
|
||||||
$formData.expand!.gpx_data = route.toString();
|
$formData.expand!.gpx_data = route.toString();
|
||||||
|
|||||||
Reference in New Issue
Block a user