<commit_before>'use strict';

angular.module('quimby.services', [])
    .service('$gadgets', ['$http', function ($http) {
        var commands = {};
        var locations = {};
        this.getGadgets = function(callback) {
            $http.get("/api/gadgets").success(function(data) {
                callback(data);
            }).error(function() {
                console.log("didn't get gadgets");
            });
        }
        this.getGadget = function(id, callback) {
            $http.get("/api/gadgets/" + id).success(function(data) {
                callback(data);
            }).error(function() {
                console.log("didn't get gadget");
            });
        }
        this.getDevices = function(id, callback) {
            $http.get("/api/gadgets/" +  id + "/values").success(function(data) {
                locations = data;
                callback(locations);
            }).error(function() {
              
            });
            $http.get("/api/gadgets/" +  id + "/status").success(function(statuses) {
                angular.forEach(statuses, function(value, key) {
                    if (value.info.direction == "output") {
                        commands[key] = {on: value.info.on, off: value.info.off};
                    }
                });
            });
        }
        this.send =  function(location, name, callback) {
            var val = locations[location][name].value;
            var onoff = val ? "off":"on";
            var command = commands[location + " " + name][onoff];
            callback(command);
        }
        this.update = function(msg) {
            
        }
    }])
    .factory('$sockets', ['$location', '$http', '$timeout', '$routeParams', function($location, $http, $timeout, $routeParams) {
        var ws;
        var outWs;
        var statusPromise;
        var host;
        
        function getWebsocket() {
            var prot = "wss";
            if ($location.protocol() == "http") {
                prot = "ws";
            }
            var url = prot + "://" + $location.host() + ":" + $location.port() + "/api/gadgets/" + $routeParams.name + "/websocket";
            ws = new WebSocket(url);
            return ws;
        }

        function doConnect(callback) {
            if(ws != undefined) {
                ws.close();
                ws = null;
            }
            ws = getWebsocket(host);
            ws.onopen = function() {
            };
            ws.onerror = function() {
            };
            ws.onmessage = function(message) {
                message = JSON.parse(message.data);
                callback(message);
            };
        }
        
        return {
            connect: function(cb) {
                doConnect(cb);
            },
            send: function(command) {
                var msg = JSON.stringify({
                    sender: "quimby",
                    type: "command",
                    body: command,
                });
                ws.send(msg);
            },
            close: function() {
                if (ws != undefined) {
                    ws.close();
                }
            }
        }
    }]);
<commit_msg>fixed websocket url<commit_after>'use strict';

angular.module('quimby.services', [])
    .service('$gadgets', ['$http', function ($http) {
        var commands = {};
        var locations = {};
        this.getGadgets = function(callback) {
            $http.get("/api/gadgets").success(function(data) {
                callback(data);
            }).error(function() {
                console.log("didn't get gadgets");
            });
        }
        this.getGadget = function(id, callback) {
            $http.get("/api/gadgets/" + id).success(function(data) {
                callback(data);
            }).error(function() {
                console.log("didn't get gadget");
            });
        }
        this.getDevices = function(id, callback) {
            $http.get("/api/gadgets/" +  id + "/values").success(function(data) {
                locations = data;
                callback(locations);
            }).error(function() {
              
            });
            $http.get("/api/gadgets/" +  id + "/status").success(function(statuses) {
                angular.forEach(statuses, function(value, key) {
                    if (value.info.direction == "output") {
                        commands[key] = {on: value.info.on, off: value.info.off};
                    }
                });
            });
        }
        this.send =  function(location, name, callback) {
            var val = locations[location][name].value;
            var onoff = val ? "off":"on";
            var command = commands[location + " " + name][onoff];
            callback(command);
        }
        this.update = function(msg) {
            
        }
    }])
    .factory('$sockets', ['$location', '$http', '$timeout', '$routeParams', function($location, $http, $timeout, $routeParams) {
        var ws;
        var outWs;
        var statusPromise;
        var host;
        
        function getWebsocket() {
            var prot = "wss";
            if ($location.protocol() == "http") {
                prot = "ws";
            }
            var url = prot + "://" + $location.host() + ":" + $location.port() + "/api/gadgets/" + $routeParams.id + "/websocket";
            ws = new WebSocket(url);
            return ws;
        }

        function doConnect(callback) {
            if(ws != undefined) {
                ws.close();
                ws = null;
            }
            ws = getWebsocket(host);
            ws.onopen = function() {
            };
            ws.onerror = function() {
            };
            ws.onmessage = function(message) {
                message = JSON.parse(message.data);
                callback(message);
            };
        }
        
        return {
            connect: function(cb) {
                doConnect(cb);
            },
            send: function(command) {
                var msg = JSON.stringify({
                    sender: "quimby",
                    type: "command",
                    body: command,
                });
                ws.send(msg);
            },
            close: function() {
                if (ws != undefined) {
                    ws.close();
                }
            }
        }
    }]);

{'fraction_non_alphanumeric': 0.14597629444791016, 'fraction_numerical': 0.0, 'mean_word_length': 1.2259632072197153, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, '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': '6695078', 'n_tokens_mistral': 1746, 'n_tokens_neox': 1659, 'n_words': 304}