mirror of
https://github.com/bellingcat/datasheet-server.git
synced 2026-06-11 04:48:32 +03:00
abstract generic logic from blueprinters to blueprinters.js
The logic in the files in the 'blueprinters' folder is now _only_ the data transformation logic. Instead of taking in arguments like the sheetId, the tabName, and the sheetName, the function now takes a single argument: the list of lists that represents the raw data from the sheet. This setup gives datasheet-server greater value, as it allows developers to only specify the transformation logic, and not worry about the other stuff that datasheet server is doing.
This commit is contained in:
26
src/blueprinters/deeprows.js
Normal file
26
src/blueprinters/deeprows.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import R from 'ramda'
|
||||
import { fmtObj } from '../lib/util'
|
||||
|
||||
/**
|
||||
* Each resource item is an object with values labelled according
|
||||
* to column names specified in the sheet's first row. If two or more
|
||||
* column names are the same except for a different integer at the end
|
||||
* (e.g. 'tag1', and 'tag2'), then the values of those two columns are
|
||||
* aggregated into a list, which is the value of the prefix's key ('tag').
|
||||
*
|
||||
* @param {type} data list of lists representing sheet data.
|
||||
* @return {type} Array the structured data.
|
||||
*/
|
||||
export default (data) => {
|
||||
// TODO: make these deep rows.
|
||||
const itemLabels = data[0]
|
||||
const fmt = fmtObj(itemLabels)
|
||||
const output = []
|
||||
|
||||
data.forEach((row, idx) => {
|
||||
if (idx === 0) return
|
||||
output.push(fmt(row))
|
||||
})
|
||||
|
||||
return output
|
||||
}
|
||||
Reference in New Issue
Block a user