Skip to content

Commit

Permalink
Merge pull request #75 from sanctuuary/update_benchmarks
Browse files Browse the repository at this point in the history
Update benchmarks
  • Loading branch information
kretep authored Dec 16, 2024
2 parents d8707c0 + 5d5652b commit aa8a197
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class BenchmarkBase {
@NonNull
private String benchmarkTitle;
@NonNull
private String benchmarkCategory;
@NonNull
private String benchmarkDescription;
@NonNull
private String unit;
Expand All @@ -24,6 +26,7 @@ public class BenchmarkBase {
public JSONObject getTitleJson() {
JSONObject benchmarkJson = new JSONObject();
benchmarkJson.put("title", benchmarkTitle);
benchmarkJson.put("category", benchmarkCategory);
benchmarkJson.put("description", benchmarkDescription);
benchmarkJson.put("unit", unit);
return benchmarkJson;
Expand Down
110 changes: 55 additions & 55 deletions src/main/java/nl/esciencecenter/restape/ToolBenchmarkingAPIs.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,63 +96,63 @@ static boolean computeBenchmarks(SolutionsList candidateSolutions, String runID)
}

/**
* Get the Pubmetric benchmarks for the workflow.
* @param workflow
* @return
*/
public static JSONObject getPubmetricBenchmarks(SolutionWorkflow workflow) {
// Generate the CWL file content
* Get the Pubmetric benchmarks for the workflow.
* @param workflow the SolutionWorkflow instance
* @return JSON response from Pubmetric API
*/
public static JSONObject getPubmetricBenchmarks(SolutionWorkflow workflow) {
DefaultCWLCreator cwlCreator = new DefaultCWLCreator(workflow);
String cwlFileContent = cwlCreator.generate();

// Convert the CWL content to a byte array
byte[] cwlFileBytes = cwlFileContent.getBytes();

return sendPostToPubmetric(cwlFileBytes);
}


/**
* Send a POST request to the Pubmetric API to get the benchmarks for the CWL file.
* @param cwlFileBytes
* @return
*/
public static JSONObject sendPostToPubmetric(byte[] cwlFileBytes) {
// Create the HTTP client
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost uploadFile = new HttpPost("http://pubmetric:8000/score_workflow/");

// Create a multipart entity with the CWL file
}

/**
* Send a POST request to the Pubmetric API to get benchmarks.
* @param cwlFileBytes byte array of CWL file content
* @return JSON response from Pubmetric API
*/
public static JSONObject sendPostToPubmetric(byte[] cwlFileBytes) {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpPost uploadFile = createHttpPost(cwlFileBytes);
return executeRequest(httpClient, uploadFile);
} catch (IOException | JSONException e) {
log.error("Error while processing Pubmetric benchmarks", e);
return new JSONObject(); // return empty JSON if an error occurs
}
}

/**
* Creates an HttpPost request with the provided CWL content.
* @param cwlFileBytes byte array of CWL file content
* @return configured HttpPost request
*/
private static HttpPost createHttpPost(byte[] cwlFileBytes) {
HttpPost uploadFile = new HttpPost("http://localhost:8000/score_workflow/");
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody("cwl_file", cwlFileBytes, org.apache.http.entity.ContentType.DEFAULT_BINARY,
"workflow.cwl");

HttpEntity multipart = builder.build();
uploadFile.setEntity(multipart);

// Execute the request
CloseableHttpResponse response;
try {
response = httpClient.execute(uploadFile);
HttpEntity responseEntity = response.getEntity();

// Print the response
if (responseEntity != null) {
String responseString = EntityUtils.toString(responseEntity);
return new JSONObject(responseString);
}

// Close resources
response.close();
httpClient.close();
} catch (IOException e) {
log.error("Error while fetching the Pubmetric benchmarks");
} catch (JSONException e) {
log.error("Error while parsing the Pubmetric benchmarks");
builder.addBinaryBody("cwl_file", cwlFileBytes, org.apache.http.entity.ContentType.DEFAULT_BINARY, "workflow.cwl");
uploadFile.setEntity(builder.build());
return uploadFile;
}

/**
* Executes the HTTP request and returns the response as a JSONObject.
* @param httpClient the HTTP client
* @param uploadFile the configured HttpPost request
* @return JSON response from Pubmetric API
* @throws IOException if an error occurs during the HTTP call
*/
private static JSONObject executeRequest(CloseableHttpClient httpClient, HttpPost uploadFile) throws IOException {
try (CloseableHttpResponse response = httpClient.execute(uploadFile)) {
HttpEntity responseEntity = response.getEntity();
if (responseEntity != null) {
String responseString = EntityUtils.toString(responseEntity);
return new JSONObject(responseString);
}
return new JSONObject(); // return empty JSON if no response entity
}

return new JSONObject();
}
}

/**
* Compute the benchmarks (based on bio.tools and OpenEBench APIs) for the
Expand Down Expand Up @@ -210,15 +210,15 @@ private static List<Benchmark> computeBiotoolsBenchmark(SolutionWorkflow workflo
List<Benchmark> benchmarks = new ArrayList<>();

String unitOS = "supported / not supported";
BenchmarkBase linuxBenchmark = new BenchmarkBase("Linux", "Linux (OS) supported tools",
BenchmarkBase linuxBenchmark = new BenchmarkBase("Linux", "OS", "Linux (OS) supported tools",
unitOS, "operatingSystem", "Linux");
benchmarks.add(BioToolsBenchmarkProcessor.benchmarkOSSupport(biotoolsAnnotations, linuxBenchmark));

BenchmarkBase macOSBenchmark = new BenchmarkBase("Mac OS", "Mac OS supported tools",
BenchmarkBase macOSBenchmark = new BenchmarkBase("Mac OS", "OS", "Mac OS supported tools",
unitOS, "operatingSystem", "Mac");
benchmarks.add(BioToolsBenchmarkProcessor.benchmarkOSSupport(biotoolsAnnotations, macOSBenchmark));

BenchmarkBase windowsBenchmark = new BenchmarkBase("Windows", "Windows (OS) supported tools",
BenchmarkBase windowsBenchmark = new BenchmarkBase("Windows", "OS", "Windows (OS) supported tools",
unitOS, "operatingSystem", "Windows");
benchmarks.add(BioToolsBenchmarkProcessor.benchmarkOSSupport(biotoolsAnnotations, windowsBenchmark));

Expand Down Expand Up @@ -259,11 +259,11 @@ private static List<Benchmark> computeOpenEBenchmarks(SolutionWorkflow workflow)

List<Benchmark> benchmarks = new ArrayList<>();

BenchmarkBase licenseBenchmark = new BenchmarkBase("License", "License information available",
BenchmarkBase licenseBenchmark = new BenchmarkBase("License", "License", "License information available",
"license type", "license", null);
benchmarks.add(OpenEBenchBenchmarkProcessor.benchmarkLicenses(openEBenchBiotoolsMetrics, licenseBenchmark));

BenchmarkBase citationsBenchmark = new BenchmarkBase("Citations", "Citations annotated per tool",
BenchmarkBase citationsBenchmark = new BenchmarkBase("Citations", "Bibliometrics", "Citations annotated per tool",
"citation count", "citation", null);
benchmarks.add(OpenEBenchBenchmarkProcessor.countCitationsBenchmark(openEBenchBiotoolsMetrics, citationsBenchmark));

Expand Down

0 comments on commit aa8a197

Please sign in to comment.