<commit_before><?php

    $services = getenv("VCAP_SERVICES");
    $services_json = json_decode($services, true);
    for ($i = 0; $i < sizeof($services_json["user-provided"]); $i++){
        if ($services_json["user-provided"][$i]["name"] == "catalogAPI"){
                $catalogHost = $services_json["user-provided"][$i]["credentials"]["host"];
        }
    }
    $parsedURL = parse_url($catalogHost);
    $catalogRoute = $parsedURL["scheme"] . "://" . $parsedURL["host"];

    if (isset($_GET['count'])) {
        $count = $_GET['count'];
    } else {
        $count = 100;
    }
    $url = $catalogRoute . "/loadTest?count=" . $count;

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $curlResult = curl_exec($curl);
    $curlError = curl_error($curl);
    $curlErrno = curl_errno($curl);
    curl_close($curl);
    $firstChar = substr($curlResult, 0, 1); /* should check if $curlResult === FALSE if newer PHP */
    if ($firstChar != "{") {
        http_response_code(500);
        $errorObject = new stdClass();
        $errorObject->error = $curlError;
        $errorObject->errno = $curlErrno;
        $errorObject->url = $url;
        echo json_encode($errorObject);
        return;
    }
    echo $curlResult;

?>
<commit_msg>adapt ajaxCatalogLoadTest to earlier changes<commit_after><?php

    $application = getenv("VCAP_APPLICATION");
    $application_json = json_decode($application, true);
    $applicationName = $application_json["name"];
    if (substr($applicationName, -3) === "-ui") { // if suffixed with "-ui", remove trailing "-ui"
        $catalogAppName = substr($applicationName, 0, -3)  . "-catalog";
    } else {
        $catalogAppName = $applicationName . "-catalog";
    }
    $applicationURI = $application_json["application_uris"][0];
    $catalogHost=substr_replace($applicationURI, $catalogAppName, 0, strlen($applicationName));
    $catalogRoute = "http://" . $catalogHost;

    if (isset($_GET['count'])) {
        $count = $_GET['count'];
    } else {
        $count = 100;
    }
    $url = $catalogRoute . "/loadTest?count=" . $count;

    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $curlResult = curl_exec($curl);
    $curlError = curl_error($curl);
    $curlErrno = curl_errno($curl);
    curl_close($curl);
    $firstChar = substr($curlResult, 0, 1); /* should check if $curlResult === FALSE if newer PHP */
    if ($firstChar != "{") {
        http_response_code(500);
        $errorObject = new stdClass();
        $errorObject->error = $curlError;
        $errorObject->errno = $curlErrno;
        $errorObject->url = $url;
        echo json_encode($errorObject);
        return;
    }
    echo $curlResult;

?>
{'fraction_non_alphanumeric': 0.1737891737891738, 'fraction_numerical': 0.008547008547008548, 'mean_word_length': 3.1800595238095237, 'pattern_counts': {'":': 1, '<': 6, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6576351', 'n_tokens_mistral': 947, 'n_tokens_neox': 882, 'n_words': 173}