Skip to content

Commit

Permalink
#27, #33 - Calculate current average speed by summing the straight-line
Browse files Browse the repository at this point in the history
distance between each of the last five track points and dividing by the
elapsed time between the first and last points in the subset.  While
this version runs in Verifier, I still need to:
- determine whether the calculated speed is correct
- fix pace (currently displays as 0)
- test boundary cases (0, 1, 2, and 3 track points)
As part of this work I eliminated the Location structured data type, as
leaving it in place will teach the students bad habits.
  • Loading branch information
John Wolfe committed Jun 14, 2014
1 parent a276296 commit 2a7f741
Show file tree
Hide file tree
Showing 12 changed files with 340 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,20 +392,20 @@ INSERT INTO SPR_PEP
INSERT INTO SPR_PO
VALUES ("409338b4-1ff4-4ce9-893d-a58f09bbf50d",
'getDistance',
'',
'// Return the straight-line distance between the two points passed as parameters.
deltaLat = param.toLocation.latitude - param.fromLocation.latitude;
deltaLong = param.toLocation.longitude - param.fromLocation.longitude;
sumSquares = (deltaLat * deltaLat) + (deltaLong * deltaLong);
return ( MATH::sqrt( x: sumSquares ) );',
'Calculate distance between the "from" and "to" coordinates passed as parameters.',
'// Return the straight-line distance between the two points passed as parameters.

deltaLat = param.toLat - param.fromLat;
deltaLong = param.toLong - param.fromLong;
sumSquares = (deltaLat * deltaLat) + (deltaLong * deltaLong);
return ( (MATH::sqrt( x: sumSquares ) * kmPerDegree) );',
1);
INSERT INTO C_EP_PROXY
VALUES ("dea2904d-4d56-4426-a11d-768d3893878f",
"b65a1f3e-0be2-4ec7-867b-c71757895c44",
-1,
'getDistance',
'',
'Calculate distance between the "from" and "to" coordinates passed as parameters.',
'../../LocationInterfaces/LocationUtil/LocationUtil.xtuml');
INSERT INTO C_I_PROXY
VALUES ("b65a1f3e-0be2-4ec7-867b-c71757895c44",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,15 +211,13 @@ INSERT INTO SM_ACT
VALUES ("bcb4824a-fdc3-41d7-970d-126c2f4ac183",
"cbd78b0b-db48-eee0-5d1c-ff567de59af8",
1,
'// prepare signal data with some dummy values that change over time
'// Simulate movement.
select any gps from instances of GPS;
gps.currentLocation.longitude = gps.currentLocation.longitude + 2.0;
gps.currentLocation.latitude = gps.currentLocation.latitude + 3.0;
gps.currentLocation.speed = (gps.currentLocation.latitude -
gps.currentLocation.longitude) / 5.0;
gps.currentLongitude = gps.currentLongitude + 0.02;
gps.currentLatitude = gps.currentLatitude + 0.03;

// pass the new location to client component
send LocationProvider::locationUpdate(location: gps.currentLocation);
// Send the new location out through the port.
send LocationProvider::locationUpdate( latitude: gps.currentLatitude, longitude: gps.currentLongitude );
',
'');
INSERT INTO SM_TAH
Expand All @@ -240,9 +238,8 @@ if (empty gps)
end if;

// reset currentLocation
gps.currentLocation.longitude = 0.0;
gps.currentLocation.latitude = 0.0;
gps.currentLocation.speed = 0.0;
gps.currentLongitude = 0.0;
gps.currentLatitude = 0.0;

LOG::LogInfo(message: "Location listener registered.");

Expand Down Expand Up @@ -714,5 +711,5 @@ INSERT INTO O_OBJ_PROXY
'',
"00000000-0000-0000-0000-000000000000",
"00000000-0000-0000-0000-000000000000",
"cbd78b0b-db48-eee0-5d1c-ff567de59af8",
"00000000-0000-0000-0000-000000000000",
'../GPS.xtuml');
Original file line number Diff line number Diff line change
@@ -1,53 +1,66 @@
-- BP 7.1 content: ModelClass syschar: 3 persistence-version: 7.1.6
-- BP 7.1.6 content: ModelClass syschar: 3 persistence-version: 7.1.6

INSERT INTO O_OBJ
VALUES ("0679851b-cc52-42de-bb1e-f7d26a404f38",
'GPS',
1,
'GPS',
'',
"00000000-0000-0000-0000-000000000000",
"00000000-0000-0000-0000-000000000000",
"00000000-0000-0000-0000-000000000000");
INSERT INTO O_NBATTR
VALUES ("b8a35c1f-5da4-4e0e-82ac-885099b524f6",
VALUES ("a7624bef-089d-40e2-9e32-c7762a24111c",
"0679851b-cc52-42de-bb1e-f7d26a404f38");
INSERT INTO O_BATTR
VALUES ("b8a35c1f-5da4-4e0e-82ac-885099b524f6",
VALUES ("a7624bef-089d-40e2-9e32-c7762a24111c",
"0679851b-cc52-42de-bb1e-f7d26a404f38");
INSERT INTO O_ATTR
VALUES ("b8a35c1f-5da4-4e0e-82ac-885099b524f6",
VALUES ("a7624bef-089d-40e2-9e32-c7762a24111c",
"0679851b-cc52-42de-bb1e-f7d26a404f38",
"00000000-0000-0000-0000-000000000000",
'currentLocation',
"4fea4076-4eb4-4c99-a3b4-d5382483335d",
'timer',
'',
'',
'currentLocation',
'timer',
0,
"cb835491-fba0-4f96-9ad3-ef020d954fa4",
"ba5eda7a-def5-0000-0000-00000000000f",
'',
'');
INSERT INTO S_DT_PROXY
VALUES ("cb835491-fba0-4f96-9ad3-ef020d954fa4",
INSERT INTO O_NBATTR
VALUES ("89922d9d-dc0d-48d2-9b3b-64ad81cbabc7",
"0679851b-cc52-42de-bb1e-f7d26a404f38");
INSERT INTO O_BATTR
VALUES ("89922d9d-dc0d-48d2-9b3b-64ad81cbabc7",
"0679851b-cc52-42de-bb1e-f7d26a404f38");
INSERT INTO O_ATTR
VALUES ("89922d9d-dc0d-48d2-9b3b-64ad81cbabc7",
"0679851b-cc52-42de-bb1e-f7d26a404f38",
"00000000-0000-0000-0000-000000000000",
'Location',
'currentLatitude',
'',
'',
'../../../../LocationDataTypes/LocationDataTypes.xtuml');
'currentLatitude',
0,
"ba5eda7a-def5-0000-0000-000000000003",
'',
'');
INSERT INTO O_NBATTR
VALUES ("a7624bef-089d-40e2-9e32-c7762a24111c",
VALUES ("4fea4076-4eb4-4c99-a3b4-d5382483335d",
"0679851b-cc52-42de-bb1e-f7d26a404f38");
INSERT INTO O_BATTR
VALUES ("a7624bef-089d-40e2-9e32-c7762a24111c",
VALUES ("4fea4076-4eb4-4c99-a3b4-d5382483335d",
"0679851b-cc52-42de-bb1e-f7d26a404f38");
INSERT INTO O_ATTR
VALUES ("a7624bef-089d-40e2-9e32-c7762a24111c",
VALUES ("4fea4076-4eb4-4c99-a3b4-d5382483335d",
"0679851b-cc52-42de-bb1e-f7d26a404f38",
"b8a35c1f-5da4-4e0e-82ac-885099b524f6",
'timer',
"89922d9d-dc0d-48d2-9b3b-64ad81cbabc7",
'currentLongitude',
'',
'',
'timer',
'currentLongitude',
0,
"ba5eda7a-def5-0000-0000-00000000000f",
"ba5eda7a-def5-0000-0000-000000000003",
'',
'');
INSERT INTO O_ID
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,16 +533,15 @@ INSERT INTO SPR_RS
'',
'// Log the newly received location data.
LOG::LogInfo(message: "location updated: ");
LOG::LogReal(message: "longitude", r: param.location.longitude);
LOG::LogReal(message: "latitude", r: param.location.latitude );
LOG::LogReal(message: "speed", r: param.location.speed );
LOG::LogReal(message: "longitude", r: param.longitude);
LOG::LogReal(message: "latitude", r: param.latitude );

// Add a track point to track log related to the singleton instance of
// the workout session.
select any session from instances of WorkoutSession;
if ( not empty session )
select one trackLog related by session->TrackLog[R4.''captures path in''];
trackLog.addTrackPoint( location: param.location );
trackLog.addTrackPoint( latitude: param.latitude, longitude: param.longitude );
end if;',
1);
INSERT INTO C_EP_PROXY
Expand Down Expand Up @@ -890,15 +889,17 @@ INSERT INTO SPR_REP
INSERT INTO SPR_RO
VALUES ("051452c4-19ef-40e2-a973-335f648d5010",
'getDistance',
'',
'Returns distance, in kilometers, between the "from" and "to" coordinates passed as parameters.
The coordinates must be passed as decimal degrees.',
'return 1;',
0);
INSERT INTO C_EP_PROXY
VALUES ("dea2904d-4d56-4426-a11d-768d3893878f",
"b65a1f3e-0be2-4ec7-867b-c71757895c44",
-1,
'getDistance',
'',
'Returns distance, in kilometers, between the "from" and "to" coordinates passed as parameters.
The coordinates must be passed as decimal degrees.',
'../../LocationInterfaces/LocationUtil/LocationUtil.xtuml');
INSERT INTO C_I_PROXY
VALUES ("b65a1f3e-0be2-4ec7-867b-c71757895c44",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@ create object instance trackPoint of TrackPoint;
select one workoutTimer related by
self->WorkoutSession[R4.''represents path for'']->WorkoutTimer[R8.''is timed by''];
trackPoint.time = workoutTimer.time;
trackPoint.longitude = param.location.longitude;
trackPoint.latitude = param.location.latitude;
trackPoint.speed = param.location.speed;
trackPoint.longitude = param.longitude;
trackPoint.latitude = param.latitude;

// Add the newly created track point to the track log.
select one firstPoint related by self->TrackPoint[R1];
select one lastPoint related by self->TrackPoint[R3];

// Explicit variable declarations for later use outside if-else clause.
isFirstTrackPoint = false;
lastKnownLocation = param.location;
lastLatitude = 0.0;
lastLongitude = 0.0;
if (empty firstPoint)
isFirstTrackPoint = true;
relate self to trackPoint across R1.''has first'';
relate self to trackPoint across R3.''has last'';
else
// Save last location for use in updating accumulated distance.
lastKnownLocation.longitude = lastPoint.longitude;
lastKnownLocation.latitude = lastPoint.latitude;
lastLatitude = lastPoint.latitude;
lastLongitude = lastPoint.longitude;
unrelate self from lastPoint across R3.''has last'';
relate self to trackPoint across R3.''has last'';
relate lastPoint to trackPoint across R2.''follows'';
Expand All @@ -56,35 +56,36 @@ end if;
// Update accumulated distance and current speed.
distance = 0.0;
if (not isFirstTrackPoint)
send distance = UTIL::getDistance(fromLocation: lastKnownLocation,
toLocation: param.location);
send distance = UTIL::getDistance( fromLat: lastLatitude, fromLong: lastLongitude,
toLat: param.latitude, toLong: param.longitude );
end if;

select one session related by self->WorkoutSession[R4.''represents path for''];
session.accumulatedDistance = session.accumulatedDistance + distance;
session.currentSpeed = param.location.speed;

// Notify UI of of the updated values.
generate Display_A2:refresh() to Display class;',
1,
'',
"00000000-0000-0000-0000-000000000000");
INSERT INTO O_TPARM
VALUES ("64c18302-2a55-4277-b153-a3823748dfcb",
VALUES ("aaeac00c-f771-40de-8ed2-f7156bca384b",
"0f45bbc6-da36-4b5b-a2dd-f739a6f0cbdd",
'location',
"cb835491-fba0-4f96-9ad3-ef020d954fa4",
'latitude',
"ba5eda7a-def5-0000-0000-000000000003",
0,
'',
"00000000-0000-0000-0000-000000000000",
'');
INSERT INTO S_DT_PROXY
VALUES ("cb835491-fba0-4f96-9ad3-ef020d954fa4",
"00000000-0000-0000-0000-000000000000",
'Location',
'',
INSERT INTO O_TPARM
VALUES ("f7d42a65-2ad9-4471-aca8-fa8ca8b8d9b6",
"0f45bbc6-da36-4b5b-a2dd-f739a6f0cbdd",
'longitude',
"ba5eda7a-def5-0000-0000-000000000003",
0,
'',
'../../../../LocationDataTypes/LocationDataTypes.xtuml');
"aaeac00c-f771-40de-8ed2-f7156bca384b",
'');
INSERT INTO O_TFR
VALUES ("7dbac40f-6e89-4ad2-a576-0f1fcfbe2dc5",
"d2828038-110a-4559-8452-91651af0adcb",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ INSERT INTO O_ATTR
"66920350-b77d-4876-9b05-0c545b5437ae",
"00000000-0000-0000-0000-000000000000",
'time',
'Number of seconds between start time for the associated workout and recording of this location.
'Number of seconds between start time for the associated workout and recording of this location.
',
'',
'time',
Expand All @@ -39,7 +39,8 @@ INSERT INTO O_ATTR
"66920350-b77d-4876-9b05-0c545b5437ae",
"7080b4f6-ebf6-47fe-be82-a1c2cf39143c",
'longitude',
'',
'Longitude, expressed in decimal degrees where eastern figures are positve
and western ones are negative.',
'',
'longitude',
0,
Expand All @@ -57,31 +58,14 @@ INSERT INTO O_ATTR
"66920350-b77d-4876-9b05-0c545b5437ae",
"e20254f9-1d38-4562-bba0-f7f597acd02d",
'latitude',
'',
'Latitude, expressed in decimal degrees, where northern figures are positive
and southern ones are negative.',
'',
'latitude',
0,
"ba5eda7a-def5-0000-0000-000000000003",
'',
'');
INSERT INTO O_NBATTR
VALUES ("fcb1ce20-5075-4388-b463-0bdb1e191283",
"66920350-b77d-4876-9b05-0c545b5437ae");
INSERT INTO O_BATTR
VALUES ("fcb1ce20-5075-4388-b463-0bdb1e191283",
"66920350-b77d-4876-9b05-0c545b5437ae");
INSERT INTO O_ATTR
VALUES ("fcb1ce20-5075-4388-b463-0bdb1e191283",
"66920350-b77d-4876-9b05-0c545b5437ae",
"0e9b613a-bc28-4a41-96e5-f6838133fe3e",
'speed',
'',
'',
'speed',
0,
"ba5eda7a-def5-0000-0000-000000000003",
'',
'');
INSERT INTO O_ID
VALUES (0,
"66920350-b77d-4876-9b05-0c545b5437ae");
Expand Down
Loading

0 comments on commit 2a7f741

Please sign in to comment.