ssscoring.mapview
1# See: https://github.com/pr3d4t0r/SSScoring/blob/master/LICENSE.txt 2 3from geopy import distance 4from ssscoring.datatypes import JumpResults 5 6import pandas as pd 7import pydeck as pdk 8 9 10# *** constants *** 11 12DISTANCE_FROM_MIDDLE = 400.0 13""" 14The distance in meters from the middle of the skydive to the outer bounding box 15for the initial view of a new rendered map. 16""" 17 18 19# *** implementation *** 20 21def viewPointBox(data: pd.DataFrame) -> pd.DataFrame: 22 """ 23 Calculate the NW and SE corners of a "box" delimiting the viewport area 24 `DISTANCE_FROM_MIDDLE` meters away from the middle of the speed skydive. 25 26 Arguments 27 --------- 28 data 29 A SSScoring dataframe with jump data. 30 31 Returns 32 ------- 33 The NW and SE corners of the box, as terrestrial coordinates, in a dataframe 34 with these columns: 35 36 - `latitude` 37 - `lontigude` 38 39 See 40 --- 41 `ssscoring.calc.convertFlySight2SSScoring` 42 """ 43 mid = len(data)//2 44 datum = data.iloc[mid] 45 origin = (datum.latitude, datum.longitude) 46 pointNW = distance.distance(meters=DISTANCE_FROM_MIDDLE).destination(origin, bearing=315) 47 pointSE = distance.distance(meters=DISTANCE_FROM_MIDDLE).destination(origin, bearing=135) 48 data = list(zip([ pointNW[0], pointSE[0], ], [ pointNW[1], pointSE[1], ])) 49 result = pd.DataFrame(data, columns=[ 'latitude', 'longitude', ]) 50 return result 51 52 53def _resolveMaxSpeedTimeFrom(jumpResult: JumpResults) -> float: 54 plotTime = jumpResult.scores[jumpResult.score] 55 56 return plotTime 57 58 59def speedJumpTrajectory(jumpResult: JumpResults) -> pdk.Deck: 60 """ 61 Build the layers for a PyDeck map showing a jumper's trajectory. 62 63 Arguments 64 --------- 65 jumpResult 66 A SSScoring `JumpResults` instance with the results of the jump. 67 68 Returns 69 ------- 70 A PyDeck `deck` instance ready for rendering using PyDeck or Streamlit 71 mapping facilities. 72 73 See 74 --- 75 `st.pydeck_chart` 76 `st.map` 77 """ 78 workData = jumpResult.data.copy() 79 maxSpeedTime = _resolveMaxSpeedTimeFrom(jumpResult) 80 layers = [ 81 pdk.Layer( 82 'ScatterplotLayer', 83 data=workData, 84 # get_color=[ 0, 160, 0, 128 ], 85 get_color=[ 0, 192, 0, 255 ], 86 get_position=[ 'longitude', 'latitude', ], 87 t_radius=4), 88 pdk.Layer( 89 'ScatterplotLayer', 90 data=workData.head(1), 91 get_color=[ 255, 126, 0, 255 ], 92 get_position=[ 'longitude', 'latitude', ], 93 get_radius=8), 94 pdk.Layer( 95 'ScatterplotLayer', 96 data=workData.tail(1), 97 get_color=[ 0, 192, 0, 160 ], 98 get_position=[ 'longitude', 'latitude', ], 99 get_radius=8), 100 pdk.Layer( 101 'ScatterplotLayer', 102 data=workData[workData.plotTime == maxSpeedTime], 103 get_color=[ 0, 255, 0, ], 104 get_position=[ 'longitude', 'latitude', ], 105 get_radius=12), 106 ] 107 viewBox = viewPointBox(workData) 108 deck = pdk.Deck( 109 map_style = None, 110 initial_view_state=pdk.data_utils.compute_view(viewBox[['longitude', 'latitude',]]), 111 layers=layers 112 ) 113 return deck
DISTANCE_FROM_MIDDLE =
400.0
The distance in meters from the middle of the skydive to the outer bounding box for the initial view of a new rendered map.
def
viewPointBox(data: pandas.core.frame.DataFrame) -> pandas.core.frame.DataFrame:
22def viewPointBox(data: pd.DataFrame) -> pd.DataFrame: 23 """ 24 Calculate the NW and SE corners of a "box" delimiting the viewport area 25 `DISTANCE_FROM_MIDDLE` meters away from the middle of the speed skydive. 26 27 Arguments 28 --------- 29 data 30 A SSScoring dataframe with jump data. 31 32 Returns 33 ------- 34 The NW and SE corners of the box, as terrestrial coordinates, in a dataframe 35 with these columns: 36 37 - `latitude` 38 - `lontigude` 39 40 See 41 --- 42 `ssscoring.calc.convertFlySight2SSScoring` 43 """ 44 mid = len(data)//2 45 datum = data.iloc[mid] 46 origin = (datum.latitude, datum.longitude) 47 pointNW = distance.distance(meters=DISTANCE_FROM_MIDDLE).destination(origin, bearing=315) 48 pointSE = distance.distance(meters=DISTANCE_FROM_MIDDLE).destination(origin, bearing=135) 49 data = list(zip([ pointNW[0], pointSE[0], ], [ pointNW[1], pointSE[1], ])) 50 result = pd.DataFrame(data, columns=[ 'latitude', 'longitude', ]) 51 return result
Calculate the NW and SE corners of a "box" delimiting the viewport area
DISTANCE_FROM_MIDDLE
meters away from the middle of the speed skydive.
Arguments
data
A SSScoring dataframe with jump data.
Returns
The NW and SE corners of the box, as terrestrial coordinates, in a dataframe with these columns:
latitude
lontigude
See
60def speedJumpTrajectory(jumpResult: JumpResults) -> pdk.Deck: 61 """ 62 Build the layers for a PyDeck map showing a jumper's trajectory. 63 64 Arguments 65 --------- 66 jumpResult 67 A SSScoring `JumpResults` instance with the results of the jump. 68 69 Returns 70 ------- 71 A PyDeck `deck` instance ready for rendering using PyDeck or Streamlit 72 mapping facilities. 73 74 See 75 --- 76 `st.pydeck_chart` 77 `st.map` 78 """ 79 workData = jumpResult.data.copy() 80 maxSpeedTime = _resolveMaxSpeedTimeFrom(jumpResult) 81 layers = [ 82 pdk.Layer( 83 'ScatterplotLayer', 84 data=workData, 85 # get_color=[ 0, 160, 0, 128 ], 86 get_color=[ 0, 192, 0, 255 ], 87 get_position=[ 'longitude', 'latitude', ], 88 t_radius=4), 89 pdk.Layer( 90 'ScatterplotLayer', 91 data=workData.head(1), 92 get_color=[ 255, 126, 0, 255 ], 93 get_position=[ 'longitude', 'latitude', ], 94 get_radius=8), 95 pdk.Layer( 96 'ScatterplotLayer', 97 data=workData.tail(1), 98 get_color=[ 0, 192, 0, 160 ], 99 get_position=[ 'longitude', 'latitude', ], 100 get_radius=8), 101 pdk.Layer( 102 'ScatterplotLayer', 103 data=workData[workData.plotTime == maxSpeedTime], 104 get_color=[ 0, 255, 0, ], 105 get_position=[ 'longitude', 'latitude', ], 106 get_radius=12), 107 ] 108 viewBox = viewPointBox(workData) 109 deck = pdk.Deck( 110 map_style = None, 111 initial_view_state=pdk.data_utils.compute_view(viewBox[['longitude', 'latitude',]]), 112 layers=layers 113 ) 114 return deck
Build the layers for a PyDeck map showing a jumper's trajectory.
Arguments
jumpResult
A SSScoring JumpResults
instance with the results of the jump.
Returns
A PyDeck deck
instance ready for rendering using PyDeck or Streamlit
mapping facilities.
See
st.pydeck_chart
st.map