-
Notifications
You must be signed in to change notification settings - Fork 155
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
fix(stats): populate empty chart axis #289
fix(stats): populate empty chart axis #289
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR mostly tweaks spacing to adhere to a particular stylistic preference. Can you revert these changes so the PR only targets the main objective and keeps the diff trim?
sorry about the initial formatting mess, |
utils/db.ts
Outdated
const dates = Array.from(metricsMap.keys()); | ||
const metricsValue = Array.from(metricsMap.values()); | ||
|
||
return { dates, metricsValue }; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's difficult to understand what's going on here. If possible, we can break this into more straightforward, smaller functions and remove unnecessary moving parts. I'm open to ideas. It'd also be good to have this tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the feedback.
there was indeed quite a lot going on there.
i refactored the logic to be more aligned w/ existing functions which were expecting a msAgo
argument.
i also introduced some small helpers:
getDatesSince
to get all dates since a given number of milliseconds agoformatDate
to have a unified way of formatting dates
with the newly created tests it should be more predictable to see what's going on.
however i'd still await the changes introduced in #296.
3d729f9
to
3c3c5da
Compare
@iuioiua thanks for the heads-up! @brunocorrea23 great job on #296! 👏 👏 |
following on the discussions of #296: |
Interesting. My current issue with stats and some of DB is that I think the functions do too much, respectively, though we're slowly getting better. E.g. I'd prefer hardcoding the respective metric instead of having a Regarding your suggestion, what if we did this, using Before: export async function getAllVisitsCountByDay(options?: Deno.KvListOptions) {
const iter = await kv.list<bigint>({ prefix: ["visits_count"] }, options);
const visits = [];
const dates = [];
for await (const res of iter) {
visits.push(Number(res.value));
dates.push(String(res.key[1]));
}
return { visits, dates };
}
const visitsCount = await getAllVisitsCountByDay(); After: export async function getManyVisitsCounts(dates: string[]) {
const keys = dates.map((date) => ["visits_count", date]);
const res = await kv.getMany<bigint[]>(keys);
return res.map((value) => value);
}
const dates = getDatesSince(DAY * 2);
const visitsCount = await getManyVisitsCounts(dates); This seems more streamlined, IMO. WDYT? |
I'd be happy to make the above simplifications to this or another PR to help you if you'd like. |
thanks for the recommendation, i really like that one! |
#312 has been merged. Please feel free to carry on with this PR now. |
5118fd0
to
cb72fe1
Compare
@iuioiua thanks for the most recent changes! bumped the limit for the metrics back to 30, while also adding a small |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly LGTM! Few nits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a few tweaks, and now, LGTM! Thank you for this! Much appreciated.
closes #276.
sets the y-axis' ticks to be of natural numbers.
populates the x-axis with sequential dates.
to prevent us from having "holes" in the retrieved dates, a new
getDatesSince
has been introduced.the returned array can then can be used to query the necessary fields from our analytics stores.