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
f7e1152f
Commit
f7e1152f
authored
6 years ago
by
Julia Friesel
Browse files
Options
Downloads
Patches
Plain Diff
Implement 5-day-rule
parent
0179c458
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/sympto/index.js
+14
-7
14 additions, 7 deletions
lib/sympto/index.js
lib/sympto/pre-ovulatory.js
+21
-0
21 additions, 0 deletions
lib/sympto/pre-ovulatory.js
test/sympto/index.spec.js
+51
-45
51 additions, 45 deletions
test/sympto/index.spec.js
with
86 additions
and
52 deletions
lib/sympto/index.js
+
14
−
7
View file @
f7e1152f
import
getTemperatureShift
from
'
./temperature
'
import
getMucusShift
from
'
./mucus
'
import
getPreOvulatoryPhase
from
'
./pre-ovulatory
'
import
{
LocalDate
}
from
'
js-joda
'
export
default
function
({
cycle
,
previousCycle
})
{
// TODO check for basic stuff, throw if nonexistent
...
...
@@ -8,8 +10,7 @@ export default function ({ cycle, previousCycle }) {
phases
:
{
periOvulatory
:
{
start
:
{
date
:
null
,
time
:
'
00:00
'
date
:
null
},
cycleDays
:
null
}
...
...
@@ -18,13 +19,19 @@ export default function ({ cycle, previousCycle }) {
// if there was no first higher measurement in the previous cycle,
// no infertile preovulatory phase may be assumed
if
(
getTemperatureShift
(
previousCycle
).
detected
&&
!
cycle
[
0
].
mucus
)
{
status
.
phases
.
preOvulatory
=
getPreOvulatoryPhase
(
cycle
)
}
if
(
getTemperatureShift
(
previousCycle
).
detected
)
{
// add preOvulatory phase
const
periPhase
=
status
.
phases
.
periOvulatory
if
(
status
.
phases
.
preOvulatory
)
{
const
prePhase
=
status
.
phases
.
preOvulatory
periPhase
.
start
.
date
=
LocalDate
.
parse
(
prePhase
.
end
.
date
).
plusDays
(
1
).
toString
()
const
lastPreDay
=
prePhase
.
cycleDays
[
prePhase
.
cycleDays
.
length
-
1
]
periPhase
.
cycleDays
=
cycle
.
slice
(
cycle
.
indexOf
(
lastPreDay
)
+
1
)
}
else
{
const
first
=
cycle
[
0
]
status
.
phases
.
periOvulatory
.
start
.
date
=
first
.
date
status
.
phases
.
periOvulatory
.
cycleDays
=
[...
cycle
]
periPhase
.
start
.
date
=
cycle
[
0
].
date
periPhase
.
cycleDays
=
[...
cycle
]
}
const
temperatureShift
=
getTemperatureShift
(
cycle
)
...
...
This diff is collapsed.
Click to expand it.
lib/sympto/pre-ovulatory.js
0 → 100644
+
21
−
0
View file @
f7e1152f
export
default
function
(
cycle
)
{
const
fiveDayRuleDays
=
cycle
.
slice
(
0
,
5
)
const
preOvulatoryDays
=
getDaysUntilFertileMucus
(
fiveDayRuleDays
)
return
{
cycleDays
:
preOvulatoryDays
,
start
:
{
date
:
preOvulatoryDays
[
0
].
date
},
end
:
{
date
:
preOvulatoryDays
[
preOvulatoryDays
.
length
-
1
].
date
,
}
}
}
function
getDaysUntilFertileMucus
(
days
)
{
const
firstFertileMucusDayIndex
=
days
.
findIndex
(
day
=>
day
.
mucus
&&
day
.
mucus
.
value
>
1
)
if
(
firstFertileMucusDayIndex
>
-
1
)
{
return
days
.
slice
(
0
,
firstFertileMucusDayIndex
)
}
return
days
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/sympto/index.spec.js
+
51
−
45
View file @
f7e1152f
...
...
@@ -4,7 +4,9 @@ import getSensiplanStatus from '../../lib/sympto'
const
expect
=
chai
.
expect
function
convertToSymptoFormat
(
val
,
i
)
{
const
sympto
=
{
date
:
i
}
++
i
const
dayString
=
i
<
10
?
`0
${
i
}
`
:
i
const
sympto
=
{
date
:
`2018-06-
${
dayString
}
`
}
if
(
val
.
temperature
)
sympto
.
temperature
=
{
value
:
val
.
temperature
}
if
(
val
.
mucus
)
sympto
.
mucus
=
{
value
:
val
.
mucus
}
if
(
val
.
bleeding
)
sympto
.
bleeding
=
{
value
:
val
.
bleeding
}
...
...
@@ -49,6 +51,31 @@ const cycleWithTempAndMucusShift = [
{
temperature
:
36.9
,
mucus
:
1
}
].
map
(
convertToSymptoFormat
)
const
cycleWithTempAndNoMucusShift
=
[
{
temperature
:
36.6
,
bleeding
:
2
},
{
temperature
:
36.65
},
{
temperature
:
36.5
},
{
temperature
:
36.6
},
{
temperature
:
36.55
},
{
temperature
:
36.7
,
mucus
:
0
},
{
temperature
:
36.75
,
mucus
:
0
},
{
temperature
:
36.45
,
mucus
:
1
},
{
temperature
:
36.5
,
mucus
:
4
},
{
temperature
:
36.4
,
mucus
:
2
},
{
temperature
:
36.5
,
mucus
:
3
},
{
temperature
:
36.55
,
mucus
:
3
},
{
temperature
:
36.45
,
mucus
:
3
},
{
temperature
:
36.5
,
mucus
:
4
},
{
temperature
:
36.55
,
mucus
:
4
},
{
temperature
:
36.7
,
mucus
:
3
},
{
temperature
:
36.65
,
mucus
:
3
},
{
temperature
:
36.75
,
mucus
:
4
},
{
temperature
:
36.8
,
mucus
:
4
},
{
temperature
:
36.85
,
mucus
:
4
},
{
temperature
:
36.8
,
mucus
:
4
},
{
temperature
:
36.9
,
mucus
:
4
}
].
map
(
convertToSymptoFormat
)
describe
(
'
sympto
'
,
()
=>
{
describe
(
'
evaluating mucus and temperature shift together
'
,
()
=>
{
describe
(
'
with no previous higher measurement
'
,
()
=>
{
...
...
@@ -74,10 +101,7 @@ describe('sympto', () => {
assumeFertility
:
true
,
phases
:
{
periOvulatory
:
{
start
:
{
date
:
0
,
time
:
'
00:00
'
},
start
:
{
date
:
'
2018-06-01
'
},
cycleDays
:
cycle
}
},
...
...
@@ -95,15 +119,12 @@ describe('sympto', () => {
expect
(
status
.
assumeFertility
).
to
.
be
.
true
()
expect
(
Object
.
keys
(
status
.
phases
)).
to
.
eql
([
'
periOvulatory
'
,
'
postOvulatory
'
])
expect
(
status
.
phases
.
periOvulatory
).
to
.
eql
({
start
:
{
date
:
0
,
time
:
'
00:00
'
},
start
:
{
date
:
'
2018-06-01
'
},
cycleDays
:
cycleWithTempAndMucusShift
.
slice
(
0
,
21
)
})
expect
(
status
.
phases
.
postOvulatory
).
to
.
eql
({
start
:
{
date
:
20
,
date
:
'
20
18-06-21
'
,
time
:
'
18:00
'
},
cycleDays
:
cycleWithTempAndMucusShift
.
slice
(
20
)
...
...
@@ -111,42 +132,27 @@ describe('sympto', () => {
})
})
})
describe
(
'
with shifts
'
,
()
=>
{
it
.
skip
(
'
reports fertile when mucus reaches best quality again within temperature evaluation phase
'
,
function
()
{
const
status
=
getSensiplanStatus
(
temperatures
)
expect
(
status
).
to
.
eql
({
assumeFertility
:
false
,
phases
:
{
preOvulatory
:
{
startDate
:
0
,
startTime
:
'
00:00
'
},
periOvulatory
:
'
TODO
'
,
postOvulatory
:
{
startDate
:
17
,
startTime
:
'
18:00
'
}
},
temperatureShift
:
{
detected
:
true
,
ltl
:
36.55
,
rule
:
0
,
firstHighMeasurementDay
:
{
date
:
15
,
temperature
:
{
value
:
36.7
},
mucus
:
{
value
:
3
}
},
evaluationCompleteDay
:
{
date
:
17
,
temperature
:
{
value
:
36.75
},
mucus
:
{
value
:
4
},
}
},
mucusShift
:
{
detected
:
true
,
mucusPeak
:
{
date
:
17
,
mucus
:
{
value
:
4
},
temperature
:
{
value
:
36.75
},
}
}
describe
(
'
with previous higher measurement
'
,
()
=>
{
describe
(
'
with no shifts detects pre- and periovulatory phase
'
,
function
()
{
it
(
'
according to 5-day-rule
'
,
function
()
{
const
status
=
getSensiplanStatus
({
cycle
:
cycleWithTempAndNoMucusShift
,
previousCycle
:
cycleWithTempShift
})
expect
(
Object
.
keys
(
status
.
phases
)).
to
.
eql
([
'
periOvulatory
'
,
'
preOvulatory
'
])
expect
(
status
.
assumeFertility
).
to
.
be
.
true
()
expect
(
status
.
phases
.
preOvulatory
).
to
.
eql
({
cycleDays
:
cycleWithTempAndNoMucusShift
.
slice
(
0
,
5
),
start
:
{
date
:
'
2018-06-01
'
},
end
:
{
date
:
'
2018-06-05
'
}
})
expect
(
status
.
phases
.
periOvulatory
).
to
.
eql
({
cycleDays
:
cycleWithTempAndNoMucusShift
.
slice
(
5
),
start
:
{
date
:
'
2018-06-06
'
}
})
})
})
})
})
})
\ 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