Skip to content

Commit

Permalink
Merge pull request #141 from yjx0003/develop
Browse files Browse the repository at this point in the history
Fix bugs and change version.
  • Loading branch information
rmartico authored Jul 26, 2024
2 parents 2fa2af5 + 728d3a9 commit 77d2af9
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 68 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>es.ubu.lsi</groupId>
<artifactId>ubumonitor</artifactId>
<version>2.10.5</version>
<version>2.10.6</version>



Expand Down
2 changes: 1 addition & 1 deletion src/main/java/es/ubu/lsi/ubumonitor/AppInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class AppInfo {


public static final String VERSION = "2.10.5";
public static final String VERSION = "2.10.6";

public static final String APPLICATION_VERSION = "v" + VERSION;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,53 +62,58 @@ public Scatter2DChart(PartitionalClusteringController clusteringController) {
*/
@Override
public void updateChart(List<ClusterWrapper> clusters) {
connector.setClusters(clusters);
LOGGER.debug("Clusters: {}", clusters);
points = AlgorithmExecuter.clustersTo(2, clusters);

Map<ClusterWrapper, Color> colors = UtilMethods.getRandomColors(clusters);

JSObject root = new JSObject();
JSArray datasets = new JSArray();
JSObject centers = new JSObject();
centers.putWithQuote("label", I18n.get("clustering.centroids"));
centers.putWithQuote("backgroundColor", "black");
JSArray centersData = new JSArray();

int total = clusters.stream().mapToInt(ClusterWrapper::size).sum();

for (int i = 0; i < points.size(); i++) {
JSObject group = new JSObject();
group.putWithQuote("label", getLegend(clusters.get(i), total));
group.put("backgroundColor", UtilMethods.colorToRGB(colors.get(clusters.get(i))));
JSArray data = new JSArray();
for (Map.Entry<UserData, double[]> userEntry : points.get(i).entrySet()) {
UserData user = userEntry.getKey();
JSObject coord = new JSObject();
double[] point = userEntry.getValue();
coord.put("x", point[0]);
coord.put("y", point.length == 2 ? point[1] : 0.0);

if (user == null) {
coord.putWithQuote("user", I18n.get("clustering.centroid"));
centersData.add(coord);
} else {
coord.putWithQuote("user", user.getEnrolledUser().getFullName());
data.add(coord);
try { // FIX #137 catch exception generating an empty dataset
connector.setClusters(clusters);
LOGGER.debug("Clusters: {}", clusters);
points = AlgorithmExecuter.clustersTo(2, clusters);

Map<ClusterWrapper, Color> colors = UtilMethods.getRandomColors(clusters);

JSObject root = new JSObject();
JSArray datasets = new JSArray();
JSObject centers = new JSObject();
centers.putWithQuote("label", I18n.get("clustering.centroids"));
centers.putWithQuote("backgroundColor", "black");
JSArray centersData = new JSArray();

int total = clusters.stream().mapToInt(ClusterWrapper::size).sum();

for (int i = 0; i < points.size(); i++) {
JSObject group = new JSObject();
group.putWithQuote("label", getLegend(clusters.get(i), total));
group.put("backgroundColor", UtilMethods.colorToRGB(colors.get(clusters.get(i))));
JSArray data = new JSArray();
for (Map.Entry<UserData, double[]> userEntry : points.get(i).entrySet()) {
UserData user = userEntry.getKey();
JSObject coord = new JSObject();
double[] point = userEntry.getValue();
coord.put("x", point[0]);
coord.put("y", point.length == 2 ? point[1] : 0.0);

if (user == null) {
coord.putWithQuote("user", I18n.get("clustering.centroid"));
centersData.add(coord);
} else {
coord.putWithQuote("user", user.getEnrolledUser().getFullName());
data.add(coord);
}
}
group.put("data", data);
datasets.add(group);
}
group.put("data", data);
datasets.add(group);
}

if (!centersData.isEmpty()) {
centers.put("data", centersData);
datasets.add(centers);
}
root.put("datasets", datasets);
LOGGER.debug("2D series: {}", root);
if (!centersData.isEmpty()) {
centers.put("data", centersData);
datasets.add(centers);
}
root.put("datasets", datasets);
LOGGER.debug("2D series: {}", root);

getWebEngine().executeScript("updateChart(" + root + ")");
getWebEngine().executeScript("updateChart(" + root + ")");
} catch (Exception e) {
LOGGER.error("Error updating chart", e);
getWebEngine().executeScript("updateChart({\"datasets\":[]})");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,34 @@ public Scatter3DChart(PartitionalClusteringController controller) {
*/
@Override
public void updateChart(List<ClusterWrapper> clusters) {
points = AlgorithmExecuter.clustersTo(3, clusters);
try { // FIX #137 catch exception generating an empty dataset
points = AlgorithmExecuter.clustersTo(3, clusters);

JSArray series = new JSArray();
int total = clusters.stream().mapToInt(ClusterWrapper::size).sum();
for (int i = 0; i < clusters.size(); i++) {
ClusterWrapper cluster = clusters.get(i);
JSObject serie = new JSObject();
serie.putWithQuote("name", getLegend(cluster, total));
JSArray data = new JSArray();
for (Entry<UserData, double[]> entry : points.get(i).entrySet()) {
double[] value = entry.getValue();
JSArray point = new JSArray();
point.add(value[0]);
point.add(value.length > 1 ? value[1] : 0.0);
point.add(value.length > 2 ? value[2] : 0.0);
data.add(point);
JSArray series = new JSArray();
int total = clusters.stream().mapToInt(ClusterWrapper::size).sum();
for (int i = 0; i < clusters.size(); i++) {
ClusterWrapper cluster = clusters.get(i);
JSObject serie = new JSObject();
serie.putWithQuote("name", getLegend(cluster, total));
JSArray data = new JSArray();
for (Entry<UserData, double[]> entry : points.get(i).entrySet()) {
double[] value = entry.getValue();
JSArray point = new JSArray();
point.add(value[0]);
point.add(value.length > 1 ? value[1] : 0.0);
point.add(value.length > 2 ? value[2] : 0.0);
data.add(point);
}
serie.put("data", data);
series.add(serie);
}
serie.put("data", data);
series.add(serie);
}

LOGGER.debug("3D series: {}", series);
getWebEngine().executeScript("updateChart(" + series + ")");
LOGGER.debug("3D series: {}", series);
getWebEngine().executeScript("updateChart(" + series + ")");
} catch (Exception e) {
LOGGER.error("Error updating chart 3D", e);
getWebEngine().executeScript("updateChart()");
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public static List<Map<UserData, double[]>> clustersTo(int dim, List<ClusterWrap
List<Map<UserData, double[]>> points = new ArrayList<>();
// PCA with T-SNE
PrincipalComponentAnalysis pca = new PrincipalComponentAnalysis();
if (matrix[0].length > dim) {
if (matrix[0].length >= dim) { // FIX #137 changed > to >=
matrix = pca.pca(matrix, dim);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/es/ubu/lsi/ubumonitor/util/UtilMethods.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ public static <T> String joinWithQuotes(List<T> list) {
* @param stringToRemove need to remove reserved character
* @return without reserved character
*/
public static String removeReservedChar(String stringToRemove) {
String newString = stringToRemove.replaceAll(":|\\\\|/|\\?|\\*|\\|", "");
public static String removeReservedChar(String stringToRemove) {
String newString = stringToRemove.replaceAll("\"|\\||<|>|:|\\\\|/|\\?|\\*|\\|", ""); // FIX #139 added more dangerous characters
return newString.trim();

}
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/es/ubu/lsi/ubumonitor/UnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public void removeBackSlashTest() {
fillMap(map, "Inglés EPS VENA-curso 2019:20", "Inglés EPS VENA-curso 201920");
fillMap(map, "Inglés EPS\\ VENA-curso 2019:20", "Inglés EPS VENA-curso 201920");
fillMap(map, "Inglés EPS ?VENA-curso 2019:20", "Inglés EPS VENA-curso 201920");
fillMap(map, "Inglés EPS \"VENA-curso 2019:20\"", "Inglés EPS VENA-curso 201920");
fillMap(map, "Inglés EPS <VENA-curso 2019:20>", "Inglés EPS VENA-curso 201920");
fillMap(map, "Inglés EPS |VENA-curso 2019:20|", "Inglés EPS VENA-curso 201920");
for (Map.Entry<String, String> entry : map.entrySet()) {
assertEquals(entry.getValue(), entry.getKey());
}
Expand Down

0 comments on commit 77d2af9

Please sign in to comment.