Skip to content

Commit

Permalink
Merge pull request #248 from dataspread/chart_memoization
Browse files Browse the repository at this point in the history
memoization for summary chart computation
  • Loading branch information
twattanawaroon authored Apr 4, 2019
2 parents 29d1f7b + 21bd932 commit 3772f5f
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 14 deletions.
2 changes: 2 additions & 0 deletions dataspread-ui/src/Components/Navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,8 @@ export default class Navigation extends Component {
queryObj.last = lastR;
queryObj.conditions = cond;
queryObj.values = value;
let childlist = this.computePath();
queryObj.path = " " + childlist;

fetch(this.state.urlPrefix + '/api/' + 'getBrushColorList', {
method: "POST",
Expand Down
19 changes: 14 additions & 5 deletions webapp/src/api/controller/NavigationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ public HashMap<String, Object> getBrushColorList(@RequestBody String value) {
JSONObject dict = (JSONObject) parser.parse(value);
String bookId = (String) dict.get("bookId");
String sheetName = (String) dict.get("sheetName");
String path = (String) dict.get("path");

JSONArray first_ls = (JSONArray) dict.get("first");
JSONArray last_ls = (JSONArray) dict.get("last");
JSONArray cond_ls = (JSONArray) dict.get("conditions");
Expand All @@ -249,7 +251,8 @@ public HashMap<String, Object> getBrushColorList(@RequestBody String value) {
SBook book = BookBindings.getBookById(bookId);
SSheet currentSheet = book.getSheetByName(sheetName);

ArrayList<Integer> indices = new ArrayList<Integer>();

List cellIndices;
Model model = currentSheet.getDataModel();
//Todo: when on demand loading available
/*for(int i=0;i<first_ls.size();i++)
Expand All @@ -264,13 +267,19 @@ public HashMap<String, Object> getBrushColorList(@RequestBody String value) {
double queryValue = Double.parseDouble((String) val_ls.get(i));
if(model.navS.isConditionSatisfied(currvalue,(String) cond_ls.get(i),queryValue))
indices.add(j);
cellIndices.add(j);
}
}*/

System.out.println("Calling brush color list");


int first = (Integer) first_ls.get(0);
int last = (Integer) last_ls.get(0);

//cellIndices = model.navS.getBrushColotList(first,last,val_ls,cond_ls,attrIndex);

cellIndices = new ArrayList<Integer>();
for(int j=first;j<=last;j++)
{
SCell sCell = currentSheet.getCell(j, attrIndex);
Expand All @@ -280,19 +289,19 @@ public HashMap<String, Object> getBrushColorList(@RequestBody String value) {
double queryValue = Double.parseDouble((String) val_ls.get(0));

if (model.navS.isConditionSatisfied(currvalue, (String) cond_ls.get(0), queryValue))
indices.add(j);
cellIndices.add(j);
}catch (Exception e)
{
String currvalue = String.valueOf(sCell.getValue());
String queryValue = (String) val_ls.get(0);

if (model.navS.isConditionSatisfiedStr(currvalue, (String) cond_ls.get(0), queryValue))
indices.add(j);
cellIndices.add(j);
}
}


return JsonWrapper.generateJson(indices);
return JsonWrapper.generateJson(cellIndices);
}

private int[] getIndices(String path) {
Expand Down
1 change: 1 addition & 0 deletions zssmodel/src/org/zkoss/zss/model/impl/Bucket.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class Bucket<T> implements Serializable {
String summary;
ArrayList<Bucket> children;
Map<String, Object> aggMem;
Map<String, Object> summaryStat;

Bucket() {
aggMem = new HashMap<>();
Expand Down
21 changes: 12 additions & 9 deletions zssmodel/src/org/zkoss/zss/model/impl/NavChartsPrototype.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ private int getChartType(String formulaStr) {



public HashMap<String,Double> summaryStat(int attr, Bucket<String> subGroup)
public Map<String,Object> summaryStat(int attr, Bucket<String> subGroup)
{
if(subGroup.summaryStat!=null)
return subGroup.summaryStat;

ArrayList<Double> numData = navS.collectDoubleValues(attr, subGroup);
HashMap<String,Double> result = new HashMap<String,Double>();
Map<String,Object> result = new HashMap<>();
//min, max, average, var, STDDEV
// 0, 1, 2, 3, 4
double min = Double.MAX_VALUE;
Expand All @@ -107,7 +110,7 @@ public HashMap<String,Double> summaryStat(int attr, Bucket<String> subGroup)
result.put("AVERAGE",avg/numData.size());
result.put("STDEV",Double.MAX_VALUE);
result.put("VAR",Double.MAX_VALUE);

subGroup.summaryStat = result;
return result;
}

Expand All @@ -133,14 +136,14 @@ private void type0Chart(Map<String, Object> obj, int attr, Bucket<String> subGro
private void type0Chart(Map<String, Object> obj, int attr, Bucket<String> subGroup, String formula) {
obj.put("chartType", 0);
List<Double> chartData = new ArrayList<>();
HashMap<String,Double> res = summaryStat(attr,subGroup);
Map<String, Object> res = summaryStat(attr,subGroup);
List<String> emptyList = new ArrayList<>();
emptyList.add("");
for (String f : type0Stat) {
if(!f.equals("MEDIAN"))
{
chartData.add(res.get(f));
navS.setBucketAggWithMemoization(model,subGroup,attr,f,emptyList,res.get(f));
chartData.add((Double) res.get(f));
navS.setBucketAggWithMemoization(model,subGroup,attr,f,emptyList,(Double) res.get(f));
}
else if(formula.equals("MEDIAN"))
{
Expand Down Expand Up @@ -177,7 +180,7 @@ private void type2Chart(Map<String, Object> obj, int attr, Bucket<String> subGro
NavigationHistogram hist = new NavigationHistogram(navS.collectDoubleValues(attr, subGroup));
hist.formattedOutput(obj, null);

HashMap<String,Double> res = summaryStat(attr,subGroup);
Map<String, Object> res = summaryStat(attr,subGroup);

HashMap<String, Object> chartData = (HashMap) obj.get("chartData");
List<String> emptyList = new ArrayList<>();
Expand All @@ -186,12 +189,12 @@ private void type2Chart(Map<String, Object> obj, int attr, Bucket<String> subGro
if(f.equals("AVERAGE"))
{
chartData.put(f,res.get(f));
navS.setBucketAggWithMemoization(model,subGroup,attr,f,emptyList,res.get(f));
navS.setBucketAggWithMemoization(model,subGroup,attr,f,emptyList,(Double) res.get(f));
}
else
{
Map<String, Object> resMed = navS.getBucketAggWithMemoization(model, subGroup, attr, f, emptyList);
chartData.put(f,(Double) resMed.get("value"));
chartData.put(f,resMed.get("value"));
}
}
}
Expand Down
49 changes: 49 additions & 0 deletions zssmodel/src/org/zkoss/zss/model/impl/NavigationStructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.model.AutoRollbackConnection;
import org.model.DBContext;
import org.model.DBHandler;
import org.zkoss.json.JSONArray;
import org.zkoss.zss.model.CellRegion;
import org.zkoss.zss.model.SBook;
import org.zkoss.zss.model.SCell;
Expand All @@ -32,6 +33,9 @@ public class NavigationStructure {
*/
private ReturnBuffer returnBuffer;
public int isNumericNavAttr;
List cellIndices;




class ReturnBuffer {
Expand Down Expand Up @@ -98,6 +102,51 @@ else if (condition.equals("<="))

}

public List<Integer> getBrushColotList(int first, int last, JSONArray val_ls,JSONArray cond_ls, int attrIndex) {

System.out.println(first+","+last);
List newCellIndices = new ArrayList<Integer>();
if(cellIndices!=null)
{

for(int i=first-1;i<last;i++)
{
if((int) cellIndices.get(i)==1)
newCellIndices.add(i+1);
}
return newCellIndices;
}
cellIndices = new ArrayList<Integer>();
for(int j=first;j<=last;j++)
{
SCell sCell = currentSheet.getCell(j, attrIndex);

try {
double currvalue = Double.parseDouble(String.valueOf(sCell.getValue()));
double queryValue = Double.parseDouble((String) val_ls.get(0));

if (isConditionSatisfied(currvalue, (String) cond_ls.get(0), queryValue)) {
cellIndices.add(1);
newCellIndices.add(j);
}
else
cellIndices.add(0);
}catch (Exception e)
{
String currvalue = String.valueOf(sCell.getValue());
String queryValue = (String) val_ls.get(0);

if (isConditionSatisfiedStr(currvalue, (String) cond_ls.get(0), queryValue)){
cellIndices.add(1);
newCellIndices.add(j);
}
else
cellIndices.add(0);
}
}
return newCellIndices;
}

public boolean isConditionSatisfied(double currValue, String condition, double queryValue) {
int conditionCode = getConditionCode(condition);

Expand Down

0 comments on commit 3772f5f

Please sign in to comment.