API Referenz¶
Apps¶
api ¶
map ¶
ranking ¶
Project: MyCyclingCity Generation: AI-based
Ranking application for MyCyclingCity.
leaderboard ¶
Project: MyCyclingCity Generation: AI-based
Leaderboard application for MyCyclingCity.
kiosk ¶
iot ¶
game ¶
mgmt ¶
Utilities¶
api.utils ¶
Project: MyCyclingCity Generation: AI-based
Shared utility functions for MyCyclingCity applications.
format_km_de ¶
format_km_de(
value: Optional[float],
decimals: int = 3,
language_code: Optional[str] = None,
) -> str
Format number based on language: German format (dot thousands, comma decimal) or English format (comma thousands, dot decimal).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
Optional[float]
|
The numeric value to format. Can be None. |
required |
decimals
|
int
|
Number of decimal places (default: 3). |
3
|
language_code
|
Optional[str]
|
Optional language code override. If None, uses current language. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Formatted string with appropriate thousands and decimal separators. |
Examples:
Source code in api/utils.py
api.helpers ¶
Project: MyCyclingCity Generation: AI-based
Shared helper functions for building group hierarchies and data structures. Used by map, ranking, and leaderboard apps.
are_all_parents_visible ¶
Check if all parent groups in the hierarchy are visible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group
|
Group
|
The group to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the group and all its parents are visible, False otherwise. |
Source code in api/helpers.py
build_cyclist_velos_api_fields ¶
build_cyclist_velos_api_fields(
cyclist: Cyclist,
*,
include_session: bool = False,
include_daily: bool = False,
period_start: Optional[datetime] = None,
period_end: Optional[datetime] = None
) -> Dict[str, int]
Standard Velos fields for cyclist API responses.
Source code in api/helpers.py
build_events_data ¶
Build event data structure for display.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kiosk
|
bool
|
Whether in kiosk mode (filters groups with distance > 0). |
False
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of dictionaries containing event data. |
Source code in api/helpers.py
build_group_hierarchy ¶
build_group_hierarchy(
target_group: Optional[Group] = None,
kiosk: bool = False,
show_cyclists: bool = True,
) -> List[Dict[str, Any]]
Build a hierarchical data structure of groups with their members and subgroups.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_group
|
Optional[Group]
|
Optional specific group to filter by. |
None
|
kiosk
|
bool
|
Whether in kiosk mode (hides groups with zero metric Velos). |
False
|
show_cyclists
|
bool
|
Whether to include cyclist data in the hierarchy. |
True
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of dictionaries containing group hierarchy data. |
Source code in api/helpers.py
build_group_velos_api_fields ¶
Ledger Velos fields for group API responses.
build_hierarchy_from_parent_groups ¶
build_hierarchy_from_parent_groups(
parent_groups,
kiosk: bool = False,
show_cyclists: bool = True,
) -> List[Dict[str, Any]]
Build hierarchy data from a parent-group queryset (map/ranking shared helper).
All Velos totals come from HourlyMetric (synced by mcc_worker for active sessions). Parent groups: sum of child group metric totals.
Source code in api/helpers.py
filter_cyclist_metrics_by_snapshot ¶
Filter HourlyMetric queryset for cyclists, excluding metrics before latest snapshot date.
This function determines snapshot dates based on the groups each cyclist belongs to, then filters metrics accordingly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
queryset
|
QuerySet
|
HourlyMetric queryset to filter (should already be filtered by cyclist) |
required |
cyclist_ids
|
List[int]
|
List of cyclist IDs |
required |
Returns:
| Type | Description |
|---|---|
QuerySet
|
Filtered queryset with snapshot-aware filtering applied |
Source code in api/helpers.py
filter_metrics_by_snapshot ¶
filter_metrics_by_snapshot(
queryset: QuerySet,
group_ids: List[int],
field_name: str = "group_at_time_id",
) -> QuerySet
Filter HourlyMetric queryset to exclude metrics before latest snapshot date.
This function applies snapshot filtering to a queryset by checking each group's latest snapshot date and only including metrics after that date.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
queryset
|
QuerySet
|
HourlyMetric queryset to filter |
required |
group_ids
|
List[int]
|
List of group IDs to check for snapshots |
required |
field_name
|
str
|
Field name to use for group filtering (default: 'group_at_time_id') Use 'group_at_time_id' for group metrics, 'cyclist__groups__id' for cyclist metrics |
'group_at_time_id'
|
Returns:
| Type | Description |
|---|---|
QuerySet
|
Filtered queryset with snapshot-aware filtering applied |
Source code in api/helpers.py
get_cyclist_by_identifier ¶
Resolve a cyclist by user_id or id_tag (case-insensitive).
Source code in api/helpers.py
get_cyclist_session_km ¶
Return cumulative session distance in km for the cyclist's active device session.
Source code in api/helpers.py
get_cyclist_session_velos ¶
Velos earned in the cyclist's active device session (not yet redeemed).
Source code in api/helpers.py
get_cyclist_velos_daily ¶
Velos earned today (metrics + active session).
Source code in api/helpers.py
get_cyclist_velos_period ¶
Sum HourlyMetric.velos for a cyclist in a date range plus overlapping session.
Source code in api/helpers.py
get_cyclist_velos_total ¶
Lifetime Velos from HourlyMetric (respecting year-end snapshots).
Source code in api/helpers.py
get_external_display_settings_context ¶
Return admin-controlled km display flags for external GUIs.
Source code in api/helpers.py
get_group_velos_ledger ¶
Return permanent group Velos ledger totals (leaderboard ranking source).
Uses Group.velos_total, not the sum of member velos_balance values.
Source code in api/helpers.py
get_leaderboard_footer_period_context ¶
Describe the time window used for footer total Velos/km (HourlyMetric sums).
Totals count metrics after each group's latest YearEndSnapshot, or all time when no snapshot exists. Returns template-friendly mode + dates.
Source code in api/helpers.py
invalidate_cache_for_top_group ¶
Invalidate all cache entries related to a TOP group and its subgroups.
This function clears cache for: - Group totals (leaderboard) - Cyclist totals (ranking) - Device totals (ranking) - All subgroups and their descendants
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
top_group
|
Group
|
The TOP group for which to invalidate cache |
required |
Source code in api/helpers.py
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | |
snapshot_session_velos ¶
sum_display_totals_from_groups_data ¶
Sum Velos and km from leaderboard-style group dicts (filtered view).
Uses the same per-group values already prepared for the UI (HourlyMetric-based where applicable).