Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
breck7 committed Dec 15, 2024
1 parent 4b1bba8 commit a9db38c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scroll-cli",
"version": "163.1.0",
"version": "163.2.0",
"description": "A language for scientists of all ages. A curated collection of tools for refining and sharing thoughts.",
"main": "scroll.js",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion parsers/root.parsers
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ scrollParser
}
get scrollVersion() {
// currently manually updated
return "163.1.0"
return "163.2.0"
}
// Use the first paragraph for the description
// todo: add a particle method version of get that gets you the first particle. (actulaly make get return array?)
Expand Down
54 changes: 54 additions & 0 deletions parsers/tables.parsers
Original file line number Diff line number Diff line change
Expand Up @@ -676,3 +676,57 @@ tableSearchParser
buildInstance() {
return ""
}

scrollSummarizeParser
extends abstractTableTransformParser
description Generate summary statistics for each column.
cue summarize
example
table data.csv
summarize
printTable
javascript
get coreTable() {
const {lodash} = this.root
const sourceData = this.parent.coreTable
if (!sourceData.length) return []
return this.parent.columnNames.map(colName => {
const values = sourceData.map(row => row[colName]).filter(val => val !== undefined && val !== null)
const numericValues = values.filter(val => typeof val === "number" && !isNaN(val))
const sorted = [...numericValues].sort((a, b) => a - b)
// Calculate mode
const frequency = {}
values.forEach(val => {
frequency[val] = (frequency[val] || 0) + 1
})
const mode = Object.entries(frequency)
.sort((a, b) => b[1] - a[1])
.map(entry => entry[0])[0]
// Calculate median for numeric values
const median = sorted.length ?
sorted.length % 2 === 0
? (sorted[sorted.length/2 - 1] + sorted[sorted.length/2]) / 2
: sorted[Math.floor(sorted.length/2)]
: null
const sum = numericValues.length ? numericValues.reduce((a, b) => a + b, 0) : null
const theType = typeof values[0]
const count = values.length
const mean = theType === "number" ? sum/count : ""
return {
name: colName,
type: theType,
incompleteCount: sourceData.length - values.length,
uniqueCount: new Set(values).size,
count,
sum,
median,
mean,
min: sorted.length ? sorted[0] : null,
max: sorted.length ? sorted[sorted.length - 1] : null,
mode
}
})
}
get columnNames() {
return ["name", "type", "incompleteCount", "uniqueCount", "count", "sum", "median", "mean", "min", "max", "mode"]
}
3 changes: 3 additions & 0 deletions releaseNotes.scroll
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ ciBadges.scroll
br
thinColumns

πŸ“¦ 163.2.0 12/15/2024
πŸŽ‰ added `summarize` parser

πŸ“¦ 163.1.0 12/15/2024
πŸŽ‰ column names in table particles now try to match users intent (case insensitive and close match).
πŸŽ‰ new `assertIgnoreBelowErrorsParser` for automated testing purposes
Expand Down
9 changes: 8 additions & 1 deletion tests/tables.scroll
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ buildTxt

theme gazette

thinColumns 1
container 800px

# Simple sparkline with inline data
sparkline 5 7 27 87 300 17 10 5
Expand Down Expand Up @@ -132,3 +132,10 @@ iris
printTable
select species
printTable

---

# Summarize
iris
summarize
printTable

0 comments on commit a9db38c

Please sign in to comment.