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
c99aa750
Commit
c99aa750
authored
6 years ago
by
tina
Browse files
Options
Downloads
Patches
Plain Diff
improves functions and stats are displayed in a nicer format
parent
6135c922
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
components/stats.js
+32
-21
32 additions, 21 deletions
components/stats.js
lib/cycle.js
+7
-11
7 additions, 11 deletions
lib/cycle.js
package-lock.json
+1494
-1494
1494 additions, 1494 deletions
package-lock.json
with
1533 additions
and
1526 deletions
components/stats.js
+
32
−
21
View file @
c99aa750
import
React
,
{
Component
}
from
'
react
'
import
{
View
,
Text
,
ScrollView
}
from
'
react-native
'
...
...
@@ -14,38 +13,50 @@ export default class Stats extends Component {
super
(
props
)
const
allMensesStarts
=
cycleModule
().
getAllMensesStarts
()
this
.
test
=
allMensesStarts
const
cycleLengths
=
getCycleLength
(
allMensesStarts
)
this
.
bla
=
cycleLengths
this
.
numberOfCycles
=
cycleLengths
.
length
this
.
periodInfo
=
getPeriodInfo
(
cycleLengths
)
this
.
state
=
{
text
:
determineStatsText
(
allMensesStarts
)
}
}
render
()
{
console
.
log
(
'
...............
'
)
console
.
log
(
this
.
test
)
console
.
log
(
this
.
bla
)
return
(
<
ScrollView
>
<
Text
style
=
{
styles
.
welcome
}
>
based
on
{
this
.
numberOfCycles
}
periods
:
<
/Text
>
<
Text
style
=
{
styles
.
welcome
}
>
min
:
{
this
.
periodInfo
.
minimum
}
<
/Text
>
<
Text
style
=
{
styles
.
welcome
}
>
mean
:
{
this
.
periodInfo
.
mean
}
<
/Text
>
<
Text
style
=
{
styles
.
welcome
}
>
max
:
{
this
.
periodInfo
.
maximum
}
<
/Text
>
<
Text
style
=
{
styles
.
welcome
}
>
median
:
{
this
.
periodInfo
.
median
}
<
/Text
>
<
Text
style
=
{
styles
.
welcome
}
>
standard
deviation
:
{
this
.
periodInfo
.
stdDeviation
}
<
/Text
>
<
Text
style
=
{
styles
.
welcome
}
>
{
this
.
state
.
text
}
<
/Text
>
<
/ScrollView
>
)
}
}
function
getCycleLength
(
cycleStartDates
)
{
const
cycleStartDatesReverse
=
cycleStartDates
.
reverse
()
const
periodLengths
=
[]
for
(
let
i
=
0
;
i
<
cycleStartDates
.
length
-
1
;
i
++
)
{
const
periodStart
=
LocalDate
.
parse
(
cycleStartDatesReverse
[
i
])
const
periodEnd
=
LocalDate
.
parse
(
cycleStartDatesReverse
[
i
+
1
])
periodLengths
.
unshift
(
periodStart
.
until
(
periodEnd
,
ChronoUnit
.
DAYS
))
const
nextPeriodStart
=
LocalDate
.
parse
(
cycleStartDates
[
i
])
const
periodStart
=
LocalDate
.
parse
(
cycleStartDates
[
i
+
1
])
periodLengths
.
push
(
periodStart
.
until
(
nextPeriodStart
,
ChronoUnit
.
DAYS
))
}
return
periodLengths
}
function
determineStatsText
(
allMensesStarts
)
{
const
emptyStats
=
'
At least one completed period is needed to present you with stats here.
'
if
(
allMensesStarts
.
length
<
2
)
{
return
emptyStats
}
else
{
const
cycleLengths
=
getCycleLength
(
allMensesStarts
)
const
numberOfCycles
=
cycleLengths
.
length
const
periodInfo
=
getPeriodInfo
(
cycleLengths
)
if
(
numberOfCycles
===
1
)
{
return
`You have documented one period of
${
cycleLengths
[
0
]}
days.`
}
else
{
const
statsText
=
`Stats are based on
${
numberOfCycles
}
completed
periods.\n\n
Average period length:
${
periodInfo
.
mean
}
days\n\n
shortest period:
${
periodInfo
.
minimum
}
days\n
longest period:
${
periodInfo
.
maximum
}
days\n
median length (meaning 50% of periods are of this length or shorter):
${
periodInfo
.
median
}
days\n
standard deviation:
${
periodInfo
.
stdDeviation
}
`
return
statsText
}
}
return
periodLengths
.
reverse
()
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
lib/cycle.js
+
7
−
11
View file @
c99aa750
...
...
@@ -133,17 +133,13 @@ export default function config(opts) {
function
getAllMensesStarts
(
day
,
collectedDates
)
{
day
=
day
||
LocalDate
.
now
().
toString
()
collectedDates
=
collectedDates
||
[]
if
(
!
day
)
{
return
null
const
lastStart
=
getLastMensesStart
(
day
)
if
(
!
lastStart
)
{
return
collectedDates
}
else
{
const
lastStart
=
getLastMensesStart
(
day
)
if
(
!
lastStart
)
{
return
collectedDates
}
else
{
const
newDay
=
LocalDate
.
parse
(
lastStart
.
date
).
minusDays
(
1
).
toString
()
collectedDates
.
push
(
lastStart
.
date
)
return
getAllMensesStarts
(
newDay
,
collectedDates
)
}
const
newDay
=
LocalDate
.
parse
(
lastStart
.
date
).
minusDays
(
1
).
toString
()
collectedDates
.
push
(
lastStart
.
date
)
return
getAllMensesStarts
(
newDay
,
collectedDates
)
}
}
...
...
@@ -151,7 +147,7 @@ export default function config(opts) {
getCycleDayNumber
,
getCycleForDay
,
getPreviousCycle
,
get
LastMensesStart
,
get
CyclesBefore
,
getAllMensesStarts
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
package-lock.json
+
1494
−
1494
View file @
c99aa750
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