2010-02-27 00:33:16 +01:00
|
|
|
package com.metaweb.gridworks.model;
|
|
|
|
|
2010-03-06 08:43:45 +01:00
|
|
|
import java.io.Writer;
|
2010-02-27 00:33:16 +01:00
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
2010-03-06 08:43:45 +01:00
|
|
|
import org.json.JSONObject;
|
2010-02-27 00:33:16 +01:00
|
|
|
import org.json.JSONWriter;
|
|
|
|
|
|
|
|
import com.metaweb.gridworks.Jsonizable;
|
|
|
|
import com.metaweb.gridworks.expr.ExpressionUtils;
|
|
|
|
import com.metaweb.gridworks.model.Recon.Judgment;
|
|
|
|
|
2010-03-07 23:37:26 +01:00
|
|
|
public class ReconStats implements Jsonizable {
|
2010-03-06 09:03:29 +01:00
|
|
|
static public ReconStats load(JSONObject obj) throws Exception {
|
2010-03-06 08:43:45 +01:00
|
|
|
return new ReconStats(
|
|
|
|
obj.getInt("nonBlanks"),
|
|
|
|
obj.getInt("newTopics"),
|
|
|
|
obj.getInt("matchedTopics")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-03-03 05:19:58 +01:00
|
|
|
final public int nonBlanks;
|
|
|
|
final public int newTopics;
|
|
|
|
final public int matchedTopics;
|
2010-02-27 00:33:16 +01:00
|
|
|
|
|
|
|
public ReconStats(int nonBlanks, int newTopics, int matchedTopics) {
|
|
|
|
this.nonBlanks = nonBlanks;
|
|
|
|
this.newTopics = newTopics;
|
|
|
|
this.matchedTopics = matchedTopics;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void write(JSONWriter writer, Properties options)
|
|
|
|
throws JSONException {
|
|
|
|
|
|
|
|
writer.object();
|
2010-03-03 05:19:58 +01:00
|
|
|
writer.key("nonBlanks"); writer.value(nonBlanks);
|
|
|
|
writer.key("newTopics"); writer.value(newTopics);
|
|
|
|
writer.key("matchedTopics"); writer.value(matchedTopics);
|
2010-02-27 00:33:16 +01:00
|
|
|
writer.endObject();
|
|
|
|
}
|
|
|
|
|
|
|
|
static public ReconStats create(Project project, int cellIndex) {
|
2010-03-03 05:19:58 +01:00
|
|
|
int nonBlanks = 0;
|
|
|
|
int newTopics = 0;
|
|
|
|
int matchedTopics = 0;
|
|
|
|
|
|
|
|
for (Row row : project.rows) {
|
|
|
|
Cell cell = row.getCell(cellIndex);
|
|
|
|
if (cell != null && ExpressionUtils.isNonBlankData(cell.value)) {
|
|
|
|
nonBlanks++;
|
|
|
|
|
|
|
|
if (cell.recon != null) {
|
|
|
|
if (cell.recon.judgment == Judgment.New) {
|
|
|
|
newTopics++;
|
|
|
|
} else if (cell.recon.judgment == Judgment.Matched) {
|
|
|
|
matchedTopics++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new ReconStats(nonBlanks, newTopics, matchedTopics);
|
2010-02-27 00:33:16 +01:00
|
|
|
}
|
2010-03-06 08:43:45 +01:00
|
|
|
|
|
|
|
public void save(Writer writer) {
|
|
|
|
JSONWriter jsonWriter = new JSONWriter(writer);
|
|
|
|
try {
|
|
|
|
write(jsonWriter, new Properties());
|
|
|
|
} catch (JSONException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2010-02-27 00:33:16 +01:00
|
|
|
}
|