Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-074
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2022-074
2022-074
Commits
381781cf
Commit
381781cf
authored
Apr 25, 2022
by
Wasala W.L.M.K.S - IT19177106
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Save results to csv
parent
a49dd9ee
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
0 deletions
+36
-0
backend/src/controllers/Registration.controller.js
backend/src/controllers/Registration.controller.js
+36
-0
No files found.
backend/src/controllers/Registration.controller.js
View file @
381781cf
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
const
mongoose
=
require
(
"
mongoose
"
);
const
mongoose
=
require
(
"
mongoose
"
);
const
User
=
mongoose
.
model
(
'
users
'
);
const
User
=
mongoose
.
model
(
'
users
'
);
const
Results
=
mongoose
.
model
(
'
results
'
);
const
Results
=
mongoose
.
model
(
'
results
'
);
const
{
Parser
}
=
require
(
"
json2csv
"
);
const
fs
=
require
(
'
fs
'
);
const
fs
=
require
(
'
fs
'
);
//const Paper = mongoose.model('paper');
//const Paper = mongoose.model('paper');
...
@@ -44,6 +45,41 @@ exports.results = async (req, res) => {
...
@@ -44,6 +45,41 @@ exports.results = async (req, res) => {
percentArray
:
req
.
body
.
percentArray
,
percentArray
:
req
.
body
.
percentArray
,
}
}
var
user
=
req
.
body
.
user
;
var
task
=
req
.
body
.
task
;
var
dataArray
=
req
.
body
.
dataArr
;
var
flattenedArrayFull
=
[];
for
(
let
slide
in
dataArray
)
{
flattenedArray
=
dataArray
[
slide
].
map
((
x
)
=>
{
x
[
'
task
'
]
=
task
;
x
[
'
user
'
]
=
user
;
x
[
'
slide
'
]
=
slide
;
return
x
;
});
flattenedArrayFull
=
flattenedArrayFull
.
concat
(
flattenedArray
);
}
console
.
log
(
"
========================
"
)
console
.
log
(
flattenedArrayFull
)
console
.
log
(
"
========================
"
)
//csv file creation part start
const
fields
=
[
'
task
'
,
'
user
'
,
'
slide
'
,
'
x
'
,
'
y
'
,
'
bb
'
,
'
type
'
,
'
timestamp
'
];
const
json2csvParser
=
new
Parser
({
fields
});
const
csv
=
json2csvParser
.
parse
(
flattenedArrayFull
);
const
content
=
csv
;
//fs.writeFile('/Users/INSIGHT/Desktop/research/vc/research-backend/results/'+req.body.task+'_'+req.body.user+'_'+Date.now()+'.csv', content, { flag: 'w+' }, function (err) {
fs
.
writeFile
(
'
./results/
'
+
req
.
body
.
task
+
'
_
'
+
req
.
body
.
user
+
'
_
'
+
Date
.
now
()
+
'
.csv
'
,
content
,
{
flag
:
'
w+
'
},
function
(
err
)
{
if
(
err
)
throw
err
;
console
.
log
(
"
It's saved!
"
);
});
//csv file creation part end
// save results
// save results
await
new
Results
(
results
).
save
((
err
,
data
)
=>
{
await
new
Results
(
results
).
save
((
err
,
data
)
=>
{
if
(
err
)
{
if
(
err
)
{
...
...
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