Sha256: 4068a8b10efde5631714f429dce1b01c9e199a3b25dce40d8939b45d5839615e

Contents?: true

Size: 2 KB

Versions: 31

Compression:

Stored size: 2 KB

Contents

var RoomPlacesSimulator = function(nutella) {
    this.nutella = nutella;
    this.hotspots = [];
    this.beacons = [];
    this.distance = 0.01;
};



RoomPlacesSimulator.prototype.start = function() {
    // Assign initial location
    var hotspots = this.hotspots;
    this.beacons.forEach((function(e,i) {
        e.l = hotspots[Math.floor(Math.random()*hotspots.length)];
        e.d = this.distance -0.1 + Math.random()*0.2;
        //console.log("Initial location for " + e.b + " set to to " + e.l);
        if (e.l != 'none')
            this.publishLocation(e);
    }).bind(this));
    // Every second, send an update to the bot
    // Location of only some beacons is changed though
    this.interval = setInterval((function() {
        this.beacons.forEach((function(e,i) {
            // Change location for a small percentage
            if(Math.random()>0.93) {
                e.l = hotspots[Math.floor(Math.random()*hotspots.length)];
                e.d = this.distance -0.1 + Math.random()*0.2;
                //console.log(e.b + " moved to " + e.l);
            }
            if (e.l != 'none')
                this.publishLocation(e);
        }).bind(this));
    }).bind(this), 1000);
};


RoomPlacesSimulator.prototype.stop = function() {
    clearInterval(this.interval);
};



RoomPlacesSimulator.prototype.setHotspots = function(hotspots) {
    this.hotspots = hotspots;
    this.hotspots.push('none');
};

RoomPlacesSimulator.prototype.setBeacons = function(beacons) {
    this.beacons = [];
    beacons.forEach((function(e){
        this.beacons.push({b: e, l: 'none'});
    }).bind(this));
};

RoomPlacesSimulator.prototype.setDistance = function(distance) {
    this.distance = distance;
};


// Function to generate location update
RoomPlacesSimulator.prototype.publishLocation = function(beacon) {
    var message = {
        rid : beacon.b,
        proximity: {
            rid: beacon.l,
            distance: beacon.d
        }
    };
    this.nutella.net.publish('location/resource/update', message);
};





Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
nutella_framework-0.9.2 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.9.1 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.9.0 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.8.0 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.7.3 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.7.2 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.7.1 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.7.0 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.6.21 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.6.20 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.6.19 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.6.18 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.6.17 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.6.16 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.6.15 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.6.13 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.6.12 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.6.11 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.6.10 framework_components/room-debugger/room_places_simulator.js
nutella_framework-0.6.9 framework_components/room-debugger/room_places_simulator.js