Created
December 29, 2018 09:01
-
-
Save skyzh/4bc50997f7dede24806ae7649cccbe48 to your computer and use it in GitHub Desktop.
Extract TPO tests from "Xiao Zhan TOEFL"
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
const QUESTIONS = require('./t_question.json'); | |
const ITEMS = require('./t_questionItem.json'); | |
const ANSWERS = require('./t_answer.json'); | |
const _ = require('lodash'); | |
const result = _.map([13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], TPO_CNT => { | |
let questions = _.filter(QUESTIONS, question => question.app_name_sub == `tpo${TPO_CNT}` && question.passage == 'listening'); | |
let items = _.map(questions, question => | |
_.chain(ITEMS) | |
.filter(item => item.question_id == question.id) | |
.sortBy(item => item.sort) | |
.value() | |
); | |
let answers = _.map(questions, question => _.chain(ANSWERS) | |
.filter(answer => answer.question_id == question.id) | |
.value()[0] | |
) | |
let data = _.zip(questions, items, answers); | |
const id_at = { | |
0: 'A', | |
1: 'B', | |
2: 'C', | |
3: 'D', | |
4: 'E', | |
5: 'F' | |
} | |
const p = d => `<p>${d}</p>`; | |
const ul = d => `<ul class="list-unstyled">${d}</ul>`; | |
const li = d => `<li>${d}</li>`; | |
const ol = d => `<ol>${d}</ol>`; | |
const table = d => `<table class="table table-sm"><tbody>${d}</tbody></table>`; | |
const tr = d => `<tr>${d}</tr>`; | |
const td = d => `<td>${d}</td>`; | |
const h1 = d => `<h1>${d}</h1>`; | |
let res = _.map(data, _tmp => { | |
const [question, items, answer] = _tmp; | |
const get_items = (type, items) => { | |
if (type == 11) { | |
let head = tr(td("") + _.map(items[1].content.split('||'), d => td(d)).join('\n')); | |
let body = _.map(items[0].content.split('||'), d => tr(td(d) + _.map(items[1].content.split('||'), d => td("")).join(""))); | |
return table(head + body.join("")); | |
} else { | |
let _res = ""; | |
_.forEach(items, (item, idx) => { | |
_res += li(item.content); | |
}) | |
return _res; | |
} | |
} | |
const g = d => d == 9 ? "<b>(Multiple)</b>" | |
: d == 7 ? "<b>(Listen Again)</b>" : ""; | |
return li( | |
` | |
${question.content} ${g(question.question_type)} | |
${ul(get_items(question.question_type, items))} | |
` | |
); | |
}); | |
let res_answer = _.map(data, _tmp => { | |
const [question, items, answer] = _tmp; | |
return li(`${answer.content} (${question.rate})`); | |
}); | |
return h1(`TPO ${TPO_CNT}`) + ol(res.join('\n')) + ol(res_answer.join('\n')); | |
}).join('\n'); | |
const html = d => ` | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<title>TPO Test</title> | |
<link href="https://fonts.googleapis.com/css?family=PT+Serif" rel="stylesheet"> | |
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> | |
<style> body { font-family: 'PT Serif', serif; } </style> | |
</head> | |
<body> | |
${d} | |
</body> | |
</html> | |
`; | |
const fs = require('fs'); | |
fs.writeFileSync('result.html', html(result)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Extract Example