> For the complete documentation index, see [llms.txt](https://docs.dbnetsoft.com/dbnetsoft/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dbnetsoft.com/dbnetsoft/finalscore/expressions/examples.md).

# Examples

Ready-made expressions for common tasks.

Keys like `km10`, `run1`, `final` or `checkedIn` stand for the keys of your event (splits, results, heats, rounds, additional fields).

## Names

| You want                    | Expression                                                            |
| --------------------------- | --------------------------------------------------------------------- |
| Last name in capitals       | `lastName \| string.upcase`                                           |
| Name column                 | `{{ lastName \| string.upcase }} {{ firstName }}`                     |
| Initial and last name       | `(firstName \| string.slice1 0) + ". " + (lastName \| string.upcase)` |
| Team, else the club         | `ifEmpty(team?.name, club)`                                           |
| Class, safe without a class | `class?.name`                                                         |
| Age group                   | `iif(age >= 50, "M50", iif(age >= 40, "M40", "Open"))`                |

## Times, ranks, status

| You want                                 | Expression                                                                                                 |
| ---------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| Time with 1 decimal                      | `formatTime(timeValue, 1)`                                                                                 |
| Class rank with a dot                    | `ordinal(ranks.class)`                                                                                     |
| Time when finished, else the status      | `iif(finished, time, iif(status != "OK", status, ""))`                                                     |
| Rank or status                           | `place`                                                                                                    |
| Gap with 1 decimal, empty for the winner | `iif(ranks.overall == 1, "", "+" + formatTime(gapValue, 1))`                                               |
| All laps                                 | `lapTimes \| array.join " / "`                                                                             |
| Speed at 10 km                           | `{{ if splits.km10.speedSinceStart }}{{ splits.km10.speedSinceStart \| math.format "0.0" }} km/h{{ end }}` |
| The fastest section                      | `maxWhere(splits, "speedSincePreviousSplit")`                                                              |

## Runs and duels

| You want                                 | Expression                                                                                                                      |
| ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| Runs won in a duel                       | `rounds.final.wins`                                                                                                             |
| The same, counted                        | `countWhere(rounds.final.runs, "rank == 1")`                                                                                    |
| Runs won, heat by heat                   | `countTrue(heats.run1.rank == 1, heats.run2.rank == 1, heats.run3.rank == 1)`                                                   |
| The finished runs' times added up        | `sumWhere(rounds.final.runs, "timeValue", "finished")`                                                                          |
| The better of two runs (formula)         | `minOf(results.run1?.timeValue, results.run2?.timeValue)`                                                                       |
| A run in brackets when it does not count | `{{ if heats.run1.counted \|\| !heats.run1.finished }}{{ heats.run1.resultOrState }}{{ else }}({{ heats.run1.time }}){{ end }}` |
| Every run of the duel (bracket list)     | `{{ heat.runs \| array.map "resultOrState" \| array.join " " }}`                                                                |

## Lists

| You want                             | Where                    | Expression                                              |
| ------------------------------------ | ------------------------ | ------------------------------------------------------- |
| Only finished athletes               | Filter                   | `finished && status == "OK"`                            |
| Live: furthest first                 | Sorting                  | 1. `lastSplit?.order` (Desc.) 2. `lastSplit?.timeValue` |
| Lap race                             | Sorting                  | 1. `laps` (Desc.) 2. `timeValue`                        |
| Top 3 in bold                        | Column → ⋯ → Bold        | `ranks.overall <= 3`                                    |
| Grey when not OK                     | Column → ⋯ → Text colour | `iif(status != "OK", "gray", "")`                       |
| The duel's winner in green           | Column → ⋯ → Text colour | `iif(heat.won, "green", "")`                            |
| Lane colour (parallel)               | Column → ⋯ → Background  | `laneColor`                                             |
| Group header with the class          | Grouping → Header        | `{{ class?.name }}`                                     |
| Only 5 rows per group, finished ones | Grouping → Max. rows     | `iif(finished, 5, 0)`                                   |
| Page numbers                         | PDF footer               | `Page {{ list.page }} / {{ list.pages }}`               |

## Setup

| You want                                    | Where                               | Expression                                              |
| ------------------------------------------- | ----------------------------------- | ------------------------------------------------------- |
| Finished after 3 laps                       | Event / Competition → Finished when | `laps >= 3`                                             |
| Started when checked in                     | Event / Competition → Started when  | `started \|\| checkedIn`                                |
| A lap at least the minimum lap time later   | Results → offset                    | `competition.minLapTime`                                |
| A different offset for women                | Results → offset                    | `iif(sex == "W", 2400, 2100)`                           |
| A lap from two reads (formula)              | Results → Formula                   | `results.lap2.timeValue - results.lap1.timeValue`       |
| A ranking for one class                     | Ranks → Filter                      | `finished && status == "OK" && class?.name == "M40"`    |
| The best 4 of the qualification into a heat | Heats → Add athletes                | Filter `heats.q1.rank <= 4`, Order `heats.q1.timeValue` |
