Solved

How to calculate max concurrency at any point of time

Posted on 2010-11-23
10
520 Views
Last Modified: 2012-05-10
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
0
Comment
Question by:Ramakanta Sahoo
10 Comments
 
LVL 26

Expert Comment

by:ksivananth
ID: 34195492
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
0
 
LVL 4

Author Comment

by:Ramakanta Sahoo
ID: 34195631
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
0
 
LVL 26

Expert Comment

by:ksivananth
ID: 34195645
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 )
0
 
LVL 26

Assisted Solution

by:ksivananth
ksivananth earned 150 total points
ID: 34195650
on the other hand you can export this file to DB table( with delimeter ) and execute the the query!
0
 
LVL 4

Author Comment

by:Ramakanta Sahoo
ID: 34195686
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.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 26

Expert Comment

by:ksivananth
ID: 34195994
>>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?
0
 
LVL 16

Accepted Solution

by:
Valeri earned 250 total points
ID: 34196101
This is the optimal solution with java:
1. make such as class:
public class Event {
    private long id;
    private Date evDate;
    private int type;
}
2. Create a Map
Map<Long, Event> events = new TreeMap<Long, Event>();
3. Assuming that for each event of type 2 you have event of type 1 before that, you have to do the following:
Loop throught the file and the following:
1) If you find event of type 1 add it to the "events", if you find event of type 2, remove the event of type 1 from the map and calculate the period using as start date the date from event type "1" and as end date the date from event type "2".
After having this period you have to disperse it to the the period you have already defined and divided by intervals by 1 hour let say. So if the user is logged in at 15:20 and logged out at 17:30, during the dispersion you have to increase by 1 the hours 15:00, 16:00 and 17:00.
After that you have to find the maximum users per hour. Ofcourse the dispersion coluld be not by hour but by every 30 min let say, or by 10 min...

0
 
LVL 4

Author Comment

by:Ramakanta Sahoo
ID: 34196144
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
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 100 total points
ID: 34201864
You could model this using nested set. The largest set would give you the largest concurrency
0
 
LVL 4

Author Closing Comment

by:Ramakanta Sahoo
ID: 34542784
Wanted Code as this was urgent requirement. Now learning and coding took my time. Any way thanks for the fantastic ideas.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
groupSum5 challenge 5 71
eclipse java  build path 6 45
jar file executable 12 43
servlet requestdispatcher include and forward differences 1 25
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now