Skip to content

Commit

Permalink
Staging cleanup before merge to main
Browse files Browse the repository at this point in the history
- Compute total while parsing and add to quantity distribution
- Remove duplicate constant
- Avoid synthetic getter conflict with expected actual getter
- Update banner.txt
  • Loading branch information
wwelling committed Jul 14, 2023
1 parent 860d135 commit 0a41e50
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ public class DiscoveryQuantityDistribution {

private final List<Slice> distribution;

private Long total;

private DiscoveryQuantityDistribution(String label, String field) {
this.label = label;
this.field = field;
this.distribution = new ArrayList<>();
this.total = 0L;
}

public String getLabel() {
Expand All @@ -35,18 +38,26 @@ public List<Slice> getDistribution() {
return distribution;
}

public Long getTotal() {
return total;
}

public void parse(QueryResponse response) {
response.getFacetField(field)
response
.getFacetField(field)
.getValues()
.stream()
.sorted(new Comparator<Count>() {

@Override
public int compare(Count o1, Count o2) {
return Long.compare(o2.getCount(), o1.getCount());
}
@Override
public int compare(Count o1, Count o2) {
return Long.compare(o2.getCount(), o1.getCount());
}

}).forEach(value -> distribution.add(new Slice(value.getName(), value.getCount())));
}).forEach(value -> {
distribution.add(new Slice(value.getName(), value.getCount()));
total += value.getCount();
});
}

public static DiscoveryQuantityDistribution from(DiscoveryQuantityDistributionDescriptor quantityDistributionDescriptor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;

import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
Expand Down Expand Up @@ -97,6 +97,8 @@ public void from(DiscoveryResearchAgeDescriptor researcherAgeDescriptor, SolrDoc

});

Collections.sort(groups, new AgeGroupComparator());

this.mean = results.size() > 0 ? sum.get() / results.size() : 0;
this.median = results.size() > 0 ? DateUtility.ageInYearsFromEpochSecond((long) results.get(results.size() / 2).getFieldValue(ageField)) : 0;
}
Expand All @@ -114,15 +116,7 @@ public Map<String, String> getRanges() {
}

public List<AgeGroup> getGroups() {
// NOTE: sorting on serialization in response
return groups.stream().sorted(new Comparator<AgeGroup>() {

@Override
public int compare(AgeGroup o1, AgeGroup o2) {
return o1.getIndex().compareTo(o2.getIndex());
}

}).collect(Collectors.toList());
return groups;
}

public double getMean() {
Expand Down Expand Up @@ -157,4 +151,13 @@ public Integer getValue() {
}
}

private class AgeGroupComparator implements Comparator<AgeGroup> {

@Override
public int compare(AgeGroup o1, AgeGroup o2) {
return o1.getIndex().compareTo(o2.getIndex());
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Date;
import java.util.Locale;

import org.apache.commons.lang3.StringUtils;
import org.springframework.context.i18n.LocaleContextHolder;

import edu.tamu.scholars.middleware.discovery.model.AbstractIndexDocument;
Expand All @@ -11,7 +12,6 @@

public class FilenameUtility {

private final static String SPACE = " ";
private final static String UNDERSCORE = "_";

private FilenameUtility() {
Expand All @@ -33,7 +33,7 @@ public static String normalizeExportFilename(Individual individual) {
private static String localizeWhileUnderscoreReplaceSpaceWithUnderscore(String value) {
Locale locale = LocaleContextHolder.getLocale();
return value.toLowerCase(locale)
.replace(SPACE, UNDERSCORE);
.replace(StringUtils.SPACE, UNDERSCORE);
}

private static String prefixWithTimestampAfterUnderscore(String value) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/banner.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
___ _ _
/ __| __| |_ ___| |__ _ _ _ ___
\__ \/ _| ' \/ _ \ / _` | '_(_-<
\__ \/ _| ' \/ _ \ / _` | '_/_-<
|___/\__|_||_\___/_\__,_|_| /__/

0 comments on commit 0a41e50

Please sign in to comment.