Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
ARC-Support
public projects
lou-server
Commits
29446b1e
Commit
29446b1e
authored
Sep 13, 2021
by
Maik Messerschmidt
Browse files
Added running id to csv export (if wanted).
Closes
#3
parent
bd9d82c1
Changes
2
Show whitespace changes
Inline
Side-by-side
app/Http/Controllers/ResultController.php
View file @
29446b1e
...
...
@@ -121,9 +121,13 @@ class ResultController extends Controller
$all_rows
=
collect
();
$id
=
config
(
'experiment.csv-id-header-start'
);
$id_format
=
config
(
'experiment.csv-id-header-format'
);
$id_header
=
config
(
'experiment.csv-id-header'
);
foreach
(
$results
as
$result
)
{
$rows
=
collect
(
$result
->
data
??
[])
->
map
(
function
(
$row
)
use
(
$header
)
{
->
map
(
function
(
$row
)
use
(
$header
,
$id_header
,
$id_format
,
$id
)
{
foreach
(
$header
as
$key
)
{
// Fill empty columns with N/A
$row
[
$key
]
=
$row
[
$key
]
??
config
(
'experiment.n-a-text'
);
...
...
@@ -133,10 +137,20 @@ class ResultController extends Controller
$row
[
$key
]
=
json_encode
(
$row
[
$key
]);
}
if
(
$id_header
)
return
array_merge
(
[
$id_header
=>
sprintf
(
$id_format
,
$id
)],
$row
);
else
return
$row
;
});
$all_rows
=
$all_rows
->
concat
(
$rows
);
$id
+=
1
;
}
if
(
$id_header
)
{
$header
->
prepend
(
$id_header
);
}
return
(
object
)
[
...
...
config/experiment.php
View file @
29446b1e
...
...
@@ -6,6 +6,13 @@ return [
*/
'n-a-text'
=>
'N/A'
,
/**
* header field of a running index added by the csv export.
*/
'csv-id-header'
=>
env
(
'EXPERIMENT_CSV_ID_HEADER'
,
null
),
'csv-id-header-start'
=>
env
(
'EXPERIMENT_CSV_ID_HEADER_START'
,
1
),
'csv-id-header-format'
=>
env
(
'EXPERIMENT_CSV_ID_HEADER_FORMAT'
,
'%d'
),
/**
* The token for the next and submit route.
* If the token is null, everyone can access these routes.
...
...
Write
Preview
Supports
Markdown
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