Skip to content

Commit 4e47b8e

Browse files
committed
AI stats chart
1 parent 892e369 commit 4e47b8e

File tree

13 files changed

+218
-72
lines changed

13 files changed

+218
-72
lines changed

logicaldoc-cmis/src/main/java/com/logicaldoc/cmis/CmisPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class CmisPlugin extends LogicalDOCPlugin {
2525
public void install() throws PluginException {
2626
super.install();
2727

28-
addServlet(SERVLET_NAME, CmisServlet.class.getName(), "/service/cmis/*", 4);
28+
addServlet(SERVLET_NAME, CmisServlet.class, "/service/cmis/*", 4);
2929

3030
File dest = new File(getPluginPath());
3131
dest = dest.getParentFile().getParentFile();

logicaldoc-core/src/main/java/com/logicaldoc/core/CorePlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void install() throws PluginException {
6767
}
6868

6969
try {
70-
addServlet("DashletContent", DashletContent.class.getName(), "/data/dashletcontent");
70+
addServlet("DashletContent", DashletContent.class, "/data/dashletcontent");
7171
} catch (Exception e) {
7272
log.error(e.getMessage(), e);
7373
}

logicaldoc-dropbox/src/main/java/com/logicaldoc/dropbox/DropboxPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ public class DropboxPlugin extends LogicalDOCPlugin {
1515
public void install() throws PluginException {
1616
super.install();
1717

18-
addServlet("DropboxService", DropboxServiceImpl.class.getName(), "/frontend/dropbox");
19-
addServlet("DropboxData", DropboxDataServlet.class.getName(), "/data/dropbox.xml");
18+
addServlet("DropboxService", DropboxServiceImpl.class, "/frontend/dropbox");
19+
addServlet("DropboxData", DropboxDataServlet.class, "/data/dropbox.xml");
2020

2121
setRestartRequired();
2222
}

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/ai/AIService.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.google.gwt.user.client.rpc.ServiceDefTarget;
99
import com.logicaldoc.gui.common.client.LDRpcRequestBuilder;
1010
import com.logicaldoc.gui.common.client.ServerException;
11+
import com.logicaldoc.gui.common.client.beans.GUIParameter;
1112
import com.logicaldoc.gui.frontend.client.ai.model.GUIModel;
1213
import com.logicaldoc.gui.frontend.client.ai.model.GUIQueryResult;
1314
import com.logicaldoc.gui.frontend.client.ai.sampler.GUISampler;
@@ -145,6 +146,18 @@ public interface AIService extends RemoteService {
145146
*/
146147
public GUIModel cloneModel(long modelId, String newName) throws ServerException;
147148

149+
/**
150+
* Loads the statistics from of the AI
151+
*
152+
* @param modelId Optional indentifier of the model
153+
* @param tenantId Optional indentifier of the tenant
154+
*
155+
* @return all the stats
156+
*
157+
* @throws ServerException an error happened in the server application
158+
*/
159+
public List<GUIParameter> getStats(Long modelId, Long tenantId) throws ServerException;
160+
148161
public static class Instance {
149162
private static AIServiceAsync inst;
150163

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/ai/AIServiceAsync.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.List;
44

55
import com.google.gwt.user.client.rpc.AsyncCallback;
6+
import com.logicaldoc.gui.common.client.beans.GUIParameter;
67
import com.logicaldoc.gui.frontend.client.ai.model.GUIModel;
78
import com.logicaldoc.gui.frontend.client.ai.model.GUIQueryResult;
89
import com.logicaldoc.gui.frontend.client.ai.sampler.GUISampler;
@@ -32,4 +33,6 @@ public interface AIServiceAsync {
3233
void importModel(String modelName, AsyncCallback<GUIModel> callback);
3334

3435
void cloneModel(long modelId, String newName, AsyncCallback<GUIModel> callback);
36+
37+
void getStats(Long modelId, Long tenantId, AsyncCallback<List<GUIParameter>> callaback);
3538
}

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/ai/model/ModelDetailsPanel.java

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public class ModelDetailsPanel extends VLayout {
3232

3333
private ModelEvaluation evaluationPanel;
3434

35+
private Layout statsTabPanel;
36+
37+
private ModelStats statsPanel;
38+
3539
private Layout historyTabPanel;
3640

3741
private ModelHistoryPanel historyPanel;
@@ -78,13 +82,28 @@ public void onSuccess(GUIModel sampler) {
7882
trainingTab.setPane(trainingTabPanel);
7983
tabSet.addTab(trainingTab);
8084

85+
evaluationTabPanel = new HLayout();
86+
evaluationTabPanel.setWidth100();
87+
evaluationTabPanel.setHeight100();
88+
Tab evaluationTab = new Tab(I18N.message(EVALUATION));
89+
evaluationTab.setID(EVALUATION);
90+
evaluationTab.setPane(evaluationTabPanel);
91+
tabSet.addTab(evaluationTab);
92+
8193
historyTabPanel = new HLayout();
8294
historyTabPanel.setWidth100();
8395
historyTabPanel.setHeight100();
8496
Tab historyTab = new Tab(I18N.message("history"));
8597
historyTab.setPane(historyTabPanel);
8698
tabSet.addTab(historyTab);
8799

100+
statsTabPanel = new HLayout();
101+
statsTabPanel.setWidth100();
102+
statsTabPanel.setHeight100();
103+
Tab statsTab = new Tab(I18N.message("stats"));
104+
statsTab.setPane(statsTabPanel);
105+
tabSet.addTab(statsTab);
106+
88107
addMember(tabSet);
89108
}
90109

@@ -111,26 +130,36 @@ private void refresh() {
111130
if (Boolean.TRUE.equals(historyTabPanel.contains(historyPanel)))
112131
historyTabPanel.removeMember(historyPanel);
113132
}
114-
133+
115134
if (evaluationPanel != null) {
116135
evaluationPanel.destroy();
117136
if (Boolean.TRUE.equals(evaluationTabPanel.contains(evaluationPanel)))
118137
evaluationTabPanel.removeMember(evaluationPanel);
119138
}
120139

140+
if (statsPanel != null) {
141+
statsPanel.destroy();
142+
if (Boolean.TRUE.equals(statsTabPanel.contains(statsPanel)))
143+
statsTabPanel.removeMember(statsPanel);
144+
}
145+
121146
propertiesPanel = new ModelProperties(model, event -> onModified());
122147
propertiesTabPanel.addMember(propertiesPanel);
123148

124149
trainingPanel = new ModelTraining(model, event -> onModified());
125150
trainingTabPanel.addMember(trainingPanel);
126151

127-
if (model.isNeuralNetwork()) {
128-
evaluationPanel = new ModelEvaluation(model, event -> onModified());
129-
evaluationTabPanel.addMember(evaluationPanel);
130-
} else {
131-
tabSet.removeTab(EVALUATION);
132-
}
133-
152+
evaluationPanel = new ModelEvaluation(model, event -> onModified());
153+
evaluationTabPanel.addMember(evaluationPanel);
154+
155+
statsPanel = new ModelStats(model);
156+
statsTabPanel.addMember(statsPanel);
157+
158+
if (model.isNeuralNetwork())
159+
tabSet.showTab(EVALUATION);
160+
else
161+
tabSet.hideTab(EVALUATION);
162+
134163
historyPanel = new ModelHistoryPanel(model.getId());
135164
historyTabPanel.addMember(historyPanel);
136165
}
@@ -141,17 +170,6 @@ public GUIModel getModel() {
141170

142171
public void setModel(GUIModel model) {
143172
this.model = model;
144-
145-
if (model.isNeuralNetwork()) {
146-
evaluationTabPanel = new HLayout();
147-
evaluationTabPanel.setWidth100();
148-
evaluationTabPanel.setHeight100();
149-
Tab evaluationTab = new Tab(I18N.message(EVALUATION));
150-
evaluationTab.setID(EVALUATION);
151-
evaluationTab.setPane(evaluationTabPanel);
152-
tabSet.addTab(evaluationTab);
153-
}
154-
155173
refresh();
156174
}
157175

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/ai/model/ModelEvaluation.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ public ModelEvaluation(GUIModel model, final ChangedHandler changedHandler) {
3333
setMembers(container);
3434

3535
ModelController.get().addObserver(this);
36+
}
3637

38+
@Override
39+
protected void onDraw() {
3740
refresh();
3841
}
3942

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package com.logicaldoc.gui.frontend.client.ai.model;
2+
3+
import java.util.Date;
4+
import java.util.List;
5+
6+
import com.logicaldoc.gui.common.client.DefaultAsyncCallback;
7+
import com.logicaldoc.gui.common.client.Session;
8+
import com.logicaldoc.gui.common.client.beans.GUIParameter;
9+
import com.logicaldoc.gui.common.client.i18n.I18N;
10+
import com.logicaldoc.gui.common.client.util.ItemFactory;
11+
import com.logicaldoc.gui.common.client.util.Util;
12+
import com.logicaldoc.gui.frontend.client.ai.AIService;
13+
import com.smartgwt.client.types.ImageStyle;
14+
import com.smartgwt.client.types.Overflow;
15+
import com.smartgwt.client.types.TitleOrientation;
16+
import com.smartgwt.client.widgets.Img;
17+
import com.smartgwt.client.widgets.form.DynamicForm;
18+
import com.smartgwt.client.widgets.form.fields.StaticTextItem;
19+
import com.smartgwt.client.widgets.layout.VLayout;
20+
21+
/**
22+
* Shows model's evaluation panel.
23+
*
24+
* @author Marco Meschieri - LogicalDOC
25+
* @since 9.2
26+
*/
27+
public class ModelStats extends ModelDetailsTab {
28+
29+
private StaticTextItem aiQueries;
30+
31+
private StaticTextItem aiQueriesCurrent;
32+
33+
private Img chartImg;
34+
35+
private VLayout content=new VLayout();
36+
37+
public ModelStats(GUIModel model) {
38+
super(model, null);
39+
setWidth100();
40+
setHeight100();
41+
content.setMembersMargin(4);
42+
addMember(content);
43+
}
44+
45+
@Override
46+
protected void onDraw() {
47+
aiQueries = ItemFactory.newStaticTextItem("aiQueries", I18N.message("totalqueries"), "0");
48+
aiQueriesCurrent = ItemFactory.newStaticTextItem("aiQueriesCurrent", I18N.message("currentmonthqueries"), "0");
49+
50+
DynamicForm form = new DynamicForm();
51+
form.setTitleOrientation(TitleOrientation.LEFT);
52+
form.setNumCols(4);
53+
form.setWidth(1);
54+
form.setPadding(5);
55+
form.setItems(aiQueries, aiQueriesCurrent);
56+
57+
content.addMember(form);
58+
59+
refreshStats();
60+
}
61+
62+
private void refreshStats() {
63+
AIService.Instance.get().getStats(model.getId(), null, new DefaultAsyncCallback<>() {
64+
@Override
65+
public void onSuccess(List<GUIParameter> parameters) {
66+
if (!parameters.isEmpty()) {
67+
for (GUIParameter parameter : parameters) {
68+
if (parameter.getName().equals("ai.queries"))
69+
aiQueries.setValue(Util.formatLong(Long.parseLong(parameter.getValue())));
70+
else if (parameter.getName().equals("ai.queries.current"))
71+
aiQueriesCurrent.setValue(Util.formatLong(Long.parseLong(parameter.getValue())));
72+
}
73+
} else {
74+
aiQueries.setValue("0");
75+
aiQueriesCurrent.setValue("0");
76+
}
77+
78+
refreshStatsChart();
79+
}
80+
});
81+
}
82+
83+
private void refreshStatsChart() {
84+
if (chartImg != null)
85+
removeMember(chartImg);
86+
87+
int chartWidth = 1200;
88+
int chartHeight = 420;
89+
String chartUrl = Util.contextPath() + "aichart?width=" + chartWidth + "&height=" + chartHeight + "&locale="
90+
+ I18N.getLocale() + "&random=" + new Date().getTime() + "&modelId=" + model.getId()+ "&tenantId=" + Session.get().getTenantId();
91+
92+
chartImg = new Img(chartUrl, 600, 440);
93+
chartImg.setImageType(ImageStyle.NORMAL);
94+
chartImg.setImageWidth(chartWidth);
95+
chartImg.setImageHeight(chartHeight);
96+
chartImg.setOverflow(Overflow.AUTO);
97+
98+
content.addMember(chartImg);
99+
}
100+
101+
boolean validate() {
102+
return true;
103+
}
104+
105+
@Override
106+
public boolean equals(Object other) {
107+
return super.equals(other);
108+
}
109+
110+
@Override
111+
public int hashCode() {
112+
return super.hashCode();
113+
}
114+
}

logicaldoc-i18n/src/main/resources/i18n/messages.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2722,4 +2722,7 @@ addanswer = Add answer
27222722
cannotunderstand = Sorry, I cannot understand what you mean
27232723
cannotfindanydoc = Sorry, I cannot find any document
27242724
function = Function
2725-
graph = Graph
2725+
graph = Graph
2726+
stats = Stats
2727+
totalqueries = Total queries
2728+
currentmonthqueries = Current month queries

logicaldoc-util/src/main/java/com/logicaldoc/util/plugin/LogicalDOCPlugin.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import java.util.List;
1010
import java.util.Properties;
1111

12+
import javax.servlet.Servlet;
13+
1214
import org.java.plugin.Plugin;
1315
import org.slf4j.Logger;
1416
import org.slf4j.LoggerFactory;
@@ -290,22 +292,22 @@ protected void addLogger(String name, String appender) {
290292
* Utility method to add a servlet in the web descriptor
291293
*
292294
* @param name Name of the servlet
293-
* @param clazz The qualified name of the servlet class
295+
* @param servletClass the servlet class
294296
* @param mapping The mapping specification
295297
*/
296-
protected void addServlet(String name, String servletClass, String mapping) {
298+
protected void addServlet(String name, Class<? extends Servlet> servletClass, String mapping) {
297299
addServlet(name, servletClass, mapping, null);
298300
}
299301

300302
/**
301303
* Utility method to add a servlet in the web descriptor
302304
*
303305
* @param name Name of the servlet
304-
* @param clazz The qualified name of the servlet class
306+
* @param servletClass the servlet class
305307
* @param mapping The mapping specification
306308
* @param optional index when loading the servlet on startup
307309
*/
308-
protected void addServlet(String name, String servletClass, String mapping, Integer loadOnStartup) {
310+
protected void addServlet(String name, Class<? extends Servlet> servletClass, String mapping, Integer loadOnStartup) {
309311
try {
310312
File webDescriptor = new File(getPluginPath());
311313
webDescriptor = webDescriptor.getParentFile().getParentFile();
@@ -318,9 +320,9 @@ protected void addServlet(String name, String servletClass, String mapping, Inte
318320

319321
WebConfigurator config = new WebConfigurator(webDescriptor.getAbsolutePath());
320322
if (loadOnStartup != null)
321-
config.addServlet(name, servletClass, loadOnStartup);
323+
config.addServlet(name, servletClass.getName(), loadOnStartup);
322324
else
323-
config.addServlet(name, servletClass);
325+
config.addServlet(name, servletClass.getName());
324326
config.writeXMLDoc();
325327

326328
if (mapping != null) {

0 commit comments

Comments
 (0)