Skip to content

Commit

Permalink
#27 - Refactored goal evaluation to produce an enumerated return code
Browse files Browse the repository at this point in the history
and no side effects, leaving the goal state machine to handle
achievement records and updating of the disposition attribute.
  • Loading branch information
John Wolfe committed Jul 10, 2014
1 parent 380c459 commit 0aca187
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ INSERT INTO O_TFR
"c1022670-c44d-401e-bb23-dfcef6084fba",
'evaluateAchievement',
'',
"ba5eda7a-def5-0000-0000-000000000000",
"e153b5eb-d36e-485d-b6a4-0b55cde4ed29",
1,
'// Based on the type of goal, determine whether this one is
// currently being achieved and update the appropriate attribute.
// currently being achieved and return a value indicating
// the disposition of the this goal.

// Find the related goal specification and workout session for this goal.
select one goalSpec related by self->GoalSpec[R9.''specified by''];
Expand All @@ -99,41 +100,26 @@ elif ( goalSpec.CriteriaType == GoalCriteria::Pace )
else
LOG::LogFailure( message: "Goal.evaluateAchievement: Unknown Goal Criteria Type." );
end if;

// Save current value for handling of achievement records.
previousAchievement = self.isBeingAchieved;

// Compare the current value against the criteria and update the attribute
// indicating goal achievement status.
if ( (goalSpec.Minimum <= currentValue) and (currentValue <= goalSpec.Maximum) )
self.isBeingAchieved = true;
else
self.isBeingAchieved = false;
end if;

// Update achievement records if necessary. There are four cases:
// 0. Still not achieving this goal.
// 1. Just started achieving this goal.
// 2. Just stopped achieving this goal.
// 3. Still achieving this goal.
// For cases 0 and 3, there is nothing to be done for achievement records.
// Case 1 requires the creation of a new achievment record, storing the start time.
// Case 2 requires the storing of the end time for the open achievement record.
if ( (not previousAchievement) and self.isBeingAchieved )
// Case 1, create achievement record, store start time, relate it as open record.
create object instance achievement of Achievement;
relate self to achievement across R14.''has open'';
select one workoutTimer related by session->WorkoutTimer[R8.''is timed by''];
achievement.startTime = workoutTimer.time;
elif ( previousAchievement and (not self.isBeingAchieved) )
// Case 2, store end time, relate as recorded record, unrelate as open record.
select one achievement related by self->Achievement[R14.''has open''];
achievement.close();
// Compare the current value against the criteria to calculate the return value.
goalDisposition = GoalDisposition::Achieving;
if ( currentValue < goalSpec.Minimum )
goalDisposition = GoalDisposition::Increase;
elif ( currentValue > goalSpec.Maximum )
goalDisposition = GoalDisposition::Decrease;
end if;
',

return( goalDisposition );',
1,
'',
"b3215204-3d02-48ba-9794-25ddbc40009c");
INSERT INTO S_DT_PROXY
VALUES ("e153b5eb-d36e-485d-b6a4-0b55cde4ed29",
"00000000-0000-0000-0000-000000000000",
'GoalDisposition',
'Disposition of a currently executing goal.',
'',
'../../TrackingDataTypes/TrackingDataTypes.xtuml');
INSERT INTO O_TFR
VALUES ("7090ad22-2865-4836-a89f-a46b868d3ac0",
"c1022670-c44d-401e-bb23-dfcef6084fba",
Expand Down Expand Up @@ -185,12 +171,12 @@ INSERT INTO O_ATTR
VALUES ("fa9000ac-0495-47fe-bbaf-66bc8f9a4f0a",
"c1022670-c44d-401e-bb23-dfcef6084fba",
"7d60ba72-b691-4687-9636-20d33798168c",
'isBeingAchieved',
'True whenver the goal is currently being achieved, false otherwise.',
'disposition',
'The disposition of this goal. See data type descriptions for details.',
'',
'isBeingAchieved',
'disposition',
0,
"ba5eda7a-def5-0000-0000-000000000001",
"e153b5eb-d36e-485d-b6a4-0b55cde4ed29",
'',
'');
INSERT INTO O_NBATTR
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,31 @@ INSERT INTO SM_ACT
"7fc80988-4415-437c-acc5-4c130cc2715d",
1,
'// Determine whether this goal is currently being achieved.
self.evaluateAchievement();
disposition = self.evaluateAchievement();

// Update achievement records if necessary. There are four cases:
// 0. Still not achieving this goal.
// 1. Just started achieving this goal.
// 2. Just stopped achieving this goal.
// 3. Still achieving this goal.
// For cases 0 and 3, there is nothing to be done for achievement records.
// Case 1 requires the creation of a new achievment record, storing the start time.
// Case 2 requires the storing of the end time for the open achievement record.
if ( (self.disposition != GoalDisposition::Achieving) and (disposition == GoalDisposition::Achieving) )
// Case 1, create achievement record, store start time, relate it as open record.
create object instance achievement of Achievement;
relate self to achievement across R14.''has open'';
select one workoutTimer related by
self->WorkoutSession[R11.''is currently executing within'']->WorkoutTimer[R8.''is timed by''];
achievement.startTime = workoutTimer.time;
elif ( (self.disposition == GoalDisposition::Achieving) and (disposition != GoalDisposition::Achieving) )
// Case 2, store end time, relate as recorded record, unrelate as open record.
select one achievement related by self->Achievement[R14.''has open''];
achievement.close();
end if;

// Update disposition of this goal.
self.disposition = disposition;

// Determine whether execution of this goal is complete,
// and if so, advance to the next one if it exists.
Expand Down Expand Up @@ -176,7 +200,7 @@ INSERT INTO SM_AH
INSERT INTO SM_ACT
VALUES ("2dc59cdd-01b1-43c9-acb1-a07fd46b57aa",
"7fc80988-4415-437c-acc5-4c130cc2715d",
3,
1,
'',
'');
INSERT INTO SM_TAH
Expand All @@ -189,7 +213,7 @@ INSERT INTO SM_AH
INSERT INTO SM_ACT
VALUES ("cb9002c9-d6c7-4e38-b011-9821a4b28430",
"7fc80988-4415-437c-acc5-4c130cc2715d",
3,
1,
'',
'');
INSERT INTO GD_MD
Expand Down Expand Up @@ -223,11 +247,11 @@ INSERT INTO GD_SHP
INSERT INTO GD_NCS
VALUES ("11ca3dfe-8c51-49db-951f-4bcf9c349dd7");
INSERT INTO DIM_ND
VALUES (349.000000,
144.000000,
VALUES (565.000000,
541.000000,
"11ca3dfe-8c51-49db-951f-4bcf9c349dd7");
INSERT INTO DIM_GE
VALUES (4104.000000,
VALUES (4032.000000,
3084.000000,
"11ca3dfe-8c51-49db-951f-4bcf9c349dd7",
"00000000-0000-0000-0000-000000000000");
Expand All @@ -237,7 +261,7 @@ INSERT INTO DIM_ELE
"00000000-0000-0000-0000-000000000000");
INSERT INTO DIM_CON
VALUES ("bf1c05cb-62f4-4158-a22c-f1eea42f07d2",
4453.000000,
4597.000000,
3132.000000,
"11ca3dfe-8c51-49db-951f-4bcf9c349dd7");
INSERT INTO DIM_CON
Expand All @@ -247,13 +271,13 @@ INSERT INTO DIM_CON
"11ca3dfe-8c51-49db-951f-4bcf9c349dd7");
INSERT INTO DIM_CON
VALUES ("0bbfb44f-3419-4927-b876-00cde45ded43",
4104.000000,
3168.000000,
4597.000000,
3324.000000,
"11ca3dfe-8c51-49db-951f-4bcf9c349dd7");
INSERT INTO DIM_CON
VALUES ("2d90f4e2-522a-43ad-8a6e-a8f46ac81cd9",
4320.000000,
3228.000000,
4500.000000,
3625.000000,
"11ca3dfe-8c51-49db-951f-4bcf9c349dd7");
INSERT INTO GD_GE
VALUES ("70725233-fd31-4b3f-8009-40b0e332d040",
Expand All @@ -271,7 +295,7 @@ INSERT INTO DIM_ND
409.000000,
"70725233-fd31-4b3f-8009-40b0e332d040");
INSERT INTO DIM_GE
VALUES (4704.000000,
VALUES (4848.000000,
3084.000000,
"70725233-fd31-4b3f-8009-40b0e332d040",
"00000000-0000-0000-0000-000000000000");
Expand All @@ -281,7 +305,7 @@ INSERT INTO DIM_ELE
"00000000-0000-0000-0000-000000000000");
INSERT INTO DIM_CON
VALUES ("6671936b-d4ef-4c36-95c4-d01cd8e0969b",
4704.000000,
4848.000000,
3132.000000,
"70725233-fd31-4b3f-8009-40b0e332d040");
INSERT INTO DIM_CON
Expand Down Expand Up @@ -329,7 +353,7 @@ INSERT INTO DIM_ND
0.000000,
"70c82ccc-754d-4204-969b-f9f10d735b95");
INSERT INTO DIM_GE
VALUES (4461.500000,
VALUES (4605.500000,
3103.000000,
"70c82ccc-754d-4204-969b-f9f10d735b95",
"00000000-0000-0000-0000-000000000000");
Expand Down Expand Up @@ -364,14 +388,14 @@ INSERT INTO GD_LS
"c7c86751-1ec7-4a14-bfc5-6efe3cf22dc0");
INSERT INTO DIM_WAY
VALUES ("fc9c1379-7b56-49eb-ae7d-9e56700c41de",
4453.000000,
4597.000000,
3132.000000,
"a8cd31e1-a403-49b2-82c8-0177f95634c1",
"00000000-0000-0000-0000-000000000000",
"00000000-0000-0000-0000-000000000000");
INSERT INTO DIM_WAY
VALUES ("c7c86751-1ec7-4a14-bfc5-6efe3cf22dc0",
4704.000000,
4848.000000,
3132.000000,
"a8cd31e1-a403-49b2-82c8-0177f95634c1",
"00000000-0000-0000-0000-000000000000",
Expand Down Expand Up @@ -429,7 +453,7 @@ INSERT INTO DIM_ND
0.000000,
"e1d94218-45bd-4a86-b11b-6f59bcb293cf");
INSERT INTO DIM_GE
VALUES (4063.000000,
VALUES (4612.000000,
3288.000000,
"e1d94218-45bd-4a86-b11b-6f59bcb293cf",
"00000000-0000-0000-0000-000000000000");
Expand Down Expand Up @@ -482,36 +506,36 @@ INSERT INTO GD_LS
"2eaff31b-b4cc-40a6-85bb-c6fe24d1a178");
INSERT INTO DIM_WAY
VALUES ("50902b0d-47ea-4166-939d-cde182942486",
4104.000000,
3168.000000,
4597.000000,
3324.000000,
"0907b6e7-e62c-41be-99cd-693a2cd24c46",
"00000000-0000-0000-0000-000000000000",
"00000000-0000-0000-0000-000000000000");
INSERT INTO DIM_WAY
VALUES ("2eaff31b-b4cc-40a6-85bb-c6fe24d1a178",
4320.000000,
3228.000000,
4500.000000,
3625.000000,
"0907b6e7-e62c-41be-99cd-693a2cd24c46",
"00000000-0000-0000-0000-000000000000",
"50902b0d-47ea-4166-939d-cde182942486");
INSERT INTO DIM_WAY
VALUES ("58a283a5-d132-4f2e-8367-6207efd9ca28",
4054.000000,
3168.000000,
4692.000000,
3324.000000,
"0907b6e7-e62c-41be-99cd-693a2cd24c46",
"00000000-0000-0000-0000-000000000000",
"00000000-0000-0000-0000-000000000000");
INSERT INTO DIM_WAY
VALUES ("83eee3fc-a8fa-4232-a079-2b24acf13826",
4054.000000,
3276.000000,
4692.000000,
3696.000000,
"0907b6e7-e62c-41be-99cd-693a2cd24c46",
"00000000-0000-0000-0000-000000000000",
"00000000-0000-0000-0000-000000000000");
INSERT INTO DIM_WAY
VALUES ("d8153263-61d3-4146-9854-5211354cb02b",
4320.000000,
3276.000000,
4500.000000,
3696.000000,
"0907b6e7-e62c-41be-99cd-693a2cd24c46",
"00000000-0000-0000-0000-000000000000",
"00000000-0000-0000-0000-000000000000");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,30 @@ INSERT INTO DIM_ELE
VALUES ("482e08f9-2455-49fb-bf09-5bcaf3ea9dfd",
0,
"00000000-0000-0000-0000-000000000000");
INSERT INTO GD_GE
VALUES ("91d2b472-fbf5-492f-9438-c2c7d5e865d5",
"8c48868c-fd80-4c09-9ff7-dd45951d216a",
"e153b5eb-d36e-485d-b6a4-0b55cde4ed29",
52,
0,
'GPS Watch::Library::Tracking::TrackingDataTypes::GoalDisposition');
INSERT INTO GD_SHP
VALUES ("91d2b472-fbf5-492f-9438-c2c7d5e865d5");
INSERT INTO GD_NCS
VALUES ("91d2b472-fbf5-492f-9438-c2c7d5e865d5");
INSERT INTO DIM_ND
VALUES (200.000000,
150.000000,
"91d2b472-fbf5-492f-9438-c2c7d5e865d5");
INSERT INTO DIM_GE
VALUES (880.000000,
0.000000,
"91d2b472-fbf5-492f-9438-c2c7d5e865d5",
"00000000-0000-0000-0000-000000000000");
INSERT INTO DIM_ELE
VALUES ("91d2b472-fbf5-492f-9438-c2c7d5e865d5",
0,
"00000000-0000-0000-0000-000000000000");
INSERT INTO DIM_DIA
VALUES ("8c48868c-fd80-4c09-9ff7-dd45951d216a",
'',
Expand Down Expand Up @@ -183,6 +207,42 @@ INSERT INTO PE_PE
"37e62abd-d1c2-4241-a4cb-9aa88fabd6e8",
"00000000-0000-0000-0000-000000000000",
3);
INSERT INTO S_DT
VALUES ("e153b5eb-d36e-485d-b6a4-0b55cde4ed29",
"00000000-0000-0000-0000-000000000000",
'GoalDisposition',
'Disposition of a currently executing goal.',
'');
INSERT INTO S_EDT
VALUES ("e153b5eb-d36e-485d-b6a4-0b55cde4ed29");
INSERT INTO S_ENUM
VALUES ("8e563bda-95e4-4245-9414-c1dc95fea6b7",
'Achieving',
'The goal is currently being achieved.',
"e153b5eb-d36e-485d-b6a4-0b55cde4ed29",
"00000000-0000-0000-0000-000000000000");
INSERT INTO S_ENUM
VALUES ("aeb64a36-39dc-45ed-bfde-24d961548a5a",
'Increase',
'The value associated with the goal is presently below the minimum
specified in the criteria for the goal, so the user must increase
that value to achieve the goal.',
"e153b5eb-d36e-485d-b6a4-0b55cde4ed29",
"8e563bda-95e4-4245-9414-c1dc95fea6b7");
INSERT INTO S_ENUM
VALUES ("59e4ad59-df4b-46b2-b301-bf5f80b7f4e7",
'Decrease',
'The value associated with the goal is presently above the maximum
specified in the criteria for the goal, so the user must decrease
that value to achieve the goal.',
"e153b5eb-d36e-485d-b6a4-0b55cde4ed29",
"aeb64a36-39dc-45ed-bfde-24d961548a5a");
INSERT INTO PE_PE
VALUES ("e153b5eb-d36e-485d-b6a4-0b55cde4ed29",
1,
"37e62abd-d1c2-4241-a4cb-9aa88fabd6e8",
"00000000-0000-0000-0000-000000000000",
3);
INSERT INTO CNST_CSP
VALUES ("cd9009a0-95bc-4a39-851d-9c2e1820316a",
'WorkoutTimer',
Expand Down

0 comments on commit 0aca187

Please sign in to comment.