Page 43 - MSDN Magazine, April 2018
P. 43

Figure 11 Python Code for Calculating G-Force
########################
# G-Force, Using Python 3.5+ ########################
#Directionless g-force (gg = Math.sqrt(Accx * Accx + Accy * Accy + Accz * Accz)) <pythagorean theorem>
#Assuming accelerometer is in meters per second squared, gforce measurement by dividing by 9.81
#1 acceleration of gravity [g] = 9.80664999999998 meter/second2 [m/s2] #our data is in feet per second so we use the converstion 1 ft/s2 = 0.3048 m/s2
#Set Conversion Metrics
G_conversion = (9.80664999999998) MperS_conversion = (.3048) #from above
#Replace na's with zeroes to avoid math errors dataset=dataset.fillna(0)
#Using acceleration measures from 'dataset' dataframe, we convert to meters per second squared
#In our case our acceleration variables are labeled AccX, AccY and AccZ #In our case, acceleration was in feet per second, so we needed to apply a conversion.
dataset["AccX_mtrpersecsqrd"] = dataset["AccX"]/MperS_conversion] dataset["AccY_mtrpersecsqrd"] = dataset["AccY"]/MperS_conversion] dataset["AccZ_mtrpersecsqrd"] = dataset["AccZ"]/MperS_conversion]
#Generate Directionless G-Force measure, call it 'DirectionlessGG' dataset["DirectionlessGG"] = ((dataset["AccX"]*dataset["AccX"])+(dataset[ "AccY"]*dataset["AccY"])+dataset["AccZ"]*dataset["AccZ"])).astype(float) dataset["DirectionlessGG"] = np.sqrt(dataset["DirectionlessGG"])#.astype(float)
#Generate Direction Specific G-Force, call them 'X_GG', 'Y_GG' and 'Z_GG'. dataset["X_GG"] = dataset["AccX"]/MperS_converstion/G_conversion dataset["Y_GG"] = dataset["AccY"]/MperS_converstion/G_conversion dataset["Z_GG"] = dataset["AccZ"]/MperS_converstion/G_conversion
experience. And for an understanding of human tolerances and limits of g-forces, refer to the Wikipedia article at bit.ly/2EPQDjE, as well as to the NASA collection of research at go.nasa.gov/2oyS9fj. More information on calculating g-force is available at bit.ly/2Fzxpfa.
Wrapping Up
We used custom-built and partner-made sensors to collect athlete data, and illustrated the use of our open source Sensor Kit that connects sensors with mobile apps and Azure Cosmos DB. We explained how to process that data with statistical tools, such as R, to extract “activity signatures” that describe the turns athletes make while skiing. Finally, we explained how to use data from sensors to calculate an athlete’s load from g-forces using Python. n
Kevin Ashley is an architect evangelist at Microsoft. He’s coauthor of “Professional Windows 8 Programming” (Wrox, 2012) and a developer of top apps and games, most notably Active Fitness (activefitness.co). He often presents on technology at various events, industry shows and webcasts. In his role, he works with start- ups and partners, advising on software design, business and technology strategy, architecture, and development. Follow him on Twitter: @kashleytwit.
OlgA vigdOrOvich is a database administrator, data scientist and an avid skier. She built the data model and back end for scalable cloud platforms based on Microsoft Azure, including Winter Sports, for Active Fitness at Summit Data Corp.
PAtty ryAn is an applied data scientist for Microsoft. She codes with its partners and customers to tackle tough problems using machine learning approaches, with sensor, text and vision data. Follow her on Twitter: @singingdata.
thAnKs to the following Microsoft technical expert who reviewed this article: Mona Soliman Habib
msdnmagazine.com


































































































   41   42   43   44   45