Modified: sis/sandbox/gsoc2013/crimgeoprofile/js/Icon.Label.Default.js
URL: 
http://svn.apache.org/viewvc/sis/sandbox/gsoc2013/crimgeoprofile/js/Icon.Label.Default.js?rev=1524712&r1=1524711&r2=1524712&view=diff
==============================================================================
--- sis/sandbox/gsoc2013/crimgeoprofile/js/Icon.Label.Default.js (original)
+++ sis/sandbox/gsoc2013/crimgeoprofile/js/Icon.Label.Default.js Thu Sep 19 
12:31:12 2013
@@ -1,29 +1,29 @@
-L.Icon.Label.Default = L.Icon.Label.extend({
-       options: {
-               //This is the top left position of the label within the 
wrapper. By default it will display at the right
-               //middle position of the default icon. x = width of icon + 
padding
-               //If the icon height is greater than the label height you will 
need to set the y value.
-               //y = (icon height - label height) / 2
-               labelAnchor: new L.Point(29, 8),
-               
-               //This is the position of the wrapper div. Use this to position 
icon + label relative to the Lat/Lng.
-               //By default the point of the default icon is anchor
-               wrapperAnchor: new L.Point(13, 41),
-               
-               //This is now the top left position of the icon within the 
wrapper.
-               //If the label height is greater than the icon you will need to 
set the y value.
-               //y = (label height - icon height) / 2
-               iconAnchor: new L.Point(0, 0),
-               
-               //label's text component, if this is null the element will not 
be created
-               labelText: null,
-               
-               /* From L.Icon.Default */
-               iconUrl: L.Icon.Default.imagePath + '/marker-icon.png',
-               iconSize: new L.Point(25, 41),
-               popupAnchor: new L.Point(0, -33),
-
-               shadowUrl: L.Icon.Default.imagePath + '/marker-shadow.png',
-               shadowSize: new L.Point(41, 41)
-       }
+L.Icon.Label.Default = L.Icon.Label.extend({
+       options: {
+               //This is the top left position of the label within the 
wrapper. By default it will display at the right
+               //middle position of the default icon. x = width of icon + 
padding
+               //If the icon height is greater than the label height you will 
need to set the y value.
+               //y = (icon height - label height) / 2
+               labelAnchor: new L.Point(29, 8),
+               
+               //This is the position of the wrapper div. Use this to position 
icon + label relative to the Lat/Lng.
+               //By default the point of the default icon is anchor
+               wrapperAnchor: new L.Point(13, 41),
+               
+               //This is now the top left position of the icon within the 
wrapper.
+               //If the label height is greater than the icon you will need to 
set the y value.
+               //y = (label height - icon height) / 2
+               iconAnchor: new L.Point(0, 0),
+               
+               //label's text component, if this is null the element will not 
be created
+               labelText: null,
+               
+               /* From L.Icon.Default */
+               iconUrl: L.Icon.Default.imagePath + '/marker-icon.png',
+               iconSize: new L.Point(25, 41),
+               popupAnchor: new L.Point(0, -33),
+
+               shadowUrl: L.Icon.Default.imagePath + '/marker-shadow.png',
+               shadowSize: new L.Point(41, 41)
+       }
 });
\ No newline at end of file

Modified: sis/sandbox/gsoc2013/crimgeoprofile/js/Icon.Label.js
URL: 
http://svn.apache.org/viewvc/sis/sandbox/gsoc2013/crimgeoprofile/js/Icon.Label.js?rev=1524712&r1=1524711&r2=1524712&view=diff
==============================================================================
--- sis/sandbox/gsoc2013/crimgeoprofile/js/Icon.Label.js (original)
+++ sis/sandbox/gsoc2013/crimgeoprofile/js/Icon.Label.js Thu Sep 19 12:31:12 
2013
@@ -1,111 +1,111 @@
-L.Icon.Label = L.Icon.extend({
-       options: {
-               /*
-               labelAnchor: (Point) (top left position of the label within the 
wrapper, default is right)
-               wrapperAnchor: (Point) (position of icon and label relative to 
Lat/Lng)
-               iconAnchor: (Point) (top left position of icon within wrapper)
-               labelText: (String) (label's text component, if this is null 
the element will not be created)
-               */
-               /* Icon options:
-               iconUrl: (String) (required)
-               iconSize: (Point) (can be set through CSS)
-               iconAnchor: (Point) (centered by default if size is specified, 
can be set in CSS with negative margins)
-               popupAnchor: (Point) (if not specified, popup opens in the 
anchor point)
-               shadowUrl: (Point) (no shadow by default)
-               shadowSize: (Point)
-               */
-               labelClassName: ''
-       },
-       
-       initialize: function (options) {
-               L.Util.setOptions(this, options);
-               L.Icon.prototype.initialize.call(this, this.options);
-       },
-
-       setLabelAsHidden: function () {
-               this._labelHidden = true;
-       },
-
-       createIcon: function () {
-               return 
this._createLabel(L.Icon.prototype.createIcon.call(this));
-       },
-       
-       createShadow: function () {
-               if (!this.options.shadowUrl) {
-                       return null;
-               }
-               var shadow = L.Icon.prototype.createShadow.call(this);
-               //need to reposition the shadow
-               if (shadow) {
-                       shadow.style.marginLeft = 
(-this.options.wrapperAnchor.x) + 'px';
-                       shadow.style.marginTop = 
(-this.options.wrapperAnchor.y) + 'px';
-               }
-               return shadow;
-       },
-
-       updateLabel: function (icon, text) {
-               if (icon.nodeName.toUpperCase() === 'DIV') {
-                       icon.childNodes[1].innerHTML = text;
-                       
-                       this.options.labelText = text;
-               }
-       },
-
-       showLabel: function (icon) {
-               if (!this._labelTextIsSet()) {
-                       return;
-               }
-
-               icon.childNodes[1].style.display = 'block';
-       },
-
-       hideLabel: function (icon) {
-               if (!this._labelTextIsSet()) {
-                       return;
-               }
-
-               icon.childNodes[1].style.display = 'none';
-       },
-
-       _createLabel: function (img) {
-               if (!this._labelTextIsSet()) {
-                       return img;
-               }
-
-               var wrapper = document.createElement('div'),
-                       label = document.createElement('span');
-
-               // set up wrapper anchor
-               wrapper.style.marginLeft = (-this.options.wrapperAnchor.x) + 
'px';
-               wrapper.style.marginTop = (-this.options.wrapperAnchor.y) + 
'px';
-
-               wrapper.className = 'leaflet-marker-icon-wrapper 
leaflet-zoom-animated';
-
-               // set up label
-               label.className = 'leaflet-marker-iconlabel ' + 
this.options.labelClassName;
-
-               label.innerHTML = this.options.labelText;
-
-               label.style.marginLeft = this.options.labelAnchor.x + 'px';
-               label.style.marginTop = this.options.labelAnchor.y + 'px';
-
-               if (this._labelHidden) {
-                       label.style.display = 'none';
-                       // Ensure that the pointer cursor shows
-                       img.style.cursor = 'pointer';
-               }
-               
-               //reset icons margins (as super makes them -ve)
-               img.style.marginLeft = this.options.iconAnchor.x + 'px';
-               img.style.marginTop = this.options.iconAnchor.y + 'px';
-               
-               wrapper.appendChild(img);
-               wrapper.appendChild(label);
-
-               return wrapper;
-       },
-       
-       _labelTextIsSet: function () {
-               return typeof this.options.labelText !== 'undefined' && 
this.options.labelText !== null;
-       }
+L.Icon.Label = L.Icon.extend({
+       options: {
+               /*
+               labelAnchor: (Point) (top left position of the label within the 
wrapper, default is right)
+               wrapperAnchor: (Point) (position of icon and label relative to 
Lat/Lng)
+               iconAnchor: (Point) (top left position of icon within wrapper)
+               labelText: (String) (label's text component, if this is null 
the element will not be created)
+               */
+               /* Icon options:
+               iconUrl: (String) (required)
+               iconSize: (Point) (can be set through CSS)
+               iconAnchor: (Point) (centered by default if size is specified, 
can be set in CSS with negative margins)
+               popupAnchor: (Point) (if not specified, popup opens in the 
anchor point)
+               shadowUrl: (Point) (no shadow by default)
+               shadowSize: (Point)
+               */
+               labelClassName: ''
+       },
+       
+       initialize: function (options) {
+               L.Util.setOptions(this, options);
+               L.Icon.prototype.initialize.call(this, this.options);
+       },
+
+       setLabelAsHidden: function () {
+               this._labelHidden = true;
+       },
+
+       createIcon: function () {
+               return 
this._createLabel(L.Icon.prototype.createIcon.call(this));
+       },
+       
+       createShadow: function () {
+               if (!this.options.shadowUrl) {
+                       return null;
+               }
+               var shadow = L.Icon.prototype.createShadow.call(this);
+               //need to reposition the shadow
+               if (shadow) {
+                       shadow.style.marginLeft = 
(-this.options.wrapperAnchor.x) + 'px';
+                       shadow.style.marginTop = 
(-this.options.wrapperAnchor.y) + 'px';
+               }
+               return shadow;
+       },
+
+       updateLabel: function (icon, text) {
+               if (icon.nodeName.toUpperCase() === 'DIV') {
+                       icon.childNodes[1].innerHTML = text;
+                       
+                       this.options.labelText = text;
+               }
+       },
+
+       showLabel: function (icon) {
+               if (!this._labelTextIsSet()) {
+                       return;
+               }
+
+               icon.childNodes[1].style.display = 'block';
+       },
+
+       hideLabel: function (icon) {
+               if (!this._labelTextIsSet()) {
+                       return;
+               }
+
+               icon.childNodes[1].style.display = 'none';
+       },
+
+       _createLabel: function (img) {
+               if (!this._labelTextIsSet()) {
+                       return img;
+               }
+
+               var wrapper = document.createElement('div'),
+                       label = document.createElement('span');
+
+               // set up wrapper anchor
+               wrapper.style.marginLeft = (-this.options.wrapperAnchor.x) + 
'px';
+               wrapper.style.marginTop = (-this.options.wrapperAnchor.y) + 
'px';
+
+               wrapper.className = 'leaflet-marker-icon-wrapper 
leaflet-zoom-animated';
+
+               // set up label
+               label.className = 'leaflet-marker-iconlabel ' + 
this.options.labelClassName;
+
+               label.innerHTML = this.options.labelText;
+
+               label.style.marginLeft = this.options.labelAnchor.x + 'px';
+               label.style.marginTop = this.options.labelAnchor.y + 'px';
+
+               if (this._labelHidden) {
+                       label.style.display = 'none';
+                       // Ensure that the pointer cursor shows
+                       img.style.cursor = 'pointer';
+               }
+               
+               //reset icons margins (as super makes them -ve)
+               img.style.marginLeft = this.options.iconAnchor.x + 'px';
+               img.style.marginTop = this.options.iconAnchor.y + 'px';
+               
+               wrapper.appendChild(img);
+               wrapper.appendChild(label);
+
+               return wrapper;
+       },
+       
+       _labelTextIsSet: function () {
+               return typeof this.options.labelText !== 'undefined' && 
this.options.labelText !== null;
+       }
 });
\ No newline at end of file

Modified: sis/sandbox/gsoc2013/crimgeoprofile/js/Marker.Label.js
URL: 
http://svn.apache.org/viewvc/sis/sandbox/gsoc2013/crimgeoprofile/js/Marker.Label.js?rev=1524712&r1=1524711&r2=1524712&view=diff
==============================================================================
--- sis/sandbox/gsoc2013/crimgeoprofile/js/Marker.Label.js (original)
+++ sis/sandbox/gsoc2013/crimgeoprofile/js/Marker.Label.js Thu Sep 19 12:31:12 
2013
@@ -1,48 +1,48 @@
-L.Marker.Label = L.Marker.extend({
-       updateLabel: function (text) {
-               this.options.icon.updateLabel(this._icon, text);
-       },
-
-       _initIcon: function () {
-               if (!(this.options.icon instanceof L.Icon.Label)) {
-                       throw new Error('Icon must be an instance of 
L.Icon.Label.');
-               }
-
-               // Ensure that the label is hidden to begin with
-               if (this.options.revealing) {
-                       this.options.icon.setLabelAsHidden();
-               }
-
-               L.Marker.prototype._initIcon.call(this);
-       },
-
-       _removeIcon: function () {
-               if (this.options.revealing) {
-                       L.DomEvent
-                               .off(this._icon, 'mouseover', this._showLabel)
-                               .off(this._icon, 'mouseout', this._hideLabel);
-               }
-
-               L.Marker.prototype._removeIcon.call(this);
-       },
-
-       _initInteraction: function () {
-               L.Marker.prototype._initInteraction.call(this);
-
-               if (!this.options.revealing) {
-                       return;
-               }
-
-               L.DomEvent
-                       .on(this._icon, 'mouseover', this._showLabel, this)
-                       .on(this._icon, 'mouseout', this._hideLabel, this);
-       },
-
-       _showLabel: function () {
-               this.options.icon.showLabel(this._icon);
-       },
-
-       _hideLabel: function () {
-               this.options.icon.hideLabel(this._icon);
-       }
+L.Marker.Label = L.Marker.extend({
+       updateLabel: function (text) {
+               this.options.icon.updateLabel(this._icon, text);
+       },
+
+       _initIcon: function () {
+               if (!(this.options.icon instanceof L.Icon.Label)) {
+                       throw new Error('Icon must be an instance of 
L.Icon.Label.');
+               }
+
+               // Ensure that the label is hidden to begin with
+               if (this.options.revealing) {
+                       this.options.icon.setLabelAsHidden();
+               }
+
+               L.Marker.prototype._initIcon.call(this);
+       },
+
+       _removeIcon: function () {
+               if (this.options.revealing) {
+                       L.DomEvent
+                               .off(this._icon, 'mouseover', this._showLabel)
+                               .off(this._icon, 'mouseout', this._hideLabel);
+               }
+
+               L.Marker.prototype._removeIcon.call(this);
+       },
+
+       _initInteraction: function () {
+               L.Marker.prototype._initInteraction.call(this);
+
+               if (!this.options.revealing) {
+                       return;
+               }
+
+               L.DomEvent
+                       .on(this._icon, 'mouseover', this._showLabel, this)
+                       .on(this._icon, 'mouseout', this._hideLabel, this);
+       },
+
+       _showLabel: function () {
+               this.options.icon.showLabel(this._icon);
+       },
+
+       _hideLabel: function () {
+               this.options.icon.hideLabel(this._icon);
+       }
 });
\ No newline at end of file

Modified: sis/sandbox/gsoc2013/crimgeoprofile/js/functions.js
URL: 
http://svn.apache.org/viewvc/sis/sandbox/gsoc2013/crimgeoprofile/js/functions.js?rev=1524712&r1=1524711&r2=1524712&view=diff
==============================================================================
--- sis/sandbox/gsoc2013/crimgeoprofile/js/functions.js (original)
+++ sis/sandbox/gsoc2013/crimgeoprofile/js/functions.js Thu Sep 19 12:31:12 2013
@@ -1,49 +1,45 @@
 function init(){       
        findroutes = 0;
-       first = 0;
-       first_transit = 0;
-       data_obj = new Object();
-       data_obj.home=new Array();
-       data_obj.office=new Array();
-       data_obj.hangout=new Array();   
-       data_obj.locations=new Array(); 
-       data_obj.transit = new Array(100);
+       first = 0;      
+       data_obj = new Object();                
+       data_obj.locations=new Array();         
        data_obj.homeid = 0;    
        data_obj.officeid = 0;  
        data_obj.lunchaid = 0;  
        data_obj.lunchbid = 0;
        data_obj.barid = 0;
        data_obj.mallid = 0;            
-       data_obj.sch_sl = new Array(100);
-       data_obj.sch_el = new Array(100);
-       data_obj.sch_t = new Array(100);
-       data_obj.sch_type = new Array(100);
+       data_obj.sch_sl = new Array();
+       data_obj.sch_el = new Array();
+       data_obj.sch_t = new Array();
+       data_obj.sch_type = new Array();
        data_obj.sch_len = 0;
        data_obj.loc_num = 0;
        data_obj.sch_init = 0;
        
+       data_obj.crime_spot = new Array();
+       crime_spot_markers = new Array();
+       data_obj.crime_reward = new Array();
+       data_obj.crime_risk = new Array();
+       data_obj.crime_freq = new Array();
+       data_obj.pp = new Array();  //prob that patrolling police is present in 
vicinity
+       data_obj.gd = new Array();  //prob that guardian is away
+       data_obj.num_crime_spot = 0;
+       data_obj.num_ajax = 0;
+       data_obj.num_ajax_counter = 0;
+       
        data_obj.routes=[];
        
-       for(var i=0; i<100; i++){
-               data_obj.transit[i] = new Array(100);
-               for(var j=0; j<100; j++){
-                       data_obj.transit[i][j]="";
-               }
-       }
-       data_obj.transit_pts = new Array(100);
-       for(var i=0; i<100; i++){
-               data_obj.transit_pts[i] = new Array(100);
-               for(var j=0; j<100; j++){
-                       data_obj.transit_pts[i][j]=null;
-               }
-       }
-       data_obj.num_home=0;
-       data_obj.num_office=0;
-       data_obj.num_hangout=0;
        data_obj.num_locations=0;
        data_obj.city_lat = 51.505, 21;
        data_obj.city_lon = 21;
        data_obj.zoom=1;
+       
+       data_obj.risk_avoidance = Math.random();
+       data_obj.profit_seeking = Math.random();
+       data_obj.maxprofitpossible = 100;
+       data_obj.maxriskpresent = 100;
+       
 }
 
 function markHome(e){  
@@ -103,15 +99,24 @@ function markMall(e){
        data_obj.loc_num++;
 }
 
-function markTransit(e){       
-       var label = "TP:"+starttp+endtp;
-       var marker=L.marker(e.latlng, { icon: new L.Icon.Label.Default({ 
labelText: label }) }).addTo(map);     
-       data_obj.transit_pts[starttp-1][endtp-1] = e.latlng;    
-       data_obj.transit[starttp-1][endtp-1]+=e.latlng.lat+","+e.latlng.lng+",";
-       data_obj.transit[endtp-1][starttp-1]+=e.latlng.lat+","+e.latlng.lng+",";
-       map.off('click', markTransit);          
+function markCrimeSpot(e){     
+       var rd = Math.random()*data_obj.maxprofitpossible;
+       var rs = Math.random()*data_obj.maxriskpresent;
+       var pp = Math.random();
+       var gd = Math.random();
+       data_obj.crime_freq[data_obj.num_crime_spot]=0;
+       var marker=L.marker(e.latlng, { icon: new L.Icon.Label.Default({ 
labelText: "CS-" + (data_obj.num_crime_spot+1) + " ["+Math.floor(rd)+", 
"+Math.floor(rs)+", "+Math.floor(pp*100)/100+", "+Math.floor(gd*100)/100+", 
0]"}) }).addTo(map);       
+       crime_spot_markers[data_obj.num_crime_spot]=marker;
+       data_obj.crime_risk[data_obj.num_crime_spot]=rs;
+       data_obj.crime_reward[data_obj.num_crime_spot]=rd;
+       data_obj.pp[data_obj.num_crime_spot] = pp;
+       data_obj.gd[data_obj.num_crime_spot] = gd;
+       data_obj.crime_spot[data_obj.num_crime_spot]=e.latlng;  
+       data_obj.num_crime_spot++;
+       map.off('click', markCrimeSpot);        
 }
 
+
 function addScript(url) {
        var script = document.createElement('script');
        script.type="text/javascript";
@@ -178,14 +183,6 @@ function showRoutes(){
                data_obj.dist3[i] = new Array(data_obj.num_locations);
        }
        
-       for(var i=0; i<data_obj.num_locations; i++){
-               for(var j=0 ;j < data_obj.num_locations; j++){
-                       if(data_obj.transit[i][j]!=""){
-                               
data_obj.transit[i][j]='['+data_obj.transit[i][j].substring(0,data_obj.transit[i][j].length-1)+'],';
-                       }
-               }
-       }
-       
        index=0;
        var idx1=0;
        var idx2=0;
@@ -217,7 +214,7 @@ function showRoutes(){
                                "route.bringToFront();"+*/
                        "}";            
                        addFunc(tmp);                   
-                       
addScript('http://routes.cloudmade.com/81aa79a9504e4430a8a32f491ef96f07/api/0.3/'
 + data_obj.locations[i].lat + ',' + data_obj.locations[i].lng + ',' + 
data_obj.transit[i][j] + data_obj.locations[j].lat + ',' + 
data_obj.locations[j].lng + '/car/shortest.js?callback=getRoute'+i+j+'1');   
+                       
addScript('http://routes.cloudmade.com/81aa79a9504e4430a8a32f491ef96f07/api/0.3/'
 + data_obj.locations[i].lat + ',' + data_obj.locations[i].lng + ',' + 
data_obj.locations[j].lat + ',' + data_obj.locations[j].lng + 
'/car/shortest.js?callback=getRoute'+i+j+'1');    
                        
                        //route2
                        tmp = "function getRoute"+i+j+"2(response){"+
@@ -243,7 +240,7 @@ function showRoutes(){
                                "route.bringToFront();"+        */              
                        "}";            
                        addFunc(tmp);
-                       
addScript('http://routes.cloudmade.com/81aa79a9504e4430a8a32f491ef96f07/api/0.3/'
 + data_obj.locations[i].lat + ',' + data_obj.locations[i].lng + ',' + 
data_obj.transit[i][j] + data_obj.locations[j].lat + ',' + 
data_obj.locations[j].lng + '/foot.js?callback=getRoute'+i+j+'2');
+                       
addScript('http://routes.cloudmade.com/81aa79a9504e4430a8a32f491ef96f07/api/0.3/'
 + data_obj.locations[i].lat + ',' + data_obj.locations[i].lng + ',' + 
data_obj.locations[j].lat + ',' + data_obj.locations[j].lng + 
'/foot.js?callback=getRoute'+i+j+'2');
                        
                        //route3
                        if(i == data_obj.num_locations-2 && j == 
data_obj.num_locations-1){
@@ -299,7 +296,7 @@ function showRoutes(){
                        "}";                    
                        }               
                        addFunc(tmp);
-                       
addScript('http://routes.cloudmade.com/81aa79a9504e4430a8a32f491ef96f07/api/0.3/'
 + data_obj.locations[i].lat + ',' + data_obj.locations[i].lng + ',' + 
data_obj.transit[i][j] + data_obj.locations[j].lat + ',' + 
data_obj.locations[j].lng + '/bicycle.js?callback=getRoute'+i+j+'3');           
             
+                       
addScript('http://routes.cloudmade.com/81aa79a9504e4430a8a32f491ef96f07/api/0.3/'
 + data_obj.locations[i].lat + ',' + data_obj.locations[i].lng + ','  + 
data_obj.locations[j].lat + ',' + data_obj.locations[j].lng + 
'/bicycle.js?callback=getRoute'+i+j+'3');                        
                //      
console.log('http://routes.cloudmade.com/81aa79a9504e4430a8a32f491ef96f07/api/0.3/'
 + data_obj.locations[i].lat + ',' + data_obj.locations[i].lng + ',' + 
data_obj.transit[i][j] + data_obj.locations[j].lat + ',' + 
data_obj.locations[j].lng + '/bicycle.js?callback=getRoute'+i+j+'3');
                }
        }       
@@ -318,16 +315,15 @@ function clearMap(){ 
        }
  }
 
-function simulateBeeline(start, end, time, last){      
+function simulateBeeline(start, end, time, last, rob){ 
        var nump = 0;
        if(time >= data_obj.time3[start][end])nump=3;
        else if(time >= data_obj.time2[start][end])nump=2;
-       else if(time >= data_obj.time1[start][end])nump=1;
-       
-       
+       else if(time >= data_obj.time1[start][end])nump=1;      
        var num = Math.floor((Math.random()*nump)+1);
-
        if(num == 1){
+               var ar =data_obj.path1[start][end];
+               
                var route= new L.Polyline(data_obj.path1[start][end], {
                        weight: 5,
                        opacity: 0.2,
@@ -335,6 +331,7 @@ function simulateBeeline(start, end, tim
                        smoothFactor: 1
                }).addTo(map);
                route.bringToFront();
+               markVisited(data_obj.path1[start][end], rob);
                data_obj.routes.push(data_obj.path1[start][end]);
        }
        else if(num ==2){
@@ -345,6 +342,7 @@ function simulateBeeline(start, end, tim
                        smoothFactor: 1
                }).addTo(map);
                route.bringToFront();
+               markVisited(data_obj.path1[start][end], rob);
                data_obj.routes.push(data_obj.path2[start][end]);
        }
        else if(num ==3){
@@ -355,11 +353,12 @@ function simulateBeeline(start, end, tim
                        smoothFactor: 1
                }).addTo(map);
                route.bringToFront();
+               markVisited(data_obj.path1[start][end], rob);
                data_obj.routes.push(data_obj.path3[start][end]);
        }       
 }
 
-function simulateRandom(start, end, time,last ){
+function simulateRandom(start, end, time,last, rob ){
        var start_lat = data_obj.locations[start].lat;
        var start_lon = data_obj.locations[start].lng;
        var end_lat = data_obj.locations[end].lat;
@@ -374,11 +373,9 @@ function simulateRandom(start, end, time
                        end_lat : end_lat ,
                        end_lon : end_lon ,
                        time : time                             
-               },
-               beforeSend: function(){
-           
if(last==1)$("#loading").dialog('open').html("<p>Simulating...</p>");
-        },
+               },              
                success: function(data){        
+                        ajaxComplete();
                        var rand_path = data;                   
                        var pt, pts = [];
                        for (var i=0; i<rand_path.route_geometry.length; i++){  
                                
@@ -393,14 +390,14 @@ function simulateRandom(start, end, time
                                smoothFactor: 1
                        }).addTo(map);
                        route.bringToFront();
-                       if(last==1)$("#loading").dialog('close');
+                       markVisited(pts, rob);                          
                }
        });     
 
 
 }
 
-function simulateHybrid(start , end, time, last){              
+function simulateHybrid(start , end, time, last, rob){         
        var start_lat = data_obj.locations[start].lat;
        var start_lon = data_obj.locations[start].lng;
        var end_lat = data_obj.locations[end].lat;
@@ -415,11 +412,9 @@ function simulateHybrid(start , end, tim
                        end_lat : end_lat ,
                        end_lon : end_lon ,
                        time : time                             
-               },
-               beforeSend: function(){
-           
if(last==1)$("#loading").dialog('open').html("<p>Simulating...</p>");
-        },
-         success: function(data){      
+               },              
+         success: function(data){
+                       ajaxComplete(); 
                        var obj = data;                                 
                        var pt, pts = [];
                        for (var i=0; i<obj.length; i++){                       
                
@@ -434,11 +429,104 @@ function simulateHybrid(start , end, tim
                                smoothFactor: 1
                        }).addTo(map);
                        route.bringToFront();
-                       if(last==1)$("#loading").dialog('close');
+                       markVisited(pts, rob);
                }
        });
 }
 
+function markVisited(points, rob){
+       var visited = new Array(data_obj.num_crime_spot);
+       for(var i=0; i<data_obj.num_crime_spot; i++){
+               visited[i]=0;
+       }
+       for(var i=1; i<points.length; i++){
+               for(var j=0; j<data_obj.num_crime_spot; j++){   
+                       if(visited[j] == 1)continue;
+                       if(liesWithin(data_obj.crime_spot[j], points[i-1], 
points[i]) == true){
+                               visited[j]=1;
+                               data_obj.crime_risk[j] +=  
data_obj.maxriskpresent*0.02;                
+                               if(rob == 1){
+                                       var risk = Math.random();
+                                       var profit = Math.random();
+                                       var ppp = Math.random();
+                                       var gw = Math.random();
+                                       if(ppp > data_obj.pp[j] ){
+                                               var rsk = 
data_obj.crime_risk[j];
+                                               if(gw < data_obj.gd[j]){
+                                                       rsk = rsk/2;
+                                               }
+                                               if(risk > 
(data_obj.risk_avoidance*rsk)/data_obj.maxriskpresent){
+                                                       if(profit < 
(data_obj.profit_seeking*data_obj.crime_reward[j])/data_obj.maxprofitpossible){
+                                                               
data_obj.crime_freq[j]++;
+                                                       }
+                                               }       
+                                       }
+                               }
+                                                       
+                       }
+               }
+               
+       }
+}
+
+function liesWithin(c , a , b){        
+       var x1 = 0;
+       var y1 = 0;
+       var x2 = 0;
+       var y2 = 0;     
+       if(a.lng < b.lng){
+               x1 = a.lat;
+               y1 = a.lng;
+               x2 = b.lat;
+               y2 = b.lng;
+       }
+       else if(a.lng > b.lng){
+               x1 = b.lat;
+               y1 = b.lng;
+               x2 = a.lat;
+               y2 = a.lng;
+       }
+       else if(a.lng = b.lng){
+               if(a.lat < b.lat){
+                       x1 = a.lat;
+                       y1 = a.lng;
+                       x2 = b.lat;
+                       y2 = b.lng;
+               }
+               else{
+                       x1 = b.lat;
+                       y1 = b.lng;
+                       x2 = a.lat;
+                       y2 = a.lng;     
+               }
+       }
+       var theta=0;
+       if(x1==x2){
+               theta = Math.PI/2;
+       }
+       else{
+               theta = Math.atan((y2-y1)/(x2-x1));
+       }
+       
+       var sw_x = x1 - 1000*Math.sin(theta)/1852/60;
+       var sw_y = y1 + 1000*Math.cos(theta)/1852/60;
+       
+       var ne_x = x2 + 1000*Math.sin(theta)/1852/60;
+       var ne_y = y2 - 1000*Math.cos(theta)/1852/60;
+       //console.log(sw_x, sw_y, ne_x, ne_y);
+       
+       var southWest = new L.LatLng(sw_x, sw_y),
+    northEast = new L.LatLng(ne_x, ne_y),      
+    bounds = new L.LatLngBounds(southWest, northEast);
+       
+       //var rect = L.rectangle(bounds, {color: 'yellow', opacity: 0.01, 
weight: 0.01}).addTo(map);
+       //console.log(c, bounds.contains(c));
+       return bounds.contains(c);
+}
+
+
+
+
 // to display saved data
 function display(){
 //     window.location.href = window.location.pathname;
@@ -460,6 +548,16 @@ function display(){
                }).addTo(map);  
                route.bringToFront();
        }               
+       //adding crime spots
+       for(var i=0; i<data_obj.crime_spot.length; i++){
+               var risk = data_obj.crime_risk[i];
+               var reward = data_obj.crime_reward[i];
+               var freq = data_obj.crime_freq[i];
+               var pp = data_obj.pp[i];
+               var gd = data_obj.gd[i];                
+               var marker=L.marker(data_obj.crime_spot[i], { icon: new 
L.Icon.Label.Default({ labelText: "CS-" + (i+1) + " ["+Math.floor(reward)+", 
"+Math.floor(risk)+", "+Math.floor(pp*100)/100+", "+Math.floor(gd*100)/100+", 
"+freq+"]"}) }).addTo(map);
+               crime_spot_markers[i]=marker;
+       }
        map.setView([data_obj.city_lat, data_obj.city_lon], data_obj.zoom);
 }
 
@@ -641,7 +739,7 @@ function initSchedule(){
        
        data_obj.sch_sl[23] = data_obj.homeid;
        data_obj.sch_el[23] = data_obj.barid;
-       data_obj.sch_t[23] = 180;
+       data_obj.sch_t[23] = 90;
        data_obj.sch_type[23] = 2;
        
        data_obj.sch_sl[24] = data_obj.barid;
@@ -652,12 +750,12 @@ function initSchedule(){
        //Sunday
        data_obj.sch_sl[25] = data_obj.homeid;
        data_obj.sch_el[25] = data_obj.mallid;
-       data_obj.sch_t[25] = 90;
+       data_obj.sch_t[25] = 60;
        data_obj.sch_type[25] = 2;
        
        data_obj.sch_sl[26] = data_obj.mallid;
        data_obj.sch_el[26] = data_obj.barid;
-       data_obj.sch_t[26] = 240;
+       data_obj.sch_t[26] = 150;
        data_obj.sch_type[26] = 2;
        
        data_obj.sch_sl[27] = data_obj.barid;
@@ -666,23 +764,77 @@ function initSchedule(){
        data_obj.sch_type[27] = 3;
        
        data_obj.sch_len = 28;
+       data_obj.num_ajax= 12;
 }
 
 function simulateRoutineActivity(){
+       $("#loading").dialog('open').html("<p>Simulating First Week where no 
crime is committed</p>");
+       //week 1
+       data_obj.num_ajax_counter=0;            
        for(var i=0; i<data_obj.sch_len; i++){
                var start = data_obj.sch_sl[i];
                var end = data_obj.sch_el[i];
                var time = data_obj.sch_t[i];
                var type = data_obj.sch_type[i];
                if(i == data_obj.sch_len-1){
-                       if(type == 1)simulateBeeline(start, end, time,1);
-                       else if(type == 2)simulateRandom(start, end, time,1);
-                       else if(type == 3)simulateHybrid(start, end, time,1);
+                       if(type == 1)simulateBeeline(start, end, time,1,0);
+                       else if(type == 2)simulateRandom(start, end, time,1,0);
+                       else if(type == 3)simulateHybrid(start, end, time,1,0);
                }else{
-                       if(type == 1)simulateBeeline(start, end, time,0 );
-                       else if(type == 2)simulateRandom(start, end, time, 0);
-                       else if(type == 3)simulateHybrid(start, end, time, 0);
+                       if(type == 1)simulateBeeline(start, end, time,0,0 );
+                       else if(type == 2)simulateRandom(start, end, time, 0,0);
+                       else if(type == 3)simulateHybrid(start, end, time, 0 , 
0);
                }
+       }       
+}
+
+function commitCrime(){
+       //week2                 
+       for(var i=0; i<data_obj.sch_len; i++){
+               var start = data_obj.sch_sl[i];
+               var end = data_obj.sch_el[i];
+               var time = data_obj.sch_t[i];
+               var type = data_obj.sch_type[i];
+               if(i == data_obj.sch_len-1){
+                       if(type == 1)simulateBeeline(start, end, time,1, 1);
+                       else if(type == 2)simulateRandom(start, end, time,1, 1);
+                       else if(type == 3)simulateHybrid(start, end, time,1, 1);
+               }else{
+                       if(type == 1)simulateBeeline(start, end, time,0, 1);
+                       else if(type == 2)simulateRandom(start, end, time, 0 , 
1);
+                       else if(type == 3)simulateHybrid(start, end, time, 0, 
1);
+               }
+       }
+}
+
+function updateSpotLabels(){
+       for(var i=0; i<crime_spot_markers.length; i++){
+               map.removeLayer(crime_spot_markers[i]);
+       }
+       for(var i=0; i<data_obj.crime_spot.length; i++){
+               var risk = data_obj.crime_risk[i];
+               var reward = data_obj.crime_reward[i];
+               var freq = data_obj.crime_freq[i];
+               var pp = data_obj.pp[i];
+               var gd = data_obj.gd[i];
+               //alert(freq);
+               var marker=L.marker(data_obj.crime_spot[i], { icon: new 
L.Icon.Label.Default({ labelText: "CS-" + (i+1) + " ["+Math.floor(reward)+", 
"+Math.floor(risk)+", "+Math.floor(pp*100)/100+", "+Math.floor(gd*100)/100+", 
"+freq+"]"}) }).addTo(map);
+       }
+       
+}
+
+function ajaxComplete(){       
+       data_obj.num_ajax_counter++;
+       console.log(data_obj.num_ajax_counter);
+       if(data_obj.num_ajax_counter == data_obj.num_ajax){
+               data_obj.num_ajax_counter=0;
+               updateSpotLabels();             
+               $("#loading").dialog('close');
+               if(first_sim == 0){                     
+                       $("#loading").dialog('open').html("<p>Simulating Second 
Week where the agent commits crime</p>");
+                       commitCrime();
+                       first_sim =1;
+               }               
        }
 }
 

Modified: sis/sandbox/gsoc2013/crimgeoprofile/js/index.js
URL: 
http://svn.apache.org/viewvc/sis/sandbox/gsoc2013/crimgeoprofile/js/index.js?rev=1524712&r1=1524711&r2=1524712&view=diff
==============================================================================
--- sis/sandbox/gsoc2013/crimgeoprofile/js/index.js (original)
+++ sis/sandbox/gsoc2013/crimgeoprofile/js/index.js Thu Sep 19 12:31:12 2013
@@ -2,8 +2,9 @@ var data_obj;
 var map; 
 var findroutes, first, first_transit;
 var start_tp, end_tp;
-
+var first_sim = 0;
 $(document).ready(function () {
+       
        map = L.map('map').setView([51.505, 21], 1);
        
L.tileLayer('http://{s}.tile.cloudmade.com/e7b61e61295a44a5b319ca0bd3150890/997/256/{z}/{x}/{y}.png',
 {
        attribution: 'Map data &copy; <a 
href="http://openstreetmap.org";>OpenStreetMap</a> contributors, <a 
href="http://creativecommons.org/licenses/by-sa/2.0/";>CC-BY-SA</a>, Imagery © 
<a href="http://cloudmade.com";>CloudMade</a>',
@@ -37,6 +38,9 @@ $(document).ready(function () {
        $('#addmall').click(function(){
                map.on('click', markMall);
        });     
+       $("#addcrime").click(function(){
+               map.on('click', markCrimeSpot);
+       })
        $('#findroutes').click(function(){
                if(data_obj.loc_num!=6){
                        alert("You must mark all locations: Home, office, bar, 
Lunch-A, Lunch-B, Mall!!! Try again after marking them");
@@ -106,6 +110,7 @@ $(document).ready(function () {
                  url: "save.php",
                  dataType : 'json', 
                        data : {
+                               
                                json : JSON.stringify(data_obj, null, 4) ,
                                fname : filename
                        },
@@ -117,12 +122,14 @@ $(document).ready(function () {
        
        $('#load').click(function(){
                var filename = prompt("Filename: ");
+               $("#loading").dialog('open').html("<p>Loading ... Please 
wait</p>");
                $.ajax({
                  url: filename,
                  dataType: 'json',               
-                 success: function (data){                     
+                 success: function (data){                             
                        data_obj = data;
                        display();
+                       $("#loading").dialog('close');
                  }
                });
                
@@ -314,6 +321,5 @@ $(document).ready(function () {
                autoOpen: false,
                closeOnEscape: false,
                open: function(event, ui) { $(".ui-dialog-titlebar-close", 
ui.dialog || ui).hide(); }
-       });
-       
+       });     
 });
\ No newline at end of file

Modified: sis/sandbox/gsoc2013/crimgeoprofile/js/leaflet_numbered_markers.js
URL: 
http://svn.apache.org/viewvc/sis/sandbox/gsoc2013/crimgeoprofile/js/leaflet_numbered_markers.js?rev=1524712&r1=1524711&r2=1524712&view=diff
==============================================================================
--- sis/sandbox/gsoc2013/crimgeoprofile/js/leaflet_numbered_markers.js 
(original)
+++ sis/sandbox/gsoc2013/crimgeoprofile/js/leaflet_numbered_markers.js Thu Sep 
19 12:31:12 2013
@@ -1,33 +1,33 @@
-L.NumberedDivIcon = L.Icon.extend({
-       options: {
-    // EDIT THIS TO POINT TO THE FILE AT 
http://www.charliecroom.com/marker_hole.png (or your own marker)
-    iconUrl: '<%= image_path("marker_hole.png") %>',
-    number: '',
-    shadowUrl: null,
-    iconSize: new L.Point(25, 41),
-               iconAnchor: new L.Point(13, 41),
-               popupAnchor: new L.Point(0, -33),
-               /*
-               iconAnchor: (Point)
-               popupAnchor: (Point)
-               */
-               className: 'leaflet-div-icon'
-       },
-
-       createIcon: function () {
-               var div = document.createElement('div');
-               var img = this._createImg(this.options['iconUrl']);
-               var numdiv = document.createElement('div');
-               numdiv.setAttribute ( "class", "number" );
-               numdiv.innerHTML = this.options['number'] || '';
-               div.appendChild ( img );
-               div.appendChild ( numdiv );
-               this._setIconStyles(div, 'icon');
-               return div;
-       },
-
-       //you could change this to add a shadow like in the normal marker if 
you really wanted
-       createShadow: function () {
-               return null;
-       }
+L.NumberedDivIcon = L.Icon.extend({
+       options: {
+    // EDIT THIS TO POINT TO THE FILE AT 
http://www.charliecroom.com/marker_hole.png (or your own marker)
+    iconUrl: '<%= image_path("marker_hole.png") %>',
+    number: '',
+    shadowUrl: null,
+    iconSize: new L.Point(25, 41),
+               iconAnchor: new L.Point(13, 41),
+               popupAnchor: new L.Point(0, -33),
+               /*
+               iconAnchor: (Point)
+               popupAnchor: (Point)
+               */
+               className: 'leaflet-div-icon'
+       },
+
+       createIcon: function () {
+               var div = document.createElement('div');
+               var img = this._createImg(this.options['iconUrl']);
+               var numdiv = document.createElement('div');
+               numdiv.setAttribute ( "class", "number" );
+               numdiv.innerHTML = this.options['number'] || '';
+               div.appendChild ( img );
+               div.appendChild ( numdiv );
+               this._setIconStyles(div, 'icon');
+               return div;
+       },
+
+       //you could change this to add a shadow like in the normal marker if 
you really wanted
+       createShadow: function () {
+               return null;
+       }
 });
\ No newline at end of file

Modified: sis/sandbox/gsoc2013/crimgeoprofile/routing.php
URL: 
http://svn.apache.org/viewvc/sis/sandbox/gsoc2013/crimgeoprofile/routing.php?rev=1524712&r1=1524711&r2=1524712&view=diff
==============================================================================
--- sis/sandbox/gsoc2013/crimgeoprofile/routing.php (original)
+++ sis/sandbox/gsoc2013/crimgeoprofile/routing.php Thu Sep 19 12:31:12 2013
@@ -90,7 +90,7 @@ function random_movement($start_lat, $st
                        $result = pg_query($con, $query);
                        $row = pg_fetch_row($result);
                        //echo $row[0]."<br>";
-                       $time = ((double)$row[0])/1000/24.5*60; 
+                       $time = ((double)$row[0])/111/1*60;     
                        
                        $first = 0;                             
                }
@@ -115,7 +115,7 @@ function random_movement($start_lat, $st
                        $row = pg_fetch_row($result);
                        $cost=(double)$row[0];                  
                        //echo $cost;
-                       $t2 = (double)$cost*111/24.5*60;
+                       $t2 = (double)$cost*111/5*60;
                        
                        $time = $time + (double)$t2;    
                        //echo $time.";TIME<br>";
@@ -147,12 +147,12 @@ function random_movement($start_lat, $st
                $result = pg_query($con, $query);
                $row = pg_fetch_row($result);
                $dist = $row[0];
-               $t2 = (double)$dist/1000/24.5*60;;
+               $t2 = (double)$dist/111/1*60;;
                
 
          //echo $time." ".$t2."<br>";
                //if time runs out break from loop
-               if($t2 > $given_time - $time - 5) break;
+               if($t2 > $given_time - $time - 15) break;
                //if($n==3)break;               
                //else get all roads at this intersection
                $query =  'SELECT geom from node_taiwan WHERE id = 
'.$curr_node.';';
@@ -287,6 +287,6 @@ function random_movement($start_lat, $st
  $dest_lon = $_POST['end_lon'];
  $time = $_POST['time'];
 
-//random_movement(25.048202776784258,121.52071952819824,25.044314791294198,121.53668403625488,60);
+//random_movement(25.048202776784258,121.52071952819824,25.044314791294198,121.53668403625488,200);
 random_movement($start_lat, $start_lon, $dest_lat, $dest_lon, $time);
 ?>


Reply via email to