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:
- tag¶
- 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, aTrack
has an associatedTrackCache
object, where the computed information can be stored.- Variables:
id (int) – Database ID.
owner_id (int) – ID of the track owner.
title (str) – Title of the track.
description (str) – Textual description of the track.
date_raw (datetime.datetime) – Set date of the track (naive
datetime
).date_tz (int) – Timezone offset of the locale date in minutes.
gpx (bytes) – Compressed GPX data.
visibility (Visibility) – Visibility of the track.
link_secret (str) – The secret string for the share link.
type (TrackType) – Type of the track
transformers (list[tuple[str, dict]]) – The enabled transformers together with their parameters.
owner (fietsboek.models.user.User) – Owner of the track.
cache (TrackCache) – Cache for the computed track metadata.
tagged_people (list[fietsboek.models.user.User]) – List of people tagged in this track.
badges (list[fietsboek.models.badge.Badge]) – Badges associated with this track.
comments (list[fietsboek.models.comment.Comment]) – Comments left on this track.
images (list[fietsboek.models.image.ImageMetadata]) – Metadata of the images saved for this track.
favourees (list[fietsboek.models.user.User]) – List of users that have this track as a favourite.
- 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.
-
cache:
Mapped
[Optional
[TrackCache
]]¶
- property date¶
The time-zone-aware date this track has set.
This combines the
date_raw
anddate_tz
values to provide a timezone awaredatetime
.- Returns:
The aware datetime.
- Return type:
- date_raw¶
- date_tz¶
- description¶
- ensure_cache(gpx_data)¶
Ensure that a cached version of this track’s metadata exists.
- 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.
- 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:
- link_secret¶
- 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:
- 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.
- text_tags()¶
Returns a set of textual tags.
- title¶
- transformer_params_for(transformer_id)¶
Returns the transformer parameters for the given transformer.
If the transformer is not active, returns
None
.
- 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_id¶
- uphill¶
- class fietsboek.models.track.TrackType(value, names=<not given>, *values, 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 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.
- html_tooltip(localizer)¶
Generate a quick summary of the track as a HTML element.
This can be used in Bootstrap tooltips.
- html_tooltip_tagged_people()¶
Returns the tagged people as HTML, ready to be shown as a tooltip.
- Return type:
- Returns:
The generated HTML.
- property images: List[ImageMetadata]¶
Images of the underlying track.
- show_organic_data()¶
Proxied method
Track.show_organic_data()
.- Return type:
- 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.
- text_tags()¶
Returns a set of textual tags.
- 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 properTrack
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.
- gpx¶
- property gpx_data¶
Access the decompressed gpx data.
- id¶
- owner_id¶
- uploaded_at¶
- class fietsboek.models.track.Visibility(value, names=<not given>, *values, 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.