Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
moobench
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SustainKieker
moobench
Commits
9da0aead
Commit
9da0aead
authored
4 years ago
by
Reiner Jung
Browse files
Options
Downloads
Patches
Plain Diff
Added files.
parent
0850ae4d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tools/compile-results/build.gradle
+18
-0
18 additions, 0 deletions
tools/compile-results/build.gradle
tools/compile-results/src/main/java/moobench/tools/compile/results/CompileResultsMain.java
+88
-0
88 additions, 0 deletions
...va/moobench/tools/compile/results/CompileResultsMain.java
with
106 additions
and
0 deletions
tools/compile-results/build.gradle
0 → 100644
+
18
−
0
View file @
9da0aead
plugins
{
id
'java'
id
'application'
}
application
{
mainClass
=
'moobench.tools.compile.results.CompileResultsMain'
}
dependencies
{
// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core
implementation
'com.fasterxml.jackson.core:jackson-databind:2.11.3'
// https://mvnrepository.com/artifact/org.apache.commons/commons-csv
implementation
'org.apache.commons:commons-csv:1.8'
implementation
'org.slf4j:slf4j-api:1.7.+'
implementation
'ch.qos.logback:logback-classic:1.2.3'
}
This diff is collapsed.
Click to expand it.
tools/compile-results/src/main/java/moobench/tools/compile/results/CompileResultsMain.java
0 → 100644
+
88
−
0
View file @
9da0aead
/**
*
*/
package
moobench.tools.compile.results
;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
org.apache.commons.csv.CSVFormat
;
import
org.apache.commons.csv.CSVParser
;
import
org.apache.commons.csv.CSVRecord
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.JsonMappingException
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
com.fasterxml.jackson.databind.node.DoubleNode
;
import
com.fasterxml.jackson.databind.node.JsonNodeFactory
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
/**
* Read the CSV output of the R script and the existing JSON file and append a
* record to the JSON file based on the CSV dataset.
*
* @author Reiner Jung
*
*/
public
class
CompileResultsMain
{
public
static
void
main
(
String
[]
args
)
{
try
{
final
JsonNode
rootNode
;
if
(
Paths
.
get
(
args
[
1
]).
toFile
().
exists
())
{
/** Read JSON file. */
rootNode
=
readJsonFile
(
Paths
.
get
(
args
[
1
]).
toFile
());
}
else
{
rootNode
=
readJsonString
();
}
JsonNode
resultsNode
=
rootNode
.
get
(
"results"
);
if
(!(
resultsNode
instanceof
ArrayNode
))
{
System
.
exit
(
1
);
}
ArrayNode
arrayResultsNode
=
(
ArrayNode
)
resultsNode
;
/** Read CSV file. */
final
CSVParser
csvParser
=
new
CSVParser
(
Files
.
newBufferedReader
(
Paths
.
get
(
args
[
0
])),
CSVFormat
.
DEFAULT
.
withHeader
());
List
<
String
>
header
=
csvParser
.
getHeaderNames
();
JsonNodeFactory
factory
=
JsonNodeFactory
.
instance
;
/** Put CSV in JSON. */
for
(
CSVRecord
record
:
csvParser
.
getRecords
())
{
Map
<
String
,
JsonNode
>
recordMap
=
new
HashMap
<>();
for
(
int
i
=
0
;
i
<
record
.
size
();
i
++)
{
recordMap
.
put
(
header
.
get
(
i
),
new
DoubleNode
(
Double
.
parseDouble
(
record
.
get
(
i
))));
}
arrayResultsNode
.
add
(
new
ObjectNode
(
factory
,
recordMap
));
}
/** Write JSON file. */
ObjectMapper
mapper
=
new
ObjectMapper
();
mapper
.
writeValue
(
Paths
.
get
(
args
[
1
]).
toFile
(),
rootNode
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
private
static
JsonNode
readJsonString
()
throws
JsonMappingException
,
JsonProcessingException
{
ObjectMapper
mapper
=
new
ObjectMapper
();
String
value
=
"{ \"results\" : [] }"
;
return
mapper
.
readTree
(
value
);
}
private
static
JsonNode
readJsonFile
(
File
file
)
throws
JsonProcessingException
,
IOException
{
ObjectMapper
mapper
=
new
ObjectMapper
();
return
mapper
.
readTree
(
file
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment