Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: How to Iterate to Identify Concurrent Users (SQL)

by fenLisesi (Priest)
on Oct 26, 2007 at 08:50 UTC ( [id://647347]=note: print w/replies, xml ) Need Help??


in reply to How to Iterate to Identify Concurrent Users

You could use SQL, as tye hinted. Suppose you load your data into a table named sesn (session) with fields sesn_id, usr_id, sesn_bgn, sesn_end and whatever else you may need, properly indexed etc. Then, a query like the following should do what you want (untested):
SELECT foo.usr_id AS user, foo.sesn_id AS session1, bar.sesn_id AS session2, foo.sesn_bgn AS start1, bar.sesn_bgn AS start2, foo.sesn_end AS end1, bar.sesn_end AS end2 FROM sesn foo, sesn bar WHERE foo.usr_id = bar.usr_id AND bar.sesn_bgn >= foo.sesn_bgn AND bar.sesn_bgn <= foo.sesn_end AND foo.sesn_id != bar.sesn_id -- AND (conditions on min duration etc here)

Here I have assumed that you are trying to track multiple simultaneous sessions by the same user. If that's not what you meant, adjust accordingly.

Hope this helps. Cheers.

Replies are listed 'Best First'.
Re^2: How to Iterate to Identify Concurrent Users (SQL)
by Anonymous Monk on Oct 26, 2007 at 13:32 UTC
    Thanks tye and fenLisesi. I initially started with a database model but found it to be more cumbersome. After your good advice, I created a view and ran fenLisesi query with some modifications. It did the trick. Its slow though but it gets me what I need. I'll benchmark it with Perl code to see which is more efficient. You monks rock!!!
    create view foo as select session_id, start_session, end_session, user +_id from bar;
    </code> Then I ran
    SELECT DISTINCT foo.user_id AS user, foo.session_id AS session1, bar.session_id AS session2, foo.start_session AS start1, bar_.start_session AS start2, foo.end_session AS end1, bar_.end_session AS end2 FROM foo,bar WHERE foo.user_id != bar_.user_id AND bar_.start_session >= foo.start_session AND bar_.start_session <= foo.end_session AND foo.session_id != bar_.session_id order by start1 ASC;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://647347]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (3)
As of 2024-04-26 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found