/**
 * REmove previous log.txt, omr_result[*].txt
 * Enter description here ...
 * @param record $scan @see table blended_scans
 * @throws OMRError
 */
function omrprocess($scan)
{
    global $CFG;
    global $scansfoldername;
    mtrace("Entering OMR phase.");
    $scan->status = JOB_STATE_BUSY;
    set_field('blended_scans', 'status', $scan->status, 'id', $scan->id);
    $scan->timestatus = time();
    set_field('blended_scans', 'timestatus', $scan->timestatus, 'id', $scan->id);
    //update_record('blended_scans', $scan);
    $strresultlink = get_string('resultlink', 'blended');
    $rutaorigen = blended_getOMRSourcePath($scan);
    $rutafieldset = blended_getOMRFieldsetDir($scan);
    $rutadestino = blended_getOMRTargetPath($scan);
    $logfile = blended_getOMRInputLogFilePath($scan);
    mtrace("Processing Scan: {$scan->scan_name}");
    mtrace("     located at: {$rutaorigen}");
    mtrace("    fieldset at: {$rutafieldset}");
    mtrace("      target at: {$rutadestino} \n");
    try {
        /**
         * Clean previous results in case of a previous error and a relaunch
         */
        blended_delete_log_file($scan);
        blended_delete_scan_results($scan);
        /**
         * Execute the recognition process
         */
        list($status, $output) = blended_execute_omr_recognition($rutaorigen, $rutadestino, $rutafieldset);
        mtrace("Command executed. Status Code =");
        print_r($status);
        if ($status != 'OK') {
            $error = new OMRError($status, OMRError::OMRPROCESS_FAILED);
            throw $error;
        } else {
            $statusMsg = "Command executed. Status Code = 0";
            print_object($output);
            register_status($scan->id, $statusMsg, $output, JOB_STATE_FINISHED);
            //register_scannedjob($rutascandir,$jobid,$scan->course);
            $scan->status = JOB_STATE_FINISHED;
            register_scannedjob($scan);
        }
    } catch (OMRError $e) {
        mtrace("Fatal OMR Error: " . $e->getMessage());
        register_exception($e, $scan->id);
    } catch (ResultsError $e) {
        mtrace("ResultsError: " . $e->getMessage());
        register_exception($e, $scan->id);
    }
    return;
}
Example #2
0
/**
 * 
 * Path to the log.txt for a scanjob
 * @param unknown_type $scan
 */
function blended_getOMRInputLogFilePath($scan)
{
    return blended_getOMRTargetPath($scan) . "/log.txt";
}
/**
 * Remove all kind of results of a scanjob
 * @param unknown_type $data
 */
function blended_delete_scan_job($scan)
{
    $jobid = $scan->id;
    //	$timestamp = get_timestamp_attempts($scan);
    //	if ($timestamp !== null)
    //	{
    //delete_records($table='blended_attempts', $field='timestampt',$value = $timestamp);
    $scanjobdir = blended_getOMRTargetPath($scan);
    // Remove results file
    blended_delete_log_file($scan);
    /**
     * Remove previous result records.
     */
    delete_records($table = 'blended_results', $field = 'jobid', $value = $jobid);
    blended_delete_scan_results($scan);
    // remove unregistered files in this directory
    $mask = $scanjobdir . '/omr_result[*].txt';
    array_map("unlink", glob($mask));
    debugging("Deleted all omr_result[*].txt");
    delete_records($table = 'blended_images', $field = 'jobid', $value = $jobid);
    /**
     * Remove debug folder
     */
    $debugdir = $scanjobdir . '/output';
    if (file_exists($debugdir)) {
        $mask = $debugdir . '/*.*';
        array_map("unlink", glob($mask));
        rmdir($debugdir);
        debugging("Removed debug files.");
    } else {
        debugging("There is no {$debugdir} to remove.");
    }
    //	}
    /**
     * remove records of the scanjob
     */
    delete_records($table = 'blended_scans', $field = 'id', $value = $jobid);
    return;
}