Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
kus-admin
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Кубота
kus-admin
Commits
57181804
Commit
57181804
authored
Mar 05, 2020
by
Иван Кубота
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use production database
parent
f570e895
Pipeline
#562
canceled with stage
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
198 additions
and
30 deletions
+198
-30
tmpjs.json
data/tmp/tmpjs.json
+37
-0
db.js
db.js
+11
-4
generateRandom.js
src/api/generateRandom.js
+150
-26
No files found.
data/tmp/tmpjs.json
0 → 100644
View file @
57181804
{
"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
db.js
View file @
57181804
...
...
@@ -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))
...
...
src/api/generateRandom.js
View file @
57181804
...
...
@@ -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'
);
cons
t
data
=
require
(
"../../db.js"
);
le
t
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
(
data
Set
)
{
ctx
.
initDataProvider
(
data
Set
);
countStdQ
=
Object
.
values
(
data
Set
.
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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment