> 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/scory/expressions/examples.md).

# Examples

Ready-made expressions for common tasks.

Keys like `km10`, `run1`, `final`, `checkedIn` or `td` 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"))`                |
| The flag and the nation      | `{{ flag nation }} {{ nation }}`                                      |
| Club and year under the name | Column → ⋯ → Second line: `{{ club }} {{ yob }}`                      |

## 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))`                                               |
| Gap to the class winner                  | `gaps.class`                                                                                               |
| "12 of 87"                               | `{{ ranks.class }} of {{ rankCounts.class }}`                                                              |
| The gap as a bar                         | Column → ⋯ → Bar: `timeValue`                                                                              |
| 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")`                                                              |
| DSQ with its gate                        | `{{ if heats.run1.status == "DSQ" }}DSQ Gate {{ heats.run1.gate }}{{ end }}`                               |

## 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 }}`                                                     |
| Group header with its size             | Grouping → Header           | `{{ group.value }} ({{ group.count }})`                                 |
| Who was fastest in the group           | Grouping → Header           | `{{ minBy(group.rows, "timeValue")?.name }}`                            |
| How many did not finish                | Grouping → Header           | `{{ countWhere(group.rows, "status == 'DNF'") }} DNF`                   |
| Only 5 rows per group, finished ones   | Grouping → Max. rows        | `iif(finished, 5, 0)`                                                   |
| A column header in the list's language | Column → Header             | `{{ translate "Rank" }}` or `{en:Rank\|de:Rang}`                        |
| The class's codex in the title         | Title                       | `{{ class?.fields.codex }} {{ class?.name }}`                           |
| "Official" / "Unofficial"              | Sub title                   | `{{ competition.resultsState }}`                                        |
| The competition's shown fields         | Sub title                   | `{{ for d in competition.data }}{{ d.label }}: {{ d.value }} {{ end }}` |
| The Jury box                           | Header                      | `## Jury` and a line `\| TD \| {{ competition.fields.td }} \|`          |
| The logo top left                      | Lists / PDF → header left   | `{{ image "logo" "15mm" }}`                                             |
| Sponsors in the footer                 | Lists / PDF → footer centre | `{{ image "sponsor-1" "12mm" }} {{ image "sponsor-2" "12mm" }}`         |
| Page numbers                           | PDF footer                  | `Page {{ list.page }} / {{ list.pages }}`                               |

## Outputs

| You want                | Where                 | Expression                                                            |
| ----------------------- | --------------------- | --------------------------------------------------------------------- |
| A JSON line per passing | Race → Outputs → Line | `{{ json { bib: bib, name: name, time: time, point: timingPoint } }}` |

## 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` |
| A class for women 40 - 49                   | Classes → Condition                   | `sex == "W" && age >= 40 && age < 50`                   |
| Only licensed athletes enter                | Competitions → Who enters → Condition | `licensed` (a Yes / no athlete field)                   |
