fietsboek.models.track module

GPX Track model definitions.

A freshly uploaded track is stored as a Upload, until the user finishes putting in the extra information. This is done so that we can parse the GPX file on the server-side and pre-fill some of the fields (such as the date) with GPX metadata.

Once the user has finished the upload, the track is saved as a Track. Each track can have an associated cache that caches the computed values. This keeps the user’s metadata and the computed information separate, and allows for example all cached data to be re-computed without interfering with the other meta information.

class fietsboek.models.track.Tag(**kwargs)

Bases: Base

A tag is a single keyword associated with a track.

Variables:
  • track_id (int) – ID of the track that this tag belongs to.

  • tag (str) – Actual text of the tag.

  • track (Track) – The track object that this tag belongs to.

tag
track: Mapped[Track]
track_id
class fietsboek.models.track.Track(**kwargs)

Bases: Base

A Track represents a single GPX track.

The Track object only contains the attributes that we need to store. Attributes and metadata that is taken from the GPX file itself is not stored here. Instead, a Track has an associated TrackCache object, where the computed information can be stored.

Variables:
add_tag(text)

Add a tag with the given text.

If a tag with the text already exists, does nothing.

Parameters:

text (str) – The text of the tag.

badges: Mapped[list[Badge]]
cache: Mapped[Optional[TrackCache]]
comments: Mapped[list[Comment]]
property date

The time-zone-aware date this track has set.

This combines the date_raw and date_tz values to provide a timezone aware datetime.

Returns:

The aware datetime.

Return type:

datetime.datetime

date_raw
date_tz
description
ensure_cache(gpx_data)

Ensure that a cached version of this track’s metadata exists.

Parameters:

gpx_data (Union[str, bytes, GPX]) – GPX data (uncompressed) from which to build the cache.

classmethod factory(request)

Factory method to pass to a route definition.

This factory retrieves the track based on the track_id matched route parameter, and returns the track. If the track is not found, HTTPNotFound is raised.

Raises:

pyramid.httpexception.NotFound – If the track is not found.

Parameters:

request (Request) – The pyramid request.

Returns:

The track.

Type:

Track

favourees: Mapped[list[User]]
id
images: Mapped[list[ImageMetadata]]
is_visible_to(user)

Checks whether the track is visible to the given user.

Parameters:

request (fietsboek.models.User) – The user.

Returns:

Whether the track is visible to the current user.

Return type:

bool

owner: Mapped[User]
owner_id
remove_tag(text)

Remove the tag with the given text.

Parameters:

text (str) – The text of the tag to remove.

show_organic_data()

Determines whether the organic data should be shown.

This includes average speed, maximum speed, record start time and record end time.

For synthetic tracks, we only show the length, uphill and downhill values.

Returns:

Whether the organic data should be shown.

Return type:

bool

sync_tags(tags)

Syncs the track’s tags with a given set of wanted tags.

This adds and removes tags from the track as needed.

Parameters:

tags (set[str]) – The wanted tags.

tagged_people: Mapped[list[User]]
tags: Mapped[list[Tag]]
text_tags()

Returns a set of textual tags.

Returns:

The tags of the track, as a set of strings.

Return type:

set[str]

title
transformer_params_for(transformer_id)

Returns the transformer parameters for the given transformer.

If the transformer is not active, returns None.

Parameters:

transformer_id (str) – The string ID of the transformer.

Return type:

Optional[dict]

Returns:

The settings as a dictionary.

transformers
type
visibility
class fietsboek.models.track.TrackCache(**kwargs)

Bases: Base

Cache for computed track metadata.

In order to repeatedly compute the track metadata from GPX files, this information (such as length, uphill, downhill, …) is stored in a TrackCache.

Variables:
  • track_id (int) – ID of the track this cache belongs to.

  • length (float) – Length of the track, in meters.

  • uphill (float) – Uphill amount, in meters.

  • downhill (float) – Downhill amount, in meters.

  • moving_time (float) – Time spent moving, in seconds.

  • stopped_time (float) – Time stopped, in seconds.

  • max_speed (float) – Maximum speed, in meters/second.

  • avg_speed (float) – Average speed, in meters/second.

  • start_time_raw (datetime.datetime) – Start time of the GPX recording.

  • start_time_tz (int) – Timezone offset of the start time in minutes.

  • end_time_raw (datetime.datetime) – End time of the GPX recording.

  • end_time_tz (int) – Timezone offset of the end time in minutes.

  • track (Track) – The track that belongs to this cache entry.

avg_speed
downhill
property end_time: datetime | None

The time-zone-aware end time of this track.

Returns:

The aware datetime.

end_time_raw
end_time_tz
length
max_speed
moving_time
property start_time: datetime | None

The time-zone-aware start time of this track.

Returns:

The aware datetime.

start_time_raw
start_time_tz
stopped_time
track: Mapped[Track]
track_id
uphill
class fietsboek.models.track.TrackType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

An enum that represents the type of a track.

ORGANIC = 1

An organic track that represents a recording of a user.

SYNTHETIC = 2

A planned track that represents a route, but not an actual recording.

This is also called a “template”.

class fietsboek.models.track.TrackWithMetadata(track, data_manager)

Bases: object

A class to add metadata to a Track.

This basically caches the result of fietsboek.util.tour_metadata(), or uses the track’s cache if possible.

Loading of the metadata is lazy on first access. The track is accessible as track, but most attributes are proxied read-only.

property avg_speed: float

Returns the average speed.

Returns:

Average speed in meters/second.

property badges: List[Badge]

Badges of the underlying track.

property comments: List[Comment]

Comments of the underlying track.

property date: datetime | None

Date of the underlying track.

property description: str | None

Description of the underlying track.

property downhill: float

Returns the downhill of the track.

Returns:

Downhill in meters.

property duration: timedelta

Returns the duration of this track.

This is equivalent to end_time - start_time, given that no DST change happens between those points.

Alternatively, it is equivalent to moving_time + stopped_time.

Returns:

The track duration.

property end_time: datetime

Returns the end time.

This is the time embedded in the GPX file, not the time in the date column.

Returns:

End time.

property favourees: List[User]

People who have favoured this track.

html_tooltip(localizer)

Generate a quick summary of the track as a HTML element.

This can be used in Bootstrap tooltips.

Parameters:

localizer (Localizer) – The localizer used for localization.

Return type:

Markup

Returns:

The generated HTML.

html_tooltip_tagged_people()

Returns the tagged people as HTML, ready to be shown as a tooltip.

Return type:

Markup

Returns:

The generated HTML.

property id: int | None

ID of the underlying track.

property images: List[ImageMetadata]

Images of the underlying track.

property length: float

Returns the length of the track..

Returns:

Length of the track in meters.

Link secret of the underlying track.

property max_speed: float

Returns the maximum speed.

Returns:

Maximum speed in meters/second.

property moving_time: timedelta

Returns the moving time.

Returns:

Moving time in seconds.

property owner: User

Owner of the undlerying track.

show_organic_data()

Proxied method Track.show_organic_data().

Return type:

bool

Returns:

Whether the organic data should be shown.

property start_time: datetime

Returns the start time.

This is the time embedded in the GPX file, not the time in the date column.

Returns:

Start time.

property stopped_time: timedelta

Returns the stopped time.

Returns:

Stopped time in seconds.

property tagged_people: List[User]

Tagged people of the underlying track.

property tags: List[Tag]

Tags of the underlying track.

text_tags()

Returns a set of textual tags.

Return type:

Set[str]

Returns:

The tags of the track, as a set of strings.

property title: str | None

Title of the underlying track.

property type: TrackType | None

Type of the underlying track.

property uphill: float

Returns the uphill of the track.

Returns:

Uphill in meters.

property visibility: Visibility | None

Visibility of the underlying track.

class fietsboek.models.track.Upload(**kwargs)

Bases: Base

A track that is currently being uploaded.

Once a upload is done, the Upload item is removed and a proper Track is created instead.

Variables:
  • id (int) – Database ID.

  • uploaded_at (datetime.datetime) – Date of the upload.

  • owner_id (int) – ID of the uploader.

  • gpx (bytes) – Compressed GPX data.

  • owner (fietsboek.model.user.User) – Uploader of this track.

classmethod factory(request)

Factory method to pass to a route definition.

This factory retrieves the upload based on the upload_id matched route parameter, and returns the upload. If the upload is not found, HTTPNotFound is raised.

Raises:

pyramid.httpexception.NotFound – If the upload is not found.

Parameters:

request (Request) – The pyramid request.

Returns:

The upload.

Type:

Track

gpx
property gpx_data

Access the decompressed gpx data.

id
owner: Mapped[User]
owner_id
uploaded_at
class fietsboek.models.track.Visibility(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: Enum

An enum that represents the visibility of tracks.

Note that the track is always visible to tagged people and via the sharing link.

FRIENDS = 2

Friends of the owner can see the track as well.

FRIENDS_TAGGED = 3

Friends of the owner or friends of tagged people can see the track.

LOGGED_IN = 4

Any logged in user can see the track.

PRIVATE = 1

Only the owner of the track can see it.

PUBLIC = 5

Anyone can see the track.