S
S
SHUstri2016-05-30 16:31:55
Database design
SHUstri, 2016-05-30 16:31:55

How to build a graph of active sessions based on the data on the beginning and end of each session?

Hello.
There is a data source with information like:
session ID; Session start time; Session end time
Based on these data, it is necessary to draw a graph of the number of active sessions.
Those. you need to get for each point X in the interval [A; B] the number of active sessions.
Potential number of sessions per day ~70k, chart intervals: 1 day (10 min interval) and 1 week (1 hour interval)
There are two solutions, I don't like both:
1. Make 24*60/10 or 7*24 database queries , for each time X: "return the number of sessions where start time <= X and end time > X".
2. Make one request to the database, for the interval [A; B] "return all sessions whose start time <= B and end time > A" and then keep counting on the client side.
Who knows a more elegant solution to the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SHUstri, 2016-06-01
@SHUstri


I came up with a solution myself: we get how many new sessions were established during the X
2 interval. we get how many sessions ended during the interval X
3. Adding (subtracting) item 1 and item 2, we get how much the number of active sessions changed during the interval X
4. With one request, we get the number of active sessions at time A (the beginning of the interval for the chart )
5. Add item 3 and item 4 and get the number of active sessions for each time interval X

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question