-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support the transform code to convert OpenRosa xform into enketo format
Original code by @atton16 in https://github.com/e-mission/e-mission-phone/tree/rk-unsw/survey-resources Modified and simplified survey from Bingrong Sun Modified further by @shankari to work with the enketo core - remove the UUID field - remove the final "estimate of commute time" field since we can get that from OpenPATH - turn on pagination e-mission/e-mission-docs#732 (comment)
- Loading branch information
Showing
9 changed files
with
3,406 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM node:8-alpine | ||
|
||
WORKDIR /usr/app | ||
COPY package.json package-lock.json index.js ./ | ||
RUN apk --no-cache add --virtual native-deps \ | ||
g++ gcc libgcc libstdc++ linux-headers make python && \ | ||
npm install --quiet node-gyp -g &&\ | ||
npm ci &&\ | ||
apk del native-deps | ||
|
||
ENTRYPOINT node . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# xform-transformer | ||
|
||
Complementary xform transformer for e-mission-phone | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
## Usage | ||
|
||
1. Put your `xml` form (xform) file into `data-xml` directory. | ||
2. Run this app `node .` | ||
3. Grab your json form file under `data-json` directory. | ||
4. Enjoy! | ||
|
||
Consult *Input Data Preparation* if you do not have xform file yet. | ||
|
||
## Input Data Preparation | ||
|
||
1. Build your survey form on [https://www.kobotoolbox.org/](https://www.kobotoolbox.org/) | ||
2. Download the XLS form file | ||
3. Convert `XLS` form to `xml` form (xform) using [http://xlsform.opendatakit.org/](http://xlsform.opendatakit.org/) | ||
4. Done! |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const fs = require('fs'); | ||
const transformer = require('enketo-transformer'); | ||
|
||
const config = { | ||
inputDir: 'data-xml', | ||
outputDir: 'data-json', | ||
}; | ||
|
||
console.log('==== xform-transformer ===='); | ||
console.log(''); | ||
console.log(`Input directory: "${config.inputDir}"`); | ||
console.log(`Output directory: "${config.outputDir}"`); | ||
console.log(''); | ||
console.log('Begin transforming xform files...'); | ||
console.log(''); | ||
|
||
fs.readdirSync(`./${config.inputDir}`, { | ||
encoding: 'utf8', | ||
withFileTypes: false, | ||
}).filter(file => { | ||
console.log("Considering "+JSON.stringify(file)+" in filter"); | ||
return file.match(/.xml$/); | ||
}).forEach(file => { | ||
const filename = file.substr(0, file.length - 4); | ||
const inputPath = `./${config.inputDir}/${file}`; | ||
const outputPath = `./${config.outputDir}/${filename}.json`; | ||
console.log(`Reading "${inputPath}" ...`); | ||
transformer.transform({ | ||
xform: fs.readFileSync(inputPath), | ||
preprocess: doc => doc, | ||
}).then(function(result){ | ||
fs.writeFileSync(outputPath, JSON.stringify(result)); | ||
console.log(`Successfully saved "${outputPath}"`); | ||
}); | ||
}); | ||
|
Oops, something went wrong.