Skip to content

Commit

Permalink
fixing the rest of the wrong /share results
Browse files Browse the repository at this point in the history
works for /share/groupBy/boundary too
  • Loading branch information
kowatsch committed May 28, 2018
1 parent dde86fb commit 092b3c1
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -621,12 +621,27 @@ public static RatioShareResponse executeCountLengthPerimeterAreaRatio(
iP.checkKeysValues(keys2, values2);
values2 = iP.createEmptyArrayIfNull(values2);
keys2 = iP.createEmptyArrayIfNull(keys2);

if (isShare) {
keys2 = iP.addFilterKeys(rPs.getKeys(), keys2);
// values2 = iP.addFilterValues(rPs.getKeys(), keys2, rPs.getValues(), values2);
List<Pair<String, String>> keys2Vals2;
if (rPs.getValues().length == 0) {
keys2 = iP.addFilterKeys(rPs.getKeys(), keys2);
} else if (keys2.length == 0) {
keys2 = rPs.getKeys();
values2 = rPs.getValues();
} else {
keys2Vals2 = iP.addFilterKeysVals(rPs.getKeys(), rPs.getValues(), keys2, values2);
String[] newKeys2 = new String[keys2Vals2.size()];
String[] newValues2 = new String[keys2Vals2.size()];
for (int i = 0; i < keys2Vals2.size(); i++) {
Pair<String, String> tag = keys2Vals2.get(i);
newKeys2[i] = tag.getKey();
newValues2[i] = tag.getValue();
}
keys2 = newKeys2;
values2 =
Arrays.stream(newValues2).filter(value -> !value.equals("")).toArray(String[]::new);
}
}

Integer[] keysInt1 = new Integer[rPs.getKeys().length];
Integer[] valuesInt1 = new Integer[rPs.getValues().length];
Integer[] keysInt2 = new Integer[keys2.length];
Expand Down Expand Up @@ -770,12 +785,27 @@ public static RatioShareResponse executeCountLengthPerimeterAreaRatioGroupByBoun
iP.checkKeysValues(keys2, values2);
values2 = iP.createEmptyArrayIfNull(values2);
keys2 = iP.createEmptyArrayIfNull(keys2);

if (isShare) {
keys2 = iP.addFilterKeys(rPs.getKeys(), keys2);
// values2 = iP.addFilterValues(rPs.getKeys(), keys2, rPs.getValues(), values2);
List<Pair<String, String>> keys2Vals2;
if (rPs.getValues().length == 0) {
keys2 = iP.addFilterKeys(rPs.getKeys(), keys2);
} else if (keys2.length == 0) {
keys2 = rPs.getKeys();
values2 = rPs.getValues();
} else {
keys2Vals2 = iP.addFilterKeysVals(rPs.getKeys(), rPs.getValues(), keys2, values2);
String[] newKeys2 = new String[keys2Vals2.size()];
String[] newValues2 = new String[keys2Vals2.size()];
for (int i = 0; i < keys2Vals2.size(); i++) {
Pair<String, String> tag = keys2Vals2.get(i);
newKeys2[i] = tag.getKey();
newValues2[i] = tag.getValue();
}
keys2 = newKeys2;
values2 =
Arrays.stream(newValues2).filter(value -> !value.equals("")).toArray(String[]::new);
}
}

Integer[] keysInt1 = new Integer[rPs.getKeys().length];
Integer[] valuesInt1 = new Integer[rPs.getValues().length];
Integer[] keysInt2 = new Integer[keys2.length];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.heigit.bigspatialdata.ohsome.ohsomeApi.controller.executor.RequestParameters;
import org.heigit.bigspatialdata.ohsome.ohsomeApi.exception.BadRequestException;
import org.heigit.bigspatialdata.ohsome.ohsomeApi.oshdb.DbConnData;
Expand Down Expand Up @@ -253,12 +257,55 @@ public boolean compareKeysValues(String[] keys, String[] keys2, String[] values,
}

/**
* Compares the given keys arrays and adds those of the first to the second, if it has
* some, which the second one has not. Only used for /share requests.
* Adds the filter parameters from keys and values to a list as tags. Only used in the processing
* of /share requests.
*/
public List<Pair<String, String>> addFilterKeysVals(String[] keys, String[] values,
String[] keys2, String[] values2) {

ArrayList<Pair<String, String>> tags = new ArrayList<Pair<String, String>>();
for (int i = 0; i < keys.length; i++) {
String key = keys[i];
Pair<String, String> tag;
if (i >= values.length)
tag = new ImmutablePair<>(key, "");
else
tag = new ImmutablePair<>(key, values[i]);
tags.add(tag);
}
for (int i = 0; i < keys2.length; i++) {
String key = keys2[i];
Pair<String, String> tag;
if (i >= values2.length)
tag = new ImmutablePair<>(key, "");
else
tag = new ImmutablePair<>(key, values2[i]);
tags.add(tag);
}
// sorting to have all Pair<key,""> at the end of the list
Collections.sort(tags, new Comparator<Pair<String, String>>() {
@Override
public int compare(Pair<String, String> p1, Pair<String, String> p2) {
if (p1.getValue().equals("") && p2.getValue().equals(""))
return 0;
else if (p1.getValue().equals("") && !p2.getValue().equals(""))
return 1;
else if (!p1.getValue().equals("") && p2.getValue().equals(""))
return -1;
else
return 0;
}
});
return tags;
}

/**
* Compares the given keys arrays and adds those of the first to the second, if it has some, which
* the second one has not. Only used in the processing of /share requests.
*/
public String[] addFilterKeys(String[] keys, String[] keys2) {

if (keys == null || keys.length == 0)
if (keys.length == 0)
return keys2;
if (Arrays.equals(keys, keys2))
return keys2;
Expand All @@ -270,26 +317,6 @@ public String[] addFilterKeys(String[] keys, String[] keys2) {
}
return keysList.toArray(new String[keysList.size()]);
}

/**
* Compares the given values arrays and adds those of the first to the second, if it has
* some, which the second one has not. Only used for /share requests.
*/
public String[] addFilterValues(String[] keys, String[] keys2, String[] values, String[] values2) {

if (keys == null || keys.length == 0 || values == null || values.length == 0)
return values2;
if (Arrays.equals(values, values2))
return values2;
ArrayList<String> valuesList = (ArrayList<String>) Arrays.asList(values);

for (String s : keys) {
if (!valuesList.contains(s)) {
valuesList.add(s);
}
}
return (String[]) valuesList.toArray();
}

/**
* Checks the given keys and values parameters on their length and includes them in the
Expand Down

0 comments on commit 092b3c1

Please sign in to comment.