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

use production database

parent f570e895
Pipeline #562 canceled with stage
{
"category": 2,
"qID": 3,
"title": "В каком году открылся первый магазин \"ВкусВилл\"",
"cardInfoID": 301,
"multiple": false,
"image": null,
"answer_type": "текст",
"category_id": 2,
"answers": [
{
"qID": 3,
"title": "2009",
"correct": false,
"id": 5
},
{
"qID": 3,
"title": "2012",
"correct": true,
"id": 6
},
{
"qID": 3,
"title": "2008",
"correct": false,
"id": 7
},
{
"qID": 3,
"title": "2000",
"correct": false,
"id": 8
}
]
}
\ No newline at end of file
......@@ -443,17 +443,24 @@ data = {tags:[], connections:[], more:[], standardQuestions: {}, standardAnswers
data.more = data.more || [];
var tid = 1, cid = 1;
var tagsHash = {};
data.more = data.more.concat([
/*data.more = data.more.concat([
{p: '1cards_2020_02_28.csv', i: '1components.csv'},
{q: '2questions.csv', a: '2answers.csv', c: '2cards_2020_2_21.csv'},
{q: '3questions.csv', a: '3answers.csv', c: '3cards.csv'},
{q: '4questions.csv', a: '4answers.csv', c: '4cards.csv'},
{c: 'top-35-march-c.csv', q: 'top-35-march-q.csv', a: 'top-35-march-a.csv'},
]);
]);*/
let id = 1;
let theInc = ()=>id++;
let was = {};
if(data.more){
if(!data.more || !data.more.length){
data.products = {};
data.components = {};
data.tags = [];
data.connections = [];
data.standardQuestions = {};
}else{
for( let i = 0, _i = data.more.length; i < _i; i++ ){
var adishen = i*300;
......@@ -641,7 +648,7 @@ data = {tags:[], connections:[], more:[], standardQuestions: {}, standardAnswers
}
}
}
await new Promise((r,j)=>setTimeout(r,100));
//git add .
// fs.writeFileSync('./data/tmp/full.json', JSON.stringify(data, null, 2))
......
......@@ -31,7 +31,7 @@ const fs = require('fs'),
var js = sources.map(a=>path.join(__dirname,'../../public',a)).map(n=>fs.readFileSync(n)+'').join('\n\n');
const data = require("../../db.js");
let data = require("../../db.js");
const body = 'const window = {}, localStorage = {getItem:()=>"{}"};'+js+'; return {quizGenerator, standardGenerator, quizTypes, probabilityRand, initDataProvider, seeded: Math.random.seeded, rand, dP}';
var ctxCtor = new Function('',body);
......@@ -43,10 +43,11 @@ var initCtx = function() {
ctx.ready = new Promise((r,j)=>{
ctx._r = r;
});
ctx.setData = function(data) {
ctx.initDataProvider( data );
countStdQ = Object.values(data.standardQuestions).length;
ctx.setData = function(dataSet) {
ctx.initDataProvider( dataSet );
countStdQ = Object.values(dataSet.standardQuestions).length;
//console.log(ctx.dP)
data = dataSet
ctx._r();
};
};
......@@ -64,7 +65,7 @@ data.after = function(inComeData, skipInit){
}
ctx.setData(theData=inComeData);
standardQuestions = inComeData.standardQuestions;
//firstRequest();
firstRequest();
}
};
......@@ -88,35 +89,63 @@ module.exports = {
options: {},
fn: firstRequest = async function() {
var request = function(o, fn){fn(false, {body:JSON.stringify(require('../../data/mocked.json'))})};//require('request');
var request = require('request');//function(o, fn){fn(false, {body:JSON.stringify(require('../../data/mocked.json'))})};//
var options = {
'method': 'GET',
'url': 'https://api.new.local.vkusvill.testin.ru/api/admin/category/',
'headers': {}
};
request(options, function (error, response) {
if (error) throw new Error(error);
request(options, function (error, response){
if( error ) throw new Error( error );
var s = data,
l = JSON.parse(response.body);
l = JSON.parse( response.body );
var options = {
'method': 'GET',
'url': 'https://api.new.local.vkusvill.testin.ru/api/admin/tag/',
'headers': {}
};
request( options, function( error, response ){
if( error ) throw new Error( error );
var tags = JSON.parse( response.body );
var options = {
'method': 'GET',
'url': 'https://api.new.local.vkusvill.testin.ru/api/admin/question/',
'headers': {}
};
request( options, function( error, response ){
if( error ) throw new Error( error );
var questions = JSON.parse( response.body );
var qCardHash = {};
questions.forEach(function(q) {
(qCardHash[q.card_info_id] || (qCardHash[q.card_info_id]=[])).push(q);
});
var mimicri = {
tags: [],
connections: [],
products: {},
components: {}
components: {},
standardQuestions: {}
};
var cmpID = 1;
l.forEach(category=>{
if(category.type === 1 && !category.hidden){
category.cards.forEach(card=>{
card.components.forEach(cmp=>{
mimicri.components[cmpID++] = {
l.forEach( category => {
if( category.type === 1 && !category.hidden ){
category.cards.forEach( card => {
card.components.forEach( cmp => {
mimicri.components[ cmpID++ ] = {
id: card.id,
iID: cmp.id,
name: cmp.name
};
});
} );
mimicri.products[ card.id ] = {
tags: card.tags.map( t => t.id ),
mimicri.products[card.id] = {
"category_id": card.category_id,
"id": card.id,
"title": card.name,
......@@ -125,17 +154,110 @@ module.exports = {
"use": card.is_test,
"image": card.image === null ? void 0 : card.image,
"type": card.type,
"items": card.components.map(a=>a.id)
"items": card.components
};
} )
}else if( category.type === 2 && !category.hidden ){
category.cards.forEach( card => {
var base = {
category: card.category_id,
cardInfoID: card.id,
category_id: card.category_id
};
if(card.id in qCardHash){
qCardHash[card.id].forEach(q=>{
mimicri.standardQuestions[q.id] = Object.assign({
qID: q.id,
title: q.text,
multiple: q.type !== 'radio',
image: card.image,
answers: q.answers.map(a=>{
return {
"qID": q.id,
"title": a.text,
"correct": a.correct,
"id": a.id
};
})
}
}, base);
});
mimicri.standardQuestions = standardQuestions
/* {
"id": 4,
"card_info_id": 480,
"text": "ДА?",
"image": null,
"type": "radio",
"created_at": "2020-03-04 20:32:05",
"updated_at": "2020-03-04 21:29:36",
"answers": [
{
"id": 99,
"question_id": 4,
"text": "Да",
"correct": true,
"created_at": "2020-03-04 20:32:44",
"updated_at": "2020-03-04 20:32:44"
},
{
"id": 100,
"question_id": 4,
"text": "Нет",
"correct": false,
"created_at": "2020-03-04 20:34:06",
"updated_at": "2020-03-04 20:34:06"
},
{
"id": 107,
"question_id": 4,
"text": "Мда",
"correct": true,
"created_at": "2020-03-04 21:29:03",
"updated_at": "2020-03-04 21:29:03"
},
{
"id": 108,
"question_id": 4,
"text": "Мнет",
"correct": false,
"created_at": "2020-03-04 21:29:05",
"updated_at": "2020-03-04 21:29:05"
},
{
"id": 113,
"question_id": 4,
"text": "TTT",
"correct": false,
"created_at": "2020-03-04 21:46:24",
"updated_at": "2020-03-04 21:46:24"
}
],
"media": []
}*/
}
} );
/*
category: 2
qID: 2
title: "С какого года на рынке компания "Избёнка"?"
cardInfoID: 301
multiple: false
image: null
answer_type: "текст"
category_id: 2
*/
}
} );
//mimicri.standardQuestions = standardQuestions;
//console.log(response.body);
initCtx();
theData = JSON.stringify(mimicri);
ctx.setData(mimicri);
theData = JSON.stringify( mimicri );
ctx.setData( mimicri );
});
} );
});
return 'true';
}
......@@ -296,10 +418,10 @@ module.exports = {
counter++;
}while( counter < 100 );
}
debugger
result = ctx.standardGenerator(()=>r);
if(result)
if(!result){
tries = 100;
break;
......@@ -308,7 +430,8 @@ module.exports = {
tries++;
if(tries === 100)
break;
}while(result.categoryId+'.'+result.productId in used || (cur.c>1 && result.categoryId === cur.c));
}while(result.categoryId+'.'+result.productId in used || ((cur.c>1 && result.categoryId === last.c)&& !useCategory));
if(error)
break;
if(tries !== 100){
......@@ -396,6 +519,7 @@ ${ result.answers.map(a=>
const TRANSFORMER = {
IMAGE: function( image ){
return image;
if( !image ){
}else{
......
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