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
e0474400
Commit
e0474400
authored
6 years ago
by
tina
Browse files
Options
Downloads
Patches
Plain Diff
changs output of getpredictedmenses, adds days to calendar
parent
497a3a3f
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
components/calendar.js
+32
-5
32 additions, 5 deletions
components/calendar.js
lib/cycle.js
+12
-8
12 additions, 8 deletions
lib/cycle.js
test/cycle.spec.js
+75
-51
75 additions, 51 deletions
test/cycle.spec.js
with
119 additions
and
64 deletions
components/calendar.js
+
32
−
5
View file @
e0474400
import
React
,
{
Component
}
from
'
react
'
import
{
CalendarList
}
from
'
react-native-calendars
'
import
{
getOrCreateCycleDay
,
bleedingDaysSortedByDate
}
from
'
../db
'
import
cycleModule
from
'
../lib/cycle
'
export
default
class
CalendarView
extends
Component
{
constructor
(
props
)
{
super
(
props
)
const
predictedMenses
=
cycleModule
().
getPredictedMenses
()
this
.
state
=
{
bleedingDaysInCalFormat
:
toCalFormat
(
bleedingDaysSortedByDate
)
bleedingDaysInCalFormat
:
toCalFormat
(
bleedingDaysSortedByDate
),
predictedBleedingDaysInCalFormat
:
predictionToCalFormat
(
predictedMenses
)
}
this
.
setStateWithCalFormattedDays
=
(
function
(
CalendarComponent
)
{
return
function
(
_
,
changes
)
{
if
(
Object
.
values
(
changes
).
every
(
x
=>
x
&&
!
x
.
length
))
return
return
function
()
{
const
predictedMenses
=
cycleModule
().
getPredictedMenses
()
CalendarComponent
.
setState
({
bleedingDaysInCalFormat
:
toCalFormat
(
bleedingDaysSortedByDate
)
bleedingDaysInCalFormat
:
toCalFormat
(
bleedingDaysSortedByDate
),
predictedBleedingDaysInCalFormat
:
predictionToCalFormat
(
predictedMenses
)
})
}
})(
this
)
...
...
@@ -35,7 +39,13 @@ export default class CalendarView extends Component {
return
(
<
CalendarList
onDayPress
=
{
this
.
passDateToDayView
.
bind
(
this
)}
markedDates
=
{
this
.
state
.
bleedingDaysInCalFormat
}
markedDates
=
{
Object
.
assign
(
{},
this
.
state
.
bleedingDaysInCalFormat
,
this
.
state
.
predictedBleedingDaysInCalFormat
)
}
markingType
=
{
'
period
'
}
/
>
)
...
...
@@ -52,4 +62,21 @@ function toCalFormat(bleedingDaysSortedByDate) {
}
return
acc
},
{})
}
function
predictionToCalFormat
(
predictedDays
)
{
if
(
!
predictedDays
.
length
)
return
{}
const
shadesOfGrey
=
[
'
#e5e5e5
'
,
'
#cccccc
'
]
// [lighter, darker]
const
middleIndex
=
(
predictedDays
[
0
].
length
-
1
)
/
2
return
predictedDays
.
reduce
((
acc
,
setOfDays
)
=>
{
setOfDays
.
reduce
((
accSet
,
day
,
i
)
=>
{
accSet
[
day
]
=
{
startingDay
:
true
,
endingDay
:
true
,
color
:
(
i
===
middleIndex
)
?
shadesOfGrey
[
1
]
:
shadesOfGrey
[
0
]
}
return
accSet
},
acc
)
return
acc
},
{})
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
lib/cycle.js
+
12
−
8
View file @
e0474400
...
...
@@ -163,12 +163,11 @@ export default function config(opts) {
function
getPredictedMenses
()
{
const
allMensesStarts
=
getAllMensesStarts
()
const
atLeastOneCycle
=
allMensesStarts
.
length
>
1
if
(
!
atLeastOneCycle
||
allMensesStarts
.
length
<
minCyclesForPrediction
)
{
return
{}
return
[]
}
const
cycleLengths
=
getCycleLength
(
allMensesStarts
)
const
cycleInfo
=
getCycleLengthStats
(
cycleLengths
)
...
...
@@ -181,15 +180,20 @@ export default function config(opts) {
}
else
{
periodStartVariation
=
2
}
var
lastStart
=
allMensesStarts
[
0
]
if
(
periodDistance
-
5
<
periodStartVariation
)
{
// otherwise predictions overlap
return
[]
}
let
lastStart
=
LocalDate
.
parse
(
allMensesStarts
[
0
])
const
predictedMenses
=
[]
for
(
let
i
=
0
;
i
<
3
;
i
++
)
{
lastStart
=
LocalDate
.
parse
(
lastStart
).
plusDays
(
periodDistance
).
toString
()
const
nextPredictedRange
=
{
'
startDate
'
:
LocalDate
.
parse
(
lastStart
).
minusDays
(
periodStartVariation
).
toString
(),
'
endDate
'
:
LocalDate
.
parse
(
lastStart
).
plusDays
(
periodStartVariation
).
toString
()
lastStart
=
lastStart
.
plusDays
(
periodDistance
)
const
nextPredictedDates
=
[
lastStart
.
toString
()]
for
(
let
j
=
0
;
j
<
periodStartVariation
;
j
++
)
{
nextPredictedDates
.
push
(
lastStart
.
minusDays
(
j
+
1
).
toString
())
nextPredictedDates
.
push
(
lastStart
.
plusDays
(
j
+
1
).
toString
())
}
predictedMenses
.
push
(
nextPredictedRange
)
nextPredictedDates
.
sort
()
predictedMenses
.
push
(
nextPredictedDates
)
}
return
predictedMenses
}
...
...
This diff is collapsed.
Click to expand it.
test/cycle.spec.js
+
75
−
51
View file @
e0474400
...
...
@@ -357,7 +357,7 @@ describe('getPredictedMenses', () => {
minCyclesForPrediction
:
1
})
const
result
=
getPredictedMenses
()
expect
(
result
).
to
.
eql
(
{}
)
expect
(
result
).
to
.
eql
(
[]
)
})
it
(
'
if one bleeding is documented (no completed cycle)
'
,
()
=>
{
const
cycleDaysSortedByDate
=
[
...
...
@@ -374,7 +374,7 @@ describe('getPredictedMenses', () => {
minCyclesForPrediction
:
1
})
const
result
=
getPredictedMenses
()
expect
(
result
).
to
.
eql
(
{}
)
expect
(
result
).
to
.
eql
(
[]
)
})
it
(
'
if number of cycles is below minCyclesForPrediction
'
,
()
=>
{
const
cycleDaysSortedByDate
=
[
...
...
@@ -397,7 +397,7 @@ describe('getPredictedMenses', () => {
bleedingDaysSortedByDate
:
cycleDaysSortedByDate
.
filter
(
d
=>
d
.
bleeding
)
})
const
result
=
getPredictedMenses
()
expect
(
result
).
to
.
eql
(
{}
)
expect
(
result
).
to
.
eql
(
[]
)
})
})
describe
(
'
works
'
,
()
=>
{
...
...
@@ -420,18 +420,27 @@ describe('getPredictedMenses', () => {
})
const
result
=
getPredictedMenses
()
const
expectedResult
=
[
{
'
startDate
'
:
'
2018-07-27
'
,
'
endDate
'
:
'
2018-07-31
'
},
{
'
startDate
'
:
'
2018-08-10
'
,
'
endDate
'
:
'
2018-08-14
'
},
{
'
startDate
'
:
'
2018-08-24
'
,
'
endDate
'
:
'
2018-08-28
'
}
[
'
2018-07-27
'
,
'
2018-07-28
'
,
'
2018-07-29
'
,
'
2018-07-30
'
,
'
2018-07-31
'
],
[
'
2018-08-10
'
,
'
2018-08-11
'
,
'
2018-08-12
'
,
'
2018-08-13
'
,
'
2018-08-14
'
,
],
[
'
2018-08-24
'
,
'
2018-08-25
'
,
'
2018-08-26
'
,
'
2018-08-27
'
,
'
2018-08-28
'
,
]
]
expect
(
result
).
to
.
eql
(
expectedResult
)
})
...
...
@@ -461,18 +470,21 @@ describe('getPredictedMenses', () => {
})
const
result
=
getPredictedMenses
()
const
expectedResult
=
[
{
'
startDate
'
:
'
2018-09-01
'
,
'
endDate
'
:
'
2018-09-03
'
},
{
'
startDate
'
:
'
2018-10-02
'
,
'
endDate
'
:
'
2018-10-04
'
},
{
'
startDate
'
:
'
2018-11-02
'
,
'
endDate
'
:
'
2018-11-04
'
}
[
'
2018-09-01
'
,
'
2018-09-02
'
,
'
2018-09-03
'
],
[
'
2018-10-02
'
,
'
2018-10-03
'
,
'
2018-10-04
'
],
[
'
2018-11-02
'
,
'
2018-11-03
'
,
'
2018-11-04
'
]
]
expect
(
result
).
to
.
eql
(
expectedResult
)
})
...
...
@@ -502,18 +514,21 @@ describe('getPredictedMenses', () => {
})
const
result
=
getPredictedMenses
()
const
expectedResult
=
[
{
'
startDate
'
:
'
2018-08-14
'
,
'
endDate
'
:
'
2018-08-16
'
},
{
'
startDate
'
:
'
2018-08-28
'
,
'
endDate
'
:
'
2018-08-30
'
},
{
'
startDate
'
:
'
2018-09-11
'
,
'
endDate
'
:
'
2018-09-13
'
}
[
'
2018-08-14
'
,
'
2018-08-15
'
,
'
2018-08-16
'
],
[
'
2018-08-28
'
,
'
2018-08-29
'
,
'
2018-08-30
'
],
[
'
2018-09-11
'
,
'
2018-09-12
'
,
'
2018-09-13
'
]
]
expect
(
result
).
to
.
eql
(
expectedResult
)
})
...
...
@@ -543,18 +558,27 @@ describe('getPredictedMenses', () => {
})
const
result
=
getPredictedMenses
()
const
expectedResult
=
[
{
'
startDate
'
:
'
2018-08-13
'
,
'
endDate
'
:
'
2018-08-17
'
},
{
'
startDate
'
:
'
2018-08-27
'
,
'
endDate
'
:
'
2018-08-31
'
},
{
'
startDate
'
:
'
2018-09-10
'
,
'
endDate
'
:
'
2018-09-14
'
}
[
'
2018-08-13
'
,
'
2018-08-14
'
,
'
2018-08-15
'
,
'
2018-08-16
'
,
'
2018-08-17
'
,
],
[
'
2018-08-27
'
,
'
2018-08-28
'
,
'
2018-08-29
'
,
'
2018-08-30
'
,
'
2018-08-31
'
,
],
[
'
2018-09-10
'
,
'
2018-09-11
'
,
'
2018-09-12
'
,
'
2018-09-13
'
,
'
2018-09-14
'
,
]
]
expect
(
result
).
to
.
eql
(
expectedResult
)
})
...
...
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