diff --git a/chasemapper/config.py b/chasemapper/config.py index 1b76d06..b335960 100644 --- a/chasemapper/config.py +++ b/chasemapper/config.py @@ -53,6 +53,7 @@ default_config = { 'bearing_weight': 1.0, 'bearing_color': 'black', 'bearing_custom_color': '#FF0000', + } @@ -140,6 +141,14 @@ def parse_config_file(filename): chase_config['selected_profile'] = "" chase_config['profiles'] = {} + + # Unit Selection + + chase_config['unitselection'] = config.get('units', 'unitselection', fallback='metric') + if chase_config['unitselection'] != "imperial": + chase_config['unitselection'] = 'metric' #unless imperial is explicitly requested do metric + chase_config['switch_miles_feet'] = config.get('units', 'switch_miles_feet', fallback = '400') + for i in range(1,_profile_count+1): _profile_section = "profile_%d" % i try: diff --git a/horusmapper.cfg.example b/horusmapper.cfg.example index 2b85597..a8d05c8 100644 --- a/horusmapper.cfg.example +++ b/horusmapper.cfg.example @@ -211,3 +211,24 @@ bearing_color = black # Custom bearing color, in hexadecimal #RRGGBB bearing_custom_color = #FF0000 + + + +[units] + +# unitselection allows choice of metric - the default or imperial - horizontal miles and feet for short distances, horizontal miles per hour, vertical feet, vertical feet per minute +# this is applied only to the indications and to the range ring settings + + +unitselection = metric +#unitselection = imperial + +# Sensible choice of unit selection (all thresholds set in metric) + +# This is the threshold for switching from miles to feet, set in metres. +switch_miles_feet = 400 + + + + + diff --git a/static/js/balloon.js b/static/js/balloon.js index e4e5337..f73e5d7 100644 --- a/static/js/balloon.js +++ b/static/js/balloon.js @@ -109,6 +109,8 @@ function add_new_balloon(data){ } function updateSummaryDisplay(){ + + if (chase_config['unitselection'] == "imperial") {updateSummaryDisplayImperial() ; return ; } // else do everything in metric // Update the 'Payload Summary' display. var _summary_update = {id:1}; // See if there is any payload data. @@ -151,6 +153,54 @@ function updateSummaryDisplay(){ $("#summary_table").tabulator("redraw", true); } } +function updateSummaryDisplayImperial(){ + + // Update the 'Payload Summary' display. + var _summary_update = {id:1}; + // See if there is any payload data. + if (balloon_positions.hasOwnProperty(balloon_currently_following) == true){ + // There is balloon data! + var _latest_telem = balloon_positions[balloon_currently_following].latest_data; + + _summary_update.alt = (_latest_telem.position[2]*3.28084).toFixed(0) + "ft (" + (_latest_telem.max_alt*3.28084).toFixed(0) + "ft)"; + var _speed = _latest_telem.speed*3.6 ; + _summary_update.speed = (_speed*0.621371).toFixed(0) + " mph"; + _summary_update.vel_v = (_latest_telem.vel_v*3.28084*60).toFixed(0) + " ft/min"; + + + if (chase_car_position.latest_data.length == 3){ + // We have a chase car position! Calculate relative position. + var _bal = {lat:_latest_telem.position[0], lon:_latest_telem.position[1], alt:_latest_telem.position[2]}; + var _car = {lat:chase_car_position.latest_data[0], lon:chase_car_position.latest_data[1], alt:chase_car_position.latest_data[2]}; + + var _look_angles = calculate_lookangles(_car, _bal); + + _summary_update.elevation = _look_angles.elevation.toFixed(0) + "°"; + _summary_update.azimuth = _look_angles.azimuth.toFixed(0) + "°"; + if (_look_angles.range > chase_config['switch_miles_feet']) { + _summary_update.range = (_look_angles.range*0.621371/1000).toFixed(1) + " miles"; + } else { + _summary_update.range = (_look_angles.range*3.28084).toFixed(1) + "ft"; + } + }else{ + // No Chase car position data - insert dummy values + _summary_update.azimuth = "---°"; + _summary_update.elevation = "--°"; + _summary_update.range = "----m"; + } + + }else{ + // No balloon data! + _summary_update = {id: 1, alt:'-----m', speed:'---kph', vel_v:'-.-m/s', azimuth:'---°', elevation:'--°', range:'----m'} + } + // Update table + $("#summary_table").tabulator("setData", [_summary_update]); + if (summary_enlarged == true){ + var row = $("#summary_table").tabulator("getRow", 1); + row.getElement().addClass("largeTableRow"); + $("#summary_table").tabulator("redraw", true); + } +} function handleTelemetry(data){ // Telemetry Event messages contain a dictionary of position data. @@ -178,7 +228,11 @@ function handleTelemetry(data){ // Update Chase Car Speed if (document.getElementById("showCarSpeed").checked){ - $("#chase_car_speed").text( (chase_car_position.speed*3.6).toFixed(0) + " kph"); + if (chase_config['unitselection'] == "imperial") { + $("#chase_car_speed").text( (chase_car_position.speed*3.6*0.621371).toFixed(0) + " mph"); + } else { + $("#chase_car_speed").text( (chase_car_position.speed*3.6).toFixed(0) + " kph"); + } $("#chase_car_speed_header").text("Chase Car Speed"); } else { $("#chase_car_speed").text(""); @@ -345,4 +399,4 @@ function showBalloon(callsign){ } } -} \ No newline at end of file +} diff --git a/static/js/car.js b/static/js/car.js index e756aef..cf9138e 100644 --- a/static/js/car.js +++ b/static/js/car.js @@ -29,6 +29,7 @@ function createRangeRings(position){ var _radius = _ring_spacing; var _color = "#FF0000"; + if (chase_config['unitselection'] == "imperial") { _radius = _ring_spacing*0.3048;} if(_ring_color == "red"){ _color = "#FF0000"; @@ -51,8 +52,8 @@ function createRangeRings(position){ opacity: 0.7 }).addTo(map); range_rings.push(_ring); - - _radius += _ring_spacing; + if (chase_config['unitselection'] == "metric") { _radius += _ring_spacing;} + if (chase_config['unitselection'] == "imperial") { _radius += _ring_spacing*0.3048;} } range_rings_on = true; @@ -107,4 +108,4 @@ function updateRangeRings(){ } -} \ No newline at end of file +} diff --git a/static/js/tables.js b/static/js/tables.js index 78b014d..3143654 100644 --- a/static/js/tables.js +++ b/static/js/tables.js @@ -152,9 +152,11 @@ function telemetryTableDialog(e, row){ divObj.dialog('open'); } + // Initialise tables function initTables(){ // Telemetry data table + if (chase_config['unitselection'] == "imperial") {initTablesImperial() ; return ; } // else do everything in metric $("#telem_table").tabulator({ layout:"fitData", layoutColumnsOnNewData:true, @@ -210,10 +212,68 @@ function initTables(){ $("#bearing_table").hide(); } +// Initialise tables in Imperial - Vertical velocity feet/min, Horizontal velocity Miles/hr, Range Miles then feet for Range < config setting +function initTablesImperial(){ + // Telemetry data table + $("#telem_table").tabulator({ + layout:"fitData", + layoutColumnsOnNewData:true, + //selectable:1, // TODO... + columns:[ //Define Table Columns + {title:"Callsign", field:"callsign", headerSort:false}, + {title:"Time (Z)", field:"short_time", headerSort:false}, + {title:"Latitude", field:"lat", headerSort:false}, + {title:"Longitude", field:"lon", headerSort:false}, + {title:"Alt (ft)", field:"alt", headerSort:false}, + {title:"V_rate (ft/min)", field:"vel_v", headerSort:false}, + {title:"SNR", field:'snr', headerSort:false, visible:false}, + {title:"Aux", field:'aux', headerSort:false, visible:false} + ], + rowClick:function(e, row){telemetryTableDialog(e, row);}, + rowTap:function(e, row){telemetryTableDialog(e, row);} + + }); + + $("#summary_table").tabulator({ + layout:"fitData", + layoutColumnsOnNewData:true, + columns:[ //Define Table Columns + {title:"Alt (ft)", field:"alt", headerSort:false}, + {title:"Speed (mph)", field:"speed", headerSort:false}, + {title:"Asc Rate (ft/min)", field:"vel_v", headerSort:false}, + {title:"Azimuth", field:"azimuth", headerSort:false}, + {title:"Elevation", field:"elevation", headerSort:false}, + {title:"Range", field:"range", headerSort:false}, + ], + data:[{id: 1, alt:'-----ft', speed:'---mph', vel_v:'---ft/min', azimuth:'---°', elevation:'--°', range:'---- miles'}], + rowClick:function(e, row){ + toggleSummarySize(); + }, + rowTap:function(e, row){ + toggleSummarySize(); + } + }); + + + $("#bearing_table").tabulator({ + layout:"fitData", + layoutColumnsOnNewData:true, + //selectable:1, // TODO... + columns:[ //Define Table Columns + {title:"Bearing", field:"bearing", headerSort:false}, + {title:"Score", field:'confidence', headerSort:false}, + {title:"Power", field:'power', headerSort:false} + ], + data:[{id: 1, bearing:0.0, confidence:0.0}] + }); + + $("#bearing_table").hide(); +} + function updateTelemetryTable(){ var telem_data = []; - + if (chase_config['unitselection'] == "imperial") {updateTelemetryTableImperial() ; return ; } // else do everything in metric if (jQuery.isEmptyObject(balloon_positions)){ telem_data = [{callsign:'None'}]; }else{ @@ -224,7 +284,7 @@ function updateTelemetryTable(){ // Modify some of the fields to fixed point values. balloon_call_data.lat = balloon_call_data.position[0].toFixed(5); balloon_call_data.lon = balloon_call_data.position[1].toFixed(5); - balloon_call_data.alt = balloon_call_data.position[2].toFixed(1) + " (" + balloon_call_data.max_alt.toFixed(0) + ")" ; + balloon_call_data.alt = balloon_call_data.position[2].toFixed(0) + " (" + balloon_call_data.max_alt.toFixed(0) + ")" ; balloon_call_data.vel_v = balloon_call_data.vel_v.toFixed(1); // Add in any extra data to the aux field. @@ -251,4 +311,45 @@ function updateTelemetryTable(){ } $("#telem_table").tabulator("setData", telem_data); -} \ No newline at end of file +} + +function updateTelemetryTableImperial(){ + var telem_data = []; + if (jQuery.isEmptyObject(balloon_positions)){ + telem_data = [{callsign:'None'}]; + }else{ + for (balloon_call in balloon_positions){ + var balloon_call_data = Object.assign({},balloon_positions[balloon_call].latest_data); + var balloon_call_age = balloon_positions[balloon_call].age; + + // Modify some of the fields to fixed point values. + balloon_call_data.lat = balloon_call_data.position[0].toFixed(5); + balloon_call_data.lon = balloon_call_data.position[1].toFixed(5); + balloon_call_data.alt = (balloon_call_data.position[2]*3.28084).toFixed(1) + " (" + (balloon_call_data.max_alt*3.28084).toFixed(0) + ")" ; + balloon_call_data.vel_v = (balloon_call_data.vel_v*3.28084*60).toFixed(1); + + // Add in any extra data to the aux field. + balloon_call_data.aux = ""; + balloon_call_data.snr = ""; + + if (balloon_call_data.hasOwnProperty('bt')){ + if ((balloon_call_data.bt >= 0) && (balloon_call_data.bt < 65535)) { + balloon_call_data.aux += "BT " + new Date(balloon_call_data.bt*1000).toISOString().substr(11, 8) + " "; + $("#telem_table").tabulator("showColumn", "aux"); + } + } + + if (balloon_positions[balloon_call].hasOwnProperty('snr')){ + if (balloon_positions[balloon_call].snr > -255.0){ + balloon_call_data.snr = balloon_positions[balloon_call].snr.toFixed(1); + $("#telem_table").tabulator("showColumn", "snr"); + } + } + + // Update table + telem_data.push(balloon_call_data); + } + } + + $("#telem_table").tabulator("setData", telem_data); +} diff --git a/templates/index.html b/templates/index.html index 3213312..3e27e0c 100644 --- a/templates/index.html +++ b/templates/index.html @@ -249,17 +249,42 @@ } // Add measurement control. + + if (chase_config['unitselection'] == "imperial") { + + + L.control.polylineMeasure({ + position: 'topleft', + unit: 'landmiles', + showClearControl: true, + }).addTo(map); + + } + + + if (chase_config['unitselection'] == "metric") { L.control.polylineMeasure({ position: 'topleft', unit: 'metres', showClearControl: true, }).addTo(map); + + } + + // Add layer selection control (top right). map.addControl(new L.Control.Layers(map_layers)); // Add map scale. - L.control.scale({imperial: false}).addTo(map); + if (chase_config['unitselection'] == "imperial") { L.control.scale({imperial: true, metric: false}).addTo(map) ;} + if (chase_config['unitselection'] == "metric") { L.control.scale({imperial: false, metric: true}).addTo(map) ;} + + + + // Units for rings + if (chase_config['unitselection'] == "imperial") { document.getElementById("ring_spacing").innerHTML = "Ring Spacing (ft)";} + if (chase_config['unitselection'] == "metric") { document.getElementById("ring_spacing").innerHTML = "Ring Spacing (m)";} // Add sidebar to map (where all of our controls are!) var sidebar = L.control.sidebar('sidebar').addTo(map); @@ -739,7 +764,7 @@ Ring Qty
- Ring Spacing (m)
+

Ring Spacing (m)


Ring Weight (px)