<commit_before>/*
  Much of the code in this file and controllers.js that has to do with SQLite is
  derived from the gist created by <NAME>, here: 
  https://gist.github.com/borissondagh/29d1ed19d0df6051c56f
*/
angular.module('cat5scouting.services', [])

.factory('DBA', function($cordovaSQLite, $q, $ionicPlatform) {
    var self = this;
    
    self.query = function(query, parameters) {
        parameters = parameters || [];
        var q = $q.defer();
        
        $ionicPlatform.ready(function() {
           $cordovaSQLite.execute(db, query, parameters)
           .then(function (result) {
               q.resolve(result);
           }, function (error) {
               console.warn('Error encountered: ');
               console.warn(error);
               q.reject(error);
           });
        });
        return q.promise;
    }
    
    self.getAll = function(result) {
        var output = [];
        
        for (var i=0; i<result.rows.length; i++) {
            output.push(result.rows.item(i));
        }
        
        return output;
    }
    
    self.getById = function(result) {
        var output = null;
        if (result.rows.length > 0) {
            output = angular.copy(result.rows.item(0));
        }
        return output;
    }
    
    return self;
})
    
/******************************************************************************/
    
.factory('Team', function($cordovaSQLite, DBA) {
    var self = this;
    
    self.all = function() {
        return DBA.query("SELECT id, name, number FROM team")
            .then(function(result) {
                return DBA.getAll(result);
            })
    }
    
    self.get = function(memberId) {
        var parameters = [memberId];
        return DBA.query("SELECT id, name, number FROM team WHERE id = (?)", parameters)
            .then(function(result) {
                return DBA.getById(result);
            })
    }
    
    return self;
})
    
/******************************************************************************/

.factory('Robot', function($cordovaSQLite, DBA) {
    var self = this;
    
    self.all = function() {
        return DBA.query("SELECT id, name FROM robot")
            .then(function(result) {
                return DBA.getAll(result);
            })
    }
    
    self.getByTeam = function(teamId) {
        var parameters = [teamId];
        return DBA.query("SELECT id, name FROM robot WHERE teamId = (?)", parameters)
            .then(function(result) {
                return DBA.getAll(result);
            })
    }
    
    self.getById = function(robotId) {
        var parameters = [robotId];
        return DBA.query("SELECT `id`, `name`, `teamId`, `driveMode`, `driveSpeed`, "
                    +    "`driveOverPlatform`, `autonomousCapability`, "
                    +    "`coopStep`, `pickupLoc`, `maxToteHeight`, "
                    +    "`maxContHeight`, `stackContInd`, `collectContStep`, "
                    +    "`note` from robot "
                    +    "WHERE id = (?)", parameters)
            .then(function(result) {
                return DBA.getById(result);
            })
    }
    
    self.update = function(origRobot, editRobot) {
        //build an update statement to include only values that have selections 
        //on the form
        var parameters = [];
        var query = "UPDATE `robot` SET ";

        if (editRobot.driveMode) { 
            parameters.push(editRobot.driveMode.id); 
            query += " driveMode = (?),";
        }
        if (editRobot.driveSpeed) { 
            parameters.push(editRobot.driveSpeed.id); 
            query += " driveSpeed = (?),";
        }
        if (editRobot.driveOverPlatform) { 
            parameters.push(editRobot.driveOverPlatform.id); 
            query += " driveOverPlatform = (?),";
        }
        if (editRobot.autonomousCapability) { 
            parameters.push(editRobot.autonomousCapability.id); 
            query += " autonomousCapability = (?),";
        }
        if (editRobot.coopStep) { 
            parameters.push(editRobot.coopStep.id); 
            query += " coopStep = (?),";
        }
        if (editRobot.pickupLoc) { 
            parameters.push(editRobot.pickupLoc.id); 
            query += " pickupLoc = (?),";
        }
        if (editRobot.maxToteHeight) { 
            parameters.push(editRobot.maxToteHeight.id); 
            query += " maxToteHeight = (?),";
        }
        if (editRobot.maxContHeight) { 
            parameters.push(editRobot.maxContHeight.id); 
            query += " maxContHeight = (?),";
        }
        if (editRobot.stackContInd) { 
            parameters.push(editRobot.stackContInd); 
            query += " stackContInd = (?),";
        }
        if (editRobot.collectContStep) { 
            parameters.push(editRobot.collectContStep.id); 
            query += " collectContStep = (?),";
        }
        if (editRobot.note) { 
            parameters.push(editRobot.note); 
            query += " note = (?),";
        }

        //add the robot ID to the parameters
        parameters.push(editRobot.id);

        //remove the trailing comma from the last part of the query text
        var length = query.length;
        if (query.substr(length-1,1) == ",") {
            query = query.substring(0,length-1);
        }
        
        //add the robot ID and the match ID to the query
        query += "WHERE (id = (?))";
        
        //output the query to the console for testing purposes
        console.log("Query to update robot match record: " + query + " with robotId '" + editRobot.id + "'");
<commit_msg>Resolved Stack Container Independent bug<commit_after>/*
  Much of the code in this file and controllers.js that has to do with SQLite is
  derived from the gist created by <NAME>, here: 
  https://gist.github.com/borissondagh/29d1ed19d0df6051c56f
*/
angular.module('cat5scouting.services', [])

.factory('DBA', function($cordovaSQLite, $q, $ionicPlatform) {
    var self = this;
    
    self.query = function(query, parameters) {
        parameters = parameters || [];
        var q = $q.defer();
        
        $ionicPlatform.ready(function() {
           $cordovaSQLite.execute(db, query, parameters)
           .then(function (result) {
               q.resolve(result);
           }, function (error) {
               console.warn('Error encountered: ');
               console.warn(error);
               q.reject(error);
           });
        });
        return q.promise;
    }
    
    self.getAll = function(result) {
        var output = [];
        
        for (var i=0; i<result.rows.length; i++) {
            output.push(result.rows.item(i));
        }
        
        return output;
    }
    
    self.getById = function(result) {
        var output = null;
        if (result.rows.length > 0) {
            output = angular.copy(result.rows.item(0));
        }
        return output;
    }
    
    return self;
})
    
/******************************************************************************/
    
.factory('Team', function($cordovaSQLite, DBA) {
    var self = this;
    
    self.all = function() {
        return DBA.query("SELECT id, name, number FROM team")
            .then(function(result) {
                return DBA.getAll(result);
            })
    }
    
    self.get = function(memberId) {
        var parameters = [memberId];
        return DBA.query("SELECT id, name, number FROM team WHERE id = (?)", parameters)
            .then(function(result) {
                return DBA.getById(result);
            })
    }
    
    return self;
})
    
/******************************************************************************/

.factory('Robot', function($cordovaSQLite, DBA) {
    var self = this;
    
    self.all = function() {
        return DBA.query("SELECT id, name FROM robot")
            .then(function(result) {
                return DBA.getAll(result);
            })
    }
    
    self.getByTeam = function(teamId) {
        var parameters = [teamId];
        return DBA.query("SELECT id, name FROM robot WHERE teamId = (?)", parameters)
            .then(function(result) {
                return DBA.getAll(result);
            })
    }
    
    self.getById = function(robotId) {
        var parameters = [robotId];
        return DBA.query("SELECT `id`, `name`, `teamId`, `driveMode`, `driveSpeed`, "
                    +    "`driveOverPlatform`, `autonomousCapability`, "
                    +    "`coopStep`, `pickupLoc`, `maxToteHeight`, "
                    +    "`maxContHeight`, `stackContInd`, `collectContStep`, "
                    +    "`note` from robot "
                    +    "WHERE id = (?)", parameters)
            .then(function(result) {
                return DBA.getById(result);
            })
    }
    
    self.update = function(origRobot, editRobot) {
        //build an update statement to include only values that have selections 
        //on the form
        var parameters = [];
        var query = "UPDATE `robot` SET ";

        if (editRobot.driveMode) { 
            parameters.push(editRobot.driveMode.id); 
            query += " driveMode = (?),";
        }
        if (editRobot.driveSpeed) { 
            parameters.push(editRobot.driveSpeed.id); 
            query += " driveSpeed = (?),";
        }
        if (editRobot.driveOverPlatform) { 
            parameters.push(editRobot.driveOverPlatform.id); 
            query += " driveOverPlatform = (?),";
        }
        if (editRobot.autonomousCapability) { 
            parameters.push(editRobot.autonomousCapability.id); 
            query += " autonomousCapability = (?),";
        }
        if (editRobot.coopStep) { 
            parameters.push(editRobot.coopStep.id); 
            query += " coopStep = (?),";
        }
        if (editRobot.pickupLoc) { 
            parameters.push(editRobot.pickupLoc.id); 
            query += " pickupLoc = (?),";
        }
        if (editRobot.maxToteHeight) { 
            parameters.push(editRobot.maxToteHeight.id); 
            query += " maxToteHeight = (?),";
        }
        if (editRobot.maxContHeight) { 
            parameters.push(editRobot.maxContHeight.id); 
            query += " maxContHeight = (?),";
        }
        if (editRobot.stackContInd) { 
            parameters.push(editRobot.stackContInd.id); 
            query += " stackContInd = (?),";
        }
        if (editRobot.collectContStep) { 
            parameters.push(editRobot.collectContStep.id); 
            query += " collectContStep = (?),";
        }
        if (editRobot.note) { 
            parameters.push(editRobot.note); 
            query += " note = (?),";
        }

        //add the robot ID to the parameters
        parameters.push(editRobot.id);

        //remove the trailing comma from the last part of the query text
        var length = query.length;
        if (query.substr(length-1,1) == ",") {
            query = query.substring(0,length-1);
        }
        
        //add the robot ID and the match ID to the query
        query += "WHERE (id = (?))";
        
        //output the query to the console for testing purposes
        console.log("Query to update robot match record: " + query + " with robotId '" + editRobot.id + "'");

{'fraction_non_alphanumeric': 0.15424778761061947, 'fraction_numerical': 0.0035398230088495575, 'mean_word_length': 1.7739322533136965, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, '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': '3079550', 'n_tokens_mistral': 3296, 'n_tokens_neox': 3165, 'n_words': 650}