<commit_before><?php 

require 'vendor/autoload.php';

use InformationMachineAPILib\Controllers as ctrl;
use InformationMachineAPILib\Models as model;


function testUserPurchase($productsController, $clientId, $clientSecret, $superMarketId, $username, $password)
{
    $email = "<EMAIL>";
    $userId = "testuserId1234";

    $usersController = new ctrl\UserManagementController($clientId, $clientSecret);
    $storesController = new ctrl\UserStoresController($clientId, $clientSecret);
    $purchasesController = new ctrl\UserPurchasesController($clientId, $clientSecret);
    $userScansController = new ctrl\UserScansController($clientId, $clientSecret);

    usersControllerTest($email, $usersController, $userId);

    $encodedImage = file_get_contents("encoded_logo.txt");
    $receiptId = "fe6ba83b-d45c-457a-afd5-35bdb3cdffff";
    $receiptRequest = new model\UploadReceiptRequest();
    $receiptRequest->image = $encodedImage;
    $receiptRequest->receiptId = $receiptId;

    $userScansController->userScansUploadReceipt($receiptRequest, $userId);

    $storeConnect = new model\ConnectUserStoreRequest();
    $storeConnect->storeId = $superMarketId;
    $storeConnect->username = $username;
    $storeConnect->password = <PASSWORD>;

    $userStore = $storesController->userStoresConnectStore($storeConnect, $userId)->result;

    $storeConnectionValid = checkStoreValidity($storesController, $userId, $userStore->id);
    if (!$storeConnectionValid)
    {
        $storesController->userStoresDeleteSingleStore($userId, $userStore->id);
        throw new Exception("Error: could not connect to store");
    }

    if (!waitForScrapeToFinish($storesController, $userId, $userStore->id))
    {
        throw new Exception("Error: scrape is not finished");
    }

    $stores = $storesController->userStoresGetAllStores($userId)->result;
    if (empty($stores) || $stores[0]->id <= 0)
    {
        throw new Exception("Error: could not get all stores");
    }

    $userProducts = $productsController->productsGetUserProducts($userId, 1, 15, true, true)->result;
    if (empty($userProducts))
    {
        throw new Exception("Error: get user products");
    }

    $userPurchases = $purchasesController->userPurchasesGetAllUserPurchases($userId, NULL, 1, 15, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, true, NULL, NULL, NULL, NULL)->result;
    if (empty($userPurchases))
    {
        throw new Exception("Error: get all user purchases");
    }
    
    $purchaseHistory = $purchasesController->userPurchasesGetPurchaseHistoryUnified($userId, NULL, NULL, NULL, NULL, NULL, NULL)->result;
    if (empty($purchaseHistory))
    {
        throw new Exception("Error: get purchase history");
    }


    $userPurchase = $purchasesController->userPurchasesGetSingleUserPurchase($userId, $userPurchases[0]->id, true)->result;
    if ($userPurchase == NULL || $userPurchase->id != $userPurchases[0]->id)
    {
        throw new Exception("Error: get single user purchases");
    }

    $barcodeRequest = new model\UploadBarcodeRequest();
    $barcodeRequest->barCode = "021130126026";
    $barcodeRequest->barCodeType = "UPC-A";

    $barcodeResponse = $userScansController->userScansUploadBarcode($barcodeRequest, $userId)->result;
    if ($barcodeResponse->bar_code_type != "UPC-A" || $barcodeResponse->bar_code != "021130126026")
    {
        throw new Exception("Error: upload barcode");
    }

    $storesController->userStoresDeleteSingleStore($userId, $userStore->id);

    $usersController->userManagementDeleteUser($userId);
}

function waitForScrapeToFinish($storesController, $userIdentifier, $storeId)
{
    // try to see if the users credentials are valid
    for ($i = 0; $i < 120; $i++)
    {
        $connectedStore = $storesController->userStoresGetSingleStore($userIdentifier, $storeId);

        if ($connectedStore != NULL &&
         ($connectedStore->result->scrape_status == "Done" || $connectedStore->result->scrape_status == "Done With Warning"))
        {
            return true;
        }

        sleep(3);
    }

    return false;
}

function checkStoreValidity($storesController, $userIdentifier, $storeId)
{
    // try to see if the users credentials are valid
    for ($i = 0; $i < 15; $i++)
    {
        $connectedStore = $storesController->userStoresGetSingleStore($userIdentifier, $storeId);

        if ($connectedStore != NULL &&
        ($connectedStore->result->scrape_status == "Done" || $connectedStore->result->scrape_status == "Done With Warning" || $connectedStore->result->scrape_status == "Scraping"))
        {
            if ($connectedStore->result->credentials_status == "Verified")
            {
                return true;<commit_msg>DoneWithWarning fixed.<commit_after><?php 

require 'vendor/autoload.php';

use InformationMachineAPILib\Controllers as ctrl;
use InformationMachineAPILib\Models as model;


function testUserPurchase($productsController, $clientId, $clientSecret, $superMarketId, $username, $password)
{
    $email = "<EMAIL>";
    $userId = "testuserId1234";

    $usersController = new ctrl\UserManagementController($clientId, $clientSecret);
    $storesController = new ctrl\UserStoresController($clientId, $clientSecret);
    $purchasesController = new ctrl\UserPurchasesController($clientId, $clientSecret);
    $userScansController = new ctrl\UserScansController($clientId, $clientSecret);

    usersControllerTest($email, $usersController, $userId);

    $encodedImage = file_get_contents("encoded_logo.txt");
    $receiptId = "fe6ba83b-d45c-457a-afd5-35bdb3cdffff";
    $receiptRequest = new model\UploadReceiptRequest();
    $receiptRequest->image = $encodedImage;
    $receiptRequest->receiptId = $receiptId;

    $userScansController->userScansUploadReceipt($receiptRequest, $userId);

    $storeConnect = new model\ConnectUserStoreRequest();
    $storeConnect->storeId = $superMarketId;
    $storeConnect->username = $username;
    $storeConnect->password = <PASSWORD>;

    $userStore = $storesController->userStoresConnectStore($storeConnect, $userId)->result;

    $storeConnectionValid = checkStoreValidity($storesController, $userId, $userStore->id);
    if (!$storeConnectionValid)
    {
        $storesController->userStoresDeleteSingleStore($userId, $userStore->id);
        throw new Exception("Error: could not connect to store");
    }

    if (!waitForScrapeToFinish($storesController, $userId, $userStore->id))
    {
        throw new Exception("Error: scrape is not finished");
    }

    $stores = $storesController->userStoresGetAllStores($userId)->result;
    if (empty($stores) || $stores[0]->id <= 0)
    {
        throw new Exception("Error: could not get all stores");
    }

    $userProducts = $productsController->productsGetUserProducts($userId, 1, 15, true, true)->result;
    if (empty($userProducts))
    {
        throw new Exception("Error: get user products");
    }

    $userPurchases = $purchasesController->userPurchasesGetAllUserPurchases($userId, NULL, 1, 15, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, true, NULL, NULL, NULL, NULL)->result;
    if (empty($userPurchases))
    {
        throw new Exception("Error: get all user purchases");
    }
    
    $purchaseHistory = $purchasesController->userPurchasesGetPurchaseHistoryUnified($userId, NULL, NULL, NULL, NULL, NULL, NULL)->result;
    if (empty($purchaseHistory))
    {
        throw new Exception("Error: get purchase history");
    }


    $userPurchase = $purchasesController->userPurchasesGetSingleUserPurchase($userId, $userPurchases[0]->id, true)->result;
    if ($userPurchase == NULL || $userPurchase->id != $userPurchases[0]->id)
    {
        throw new Exception("Error: get single user purchases");
    }

    $barcodeRequest = new model\UploadBarcodeRequest();
    $barcodeRequest->barCode = "021130126026";
    $barcodeRequest->barCodeType = "UPC-A";

    $barcodeResponse = $userScansController->userScansUploadBarcode($barcodeRequest, $userId)->result;
    if ($barcodeResponse->bar_code_type != "UPC-A" || $barcodeResponse->bar_code != "021130126026")
    {
        throw new Exception("Error: upload barcode");
    }

    $storesController->userStoresDeleteSingleStore($userId, $userStore->id);

    $usersController->userManagementDeleteUser($userId);
}

function waitForScrapeToFinish($storesController, $userIdentifier, $storeId)
{
    // try to see if the users credentials are valid
    for ($i = 0; $i < 120; $i++)
    {
        $connectedStore = $storesController->userStoresGetSingleStore($userIdentifier, $storeId);

        if ($connectedStore != NULL &&
         ($connectedStore->result->scrape_status == "Done" || $connectedStore->result->scrape_status == "DoneWithWarning"))
        {
            return true;
        }

        sleep(3);
    }

    return false;
}

function checkStoreValidity($storesController, $userIdentifier, $storeId)
{
    // try to see if the users credentials are valid
    for ($i = 0; $i < 15; $i++)
    {
        $connectedStore = $storesController->userStoresGetSingleStore($userIdentifier, $storeId);

        if ($connectedStore != NULL &&
        ($connectedStore->result->scrape_status == "Done" || $connectedStore->result->scrape_status == "DoneWithWarning" || $connectedStore->result->scrape_status == "Scraping"))
        {
            if ($connectedStore->result->credentials_status == "Verified")
            {
                return true;
{'fraction_non_alphanumeric': 0.13471557682083998, 'fraction_numerical': 0.012333864965443912, 'mean_word_length': 4.137083560895685, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 105, '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': '1714830', 'n_tokens_mistral': 2910, 'n_tokens_neox': 2764, 'n_words': 550}