Usage statistics [message #1228621] |
Tue, 07 January 2014 11:39  |
Eclipse User |
|
|
|
We need to get our program to gather usage statistics on the client side. We want to know what pages/forms a user is using. We were looking into AOP for this, but it doesn't seem to be quite the right technology. Is there a scout way of doing this?
Thanks,
Kathlyn
|
|
|
|
Re: Usage statistics [message #1229445 is a reply to message #1228640] |
Thu, 09 January 2014 08:09  |
Eclipse User |
|
|
|
Hi Kathlyn,
thanks for your question.
Unfortunately Scout has no such built in feature. Not yet 
I agree with Jérémie's proposal to do the profiling on the Server side. This is how I would do it:
1) Create a new Service on the server: 'ProfileService'
My implementation looks as follows:
public class ProfileService extends AbstractService implements IProfileService {
private static final IScoutLogger LOG = ScoutLogManager.getLogger(ProfileService.class);
private static Map<String, Integer> numberOfUses = new HashMap<String, Integer>();
@Override
public void log(String name) throws ProcessingException {
LOG.info("Log the following element: " + name);
if (numberOfUses.containsKey(name)) {
int number = numberOfUses.get(name);
number++;
numberOfUses.put(name, number);
LOG.info("The element " + name + " has been used " + number + " times.");
}
else {
LOG.info("The element " + name + " has been used the first time");
numberOfUses.put(name, 1);
}
}
}
It is simply a method which count's how often a certain string has been passed. In a real world scenario I would log it into a database.
2) In order to log pages, I override the page's 'execPageActivated()' method:
@Override
protected void execPageActivated() throws ProcessingException {
super.execPageActivated();
SERVICES.getService(IProfileService.class).log(MyTablePage.class.getSimpleName());
}
Every time the page is activated, it will profile it.
3) In order to log forms, I override the form's 'execFormActivated()' method:
@Override
protected void execFormActivated() throws ProcessingException {
super.execFormActivated();
SERVICES.getService(IProfileService.class).log(MyForm.class.getSimpleName());
}
And here is some sample output from the Server:
...
Log the following element: MyTablePage
The element MyTablePage has been used 2 times.
Log the following element: MyTablePage
The element MyTablePage has been used 3 times.
Log the following element: MyForm
The element MyForm has been used the first time
Log the following element: MyForm
The element MyForm has been used 3 times.
Note: If you have a lot of pages and forms it is cumbersome to always add the logging to the execPageActivated method (dry - don't repeat yourself). Therefore I would suggest to move the code to the super class and then extend your forms/pages from those class, e.g. instead of
public class MyForm extends AbstractForm
use
public class MyForm extends ProfilingAbstractForm
and then in ProfilingAbstractForm implement the logging.
I hope this helps and meets your requirements. If you have any further questions, let us know.
Best regards,
Matthias
|
|
|
Powered by
FUDForum. Page generated in 0.04156 seconds