<commit_before>var RPi;

function RaspberryPi(model, stage3d)
{
    'use strict'
    var self = this;
    this.model = $( model );
    this.rotateX = 70;
    this.rotateY = 0;
    this.rotateZ = 40;
    this.connected = true;
    this.infoBox = $(".info-content")

    this.processes = [];

    this.traqball = new Traqball({
        stage: stage3d,
        //axis: [0.5,1,0,0.25],
        prespective: 1000
    });

    this.components = {
        ethernet:   new HWComponent("ethernet", this),
        usb:        new HWComponent("usb", this),
        cpu:        new HWComponent("cpu", this),
        ram:        new HWComponent("ram", this),
        sd:         new HWComponent("sd", this)
    };

    /*
    this.ledsControl = {

        leds: [
            $("led1"),
            $("led2"),
            $("led3"),
            $("led4"),
            $("led5")
        ],
        ledTimer: setTimer(function(){
            if()
        },10)
    }*/



    this.initSelf();
}

RaspberryPi.prototype.initSelf = function ()
{
    'use strict'
    var self = this;

    $("#default_button").click(function (){
        self.defaultPosition();
    });
    $("#logout_button").click(function(){
        sessionStorage.setItem("socketIOtoken", "")
    })


    this.socket = io("/sysStat", {
      'query': 'token=' + sessionStorage.getItem("socketIOtoken")
    });

    this.socket.on("info", function(data){
        console.log(data)
        self.processes = data.processes;
        self.update();
    });


    // TODO: make the error hadeling work
    this.socket.on("error", function(error) {
        console.log("error")
        if (error.type == "UnauthorizedError" || error.code == "invalid_token") {
            console.log("Invalid token");

        }
    });
};

RaspberryPi.prototype.defaultPosition = function ()
{
    'use strict'
    //this.traqball.disable();
    this.model.addClass( "picontainer_mover" );
    this.model.css( "-webkit-transform", "rotateX(58deg) rotateY(0deg) rotateZ(45deg)");
    this.model.css( "transform", "rotateX(58deg) rotateY(0deg) rotateZ(45deg)" );
    var self = this;
    setTimeout(function(){
        self.model.removeClass( "picontainer_mover" );
        //self.traqball.activate();
    },500);


};

RaspberryPi.prototype.hideAll = function()
{
    'use strict'
    for(var key in this.components)
    {
        var comp = this.components[key];
        if(comp.out)
        {
            comp.animateIn();
        }
    }
}

RaspberryPi.prototype.renderInfo = function(comp)
{
    if( comp == null)
    {
        this.infoBox.html("<div id='default_info_content'>Click one of the components on the model to get information about it.</div>")
    }
    else
    {
        this.infoBox.html("");
    }
}

RaspberryPi.prototype.update = function()
{
    this.renderProcList();

}

RaspberryPi.prototype.renderProcList = function()
{
    var self = this;
    var list = $("#processList > tbody");
    list.html("")
    var row = []
    var i = 0;
    for (proc in this.processes) {
        row = [];
        i = 0;

        row[i++] = "<tr>";
        row[i++] = "<td>" + this.processes[proc].pid + "</td>";
        row[i++] = "<td>" + this.processes[proc].user + "</td>";
        row[i++] = "<td>" + this.processes[proc].cpu + "</td>";
        row[i++] = "<td>" + this.processes[proc].mem + "</td>";
        row[i++] = "<td>" + this.processes[proc].vir + "</td>";
        row[i++] = "<td>" + this.processes[proc].time + "</td>";
        row[i++] = "<td>" + this.processes[proc].command + "</td>";
        row[i++] = "</tr>";

        list.append(row.join(""))
    }
}


function HWComponent( id, rpi )
{
    'use strict'
    var self = this;<commit_msg>start sort<commit_after>var RPi;

function RaspberryPi(model, stage3d)
{
    'use strict'
    var self = this;
    this.model = $( model );
    this.rotateX = 70;
    this.rotateY = 0;
    this.rotateZ = 40;
    this.connected = true;
    this.infoBox = $(".info-content")

    this.processes = [];
    this.processTable = new ProcessTable("#processList", this)

    this.traqball = new Traqball({
        stage: stage3d,
        //axis: [0.5,1,0,0.25],
        prespective: 1000
    });

    this.components = {
        ethernet:   new HWComponent("ethernet", this),
        usb:        new HWComponent("usb", this),
        cpu:        new HWComponent("cpu", this),
        ram:        new HWComponent("ram", this),
        sd:         new HWComponent("sd", this)
    };

    /*
    this.ledsControl = {

        leds: [
            $("led1"),
            $("led2"),
            $("led3"),
            $("led4"),
            $("led5")
        ],
        ledTimer: setTimer(function(){
            if()
        },10)
    }*/



    this.initSelf();
}

RaspberryPi.prototype.initSelf = function ()
{
    'use strict'
    var self = this;

    $("#default_button").click(function (){
        self.defaultPosition();
    });
    $("#logout_button").click(function(){
        sessionStorage.setItem("socketIOtoken", "")
    })


    this.socket = io("/sysStat", {
      'query': 'token=' + sessionStorage.getItem("socketIOtoken")
    });

    this.socket.on("info", function(data){
        self.processes = data.processes;
        self.update();
    });


    // TODO: make the error hadeling work
    this.socket.on("error", function(error) {
        console.log("error")
        if (error.type == "UnauthorizedError" || error.code == "invalid_token") {
            console.log("Invalid token");

        }
    });
};

RaspberryPi.prototype.defaultPosition = function ()
{
    'use strict'
    //this.traqball.disable();
    this.model.addClass( "picontainer_mover" );
    this.model.css( "-webkit-transform", "rotateX(58deg) rotateY(0deg) rotateZ(45deg)");
    this.model.css( "transform", "rotateX(58deg) rotateY(0deg) rotateZ(45deg)" );
    var self = this;
    setTimeout(function(){
        self.model.removeClass( "picontainer_mover" );
        //self.traqball.activate();
    },500);


};

RaspberryPi.prototype.hideAll = function()
{
    'use strict'
    for(var key in this.components)
    {
        var comp = this.components[key];
        if(comp.out)
        {
            comp.animateIn();
        }
    }
}

RaspberryPi.prototype.renderInfo = function(comp)
{
    if( comp == null)
    {
        this.infoBox.html("<div id='default_info_content'>Click one of the components on the model to get information about it.</div>")
    }
    else
    {
        this.infoBox.html("");
    }
}

RaspberryPi.prototype.update = function()
{
    this.processTable.renderProcList();

}


// Object representing the List of processes
function ProcessTable( id, rpi) {
    this.table = $(id);
    this.list = $(id+ " > tbody");
    this.rpi = rpi;

    this.sort = 1; // id of the element we are sorting by
    this.reverse = false; // are we sorting in reverse?
}

ProcessTable.prototype.renderProcList = function()
{
    var self = this;
    function compare(a,b)
    {
        var ret = 0

        // TODO: fix time and text sorting
        switch (self.sort){

            case 0: // PID
                if(parseInt(a.pid) < parseInt(b.pid))
                    ret = -1;
                if(parseInt(a.pid) > parseInt(b.pid))
                    ret = 1;
                break;

            case 1: // User
                if(a.user < b.user)
                    ret = -1;
                if(a.user > b.user)
                    ret = 1;
                break;

            case 2: // CPU
                if(parseFloat(a.cpu) < parseFloat(b.cpu))
                    ret = -1;
                if(parseFloat(a.cpu) > parseFloat(b.cpu))
                    ret = 1;
                break;
            case 3: // RAM
                if(parseFloat(a.ram) < parseFloat(b.ram))
                    ret = -1;
                if(parseFloat(a.ram) > parseFloat(b.ram))
                    ret = 1;
                break;

            case 4: // VIR
                if(parseFloat(a.vir) < parseFloat(b.vir))
                    ret = -1;
                if(parseFloat(a.vir) > parseFloat(b.vir))
                    ret = 1;
                break;

            case 5: // Time
                if(a.time < b.time)
                    ret = -1;
                if(a.time > b.time)
                    ret = 1;
                break;

            case 6: // Command
                if(a.command < b.command)
                    ret = -1;
                if(a.command > b.command)
                    ret = 1;
                break;
        }

        if (self.reverse) {
            ret *= -1;
        }
        return ret;
    }
    this.list.html("")
    var row = []
    var i = 0;
    this.rpi.processes.sort(compare)
    for (proc in this.rpi.processes) {
        row = [];
        i = 0;

        row[i++] = "<tr>";
        row[i++] = "<td>" +     this.rpi.processes[proc].pid    + "</td>";
        row[i++] = "<td>" +     this.rpi.processes[proc].user   + "</td>";
        row[i++] = "<td><em>" + this.rpi.processes[proc].cpu    + "</em></td>";
        row[i++] = "<td><em>" + this.rpi.processes[proc].mem    + "</em></td>";
        row[i++] = "<td>" +     this.rpi.processes[proc].vir    + "</td>";
        row[i++] = "<td>" +     this.rpi.processes[proc].time   + "</td>";
        row[i++] = "<td>" +     this.rpi.processes[proc].command + "</td>";
        row[i++] = "</tr>";

        this.list.append(row.join(""))
    }
}


function HWComponent( id, rpi )
{
    'use strict'
    var self = this;
{'fraction_non_alphanumeric': 0.16942366452428617, 'fraction_numerical': 0.010957749446844378, 'mean_word_length': 1.7568980540226546, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 52, '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': '573229', 'n_tokens_mistral': 3165, 'n_tokens_neox': 3004, 'n_words': 595}