Skip to content

Commit de21448

Browse files
committed
more AI panels
1 parent 6facbac commit de21448

File tree

12 files changed

+168
-33
lines changed

12 files changed

+168
-33
lines changed

logicaldoc-core/src/main/java/com/logicaldoc/core/job/JobManager.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
@Component("jobManager")
4343
public class JobManager {
4444

45+
public static final String JOB = "job";
46+
4547
public static final String TENANT_ID = "tenantId";
4648

4749
public static final String MISSFIRE_RUNNOW = "runnow";
@@ -94,6 +96,7 @@ public void schedule(AbstractJob job, Map<String, Object> dictionary, Map<Object
9496
dictionary=new HashMap<>(dictionary);
9597

9698
dictionary.computeIfAbsent(TENANT_ID, k -> job.getTenantId());
99+
dictionary.computeIfAbsent(JOB, k -> job);
97100

98101
JobKey jobKey = JobKey.jobKey(job.getName(), job.getGroup());
99102
JobDetail jobDetail = scheduler.getJobDetail(jobKey);

logicaldoc-gui/src/main/java/com/logicaldoc/gui/common/client/grid/RunningListGridField.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,21 @@ public RunningListGridField() {
2020
setCanSort(true);
2121
setCellFormatter((value, rec, rowNum, colNum) -> formatStatusIconCell(rec));
2222
}
23+
24+
public RunningListGridField(String name) {
25+
super(name, " ", 30);
26+
setCanFilter(true);
27+
setCanSort(true);
28+
setCellFormatter((value, rec, rowNum, colNum) -> formatStatusIconCell(rec));
29+
}
2330

2431
private String formatStatusIconCell(ListGridRecord rec) {
2532
String color = rec.getAttributeAsString(colorFieldName);
2633
String content = "<div style='display: flex; text-align: center; justify-content: center;'>";
27-
if (Boolean.TRUE.equals(rec.getAttributeAsBoolean(RUNNING))) {
28-
content += AwesomeFactory.getIconButtonHTML("cog", null, RUNNING, color, "spin", null);
34+
if (Boolean.TRUE.equals(rec.getAttributeAsBoolean(getName()))) {
35+
content += AwesomeFactory.getIconButtonHTML("refresh", null, getName(), color, "spin", null);
2936
} else {
30-
content += AwesomeFactory.getIconButtonHTML("cog", null, "idle", color, null);
37+
content += AwesomeFactory.getIconButtonHTML("refresh", null, "idle", color, null);
3138
}
3239
content += "</div>";
3340
return content;

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,25 @@ public interface AIService extends RemoteService {
8282
*/
8383
public GUIModel getModel(long modelId) throws ServerException;
8484

85+
86+
/**
87+
* Retrieves all the models
88+
*
89+
* @return the list of models
90+
*
91+
* @throws ServerException an error happened in the server application
92+
*/
93+
public List<GUIModel> getModels() throws ServerException;
94+
95+
/**
96+
* Trains a model
97+
*
98+
* @param modelId identifier of the model to train
99+
*
100+
* @throws ServerException an error happened in the server application
101+
*/
102+
public void trainModel(long modelId) throws ServerException;
103+
85104
public static class Instance {
86105
private static AIServiceAsync inst;
87106

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,8 @@ public interface AIServiceAsync {
1919
void saveModel(GUIModel model, AsyncCallback<GUIModel> callback);
2020

2121
void getModel(long modelId, AsyncCallback<GUIModel> callback);
22+
23+
void getModels(AsyncCallback<List<GUIModel>> callback);
24+
25+
void trainModel(long modelId, AsyncCallback<Void> callback);
2226
}

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ public class GUIModel implements Serializable {
4242

4343
private GUITraining training = new GUITraining();
4444

45+
private int cutoff = 1;
46+
47+
private int ngramMin = 2;
48+
49+
private int ngramMax = 4;
50+
51+
private String language = "en";
52+
4553
public GUIModel(long id, String name) {
4654
super();
4755
this.id = id;
@@ -52,6 +60,38 @@ public GUIModel() {
5260
super();
5361
}
5462

63+
public int getCutoff() {
64+
return cutoff;
65+
}
66+
67+
public void setCutoff(int cutoff) {
68+
this.cutoff = cutoff;
69+
}
70+
71+
public int getNgramMin() {
72+
return ngramMin;
73+
}
74+
75+
public void setNgramMin(int ngramMin) {
76+
this.ngramMin = ngramMin;
77+
}
78+
79+
public int getNgramMax() {
80+
return ngramMax;
81+
}
82+
83+
public void setNgramMax(int ngramMax) {
84+
this.ngramMax = ngramMax;
85+
}
86+
87+
public String getLanguage() {
88+
return language;
89+
}
90+
91+
public void setLanguage(String language) {
92+
this.language = language;
93+
}
94+
5595
public long getId() {
5696
return id;
5797
}

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ public class GUITraining implements Serializable {
1717

1818
private Date lastTrained;
1919

20+
private String report;
21+
2022
private int epochs = 1000;
2123

2224
private String cron;
2325

2426
private boolean enabled = true;
2527

2628
private GUISampler sampler;
27-
29+
2830
public Date getLastTrained() {
2931
return lastTrained;
3032
}
@@ -64,4 +66,12 @@ public GUISampler getSampler() {
6466
public void setSampler(GUISampler sampler) {
6567
this.sampler = sampler;
6668
}
69+
70+
public String getReport() {
71+
return report;
72+
}
73+
74+
public void setReport(String report) {
75+
this.report = report;
76+
}
6777
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.logicaldoc.gui.frontend.client.ai.model;
22

33
import com.smartgwt.client.data.DataSource;
4+
import com.smartgwt.client.data.fields.DataSourceDateTimeField;
45
import com.smartgwt.client.data.fields.DataSourceTextField;
56

67
/**
@@ -28,8 +29,9 @@ private void init(String url) {
2829
DataSourceTextField label = new DataSourceTextField("label");
2930
DataSourceTextField description = new DataSourceTextField("description");
3031
DataSourceTextField typeField = new DataSourceTextField("type");
32+
DataSourceDateTimeField trained = new DataSourceDateTimeField("trained");
3133

32-
setFields(id, name, label, description, typeField);
34+
setFields(id, name, label, trained, description, typeField);
3335
setClientOnly(true);
3436

3537
setDataURL("data/ai.xml?object=model");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ private void refresh() {
103103
type.setDisplayField(VALUE);
104104
type.setValue(model.getType());
105105
type.addChangedHandler(changedHandler);
106+
type.addChangedHandler(changed -> layersStack.setVisible(NEURAL.equals(type.getValueAsString())));
106107
type.setRequired(true);
107108
type.setDisabled(model.getId() != 0L);
108109
type.setVisible(model.getId() == 0L);

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

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import com.smartgwt.client.types.TitleOrientation;
99
import com.smartgwt.client.widgets.form.DynamicForm;
1010
import com.smartgwt.client.widgets.form.fields.SpinnerItem;
11-
import com.smartgwt.client.widgets.form.fields.StaticTextItem;
11+
import com.smartgwt.client.widgets.form.fields.TextAreaItem;
1212
import com.smartgwt.client.widgets.form.fields.TextItem;
1313
import com.smartgwt.client.widgets.form.fields.ToggleItem;
1414
import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
@@ -44,15 +44,6 @@ private void refresh() {
4444
if (Boolean.TRUE.equals(container.contains(form)))
4545
container.removeChild(form);
4646

47-
form = new DynamicForm();
48-
form.setNumCols(4);
49-
form.setWidth(1);
50-
form.setTitleOrientation(TitleOrientation.TOP);
51-
52-
StaticTextItem lastTrained = ItemFactory.newStaticTextItem("lasttrained",
53-
model.getTraining().getLastTrained() != null ? I18N.formatDate(model.getTraining().getLastTrained())
54-
: "");
55-
5647
ToggleItem enabled = ItemFactory.newToggleItem(ENABLED, "enableschedule", model.getTraining().isEnabled());
5748
enabled.addChangedHandler(changedHandler);
5849

@@ -73,10 +64,29 @@ private void refresh() {
7364
sampler.setRequired(true);
7465
sampler.addChangedHandler(changedHandler);
7566

76-
form.setItems(lastTrained, enabled, cron, epochs, sampler);
67+
form = new DynamicForm();
68+
form.setNumCols(4);
69+
form.setWidth(1);
70+
form.setTitleOrientation(TitleOrientation.TOP);
71+
form.setItems(enabled, cron, epochs, sampler);
7772

73+
container.setWidth100();
7874
container.setMembersMargin(3);
7975
container.addMember(form);
76+
77+
TextAreaItem report = ItemFactory.newTextAreaItem("report",
78+
model.getTraining().getLastTrained() != null
79+
? I18N.message("lasttrainedon", I18N.formatDate(model.getTraining().getLastTrained()))
80+
: I18N.message("report"),
81+
model.getTraining().getReport());
82+
report.setWidth("*");
83+
84+
DynamicForm reportForm = new DynamicForm();
85+
reportForm.setWidth100();
86+
reportForm.setNumCols(1);
87+
reportForm.setTitleOrientation(TitleOrientation.TOP);
88+
reportForm.setItems(report);
89+
container.addMember(reportForm);
8090
}
8191

8292
boolean validate() {

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

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,25 @@
44
import java.util.List;
55

66
import com.logicaldoc.gui.common.client.DefaultAsyncCallback;
7+
import com.logicaldoc.gui.common.client.beans.GUITask;
8+
import com.logicaldoc.gui.common.client.grid.DateListGridField;
79
import com.logicaldoc.gui.common.client.grid.IdListGridField;
810
import com.logicaldoc.gui.common.client.grid.RefreshableListGrid;
11+
import com.logicaldoc.gui.common.client.grid.RunningListGridField;
912
import com.logicaldoc.gui.common.client.i18n.I18N;
1013
import com.logicaldoc.gui.common.client.util.LD;
1114
import com.logicaldoc.gui.common.client.widgets.HTMLPanel;
1215
import com.logicaldoc.gui.common.client.widgets.InfoPanel;
1316
import com.logicaldoc.gui.frontend.client.ai.AIService;
17+
import com.logicaldoc.gui.frontend.client.services.SystemService;
1418
import com.smartgwt.client.data.AdvancedCriteria;
1519
import com.smartgwt.client.data.Record;
1620
import com.smartgwt.client.types.Alignment;
1721
import com.smartgwt.client.types.AutoFitWidthApproach;
1822
import com.smartgwt.client.types.OperatorId;
1923
import com.smartgwt.client.types.SelectionStyle;
2024
import com.smartgwt.client.widgets.Canvas;
25+
import com.smartgwt.client.widgets.Progressbar;
2126
import com.smartgwt.client.widgets.grid.ListGrid;
2227
import com.smartgwt.client.widgets.grid.ListGridField;
2328
import com.smartgwt.client.widgets.grid.ListGridRecord;
@@ -83,13 +88,17 @@ public void onDraw() {
8388
ListGridField modelType = new ListGridField("type", I18N.message("type"));
8489
modelType.setAutoFit(AutoFitWidthApproach.BOTH);
8590

91+
DateListGridField trained = new DateListGridField("trained", I18N.message("lasttrained"));
92+
93+
ListGridField training = new RunningListGridField();
94+
8695
list = new RefreshableListGrid();
8796
list.setEmptyMessage(I18N.message("notitemstoshow"));
8897
list.setShowAllRecords(true);
8998
list.setAutoFetchData(true);
9099
list.setWidth100();
91100
list.setHeight100();
92-
list.setFields(id, name, label, modelType, description);
101+
list.setFields(id, name, label, modelType, training, trained, description);
93102
list.setSelectionType(SelectionStyle.SINGLE);
94103
list.setShowRecordComponents(true);
95104
list.setShowRecordComponentsByCell(true);
@@ -170,7 +179,20 @@ public void onSuccess(Void result) {
170179
}
171180
}));
172181

173-
contextMenu.setItems(delete);
182+
MenuItem train = new MenuItem();
183+
train.setTitle(I18N.message("starttraining"));
184+
train.addClickHandler(event -> LD.ask(I18N.message("question"), I18N.message("confirmtraining"), confirm -> {
185+
if (Boolean.TRUE.equals(confirm)) {
186+
AIService.Instance.get().trainModel(ids.get(0), new DefaultAsyncCallback<>() {
187+
@Override
188+
public void onSuccess(Void result) {
189+
// Nothing to do
190+
}
191+
});
192+
}
193+
}));
194+
195+
contextMenu.setItems(train, delete);
174196
contextMenu.showContextMenu();
175197
}
176198

@@ -205,6 +227,7 @@ public void updateRecord(GUIModel model) {
205227
rec.setAttribute("name", model.getName());
206228
rec.setAttribute(LABEL, model.getLabel() != null ? model.getLabel() : model.getName());
207229
rec.setAttribute(DESCRIPTION, model.getDescription());
230+
rec.setAttribute("training", model.getTraining().isEnabled());
208231
list.refreshRow(list.getRecordIndex(rec));
209232

210233
}
@@ -223,4 +246,15 @@ public boolean equals(Object other) {
223246
public int hashCode() {
224247
return super.hashCode();
225248
}
249+
250+
private void loadTasks() {
251+
AIService.Instance.get().getModels(new DefaultAsyncCallback<>() {
252+
@Override
253+
public void onSuccess(List<GUIModel> models) {
254+
for (GUIModel guiModel : models) {
255+
updateRecord(guiModel);
256+
}
257+
}
258+
});
259+
}
226260
}

0 commit comments

Comments
 (0)