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
a90d3935
Commit
a90d3935
authored
6 years ago
by
Julia Friesel
Browse files
Options
Downloads
Patches
Plain Diff
Return potential high temps as well
parent
5e060132
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
+24
-19
24 additions, 19 deletions
lib/sensiplan.js
test/sensiplan.spec.js
+11
-13
11 additions, 13 deletions
test/sensiplan.spec.js
with
35 additions
and
32 deletions
lib/sensiplan.js
+
24
−
19
View file @
a90d3935
...
@@ -2,8 +2,6 @@ function detectTemperatureShift(temperaturesOfCycle) {
...
@@ -2,8 +2,6 @@ function detectTemperatureShift(temperaturesOfCycle) {
// sensiplan rounds temps to the nearest 0.05
// sensiplan rounds temps to the nearest 0.05
const
tempValues
=
temperaturesOfCycle
.
map
(
val
=>
rounded
(
val
,
0.05
))
const
tempValues
=
temperaturesOfCycle
.
map
(
val
=>
rounded
(
val
,
0.05
))
let
detectingPotentialHighLevel
=
false
return
tempValues
.
reduce
((
acc
,
curr
)
=>
{
return
tempValues
.
reduce
((
acc
,
curr
)
=>
{
// if we don't yet have 6 lower temps, we just collect
// if we don't yet have 6 lower temps, we just collect
// if no shift has been detected, we collect low temps
// if no shift has been detected, we collect low temps
...
@@ -11,32 +9,23 @@ function detectTemperatureShift(temperaturesOfCycle) {
...
@@ -11,32 +9,23 @@ function detectTemperatureShift(temperaturesOfCycle) {
// of the higher temperature phase
// of the higher temperature phase
if
(
acc
.
low
.
length
<
6
)
{
if
(
acc
.
low
.
length
<
6
)
{
acc
.
low
.
push
(
curr
)
acc
.
low
.
push
(
curr
)
acc
.
ltl
=
Math
.
max
(...
acc
.
low
.
slice
(
-
6
)
)
acc
.
ltl
=
Math
.
max
(...
acc
.
low
)
// TODO these are the same
// TODO these are the same
}
else
if
(
curr
<=
acc
.
ltl
&&
!
detectingP
otentialHigh
Level
&&
!
acc
.
shiftDetected
)
{
}
else
if
(
curr
<=
acc
.
ltl
&&
!
acc
.
p
otentialHigh
&&
!
acc
.
shiftDetected
)
{
acc
.
low
.
push
(
curr
)
acc
.
low
.
push
(
curr
)
acc
.
ltl
=
Math
.
max
(...
acc
.
low
.
slice
(
-
6
))
acc
.
low
.
shift
(
curr
)
acc
.
ltl
=
Math
.
max
(...
acc
.
low
)
}
else
if
(
!
acc
.
shiftDetected
){
if
(
!
acc
.
potentialHigh
)
acc
.
potentialHigh
=
[]
acc
.
potentialHigh
.
push
(
curr
)
checkRules
(
acc
,
curr
)
}
else
{
}
else
{
detectingPotentialHighLevel
=
true
acc
.
high
.
push
(
curr
)
acc
.
high
.
push
(
curr
)
}
}
// regular rule
// we round the difference because of JS decimal weirdness
if
(
acc
.
high
.
length
===
3
&&
rounded
(
curr
-
acc
.
ltl
,
0.01
)
>=
0.2
)
{
acc
.
shiftDetected
=
true
detectingPotentialHighLevel
=
false
}
// 1st exception rule
if
(
acc
.
high
.
length
===
4
&&
curr
>
acc
.
ltl
)
{
acc
.
shiftDetected
=
true
detectingPotentialHighLevel
=
false
}
return
acc
return
acc
},
{
},
{
low
:
[],
low
:
[],
high
:
[],
ltl
:
null
,
ltl
:
null
,
shiftDetected
:
false
shiftDetected
:
false
})
})
...
@@ -47,6 +36,22 @@ function rounded(val, step) {
...
@@ -47,6 +36,22 @@ function rounded(val, step) {
return
Math
.
round
(
val
*
inverted
)
/
inverted
return
Math
.
round
(
val
*
inverted
)
/
inverted
}
}
function
checkRules
(
acc
,
curr
)
{
function
regularRuleApplies
()
{
// we round the difference because of JS decimal weirdness
return
acc
.
potentialHigh
.
length
===
3
&&
rounded
(
curr
-
acc
.
ltl
,
0.01
)
>=
0.2
}
function
firstExceptionRuleApplies
()
{
return
acc
.
potentialHigh
.
length
===
4
&&
curr
>
acc
.
ltl
}
if
(
regularRuleApplies
()
||
firstExceptionRuleApplies
())
{
acc
.
shiftDetected
=
true
acc
.
high
=
acc
.
potentialHigh
delete
acc
.
potentialHigh
}
}
export
{
export
{
detectTemperatureShift
detectTemperatureShift
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/sensiplan.spec.js
+
11
−
13
View file @
a90d3935
...
@@ -12,8 +12,7 @@ describe.only('sensiplan', () => {
...
@@ -12,8 +12,7 @@ describe.only('sensiplan', () => {
expect
(
status
).
to
.
eql
({
expect
(
status
).
to
.
eql
({
low
:
[
36.7
,
36.55
,
36.45
,
36.5
,
36.55
],
low
:
[
36.7
,
36.55
,
36.45
,
36.5
,
36.55
],
ltl
:
36.7
,
ltl
:
36.7
,
high
:
[],
shiftDetected
:
false
,
shiftDetected
:
false
})
})
})
})
...
@@ -21,7 +20,7 @@ describe.only('sensiplan', () => {
...
@@ -21,7 +20,7 @@ describe.only('sensiplan', () => {
const
tempShift
=
[
36.7
,
36.57
,
36.47
,
36.49
,
36.57
,
36.62
,
36.55
,
36.8
,
36.86
,
36.8
]
const
tempShift
=
[
36.7
,
36.57
,
36.47
,
36.49
,
36.57
,
36.62
,
36.55
,
36.8
,
36.86
,
36.8
]
const
status
=
detectTemperatureShift
(
tempShift
)
const
status
=
detectTemperatureShift
(
tempShift
)
expect
(
status
).
to
.
eql
({
expect
(
status
).
to
.
eql
({
low
:
[
36.7
,
36.55
,
36.45
,
36.5
,
36.55
,
36.6
,
36.55
],
low
:
[
36.55
,
36.45
,
36.5
,
36.55
,
36.6
,
36.55
],
ltl
:
36.6
,
ltl
:
36.6
,
high
:
[
36.8
,
36.85
,
36.8
],
high
:
[
36.8
,
36.85
,
36.8
],
shiftDetected
:
true
shiftDetected
:
true
...
@@ -34,7 +33,7 @@ describe.only('sensiplan', () => {
...
@@ -34,7 +33,7 @@ describe.only('sensiplan', () => {
expect
(
status
).
to
.
eql
({
expect
(
status
).
to
.
eql
({
low
:
[
36.45
,
36.5
,
36.55
,
36.6
,
36.55
,
36.8
],
low
:
[
36.45
,
36.5
,
36.55
,
36.6
,
36.55
,
36.8
],
ltl
:
36.8
,
ltl
:
36.8
,
h
igh
:
[
36.85
,
36.8
],
potentialH
igh
:
[
36.85
,
36.8
],
shiftDetected
:
false
shiftDetected
:
false
})
})
})
})
...
@@ -43,9 +42,9 @@ describe.only('sensiplan', () => {
...
@@ -43,9 +42,9 @@ describe.only('sensiplan', () => {
const
tempShift
=
[
36.57
,
36.7
,
36.47
,
36.49
,
36.57
,
36.62
,
36.55
,
36.8
,
36.86
,
36.8
]
const
tempShift
=
[
36.57
,
36.7
,
36.47
,
36.49
,
36.57
,
36.62
,
36.55
,
36.8
,
36.86
,
36.8
]
const
status
=
detectTemperatureShift
(
tempShift
)
const
status
=
detectTemperatureShift
(
tempShift
)
expect
(
status
).
to
.
eql
({
expect
(
status
).
to
.
eql
({
low
:
[
36.55
,
36.7
,
36.45
,
36.5
,
36.55
,
36.6
,
36.55
],
low
:
[
36.7
,
36.45
,
36.5
,
36.55
,
36.6
,
36.55
],
ltl
:
36.7
,
ltl
:
36.7
,
h
igh
:
[
36.8
,
36.85
,
36.8
],
potentialH
igh
:
[
36.8
,
36.85
,
36.8
],
shiftDetected
:
false
shiftDetected
:
false
})
})
})
})
...
@@ -54,9 +53,9 @@ describe.only('sensiplan', () => {
...
@@ -54,9 +53,9 @@ describe.only('sensiplan', () => {
const
noTempShift
=
[
36.7
,
36.57
,
36.47
,
36.49
,
36.57
,
36.62
,
36.55
,
36.8
,
36.86
,
36.77
]
const
noTempShift
=
[
36.7
,
36.57
,
36.47
,
36.49
,
36.57
,
36.62
,
36.55
,
36.8
,
36.86
,
36.77
]
const
status
=
detectTemperatureShift
(
noTempShift
)
const
status
=
detectTemperatureShift
(
noTempShift
)
expect
(
status
).
to
.
eql
({
expect
(
status
).
to
.
eql
({
low
:
[
36.7
,
36.55
,
36.45
,
36.5
,
36.55
,
36.6
,
36.55
],
low
:
[
36.55
,
36.45
,
36.5
,
36.55
,
36.6
,
36.55
],
ltl
:
36.6
,
ltl
:
36.6
,
h
igh
:
[
36.8
,
36.85
,
36.75
],
potentialH
igh
:
[
36.8
,
36.85
,
36.75
],
shiftDetected
:
false
shiftDetected
:
false
})
})
})
})
...
@@ -67,20 +66,19 @@ describe.only('sensiplan', () => {
...
@@ -67,20 +66,19 @@ describe.only('sensiplan', () => {
const
firstException
=
[
36.7
,
36.57
,
36.47
,
36.49
,
36.57
,
36.62
,
36.55
,
36.8
,
36.86
,
36.77
,
36.63
]
const
firstException
=
[
36.7
,
36.57
,
36.47
,
36.49
,
36.57
,
36.62
,
36.55
,
36.8
,
36.86
,
36.77
,
36.63
]
const
status
=
detectTemperatureShift
(
firstException
)
const
status
=
detectTemperatureShift
(
firstException
)
expect
(
status
).
to
.
eql
({
expect
(
status
).
to
.
eql
({
low
:
[
36.7
,
36.55
,
36.45
,
36.5
,
36.55
,
36.6
,
36.55
],
low
:
[
36.55
,
36.45
,
36.5
,
36.55
,
36.6
,
36.55
],
ltl
:
36.6
,
ltl
:
36.6
,
high
:
[
36.8
,
36.85
,
36.75
,
36.65
],
high
:
[
36.8
,
36.85
,
36.75
,
36.65
],
shiftDetected
:
true
shiftDetected
:
true
})
})
})
})
it
(
'
detects missing temperature shift correctly
'
,
function
()
{
it
.
skip
(
'
detects missing temperature shift correctly
'
,
function
()
{
const
firstExceptionNoShift
=
[
36.7
,
36.57
,
36.47
,
36.49
,
36.57
,
36.62
,
36.55
,
36.8
,
36.86
,
36.77
,
36.57
]
const
firstExceptionNoShift
=
[
36.7
,
36.57
,
36.47
,
36.49
,
36.57
,
36.62
,
36.55
,
36.8
,
36.86
,
36.77
,
36.57
]
const
status
=
detectTemperatureShift
(
firstExceptionNoShift
)
const
status
=
detectTemperatureShift
(
firstExceptionNoShift
)
expect
(
status
).
to
.
eql
({
expect
(
status
).
to
.
eql
({
low
:
[
36.7
,
36.55
,
36.45
,
36.5
,
36.55
,
36.6
,
36.55
],
low
:
[
36.7
,
36.55
,
36.45
,
36.5
,
36.55
,
36.6
,
36.55
,
36.8
,
36.85
,
36.75
,
36.55
],
ltl
:
36.6
,
ltl
:
36.85
,
high
:
[
36.8
,
36.85
,
36.75
,
36.55
],
shiftDetected
:
false
shiftDetected
:
false
})
})
})
})
...
...
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