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
85e2703b
Commit
85e2703b
authored
6 years ago
by
Julia Friesel
Browse files
Options
Downloads
Patches
Plain Diff
Get previous cycles before detecting fertility status
parent
8a8b1310
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
components/cycle-day.js
+1
-2
1 addition, 2 deletions
components/cycle-day.js
lib/cycle.js
+27
-3
27 additions, 3 deletions
lib/cycle.js
lib/sympto-adapter.js
+10
-6
10 additions, 6 deletions
lib/sympto-adapter.js
test/cycle.spec.js
+135
-47
135 additions, 47 deletions
test/cycle.spec.js
with
173 additions
and
58 deletions
components/cycle-day.js
+
1
−
2
View file @
85e2703b
...
...
@@ -43,10 +43,9 @@ export default class Day extends Component {
Cycle
day
{
cycleDayNumber
}
<
/Text>
}
{
cycleDayNumber
&&
<
Text
style
=
{
styles
.
cycleDayNumber
}
>
{
fertilityStatus
}
<
/Text>
}
<
/Text
>
<
/View
>
<
View
style
=
{
styles
.
cycleDaySymptomsView
}
>
{
...
...
This diff is collapsed.
Click to expand it.
lib/cycle.js
+
27
−
3
View file @
85e2703b
import
*
as
joda
from
'
js-joda
'
const
LocalDate
=
joda
.
LocalDate
export
default
function
config
(
opts
)
{
...
...
@@ -49,14 +50,16 @@ export default function config(opts) {
return
!
previousBleedingDays
.
some
(({
wrappedDate
})
=>
wrappedDate
.
equals
(
periodThreshold
)
||
wrappedDate
.
isAfter
(
periodThreshold
))
}
withWrappedDates
.
forEach
(
day
=>
delete
day
.
wrappedDate
)
return
lastPeriodStart
}
function
getCycleDayNumber
(
targetDateString
)
{
const
lastMensesStart
=
getLastMensesStart
(
targetDateString
)
if
(
!
lastMensesStart
)
return
null
const
targetDate
=
joda
.
LocalDate
.
parse
(
targetDateString
)
const
diffInDays
=
lastMensesStart
.
wrappedDate
.
until
(
targetDate
,
joda
.
ChronoUnit
.
DAYS
)
const
targetDate
=
LocalDate
.
parse
(
targetDateString
)
const
lastMensesLocalDate
=
LocalDate
.
parse
(
lastMensesStart
.
date
)
const
diffInDays
=
lastMensesLocalDate
.
until
(
targetDate
,
joda
.
ChronoUnit
.
DAYS
)
// cycle starts at day 1
return
diffInDays
+
1
...
...
@@ -73,15 +76,36 @@ export default function config(opts) {
function
getCycleDaysBeforeDay
(
targetDateString
)
{
const
firstCycleDay
=
getLastMensesStart
(
targetDateString
)
if
(
!
firstCycleDay
)
return
null
return
cycleDaysSortedByDate
.
filter
(({
date
})
=>
{
return
date
>=
firstCycleDay
.
date
&&
date
<=
targetDateString
})
}
function
getPreviousCycles
(
targetCycleStartDay
)
{
let
previousCycleStartIndex
=
cycleDaysSortedByDate
.
indexOf
(
targetCycleStartDay
)
const
cycles
=
[]
while
(
previousCycleStartIndex
<
cycleDaysSortedByDate
.
length
-
1
)
{
const
prevDate
=
cycleDaysSortedByDate
[
previousCycleStartIndex
+
1
].
date
const
cycleStart
=
getLastMensesStart
(
prevDate
)
if
(
!
cycleStart
)
break
const
cycleStartIndex
=
cycleDaysSortedByDate
.
indexOf
(
cycleStart
)
const
lastDayInCycle
=
previousCycleStartIndex
+
1
const
cycle
=
cycleDaysSortedByDate
.
slice
(
lastDayInCycle
,
cycleStartIndex
+
1
)
cycles
.
push
(
cycle
)
previousCycleStartIndex
=
cycleStartIndex
}
return
cycles
}
return
{
getCycleDayNumber
,
getLastMensesStart
,
getPreviousTemperaturesInCycle
,
getCycleDaysBeforeDay
getCycleDaysBeforeDay
,
getPreviousCycles
}
}
This diff is collapsed.
Click to expand it.
lib/sympto-adapter.js
+
10
−
6
View file @
85e2703b
import
getFertilityStatus
from
'
./sympto
'
import
cycleModule
from
'
./cycle
'
const
{
getCycleDaysBeforeDay
}
=
cycleModule
()
const
{
getCycleDaysBeforeDay
,
getPreviousCycles
}
=
cycleModule
()
export
default
function
(
dateString
)
{
const
cycle
=
getCycleDaysBeforeDay
(
dateString
)
if
(
!
cycle
)
return
`We cannot show any cycle information because no menses has been entered`
// we get earliest last, but sympto wants earliest first
const
cycle
=
getCycleDaysBeforeDay
(
dateString
).
reverse
()
// const previousCycles = getPreviousCycles()
const
status
=
getFertilityStatus
({
cycle
})
cycle
.
reverse
()
const
previousCycles
=
getPreviousCycles
(
cycle
[
0
])
previousCycles
.
forEach
(
cycle
=>
cycle
.
reverse
())
const
status
=
getFertilityStatus
({
cycle
,
previousCycles
})
return
formatStatusForApp
(
status
)
}
function
formatStatusForApp
(
status
)
{
const
fertileStatus
=
status
.
assumeFertility
?
'
fertile
'
:
'
infertile
'
return
`You are currently
${
fertileStatus
}
`
return
status
.
assumeFertility
?
'
fertile
'
:
'
infertile
'
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/cycle.spec.js
+
135
−
47
View file @
85e2703b
...
...
@@ -23,7 +23,7 @@ describe('getCycleDay', () => {
value
:
2
}
}]
const
getCycleDayNumber
=
cycleModule
({
bleedingDaysSortedByDate
:
bleedingDays
}).
getCycleDayNumber
const
getCycleDayNumber
=
cycleModule
({
bleedingDaysSortedByDate
:
bleedingDays
}).
getCycleDayNumber
const
targetDate
=
'
2018-05-17
'
const
result
=
getCycleDayNumber
(
targetDate
)
expect
(
result
).
to
.
eql
(
9
)
...
...
@@ -49,7 +49,7 @@ describe('getCycleDay', () => {
}
}]
const
targetDate
=
'
2018-05-17
'
const
getCycleDayNumber
=
cycleModule
({
bleedingDaysSortedByDate
:
bleedingDays
}).
getCycleDayNumber
const
getCycleDayNumber
=
cycleModule
({
bleedingDaysSortedByDate
:
bleedingDays
}).
getCycleDayNumber
const
result
=
getCycleDayNumber
(
targetDate
)
expect
(
result
).
to
.
eql
(
15
)
})
...
...
@@ -73,7 +73,7 @@ describe('getCycleDay', () => {
}]
const
targetDate
=
'
2018-04-27
'
const
getCycleDayNumber
=
cycleModule
({
bleedingDaysSortedByDate
:
bleedingDays
}).
getCycleDayNumber
const
getCycleDayNumber
=
cycleModule
({
bleedingDaysSortedByDate
:
bleedingDays
}).
getCycleDayNumber
const
result
=
getCycleDayNumber
(
targetDate
)
expect
(
result
).
to
.
eql
(
18
)
})
...
...
@@ -87,59 +87,147 @@ describe('getCycleDay', () => {
}]
const
targetDate
=
'
2018-05-13
'
const
getCycleDayNumber
=
cycleModule
({
bleedingDaysSortedByDate
:
bleedingDays
}).
getCycleDayNumber
const
getCycleDayNumber
=
cycleModule
({
bleedingDaysSortedByDate
:
bleedingDays
}).
getCycleDayNumber
const
result
=
getCycleDayNumber
(
targetDate
)
expect
(
result
).
to
.
eql
(
1
)
})
})
describe
(
'
getCycleDay returns null
'
,
()
=>
{
it
(
'
if there are no bleeding days
'
,
function
()
{
const
bleedingDays
=
[]
const
targetDate
=
'
2018-05-17
'
const
getCycleDayNumber
=
cycleModule
({
bleedingDaysSortedByDate
:
bleedingDays
}).
getCycleDayNumber
const
result
=
getCycleDayNumber
(
targetDate
)
expect
(
result
).
to
.
be
.
null
()
describe
(
'
getCycleDay returns null
'
,
()
=>
{
it
(
'
if there are no bleeding days
'
,
function
()
{
const
bleedingDays
=
[]
const
targetDate
=
'
2018-05-17
'
const
getCycleDayNumber
=
cycleModule
({
bleedingDaysSortedByDate
:
bleedingDays
}).
getCycleDayNumber
const
result
=
getCycleDayNumber
(
targetDate
)
expect
(
result
).
to
.
be
.
null
()
})
})
})
describe
(
'
getCycleDay with cycle thresholds
'
,
()
=>
{
const
maxBreakInBleeding
=
3
describe
(
'
getCycleDay with cycle thresholds
'
,
()
=>
{
const
maxBreakInBleeding
=
3
it
(
'
disregards bleeding breaks shorter than max allowed bleeding break in a bleeding period
'
,
()
=>
{
const
bleedingDays
=
[{
date
:
'
2018-05-14
'
,
bleeding
:
{
value
:
2
}
},
{
date
:
'
2018-05-10
'
,
bleeding
:
{
value
:
2
}
}]
it
(
'
disregards bleeding breaks shorter than max allowed bleeding break in a bleeding period
'
,
()
=>
{
const
bleedingDays
=
[{
date
:
'
2018-05-14
'
,
bleeding
:
{
value
:
2
}
},
{
date
:
'
2018-05-10
'
,
bleeding
:
{
value
:
2
}
}]
const
targetDate
=
'
2018-05-17
'
const
getCycleDayNumber
=
cycleModule
({
bleedingDaysSortedByDate
:
bleedingDays
,
maxBreakInBleeding
}).
getCycleDayNumber
const
result
=
getCycleDayNumber
(
targetDate
)
expect
(
result
).
to
.
eql
(
8
)
const
targetDate
=
'
2018-05-17
'
const
getCycleDayNumber
=
cycleModule
({
bleedingDaysSortedByDate
:
bleedingDays
,
maxBreakInBleeding
}).
getCycleDayNumber
const
result
=
getCycleDayNumber
(
targetDate
)
expect
(
result
).
to
.
eql
(
8
)
})
it
(
'
counts bleeding breaks longer than maxAllowedBleedingBreak in a bleeding period
'
,
()
=>
{
const
bleedingDays
=
[{
date
:
'
2018-05-14
'
,
bleeding
:
{
value
:
2
}
},
{
date
:
'
2018-05-09
'
,
bleeding
:
{
value
:
2
}
}]
const
targetDate
=
'
2018-05-17
'
const
getCycleDayNumber
=
cycleModule
({
bleedingDaysSortedByDate
:
bleedingDays
,
maxBreakInBleeding
}).
getCycleDayNumber
const
result
=
getCycleDayNumber
(
targetDate
)
expect
(
result
).
to
.
eql
(
4
)
})
})
})
it
(
'
counts bleeding breaks longer than maxAllowedBleedingBreak in a bleeding period
'
,
()
=>
{
const
bleedingDays
=
[{
date
:
'
2018-05-14
'
,
bleeding
:
{
value
:
2
}
},
{
date
:
'
2018-05-09
'
,
bleeding
:
{
value
:
2
}
}]
const
targetDate
=
'
2018-05-17
'
const
getCycleDayNumber
=
cycleModule
({
bleedingDaysSortedByDate
:
bleedingDays
,
maxBreakInBleeding
}).
getCycleDayNumber
const
result
=
getCycleDayNumber
(
targetDate
)
expect
(
result
).
to
.
eql
(
4
)
describe
(
'
getPreviousCycles
'
,
()
=>
{
it
(
'
gets previous cycles
'
,
()
=>
{
const
cycleDaysSortedByDate
=
[
{
date
:
'
2018-07-05
'
,
bleeding
:
{
value
:
2
}
},
{
date
:
'
2018-06-05
'
,
bleeding
:
{
value
:
2
}
},
{
date
:
'
2018-05-05
'
,
mucus
:
{
value
:
2
}
},
{
date
:
'
2018-05-04
'
,
bleeding
:
{
value
:
2
}
},
{
date
:
'
2018-05-03
'
,
bleeding
:
{
value
:
2
}
},
{
date
:
'
2018-04-05
'
,
mucus
:
{
value
:
2
}
},
{
date
:
'
2018-04-04
'
,
mucus
:
{
value
:
2
}
},
{
date
:
'
2018-04-03
'
,
mucus
:
{
value
:
2
}
},
{
date
:
'
2018-04-02
'
,
bleeding
:
{
value
:
2
}
},
]
const
{
getPreviousCycles
}
=
cycleModule
({
cycleDaysSortedByDate
,
bleedingDaysSortedByDate
:
cycleDaysSortedByDate
.
filter
(
d
=>
d
.
bleeding
)
})
const
result
=
getPreviousCycles
(
cycleDaysSortedByDate
[
0
])
expect
(
result
.
length
).
to
.
eql
(
3
)
expect
(
result
).
to
.
eql
([
[
{
date
:
'
2018-06-05
'
,
bleeding
:
{
value
:
2
}
}
],
[
{
date
:
'
2018-05-05
'
,
mucus
:
{
value
:
2
}
},
{
date
:
'
2018-05-04
'
,
bleeding
:
{
value
:
2
}
},
{
date
:
'
2018-05-03
'
,
bleeding
:
{
value
:
2
}
}
],
[
{
date
:
'
2018-04-05
'
,
mucus
:
{
value
:
2
}
},
{
date
:
'
2018-04-04
'
,
mucus
:
{
value
:
2
}
},
{
date
:
'
2018-04-03
'
,
mucus
:
{
value
:
2
}
},
{
date
:
'
2018-04-02
'
,
bleeding
:
{
value
:
2
}
},
]
])
})
})
\ 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