function classifyImage(imagedata, cacheKey, lastmodified, callback) {
        $.ajax({
            url : '{{{ classifyurl }}}',
            dataType : 'json',
            type : 'POST',
            contentType : 'application/json',
            data : '{"data":"' + imagedata + '"}',
            headers : {
                'If-Modified-Since': lastmodified
            },
            success : function (data, status) {
                var result;

                if (status === 'notmodified') {
                    // the API returned an HTTP-304 so we'll reuse
                    //  the value we got last time
                    result = ext.resultscache[cacheKey];
                }
                else if (data && data.length > 0) {
                    // we got a result from the classifier
                    result = data[0];
                }
                else {
                    // we got an API response successfully, but the response
                    //  is that the classifier could not classify the image
                    result = {
                        class_name : 'Unknown',
                        confidence : 0,
                        classifierTimestamp : nowAsString()
                    };
                }


                if (result.random) {
                    if (classifierStatus.status === STATUS_OK) {
                        // We got a randomly selected result (which means we must not
                        //  have a working classifier) but we thought we had a model
                        //  with a good status.
                        // This should not be possible - we've gotten into a weird
                        //  unexpected state.
                        //
                        // Check the status again!
                        initStatusCheck();
                    }
                }
                else {
                    // timestamp used for local throttling
                    result.fetched = Date.now();

                    // if the result was chosen at random (instead of using
                    //  a trained classifier) then we don't cache it
                    ext.resultscache[cacheKey] = result;
                }

                // return the final result (either from cache or API response)
                callback(result);
            },
            error : function (err) {
                console.log(err);

                classifierStatus = {
                    status : STATUS_ERROR,
                    msg : 'Failed to submit image to machine learning service'
                };

                callback({ class_name : 'Unknown', confidence : 0 });

                pollStatus();
            }
        });
    }
// Submit xhr request to the classify API to get a label for the image
Submit xhr request to the classify API to get a label for the image
Submit xhr request to the classify API to get a label for the image
function classifyImage(imagedata, cacheKey, lastmodified, callback) {
        $.ajax({
            url : '{{{ classifyurl }}}',
            dataType : 'json',
            type : 'POST',
            contentType : 'application/json',
            data : '{"data":"' + imagedata + '"}',
            headers : {
                'If-Modified-Since': lastmodified
            },
            success : function (data, status) {
                var result;
                if (status === 'notmodified') {
                    result = ext.resultscache[cacheKey];
                }
                else if (data && data.length > 0) {
                    result = data[0];
                }
                else {
                    result = {
                        class_name : 'Unknown',
                        confidence : 0,
                        classifierTimestamp : nowAsString()
                    };
                }
                if (result.random) {
                    if (classifierStatus.status === STATUS_OK) {
                         Check the status again!
                        initStatusCheck();
                    }
                }
                else {
                     timestamp used for local throttling
                    result.fetched = Date.now();
                     if the result was chosen at random (instead of using
                      a trained classifier) then we don't cache it
                    ext.resultscache[cacheKey] = result;
                }
                 return the final result (either from cache or API response)
                callback(result);
            },
            error : function (err) {
                console.log(err);
                classifierStatus = {
                    status : STATUS_ERROR,
                    msg : 'Failed to submit image to machine learning service'
                };
                callback({ class_name : 'Unknown', confidence : 0 });
                pollStatus();
            }
        });
    }
function classifyImage ( imagedata , cacheKey , lastmodified , callback ) { $ . ajax ( { url : '{{{ classifyurl }}}' , dataType : 'json' , type : 'POST' , contentType : 'application/json' , data : '{"data":"' + imagedata + '"}' , headers : { 'If-Modified-Since' : lastmodified } , success : function ( data , status ) { var result ; if ( status === 'notmodified' ) { result = ext . resultscache [ cacheKey ] ; } else if ( data && data . length > 0 ) { result = data [ 0 ] ; } else { result = { class_name : 'Unknown' , confidence : 0 , classifierTimestamp : nowAsString ( ) } ; } if ( result . random ) { if ( classifierStatus . status === STATUS_OK ) { initStatusCheck ( ) ; } } else { result . fetched = Date . now ( ) ; ext . resultscache [ cacheKey ] = result ; } callback ( result ) ; } , error : function ( err ) { console . log ( err ) ; classifierStatus = { status : STATUS_ERROR , msg : 'Failed to submit image to machine learning service' } ; callback ( { class_name : 'Unknown' , confidence : 0 } ) ; pollStatus ( ) ; } } ) ; }
Submit xhr request to the classify API to get a label for the image
Submit xhr request to the classify API to get a label for the image
// the API returned an HTTP-304 so we'll reuse //  the value we got last time // we got a result from the classifier // we got an API response successfully, but the response //  is that the classifier could not classify the image // We got a randomly selected result (which means we must not //  have a working classifier) but we thought we had a model //  with a good status. // This should not be possible - we've gotten into a weird //  unexpected state. // // Check the status again! // timestamp used for local throttling // if the result was chosen at random (instead of using //  a trained classifier) then we don't cache it // return the final result (either from cache or API response)