Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: empty points generator function for graphs #1460

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/screens/NewAnalytics/NewAnalyticsUtils.res
Original file line number Diff line number Diff line change
@@ -1,2 +1,39 @@
//Logic utils

open NewAnalyticsTypes
let getBucketSize = (granularity: granularity) => {
switch granularity {
| #hour_wise => "hour"
| #day_wise => "day"
| #week_wise => "week"
}
}

let fillMissingDataPoints = (
~data,
~startDate,
~endDate,
~timeKey="time_bucket",
~defaultValue: Dict.t<JSON.t>,
~granularity: granularity,
) => {
open LogicUtils
let dataPoints = Dict.make()
let startingPoint = startDate->DayJs.getDayJsForString
let endingPoint = endDate->DayJs.getDayJsForString
let gap = granularity->getBucketSize

for x in 1 to endingPoint.diff(startingPoint.toString(), gap) {
let newDict = defaultValue->Dict.copy
let timeVal = startingPoint.add(x, gap).endOf(gap).format("YYYY-MM-DD HH:MM:SS")
newDict->Dict.set(timeKey, timeVal->JSON.Encode.string)
dataPoints->Dict.set(timeVal, newDict->JSON.Encode.object)
}

data->Array.forEach(value => {
let dataDict = value->getDictFromJsonObject
dataPoints->Dict.set(dataDict->getString(timeKey, ""), value)
})

dataPoints->Dict.valuesToArray
}
Loading