Commit bf32a3f5 by Иван Кубота

database dir option

parent f468f888
Pipeline #522 failed with stage
...@@ -14,6 +14,7 @@ const options = yargs ...@@ -14,6 +14,7 @@ const options = yargs
.option("o", { alias: "output", describe: "file for output", type: "string"}) .option("o", { alias: "output", describe: "file for output", type: "string"})
.option("v", { alias: "verbose", describe: "print log", type: "boolean"}) .option("v", { alias: "verbose", describe: "print log", type: "boolean"})
.option("n", { alias: "nolog", describe: "no text log in object", type: "boolean"}) .option("n", { alias: "nolog", describe: "no text log in object", type: "boolean"})
.option("d", { alias: "dir", describe: "database dir", type: "string"})
.argv; .argv;
...@@ -51,6 +52,8 @@ const sources = [ ...@@ -51,6 +52,8 @@ const sources = [
var js = sources.map(a=>'./public/'+a).map(n=>fs.readFileSync(n)+'').join('\n\n'); var js = sources.map(a=>'./public/'+a).map(n=>fs.readFileSync(n)+'').join('\n\n');
if(options.dir)
process.env.KUS_DATA_DIR = options.dir;
const data = require("../db.js"); const data = require("../db.js");
const body = 'const window = {};'+js+'; return {quizGenerator, initDataProvider, seeded: Math.random.seeded}'; const body = 'const window = {};'+js+'; return {quizGenerator, initDataProvider, seeded: Math.random.seeded}';
var ctx = new Function('',body)(); var ctx = new Function('',body)();
......
const csv = require('csv-parser'), const csv = require('csv-parser'),
fs = require('fs'); fs = require('fs'),
path = require('path');
const readCSV = async function(scope) { const readCSV = async function(scope) {
const {fileName, types, keys, index} = scope, const {fileName, types, keys, index} = scope,
...@@ -26,15 +27,15 @@ const readCSV = async function(scope) { ...@@ -26,15 +27,15 @@ const readCSV = async function(scope) {
}); });
}); });
}; };
const base = process.env.KUS_DATA_DIR || './data';
const connections = JSON.parse(fs.readFileSync(path.join(base,'connections.json'))+'');
const connections = JSON.parse(fs.readFileSync('./data/connections.json')+''); const tags = JSON.parse(fs.readFileSync(path.join(base,'tags.json'))+'');
const tags = JSON.parse(fs.readFileSync('./data/tags.json')+'');
data = {tags, connections}; data = {tags, connections};
(async()=>{ (async()=>{
data.components = await readCSV({ data.components = await readCSV({
fileName: './data/components.csv', fileName: path.join(base,'components.csv'),
keys: { keys: {
'номер карточки': 'id', 'номер карточки': 'id',
'ингредиент': 'name' 'ингредиент': 'name'
...@@ -48,7 +49,7 @@ data = {tags, connections}; ...@@ -48,7 +49,7 @@ data = {tags, connections};
}); });
data.products = await readCSV({ data.products = await readCSV({
fileName: './data/products.csv', fileName: path.join(base,'products.csv'),
keys: { keys: {
'': 'id', '': 'id',
'название': 'title', 'название': 'title',
......
{ {
"question": какой из продуктов входят данные ингредиенты: томаты сушеные, перец сладкий сушеный, масло подсолнечное нерафинированное, майоран сушеный", "question": ыберите лишний ингредиент, НЕ входящий в продукт \"Салат винегрет с маринованной капустой\"",
"answers": [ "answers": [
{ {
"correct": false, "correct": false,
"text": "Паштет мясной запеченный" "text": "горошек зелёный консервированный"
}, },
{ {
"correct": true, "correct": true,
"text": "Паштет из тофу «По-испански»" "text": "шампиньоны"
}, },
{ {
"correct": false, "correct": false,
"text": "Паштет из печени кролика с шампиньонами" "text": "масло подсолнечное нерафинированно"
}, },
{ {
"correct": false, "correct": false,
"text": "Риет из горбуши с миндалем" "text": "капуста маринованная"
}, },
{ {
"correct": false, "correct": false,
"text": "Паштет мясной с печенью индейки и грушей" "text": "огурцы консервированные"
},
{
"correct": false,
"text": "свекла столовая отварная,"
} }
], ],
"log": [ "log": [
"Random seed: m1vuhh", "Random seed: bxa9uo",
"Quiz generate radio „Product contains 4 components“", "Quiz generate radio „Do not contain“",
"Have >= 4 components: 51", "Have >= 2 components: 75",
"Clusters that have >= 1 similar tags: 7", "Matched product: Салат винегрет с маринованной капустой",
"Used cluster tags: Паштеты, холодцы", "Have 7 components. Took 5:",
"Base products:", " > огурцы консервированные",
" > Паштет из тофу «По-испански»", " > горошек зелёный консервированный",
" > Риет из горбуши с миндалем", " > масло подсолнечное нерафинированно",
" > Паштет из печени кролика с шампиньонами", " > капуста маринованная",
" > Паштет мясной с печенью индейки и грушей", " > свекла столовая отварная,",
" > Паштет мясной запеченный", "\nTags: Салаты и закуски",
"", "Matched 4 component donors.",
"Product „Паштет из тофу «По-испански»“ have >= 4 uniq components (7):", "Nearest candidate have got 1 similar tag.",
" > «сыр» тофу", "Filtered candidates with [1] similar tags.",
"+ > масло подсолнечное нерафинированное", "Use Салат «Грин Энерджи» as donor.",
" > масло оливковое нерафинированное", "Because it has 1 similar tags: Салаты и закуски",
"+ > перец сладкий сушеный", "\n << шампиньоны"
"+ > томаты сушеные",
" > зеленый базилик сушеный",
"+ > майоран сушеный"
], ],
"type": "radio", "type": "radio",
"image": "", "image": "",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment