-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
128 lines (119 loc) · 5.42 KB
/
main.js
File metadata and controls
128 lines (119 loc) · 5.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
function onLap() { trace('--- onLap ---'); }
function onAutoLap() { trace('--- onAutoLap ---'); }
function onInterval() { trace('--- onInterval ---'); }
function onPoolLength() { trace('--- onPoolLength ---'); }
function onExerciseStart() { trace('--- onExerciseStart ---'); }
function onExercisePause() { trace('--- onExercisePause ---'); }
function onExerciseContinue() { trace('--- onExerciseContinue ---'); }
function onExerciseEnd() { trace('--- onExerciseEnd ---'); }
function onExercisePause() { trace('--- onExerciseEnd ---'); }
function onExerciseContinue() { trace('--- onExerciseEnd ---'); }
*/
// Output var climbAttempts: Number of times you make a route or ascent/descent in indoor climbing.
// Output var climbDurationAscentDescent: The time it takes to complete a route or ascent/descent in indoor climbing.
// Output var climbDurationAscent: The ascent in meters in indoor climbing.
// main.js var climbDurationDescent: The time it takes to descend in indoor climbing.
// main.js var climbTotalAscent: Total training climb minus current climb.
// main.js var climbTotalDescent: Total training decrease minus current decrease.
// Output var climbAttemptAscent: Ascent in meters of actual ascent or indoor climbing route.
// main.js var climbAttemptDescent: Descent in meters of actual descent or indoor climbing route.
// main.js var limbTotalDurationAscent: Total Time Duration Ascent in workout
// main.js var climbTotalDurationDescent: Total Time Duration Descent in workout
// main.js var Ascending: Value True o Fasle to detect if is Ascending
// main.js var Descending: Value True o Fasle to detect if is Descending
// Watch var DurationAscent: Total time in the workout that the watch calculate Ascent Time.
// Watch var DurationDescent: Total time in the workout that the watch calculate Descent Time.
// Watch var AscentMeters: Total Ascent meters in the workout.
// Watch var DescentMeters: Total Descent meters in the workout.
// .toFixed(0) Without decimals
var Ascending, Descending, climbAttemptDescent, climbTotalAscent, climbTotalDescent, climbDistanceAttempAscent,
climbDistanceStartAttempAscent, climbRightTriangle;
function evaluate(input, output) {
output.climbAttemptAscent = input.AscentMeters.toFixed(0) - climbTotalAscent;
climbAttemptDescent = input.DescentMeters.toFixed(0) - climbTotalDescent;
if ((output.climbAttemptAscent > 0) && (climbAttemptDescent == 0)) {
if (climbDistanceStartAttempAscent == 0) {
// Save the distance when start the Ascent
climbDistanceStartAttempAscent = input.Distance
}else{
// Save the Speed
output.climbPaceAscent = input.Speed
// Save the Distance in meters when ascensing because later generate the angle of each Attempt
climbDistanceAttempAscent = input.Distance - climbDistanceStartAttempAscent;
if (climbDistanceAttempAscent > output.climbAttemptAscent) {
// Pythagoras theorem ( Calc the Right Triangle )
climbRightTriangle = Math.sqrt(Math.pow(climbDistanceAttempAscent, 2) - Math.pow(output.climbAttemptAscent, 2));
// Calculate the angle of Cos
output.climbAngleAscent = Math.acos(climbRightTriangle/climbDistanceAttempAscent)*(180/Math.PI);;
} else if (climbDistanceAttempAscent == output.climbAttemptAscent){
output.climbAngleAscent = 90;
} else {
output.climbAngleAscent = 0;
}
}
Ascending = true;
Ascending = false;
} else if ((climbAttemptDescent > 0) && (output.climbAttemptAscent > 0)) {
Descending = true;
Ascending = false;
}else {
climbTotalDescent = input.DescentMeters.toFixed(0);
}
if ((output.climbAttemptAscent <= climbAttemptDescent) &&
((Ascending == false ) && (Descending == true))) {
// Trigger lap once
$.put("/Activity/Trigger", 0);
}
}
function onExerciseStart(input, output) {
// Initializing Variables
output.climbPaceAscent = 0;
output.climbAttempts = 0;
climbTotalAscent = 0;
climbTotalDescent = 0;
output.climbAttemptAscent = 0;
climbAttemptDescent = 0;
climbDistanceAttempAscent = 0;
climbDistanceStartAttempAscent = 0;
climbRightTriangle = 0;
Ascending = 'false';
Descending = 'false';
}
function onLap(input, output) {
// Collect the latest data
// Use this var to save the data on SA for each lap
climbDistanceAttempAscent = input.Distance - climbDistanceStartAttempAscent;
// Initializing Variables for new Ascent and increase output.climbAttempts Variable
output.climbPaceAscent = 0;
output.climbAttemptAscent = 0;
climbAttemptDescent = 0;
climbDistanceAttempAscent = 0;
climbDistanceStartAttempAscent = 0;
output.climbAngleAscent = 0;
climbRightTriangle = 0;
climbTotalAscent = input.AscentMeters.toFixed(0);
climbTotalDescent = input.DescentMeters.toFixed(0);
output.climbAttempts = output.climbAttempts + 1;
Ascending = 'false';
Descending = 'false';
}
function getUserInterface(input, output) {
return {
template: 't'
};
}
// This is called also when user backs from exercise start panel without starting
// exercise. onExerciseEnd() is not working at all as zapp gets disabled before
// it is called (and it would be called only when exercise is really started).
function getSummaryOutputs(input, output) {
return [
{
// Save the data of number of times you make a route or ascent/descent in indoor climbing into SA.
id: 'climbAttempts',
name: "Number of Ascent",
format: 'Count_Threedigits',
value: output.climbAttempts
},
];
}