8618aa1be3
- frontend/functions/core/format_datetime_short.md - frontend/functions/core/format_datetime_short.test.ts - frontend/functions/core/format_datetime_short.ts - frontend/functions/core/format_duration.md - frontend/functions/core/format_duration.test.ts - frontend/functions/core/format_duration.ts - frontend/functions/core/month_grid.md - frontend/functions/core/month_grid.test.ts - frontend/functions/core/month_grid.ts - frontend/functions/core/string_hash_palette.md - ... Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
53 lines
1.7 KiB
Markdown
53 lines
1.7 KiB
Markdown
---
|
|
name: percentile_int64
|
|
kind: function
|
|
lang: go
|
|
domain: datascience
|
|
version: "1.0.0"
|
|
purity: pure
|
|
signature: "func Percentile(sorted []int64, p float64) int64"
|
|
description: "Calcula el percentil p (0.0-1.0) de un slice de int64 pre-ordenado ascendente. Retorna 0 para slice vacio. idx = int(float64(len-1)*p), clamped a [0, len-1]."
|
|
tags: [statistics, percentile, quantile, int64, sorted]
|
|
uses_functions: []
|
|
uses_types: []
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: ""
|
|
imports: []
|
|
params:
|
|
- name: sorted
|
|
desc: "Slice de int64 pre-ordenado en orden ascendente. No se reordena internamente."
|
|
- name: p
|
|
desc: "Percentil a calcular, en rango [0.0, 1.0]. 0.5 = mediana, 0.9 = P90, 0.99 = P99."
|
|
output: "El valor en la posicion del percentil p dentro del slice. Retorna 0 si el slice esta vacio."
|
|
tested: true
|
|
tests:
|
|
- "slice vacio retorna cero"
|
|
- "un solo elemento retorna ese elemento"
|
|
- "p0 retorna minimo"
|
|
- "p100 retorna maximo"
|
|
- "p50 retorna mediana de cinco elementos"
|
|
- "p90 de diez elementos usa idx int truncado"
|
|
- "p99 de slice pequeno usa idx truncado a cero"
|
|
test_file_path: "functions/datascience/percentile_int64_test.go"
|
|
file_path: "functions/datascience/percentile_int64.go"
|
|
source_repo: "https://github.com/egutierrez/fn_registry/apps/kanban"
|
|
source_license: "private"
|
|
source_file: "apps/kanban/backend/metrics.go"
|
|
---
|
|
|
|
## Ejemplo
|
|
|
|
```go
|
|
sorted := []int64{10, 20, 30, 40, 50}
|
|
p50 := Percentile(sorted, 0.5) // 30
|
|
p90 := Percentile(sorted, 0.9) // 50
|
|
p99 := Percentile(sorted, 0.99) // 50
|
|
```
|
|
|
|
## Notas
|
|
|
|
El input debe estar ordenado ascendente antes de llamar a esta funcion.
|
|
`DurationStatsFrom` se encarga de ordenar antes de llamarla.
|
|
Extraido de `apps/kanban/backend/metrics.go:99-111`.
|