Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a complete list of delay in both normal and delayed segments

  • Loading branch information...
commit 4ff89c963689a174a1270f9331acf2110569a61e 1 parent 579e9c2
@snktagarwal authored
Showing with 47 additions and 66 deletions.
  1. +6 −7 delay_simulation/index.html
  2. +41 −59 delay_simulation/js/helper.js
View
13 delay_simulation/index.html
@@ -60,16 +60,15 @@
<tr> <!-- Bussiest segments row -->
<td>
- <h5>Three Bussiest Segments(MAP_NORMAL)</h5>
- <div id="busy1_normal"></div>
- <div id="busy2_normal"></div>
- <div id="busy3_normal"></div>
+ <h5>Bussiest segments(MAP_NORMAL)</h5>
+
+ <ul id="bus_seg_normal"></ul>
+ <!-- Taken dynamically from the Javascript -->
</td>
<td>
<h5>Three Bussiest Segments(MAP_DELAY)</h5>
- <div id="busy1_delay"></div>
- <div id="busy2_delay"></div>
- <div id="busy3_delay"></div>
+ <ul id="bus_seg_delay"></ul>
+ <!-- Taken dynamically from the Javascript -->
</td>
</tr> <!-- Bussiest segments row ends -->
View
100 delay_simulation/js/helper.js
@@ -446,74 +446,56 @@ function search_seg(v){
}
}
+function sort_traffic(a,b){
+ return b.traffic - a.traffic;
+}
+function segment_obj(sname, traffic){
+ this.sname = sname;
+ this.traffic = traffic;
+}
+
function busy3high_normal(){
var busy1_name, busy2_name, busy3_name;
- var busy1_info = 0, busy2_info = 0, busy3_info = 0;
- var i;
- for(i in segments_normal)
- {
- if(segments_normal[i] > busy1_info)
- {
- busy1_info = segments_normal[i];
- var s = Segments[i].segment;
- busy1_name = s.seg_name;
- }
- }
- for(i in segments_normal)
- {
- if(segments_normal[i] > busy2_info && segments_normal[i] < busy1_info)
- {
- busy2_info = segments_normal[i];
- var s = Segments[i].segment;
- busy2_name = s.seg_name;
- }
+ var seg_traffic_array = new Array();
+
+ /* Create an array of objects for various segments */
+ for(var i in segments_normal){
+ //alert(segments_normal[i]);
+ var seg_obj = new segment_obj(Segments[i].segment.seg_name, segments_normal[i]);
+ seg_traffic_array[i] = seg_obj;
}
- for(i in segments_normal)
- {
- if(segments_normal[i] > busy3_info && segments_normal[i] < busy2_info)
- {
- busy3_info = segments_normal[i];
- var s = Segments[i].segment;
- busy3_name = s.seg_name;
- }
+
+
+ /* Now sort them */
+ seg_traffic_array.sort(sort_traffic);
+
+ /* Display in HTML */
+ $("#bus_seg_normal").children().remove();
+ for(var i in seg_traffic_array){
+ $("#bus_seg_normal").append('<li>'+seg_traffic_array[i].sname+'\t'+seg_traffic_array[i].traffic+'</li>');
}
- $("#busy1_normal").html("1. " + busy1_name + "\t" + busy1_info);
- $("#busy2_normal").html("2. " + busy2_name + "\t" + busy2_info);
- $("#busy3_normal").html("3. " + busy3_name + "\t" + busy3_info);
+
+
}
function busy3high_delay(){
var busy1_name, busy2_name, busy3_name;
var busy1_info = 0, busy2_info = 0, busy3_info = 0;
- var i;
- for(i in segments_delay)
- {
- if(segments_delay[i] > busy1_info)
- {
- busy1_info = segments_delay[i];
- var s = Segments[i].segment;
- busy1_name = s.seg_name;
- }
+ var seg_traffic_array = new Array();
+
+ /* Create an array of objects for various segments */
+ for(var i in segments_normal){
+ //alert(segments_normal[i]);
+ var seg_obj = new segment_obj(Segments[i].segment.seg_name, segments_delay[i]);
+ seg_traffic_array[i] = seg_obj;
}
- for(i in segments_delay)
- {
- if(segments_delay[i] > busy2_info && segments_delay[i] < busy1_info)
- {
- busy2_info = segments_delay[i];
- var s = Segments[i].segment;
- busy2_name = s.seg_name;
- }
+
+ /* Now sort them */
+ seg_traffic_array.sort(sort_traffic);
+
+ /* Display in HTML */
+ $("#bus_seg_delay").children().remove();
+ for(var i in seg_traffic_array){
+ $("#bus_seg_delay").append('<li>'+seg_traffic_array[i].sname+'\t'+seg_traffic_array[i].traffic+'</li>');
}
- for(i in segments_delay)
- {
- if(segments_delay[i] > busy3_info && segments_delay[i] < busy2_info)
- {
- busy3_info = segments_delay[i];
- var s = Segments[i].segment;
- busy3_name = s.seg_name;
- }
}
- $("#busy1_delay").html("1. " + busy1_name + "\t" + busy1_info);
- $("#busy2_delay").html("2. " + busy2_name + "\t" + busy2_info);
- $("#busy3_delay").html("3. " + busy3_name + "\t" + busy3_info);
-}
Please sign in to comment.
Something went wrong with that request. Please try again.