Onboarding, Cycle, Info, Settings API - uoftblueprint/the-period-purse-ios GitHub Wiki
Onboarding
POSTInitialPeriodLength
- This will create the user's initial period length
- JSONifies periodLength into a string and then calls
AsyncStorage.setItem()
using "periodLength" as the key and the periodLength string as the value and using "averagePeriodLength" as the key and the periodLength string as the value
Signature
static POSTInitialPeriodLength(periodLength: int): Promise
Returns
- A promise resolving when the set operation is completed.
POSTInitialPeriodStart
- This will create entries for the user's last period given the start date and end date of their last period
- Calls
AsyncStorage.setItem()
using year as the key and a dictionary mapping month to a certain number of day arrays as the value - The number of day arrays is determined by how many days there are between the entered start date and end date
- The creation only happens when the user has given inputs for both start date and end date
Signature
static POSTInitialPeriodStart(periodStart: date, periodEnd: date): Promise
Returns
- A promise resolving when the set operation is completed.
POSTSymptomsToTrack
- This will create the user's initial tracking preferences for what symptoms to track
- At least one symptom has to be selected
- Calls
AsyncStorage.setItem()
using a specific symptom (string) as the key and the corresponding JSONified boolean as the value
Signature
static POSTSymptomsToTrack(flow: bool, mood: bool, sleep: bool, cramps: bool, exercise: bool): Promise
Returns
- A promise resolving when the set operation is completed.
Cycle
GETAveragePeriodLength
- This will get the user's average period length which is stored as a key value pair
- No calculation necessary, assume there is a key
averagePeriodLength
inAsyncStorage
- Calls
AsyncStorage.getItem()
using "averagePeriodLength" as the key
Signature
static GETAveragePeriodLength(): Promise
Returns
- A Promise that resolves into either an integer representing the user's average period length or NULL if no data had been given.
GETAverageCycleLength
- This will get the user's average cycle length which is stored as a key value pair
- No calculation necessary, assume there is a key
averageCycleLength
inAsyncStorage
- Calls
AsyncStorage.getItem()
using "averageCycleLength" as the key
Signature
static GETAverageCycleLength(): Promise
Returns
- A Promise that resolves into either an integer representing the user's average cycle length or NULL if no data had been given.
GETPeriodDay
-
Checks if the user is currently on their period
-
Takes optional argument
calendar
for an object containing symptoms data to query symptoms for dates from. If not provided, it is created. -
Return a Promise that resolves into 0 if user is not on period, and a positive number of period day otherwise if user is on period (walk backwards to count number of period days)
-
Checks to see if the current date is logged as a period day or non-period day
Signature
static GETPeriodDay(calendar = null): Promise
Returns
- a promise that contains an integer with 0 if user is not on period, and otherwise the number of days the user has been on their period.
GETMostRecentPeriodStartDate
- Gets the start date of the most recent period by traversing through records until you find the most recent date logged as a period day
- Basically most recent matched pattern of " _ _ X "(2 non-period then period) where _ is a non period day and X is a period day
- Takes optional argument
calendar
for an object containing symptoms data to query symptoms for dates from. If not provided, it is created.
Signature
static GETMostRecentPeriodStartDate(calendar = null): Promise
Returns
- A Promise that resolves into a Date object https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date saying when the most recent period started
GETCycleDonutPercent
- EXAMPLE: average cycle length = 30, most recent start date = 2022-01-01, get period day = 0
- Produces the progress ring that displays where the user is at in their cycle
- Returns the percent away they are from their next period
- First check if
CycleDonutPercentage
has a value in AsyncStorage for today's date, if yes just use that percentage, if no, do calculation and usePOSTCycleDonutPercent
to replace with new date and percentage - calls on
GETPeriodDay
- calls on
GETAverageCycleLength
- calls on
GETMostRecentPeriodStartDate
- if the user is not on their period, call
GETMostRecentPeriodStartDate()
,GETAverageCycleLength()
, and the current date to calculate how far they are from their period starting as a percentage - Takes optional argument
calendar
for an object containing symptoms data to query symptoms for dates from. If not provided, it is created.
Signature
GETCycleDonutPercent(calendar = null): float
Returns
- float denoting how far away they are from their next period by percentage
POSTCycleDonutPercent
- Posts how far the user is to their period as a percentage
- calls setsItem("CycleDonutPercentage", object)
- object is in format {'2022-01-01': float}
Signature
POSTCycleDonutPercent(percent: float): Promise
Returns
- A promise resolving when the set operation is completed.
GETCycleHistoryByYear
- Given the year, get the intervals the user had a period in that year
- Note that if an interval spans the boundary between years (Say a period from Dec 30, 2021 to Jan 4th 2022), it is included in the returned item from both the call for
GETCycleHistoryByYear(2021)
andGETCycleHistoryByYear(2022)
. - This is the new replacement for year view
- NOTE: X _ _ where X is period day, _ is non-period day means the period is ended.
- NOTE: _ _ X where X is period day, _ is non-period day means the period has started.
Signature
GETCycleHistoryByYear(year: int): Promise
Returns
- A promise which resolves with an object containing intervals of the users period in that year
- Example return object:
{
{
start: 2022-01-01,
periodDays: 5
},
}
start: 2022-01-28,
periodDays: 6
},
...
}
GETDaysSinceLastPeriodEnd
- This will get the days since the last period ended
Signature
GETDaysSinceLastPeriodEnd(): promise
Return
- A Promise that resolves into 0 if the user is on their period, and an integer of the days they have been on their period otherwise. If a last period is not found, 0 is returned.
Info
GETFactCycle
- This will get the last date when the user accessed the Info page and the fact number they last saw
- Calls
AsyncStorage.getItem()
- Uses the key "factCycle"
Signature
static GETFactCycle(): promise
Returns
- A promise resolving with an array where the first index is the date in string form and the second index is the fact number
- Example return object:
['2022-01-01', '1']
POSTFactCycle
- This will update the date when the user accessed the Info page and updates the fact number they saw
- Calls
AsyncStorage.mergeItem()
"factCycle": ['2022-01-01', '1']
- Calls on
GETFactCycle()
- If
GETFactCycle()
returns a null, callsAsyncStorage.setItem("factCycle", [currentDate, "1"])
Signature
static POSTFactCycle(): Promise
Returns
- A promise resolving when the set operation is completed.
Settings
DELETEAccountData
- This will remove the whole AsyncStorage data, for all clients, libraries, etc.
- Calls
AsyncStorage.clear()
Signature
static DELETEAccountData(): Promise
Returns
- A promise resolving when the set operation is completed.
GETAllTrackingPreferences
- This will get whether the user wants to track a certain symptom
- Calls
AsyncStorage.getItem()
Signature
static GETAllTrackingPreferences(): bool[]
Returns
- An array of 5 booleans representing whether the user wants to track [flow, mood, sleep, cramps, exercise]
POSTUpdatePreferences
- This will update the user's tracking preferences
- Calls
AsyncStorage.mergeItem()
using the symptom as the key and the corresponding JSONified boolean as the value
Signature
static POSTUpdatePreferences([flow: bool, mood: bool, sleep: bool, cramps: bool, exercise: bool]): Promise
Returns
- A promise resolving when the set operation is completed.
POSTRemindLogPeriod
- This will update user's preferences for whether to get reminded about logging periods
- Calls
AsyncStorage.setItem()
using the “RemindLogPeriod” as the key and the given boolean as the value
Signature
static POSTRemindLogPeriod(remind: bool): Promise
Returns
- A promise resolving when the set operation is completed.
POSTRemindLogSymptoms
- This will update user's preferences for whether to get reminded about logging symptoms
- Calls
AsyncStorage.setItem()
using the “RemindLogSymptoms” as the key and the given boolean as the value
Signature
static POSTRemindLogSymptoms(remind: bool): Promise
Returns
- A promise resolving when the set operation is completed.