Link to home
Start Free TrialLog in
Avatar of Ramakanta Sahoo
Ramakanta SahooFlag for United States of America

asked on

How to calculate max concurrency at any point of time

Hi,

I am having  a file(sorted from old timestamp to latest) like below
512912.00             6/1/2010 11:20:02  1.00                  
512913.00             6/1/2010 11:20:03  1.00                  
512912.00             6/1/2010 11:20:03  2.00                
512914.00             6/1/2010 11:22:53  1.00                  
512917.00             6/1/2010 11:23:38  1.00                  
512918.00             6/1/2010 11:25:04  1.00                  
512919.00             6/1/2010 11:25:13  1.00                  
512920.00             6/1/2010 11:26:40  1.00                  
512921.00             6/1/2010 11:26:49  1.00                  
512953.00             6/1/2010 11:41:05  1.00                  
512954.00             6/1/2010 11:41:19  1.00                  
512943.00             6/1/2010 11:41:21  2.00                  
512861.00             6/1/2010 11:41:56  2.00                  
512958.00             6/1/2010 11:42:35  1.00                  
512959.00             6/1/2010 11:43:39  1.00                  
512895.00             6/1/2010 11:48:56  2.00                  
512906.00             6/1/2010 11:48:56  2.00                  
512901.00             6/1/2010 11:49:56  2.00        

where
1column unique userid's
2nd column timestamp
3rd column:
1.00 and 4.00 = logged in
2.00 and 3.00 =logged out

Please do let me know any script which will be able to calculate the maximum number of concurrency from the entries in file
login.zip
Avatar of ksivananth
ksivananth
Flag of United States of America image

in Java use scanner to read the file and check if the last token in each line is 1 or 4 if so, add them into concurrent!

http://www.java-tips.org/java-se-tips/java.util/scanning-text-with-java.util.scanner-3.html
Avatar of Ramakanta Sahoo

ASKER

Thanks. but if I am calculating max concurrent users what shall be the algorithm as users are also logging out too. so I can not blindly add all 1,4 to find maximum concurrent usage over a date range

It will be great if anyone can provide me a script or java or perl code to do it.

I found some thing where you can calculate in DB but dont know how to put it for this file.
SELECT MAX(ConcurrentUsers)
FROM  (SELECT     a.StartTime, COUNT(*) AS ConcurrentUsers
       FROM       MyTable AS a
       INNER JOIN MyTable AS b
             ON   b.StartTime <= a.StartTime
             AND  b.EndTime >= a.EndTime
       WHERE      a.StartTime >= @StartOfPeriod
       AND        a.StartTime <= @EndOfPeriod
       GROUP BY   a.StartTime) AS x

http://www.sqlnewsgroups.net/sqlserver/t839-calculate-concurrent-users-between-date-time-range.aspx
got you, you can have a map( userid as key and count as value ) and then finally travers through the map and add up all the counts( non negative )
SOLUTION
Avatar of ksivananth
ksivananth
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Am new to this. It will be great if I can get the code to do that.
DB import is not an  option as it takes huge amount of time if the data is huge and its time taking too.
>>Am new to this. It will be great if I can get the code to do that.

why don't you try coding using the example of Scanner and come back if you struck?
ASKER CERTIFIED SOLUTION
Avatar of Valeri
Valeri
Flag of Bulgaria image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks I will try it but i need to prepare for java first. :) .  i wanted some script in perl which will be able to do it. The issue is I have very less time in my hand. But sure i will try it.

Any other help appreciated.! thanks
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wanted Code as this was urgent requirement. Now learning and coding took my time. Any way thanks for the fantastic ideas.