Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
Drip
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
backup
Drip
Commits
03a0f1fb
Commit
03a0f1fb
authored
6 years ago
by
Julia Friesel
Browse files
Options
Downloads
Patches
Plain Diff
Implement second exception rule
parent
8db92e96
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/sensiplan.js
+31
-1
31 additions, 1 deletion
lib/sensiplan.js
test/sensiplan.spec.js
+56
-0
56 additions, 0 deletions
test/sensiplan.spec.js
with
87 additions
and
1 deletion
lib/sensiplan.js
+
31
−
1
View file @
03a0f1fb
...
...
@@ -42,6 +42,7 @@ function detectTemperatureShift(temperaturesOfCycle) {
}
function
rounded
(
val
,
step
)
{
// we round the difference because of JS decimal weirdness
const
inverted
=
1
/
step
return
Math
.
round
(
val
*
inverted
)
/
inverted
}
...
...
@@ -73,6 +74,16 @@ function checkIfFirstHighMeasurement(temp, i, temps, ltl) {
}
}
if
(
secondExceptionRuleApplies
(
temp
,
nextTemps
,
ltl
))
{
return
{
isFirstHighMeasurement
:
true
,
rules
:
{
secondException
:
true
,
},
ltl
}
}
return
{
isFirstHighMeasurement
:
false
}
...
...
@@ -81,18 +92,37 @@ function checkIfFirstHighMeasurement(temp, i, temps, ltl) {
function
regularRuleApplies
(
temp
,
nextTemps
,
ltl
)
{
if
(
!
nextTemps
.
every
(
temp
=>
temp
>
ltl
))
return
false
const
thirdTemp
=
nextTemps
[
1
]
// we round the difference because of JS decimal weirdness
if
(
rounded
(
thirdTemp
-
ltl
,
0.1
)
<
0.2
)
return
false
return
true
}
function
firstExceptionRuleApplies
(
temp
,
nextTemps
,
ltl
)
{
if
(
nextTemps
.
length
<
3
)
return
false
if
(
!
nextTemps
.
every
(
temp
=>
temp
>
ltl
))
return
false
const
fourthTemp
=
nextTemps
[
2
]
if
(
fourthTemp
>
ltl
)
return
true
return
false
}
function
secondExceptionRuleApplies
(
temp
,
nextTemps
,
ltl
)
{
if
(
nextTemps
.
length
<
3
)
return
false
if
(
secondOrThirdTempIsAtOrBelowLtl
(
nextTemps
,
ltl
))
{
const
fourthTemp
=
nextTemps
[
2
]
if
(
rounded
(
fourthTemp
-
ltl
,
0.1
)
>=
0.2
)
return
true
}
return
false
}
function
secondOrThirdTempIsAtOrBelowLtl
(
nextTemps
,
ltl
)
{
const
secondIsLow
=
nextTemps
[
0
]
<=
ltl
const
thirdIsLow
=
nextTemps
[
1
]
<=
ltl
if
((
secondIsLow
||
thirdIsLow
)
&&
!
(
secondIsLow
&&
thirdIsLow
))
{
return
true
}
else
{
return
false
}
}
export
{
detectTemperatureShift
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/sensiplan.spec.js
+
56
−
0
View file @
03a0f1fb
...
...
@@ -82,6 +82,12 @@ describe.only('sensiplan', () => {
expect
(
status
).
to
.
eql
({
detected
:
false
})
})
it
(
'
detects missing temperature shift with not enough high temps
'
,
function
()
{
const
temps
=
[
36.7
,
36.57
,
36.47
,
36.49
,
36.57
,
36.62
,
36.55
,
36.8
,
36.86
,
36.77
]
const
status
=
detectTemperatureShift
(
temps
)
expect
(
status
).
to
.
eql
({
detected
:
false
})
})
it
(
'
detects shift after an earlier one was invalid
'
,
function
()
{
const
temps
=
[
36.4
,
36.4
,
36.4
,
36.4
,
36.4
,
36.4
,
36.6
,
36.6
,
36.4
,
36.4
,
36.7
,
36.7
,
36.7
,
36.7
]
...
...
@@ -95,5 +101,55 @@ describe.only('sensiplan', () => {
})
})
})
describe
(
'
2nd exception rule
'
,
()
=>
{
it
(
'
detects temperature shift with exception temp eql ltl
'
,
function
()
{
const
secondException
=
[
36.7
,
36.57
,
36.47
,
36.49
,
36.57
,
36.62
,
36.55
,
36.8
,
36.86
,
36.6
,
36.8
]
const
status
=
detectTemperatureShift
(
secondException
)
expect
(
status
).
to
.
eql
({
low
:
[
36.55
,
36.45
,
36.5
,
36.55
,
36.6
,
36.55
],
ltl
:
36.6
,
high
:
[
36.8
,
36.85
,
36.6
,
36.8
],
detected
:
true
,
rules
:
{
secondException
:
true
}
})
})
it
(
'
detects temperature shift with exception temp lower than ltl
'
,
function
()
{
const
secondException
=
[
36.7
,
36.57
,
36.47
,
36.49
,
36.57
,
36.62
,
36.55
,
36.8
,
36.86
,
36.4
,
36.8
]
const
status
=
detectTemperatureShift
(
secondException
)
expect
(
status
).
to
.
eql
({
low
:
[
36.55
,
36.45
,
36.5
,
36.55
,
36.6
,
36.55
],
ltl
:
36.6
,
high
:
[
36.8
,
36.85
,
36.4
,
36.8
],
detected
:
true
,
rules
:
{
secondException
:
true
}
})
})
it
(
'
detects missing temperature shift correctly
'
,
function
()
{
const
temps
=
[
36.7
,
36.57
,
36.47
,
36.49
,
36.57
,
36.62
,
36.55
,
36.8
,
36.86
,
36.4
,
36.77
,
36.77
]
const
status
=
detectTemperatureShift
(
temps
)
expect
(
status
).
to
.
eql
({
detected
:
false
})
})
it
(
'
detects missing temperature shift when not enough high temps
'
,
function
()
{
const
temps
=
[
36.7
,
36.57
,
36.47
,
36.49
,
36.57
,
36.62
,
36.55
,
36.8
,
36.86
,
36.4
]
const
status
=
detectTemperatureShift
(
temps
)
expect
(
status
).
to
.
eql
({
detected
:
false
})
})
it
(
'
detects shift after an earlier one was invalid
'
,
function
()
{
const
temps
=
[
36.7
,
36.57
,
36.47
,
36.49
,
36.57
,
36.62
,
36.55
,
36.8
,
36.86
,
36.4
,
36.77
,
36.9
,
36.9
,
36.86
,
37.04
]
const
status
=
detectTemperatureShift
(
temps
)
expect
(
status
).
to
.
eql
({
low
:
[
36.6
,
36.55
,
36.8
,
36.85
,
36.4
,
36.75
],
ltl
:
36.85
,
high
:
[
36.9
,
36.9
,
36.85
,
37.05
],
detected
:
true
,
rules
:
{
secondException
:
true
}
})
})
})
})
})
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment