From d32cffd0e8524799635b1ce18c33cadb048da4fa Mon Sep 17 00:00:00 2001 From: Jonathan Matthews Date: Wed, 10 Jan 2024 14:07:42 +0000 Subject: [PATCH] docs/howto: use list.{Avg,Max,Min,Sum} This adds a Commented CUE guide that demonstrates the use of list.Avg, list.Max, list.Min and list.Sum to produce simple summary statistics of numeric lists. A manually calculated mean using len() and the result of list.Sum is included in order to highlight the equivalence of this method and list.Avg. List contents are selected that elongate the mean's decimal representation, which further highlights the two methods' equality. Preview-Path: /docs/howto/use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers/ Signed-off-by: Jonathan Matthews Change-Id: I439b302a51f84c724af58c4f9c56ecca912778ae Dispatch-Trailer: {"type":"trybot","CL":1174381,"patchset":2,"ref":"refs/changes/81/1174381/2","targetBranch":"alpha"} --- .../en.md | 52 +++++++++++++++++++ .../gen_cache.cue | 18 +++++++ .../page.cue | 3 ++ .../index.md | 51 ++++++++++++++++++ 4 files changed, 124 insertions(+) create mode 100644 content/docs/howto/use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers/en.md create mode 100644 content/docs/howto/use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers/gen_cache.cue create mode 100644 content/docs/howto/use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers/page.cue create mode 100644 hugo/content/en/docs/howto/use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers/index.md diff --git a/content/docs/howto/use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers/en.md b/content/docs/howto/use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers/en.md new file mode 100644 index 000000000..3e7a66e54 --- /dev/null +++ b/content/docs/howto/use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers/en.md @@ -0,0 +1,52 @@ +--- +title: Using the builtin functions "list.Avg", "list.Max", "list.Min, and "list.Sum" to summarise lists of numbers +tags: +- commented cue +authors: +- jpluscplusm +toc_hide: true +--- + +This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}}) +demonstrates how to use the builtin functions `list.Avg`, `list.Max`, +`list.Min` and `list.Sum` to calculate various simple summary statistics for a +list of numbers including the list's arithmetic mean, its maximum and minimum +values, and the sum of its values. + +{{{with code "en" "cc"}}} +#location left right + +exec cue eval +cmp stdout out +-- file.cue -- +package example + +import "list" + +sum: list.Sum(_data) +min: list.Min(_data) +max: list.Max(_data) +mean: list.Avg(_data) + +manualMean: sum / len(_data) + +_data: [ + -0.00000000001, + 0, + 1, + 5, + 10, + 42, + -999, +] +-- out -- +sum: -941.00000000001 +min: -999 +max: 42 +mean: -134.4285714285728571428571428571429 +manualMean: -134.4285714285728571428571428571429 +{{{end}}} + +## Related content + +- The [`list`](https://pkg.go.dev/cuelang.org/go/pkg/list) builtin package diff --git a/content/docs/howto/use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers/gen_cache.cue b/content/docs/howto/use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers/gen_cache.cue new file mode 100644 index 000000000..2c85f5a4c --- /dev/null +++ b/content/docs/howto/use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers/gen_cache.cue @@ -0,0 +1,18 @@ +package site +{ + content: { + docs: { + howto: { + "use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers": { + page: { + cache: { + code: { + cc: "5rBRQCW3czcAE68hKXRNyM1yY5RJP7Z1i3NXzQDbTqI=" + } + } + } + } + } + } + } +} diff --git a/content/docs/howto/use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers/page.cue b/content/docs/howto/use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers/page.cue new file mode 100644 index 000000000..420718d66 --- /dev/null +++ b/content/docs/howto/use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers/page.cue @@ -0,0 +1,3 @@ +package site + +content: docs: howto: "use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers": {} diff --git a/hugo/content/en/docs/howto/use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers/index.md b/hugo/content/en/docs/howto/use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers/index.md new file mode 100644 index 000000000..382ddb579 --- /dev/null +++ b/hugo/content/en/docs/howto/use-the-builtin-functions-list-avg-list-max-list-min-list-sum-to-summarise-lists-of-numbers/index.md @@ -0,0 +1,51 @@ +--- +title: Using the builtin functions "list.Avg", "list.Max", "list.Min, and "list.Sum" to summarise lists of numbers +tags: +- commented cue +authors: +- jpluscplusm +toc_hide: true +--- + +This [Commented CUE]({{< relref "docs/howto#commented-cue-guides" >}}) +demonstrates how to use the builtin functions `list.Avg`, `list.Max`, +`list.Min` and `list.Sum` to calculate various simple summary statistics for a +list of numbers including the list's arithmetic mean, its maximum and minimum +values, and the sum of its values. + +{{< code-tabs >}} +{{< code-tab name="file.cue" language="cue" area="left" >}} +package example + +import "list" + +sum: list.Sum(_data) +min: list.Min(_data) +max: list.Max(_data) +mean: list.Avg(_data) + +manualMean: sum / len(_data) + +_data: [ + -0.00000000001, + 0, + 1, + 5, + 10, + 42, + -999, +] +{{< /code-tab >}} +{{< code-tab name="TERMINAL" language="" type="terminal" area="right" >}} +$ cue eval +sum: -941.00000000001 +min: -999 +max: 42 +mean: -134.4285714285728571428571428571429 +manualMean: -134.4285714285728571428571428571429 +{{< /code-tab >}} +{{< /code-tabs >}} + +## Related content + +- The [`list`](https://pkg.go.dev/cuelang.org/go/pkg/list) builtin package