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 ...@@ -443,17 +443,24 @@ data = {tags:[], connections:[], more:[], standardQuestions: {}, standardAnswers
data.more = data.more || []; data.more = data.more || [];
var tid = 1, cid = 1; var tid = 1, cid = 1;
var tagsHash = {}; var tagsHash = {};
data.more = data.more.concat([
/*data.more = data.more.concat([
{p: '1cards_2020_02_28.csv', i: '1components.csv'}, {p: '1cards_2020_02_28.csv', i: '1components.csv'},
{q: '2questions.csv', a: '2answers.csv', c: '2cards_2020_2_21.csv'}, {q: '2questions.csv', a: '2answers.csv', c: '2cards_2020_2_21.csv'},
{q: '3questions.csv', a: '3answers.csv', c: '3cards.csv'}, {q: '3questions.csv', a: '3answers.csv', c: '3cards.csv'},
{q: '4questions.csv', a: '4answers.csv', c: '4cards.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'}, {c: 'top-35-march-c.csv', q: 'top-35-march-q.csv', a: 'top-35-march-a.csv'},
]); ]);*/
let id = 1; let id = 1;
let theInc = ()=>id++; let theInc = ()=>id++;
let was = {}; 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++ ){ for( let i = 0, _i = data.more.length; i < _i; i++ ){
var adishen = i*300; var adishen = i*300;
...@@ -641,7 +648,7 @@ data = {tags:[], connections:[], more:[], standardQuestions: {}, standardAnswers ...@@ -641,7 +648,7 @@ data = {tags:[], connections:[], more:[], standardQuestions: {}, standardAnswers
} }
} }
} }
await new Promise((r,j)=>setTimeout(r,100));
//git add . //git add .
// fs.writeFileSync('./data/tmp/full.json', JSON.stringify(data, null, 2)) // fs.writeFileSync('./data/tmp/full.json', JSON.stringify(data, null, 2))
......
...@@ -31,7 +31,7 @@ const fs = require('fs'), ...@@ -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'); 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}'; const body = 'const window = {}, localStorage = {getItem:()=>"{}"};'+js+'; return {quizGenerator, standardGenerator, quizTypes, probabilityRand, initDataProvider, seeded: Math.random.seeded, rand, dP}';
var ctxCtor = new Function('',body); var ctxCtor = new Function('',body);
...@@ -43,10 +43,11 @@ var initCtx = function() { ...@@ -43,10 +43,11 @@ var initCtx = function() {
ctx.ready = new Promise((r,j)=>{ ctx.ready = new Promise((r,j)=>{
ctx._r = r; ctx._r = r;
}); });
ctx.setData = function(data) { ctx.setData = function(dataSet) {
ctx.initDataProvider( data ); ctx.initDataProvider( dataSet );
countStdQ = Object.values(data.standardQuestions).length; countStdQ = Object.values(dataSet.standardQuestions).length;
//console.log(ctx.dP) //console.log(ctx.dP)
data = dataSet
ctx._r(); ctx._r();
}; };
}; };
...@@ -64,7 +65,7 @@ data.after = function(inComeData, skipInit){ ...@@ -64,7 +65,7 @@ data.after = function(inComeData, skipInit){
} }
ctx.setData(theData=inComeData); ctx.setData(theData=inComeData);
standardQuestions = inComeData.standardQuestions; standardQuestions = inComeData.standardQuestions;
//firstRequest(); firstRequest();
} }
}; };
...@@ -88,54 +89,175 @@ module.exports = { ...@@ -88,54 +89,175 @@ module.exports = {
options: {}, options: {},
fn: firstRequest = async function() { 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 = { var options = {
'method': 'GET', 'method': 'GET',
'url': 'https://api.new.local.vkusvill.testin.ru/api/admin/category/', 'url': 'https://api.new.local.vkusvill.testin.ru/api/admin/category/',
'headers': {} 'headers': {}
}; };
request(options, function (error, response) { request(options, function (error, response){
if (error) throw new Error(error); if( error ) throw new Error( error );
var s = data, var s = data,
l = JSON.parse(response.body); l = JSON.parse( response.body );
var mimicri = {
tags: [],
connections: [], var options = {
products: {}, 'method': 'GET',
components: {} 'url': 'https://api.new.local.vkusvill.testin.ru/api/admin/tag/',
'headers': {}
}; };
var cmpID = 1; request( options, function( error, response ){
l.forEach(category=>{ if( error ) throw new Error( error );
if(category.type === 1 && !category.hidden){ var tags = JSON.parse( response.body );
category.cards.forEach(card=>{
card.components.forEach(cmp=>{ var options = {
mimicri.components[cmpID++] = { 'method': 'GET',
id: card.id, 'url': 'https://api.new.local.vkusvill.testin.ru/api/admin/question/',
iID: cmp.id, 'headers': {}
name: cmp.name };
}; request( options, function( error, response ){
}); if( error ) throw new Error( error );
var questions = JSON.parse( response.body );
mimicri.products[card.id] = {
"category_id": card.category_id, var qCardHash = {};
"id": card.id, questions.forEach(function(q) {
"title": card.name, (qCardHash[q.card_info_id] || (qCardHash[q.card_info_id]=[])).push(q);
"description": card.text, });
"subcat": subcats[ normalizeText( card.name ) ],
"use": card.is_test, var mimicri = {
"image": card.image === null ? void 0 : card.image, tags: [],
"type": card.type, connections: [],
"items": card.components.map(a=>a.id) products: {},
}; components: {},
}) standardQuestions: {}
} };
}); var cmpID = 1;
mimicri.standardQuestions = standardQuestions l.forEach( category => {
//console.log(response.body); if( category.type === 1 && !category.hidden ){
initCtx(); category.cards.forEach( card => {
theData = JSON.stringify(mimicri); card.components.forEach( cmp => {
ctx.setData(mimicri); mimicri.components[ cmpID++ ] = {
id: card.id,
iID: cmp.id,
name: cmp.name
};
} );
mimicri.products[ card.id ] = {
tags: card.tags.map( t => t.id ),
"category_id": card.category_id,
"id": card.id,
"title": card.name,
"description": card.text,
"subcat": subcats[ normalizeText( card.name ) ],
"use": card.is_test,
"image": card.image === null ? void 0 : card.image,
"type": card.type,
"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);
});
/* {
"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 );
});
} );
}); });
return 'true'; return 'true';
} }
...@@ -296,10 +418,10 @@ module.exports = { ...@@ -296,10 +418,10 @@ module.exports = {
counter++; counter++;
}while( counter < 100 ); }while( counter < 100 );
} }
debugger
result = ctx.standardGenerator(()=>r); result = ctx.standardGenerator(()=>r);
if(result)
if(!result){ if(!result){
tries = 100; tries = 100;
break; break;
...@@ -308,7 +430,8 @@ module.exports = { ...@@ -308,7 +430,8 @@ module.exports = {
tries++; tries++;
if(tries === 100) if(tries === 100)
break; 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) if(error)
break; break;
if(tries !== 100){ if(tries !== 100){
...@@ -396,6 +519,7 @@ ${ result.answers.map(a=> ...@@ -396,6 +519,7 @@ ${ result.answers.map(a=>
const TRANSFORMER = { const TRANSFORMER = {
IMAGE: function( image ){ IMAGE: function( image ){
return image;
if( !image ){ if( !image ){
}else{ }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