mirror of
https://github.com/umami-software/umami.git
synced 2026-02-13 00:55:37 +01:00
Refactored realtime API. Add dot component and colored dots in log.
This commit is contained in:
parent
f2cfab5078
commit
b72a4c001c
12 changed files with 153 additions and 86 deletions
|
|
@ -62,3 +62,19 @@ export function formatLongNumber(value) {
|
|||
|
||||
return formatNumber(n);
|
||||
}
|
||||
|
||||
export function stringToColor(str) {
|
||||
if (!str) {
|
||||
return '#ffffff';
|
||||
}
|
||||
let hash = 0;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
hash = str.charCodeAt(i) + ((hash << 5) - hash);
|
||||
}
|
||||
let color = '#';
|
||||
for (let i = 0; i < 3; i++) {
|
||||
let value = (hash >> (i * 8)) & 0xff;
|
||||
color += ('00' + value.toString(16)).substr(-2);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -500,3 +500,30 @@ export function getEventMetrics(
|
|||
params,
|
||||
);
|
||||
}
|
||||
|
||||
export async function getRealtimeData(websites, time) {
|
||||
const [pageviews, sessions, events] = await Promise.all([
|
||||
getPageviews(websites, time),
|
||||
getSessions(websites, time),
|
||||
getEvents(websites, time),
|
||||
]);
|
||||
|
||||
return {
|
||||
pageviews: pageviews.map(({ view_id, ...props }) => ({
|
||||
__id: `p${view_id}`,
|
||||
view_id,
|
||||
...props,
|
||||
})),
|
||||
sessions: sessions.map(({ session_id, ...props }) => ({
|
||||
__id: `s${session_id}`,
|
||||
session_id,
|
||||
...props,
|
||||
})),
|
||||
events: events.map(({ event_id, ...props }) => ({
|
||||
__id: `e${event_id}`,
|
||||
event_id,
|
||||
...props,
|
||||
})),
|
||||
timestamp: Date.now(),
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue