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
2b2e24bb
Commit
2b2e24bb
authored
6 years ago
by
Julia Friesel
Browse files
Options
Downloads
Patches
Plain Diff
Add isMensesStart
parent
1b20658e
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/cycle.js
+21
-1
21 additions, 1 deletion
lib/cycle.js
test/cycle.spec.js
+142
-0
142 additions, 0 deletions
test/cycle.spec.js
with
163 additions
and
1 deletion
lib/cycle.js
+
21
−
1
View file @
2b2e24bb
...
...
@@ -133,6 +133,25 @@ export default function config(opts) {
}
}
function
isMensesStart
(
cycleDay
)
{
if
(
!
cycleDay
.
bleeding
||
cycleDay
.
bleeding
.
exclude
)
return
false
const
bleedingDays
=
bleedingDaysSortedByDate
if
(
noBleedingDayWithinThreshold
(
cycleDay
))
{
return
true
}
return
false
function
noBleedingDayWithinThreshold
(
day
)
{
const
localDate
=
LocalDate
.
parse
(
day
.
date
)
const
threshold
=
localDate
.
minusDays
(
maxBreakInBleeding
+
1
).
toString
()
const
index
=
bleedingDays
.
findIndex
(
day
=>
day
.
date
===
cycleDay
.
date
)
const
previousBleedingDays
=
bleedingDays
.
slice
(
index
+
1
)
return
!
previousBleedingDays
.
some
(
day
=>
{
return
day
.
date
>=
threshold
&&
!
day
.
bleeding
.
exclude
})
}
}
function
getCycleLength
(
cycleStartDates
)
{
const
cycleLengths
=
[]
for
(
let
i
=
0
;
i
<
cycleStartDates
.
length
-
1
;
i
++
)
{
...
...
@@ -188,6 +207,7 @@ export default function config(opts) {
getCyclesBefore
,
getAllMensesStarts
,
getCycleLength
,
getPredictedMenses
getPredictedMenses
,
isMensesStart
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
test/cycle.spec.js
+
142
−
0
View file @
2b2e24bb
...
...
@@ -685,4 +685,146 @@ describe('getAllMensesStart', () => {
expect
(
result
.
length
).
to
.
eql
(
500
)
expect
(
duration
).
to
.
be
.
lessThan
(
100
)
})
})
describe
(
'
isMensesStart
'
,
()
=>
{
it
(
'
works for simple menses start
'
,
()
=>
{
const
cycleDaysSortedByDate
=
[
{
date
:
'
2018-05-04
'
,
},
{
date
:
'
2018-05-03
'
,
bleeding
:
{
value
:
1
}
},
{
date
:
'
2018-05-02
'
,
bleeding
:
{
value
:
1
}
},
{
date
:
'
2018-05-01
'
,
bleeding
:
{
value
:
1
}
},
{
date
:
'
2018-04-30
'
,
}
]
const
{
isMensesStart
}
=
cycleModule
({
cycleDaysSortedByDate
,
bleedingDaysSortedByDate
:
cycleDaysSortedByDate
.
filter
(
d
=>
d
.
bleeding
)
})
const
start
=
isMensesStart
(
cycleDaysSortedByDate
[
3
])
expect
(
start
).
to
.
be
.
true
()
expect
(
isMensesStart
(
cycleDaysSortedByDate
[
0
])).
to
.
be
.
false
()
expect
(
isMensesStart
(
cycleDaysSortedByDate
[
1
])).
to
.
be
.
false
()
expect
(
isMensesStart
(
cycleDaysSortedByDate
[
2
])).
to
.
be
.
false
()
expect
(
isMensesStart
(
cycleDaysSortedByDate
[
4
])).
to
.
be
.
false
()
})
it
(
'
works with previous excluded value
'
,
()
=>
{
const
cycleDaysSortedByDate
=
[
{
date
:
'
2018-06-01
'
,
bleeding
:
{
value
:
2
}
},
{
date
:
'
2018-05-01
'
,
bleeding
:
{
value
:
2
}
},
{
date
:
'
2018-04-30
'
,
bleeding
:
{
value
:
2
,
exclude
:
true
}
},
]
const
{
isMensesStart
}
=
cycleModule
({
cycleDaysSortedByDate
,
bleedingDaysSortedByDate
:
cycleDaysSortedByDate
.
filter
(
d
=>
d
.
bleeding
)
})
const
start
=
isMensesStart
(
cycleDaysSortedByDate
[
1
])
expect
(
start
).
to
.
be
.
true
()
const
notStart
=
isMensesStart
(
cycleDaysSortedByDate
[
2
])
expect
(
notStart
).
to
.
be
.
false
()
})
it
(
'
returns false when day has no bleeding
'
,
()
=>
{
const
cycleDaysSortedByDate
=
[
{
date
:
'
2018-06-01
'
,
},
{
date
:
'
2018-05-01
'
,
},
{
date
:
'
2018-04-30
'
,
bleeding
:
{
value
:
2
,
exclude
:
true
}
},
]
const
{
isMensesStart
}
=
cycleModule
({
cycleDaysSortedByDate
,
bleedingDaysSortedByDate
:
cycleDaysSortedByDate
.
filter
(
d
=>
d
.
bleeding
)
})
const
start
=
isMensesStart
(
cycleDaysSortedByDate
[
0
])
expect
(
start
).
to
.
be
.
false
()
})
it
(
'
returns false when there is a previous bleeding day within the threshold
'
,
()
=>
{
const
cycleDaysSortedByDate
=
[
{
date
:
'
2018-06-01
'
,
},
{
date
:
'
2018-05-01
'
,
},
{
date
:
'
2018-04-30
'
,
bleeding
:
{
value
:
2
}
},
{
date
:
'
2018-04-29
'
},
{
date
:
'
2018-04-28
'
,
bleeding
:
{
value
:
2
}
},
]
const
{
isMensesStart
}
=
cycleModule
({
cycleDaysSortedByDate
,
bleedingDaysSortedByDate
:
cycleDaysSortedByDate
.
filter
(
d
=>
d
.
bleeding
)
})
const
start
=
isMensesStart
(
cycleDaysSortedByDate
[
2
])
expect
(
start
).
to
.
be
.
false
()
})
it
(
'
returns true when there is a previous excluded bleeding day within the threshold
'
,
()
=>
{
const
cycleDaysSortedByDate
=
[
{
date
:
'
2018-06-01
'
,
},
{
date
:
'
2018-05-01
'
,
},
{
date
:
'
2018-04-30
'
,
bleeding
:
{
value
:
2
}
},
{
date
:
'
2018-04-29
'
},
{
date
:
'
2018-04-28
'
,
bleeding
:
{
value
:
2
,
exclude
:
true
}
},
]
const
{
isMensesStart
}
=
cycleModule
({
cycleDaysSortedByDate
,
bleedingDaysSortedByDate
:
cycleDaysSortedByDate
.
filter
(
d
=>
d
.
bleeding
)
})
const
start
=
isMensesStart
(
cycleDaysSortedByDate
[
2
])
expect
(
start
).
to
.
be
.
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