Skip to content

Commit

Permalink
create aggregated scorecard #207
Browse files Browse the repository at this point in the history
  • Loading branch information
TatianaBurek committed Oct 12, 2020
1 parent 6d4aa43 commit 930ba33
Show file tree
Hide file tree
Showing 9 changed files with 735 additions and 461 deletions.
370 changes: 283 additions & 87 deletions java/edu/ucar/metviewer/scorecard/GraphicalOutputManager.java

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions java/edu/ucar/metviewer/scorecard/Scorecard.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import edu.ucar.metviewer.scorecard.exceptions.MissingFileException;
import edu.ucar.metviewer.scorecard.model.Entry;
import edu.ucar.metviewer.scorecard.model.Field;
import edu.ucar.metviewer.scorecard.model.WeightRequirements;
import edu.ucar.metviewer.scorecard.model.WorkingFolders;
import edu.ucar.metviewer.scorecard.rscript.*;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -68,6 +69,7 @@ public class Scorecard {
private String statValue;
private String statSymbol;
private String thresholdFile = null;
private String weightFile = null;
private List<String> leftColumnsNames = new ArrayList<>();
private String symbolSize = "100%";
private String executionType = RSCRIPT;
Expand Down Expand Up @@ -421,6 +423,13 @@ public String getThresholdFile() {
public void setThresholdFile(String thresholdFile) {
this.thresholdFile = thresholdFile;
}
public String getWeightFile() {
return weightFile;
}

public void setWeightFile(String weightFile) {
this.weightFile = weightFile;
}

public List<String> getLeftColumnsNames() {
return leftColumnsNames;
Expand Down
9 changes: 6 additions & 3 deletions java/edu/ucar/metviewer/scorecard/XmlParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ private void setPlot(Scorecard scorecard, Node scorecardSpecNode) {
}
} else if ("threshold_file".equals(plotNode.getNodeName())) {
scorecard.setThresholdFile(plotNode.getTextContent());
} else if ("weight_file".equals(plotNode.getNodeName())) {
scorecard.setWeightFile(plotNode.getTextContent());
} else if ("printSQL".equals(plotNode.getNodeName())) {
if (plotNode.getTextContent().equalsIgnoreCase(String.valueOf(Boolean.TRUE))) {
scorecard.setPrintSQL(Boolean.TRUE);
Expand Down Expand Up @@ -241,6 +243,7 @@ private List<Field> constructFields(Node plotNode) {
private Field constructField(Node fieldNode) {
Field field = new Field();
field.setName(getFieldName(fieldNode));
field.setLabel(getFieldLabel(fieldNode));
List<Entry> values = new ArrayList<>();
List<Field> fields = new ArrayList<>();
NodeList fieldNodeList = fieldNode.getChildNodes();
Expand Down Expand Up @@ -280,15 +283,15 @@ private String getFieldName(Node fieldsNode) {
}

private String getFieldLabel(Node fieldsNode) {
String fieldName = null;
String fieldLabel = null;
NamedNodeMap fieldAtts = fieldsNode.getAttributes();
for (int k = 0; k < fieldAtts.getLength(); k++) {
if ("label".equals(fieldAtts.item(k).getNodeName())) {
fieldName = fieldAtts.item(k).getNodeValue();
fieldLabel = fieldAtts.item(k).getNodeValue();
break;
}
}
return fieldName;
return fieldLabel;
}

private void setFolders(Scorecard scorecard, Node scorecardSpecNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public HtmlImageGenerator() {
editorPane.setOpaque(true);
//editorPane.setSize(DEFAULT_SIZE);
Font font;
try (InputStream is = getClass().getResourceAsStream("l_10646.ttf")) {
try (InputStream is = getClass().getResourceAsStream("DejaVuSans.ttf")) {
font = Font.createFont(Font.TRUETYPE_FONT, is).deriveFont(Font.PLAIN, 14);
} catch (FontFormatException | IOException e) {
font = new Font("SansSerif", Font.PLAIN, 14);
Expand Down
11 changes: 11 additions & 0 deletions java/edu/ucar/metviewer/scorecard/model/Field.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*/
public class Field {
private String name;
private String label;

private List<Entry> values = new ArrayList<>();
private List<Field> fields = new ArrayList<>();

Expand Down Expand Up @@ -41,5 +43,14 @@ public void setValues(List<Entry> values) {
this.values = values;
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}



}
125 changes: 69 additions & 56 deletions java/edu/ucar/metviewer/scorecard/rscript/AggPythonManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import edu.ucar.metviewer.scorecard.Scorecard;
import edu.ucar.metviewer.scorecard.Util;
import edu.ucar.metviewer.scorecard.model.Entry;
import edu.ucar.metviewer.scorecard.model.Field;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.Marker;
Expand Down Expand Up @@ -75,65 +76,77 @@ public AggPythonManager(final Scorecard scorecard) {

@Override
public void calculateStatsForRow(Map<String, Entry> mapRow, String threadName) {
clean();
initModels();
if (models != null) {

init(mapRow);
initAggBool(yamlInfo, Util.getAggTypeForStat(stat));

//create a template
yamlInfo.put("indy_var", indyVar);
yamlInfo.put("indy_vals", indyList.get(indyVar));

List<String> statList = new ArrayList<>();
statList.add(stat);
yamlInfo.put("list_stat_1", statList);


Map<String, String> list_static_val = new HashMap<>();
list_static_val.put("fcst_var", fcstVar);
yamlInfo.put("list_static_val", list_static_val);
yamlInfo.put("series_val_1", seriesList);

yamlInfo.put("derived_series_1", seriesDiffList);
Map<String, List<String>> fcst_var_val_1 = new HashMap<>();
List<String> fcst_var_val_1_list = new ArrayList<>();
fcst_var_val_1_list.add(stat);
fcst_var_val_1.put(fcstVar, fcst_var_val_1_list);
yamlInfo.put("fcst_var_val_1", fcst_var_val_1);

//check id output file exists and its length not 0
File output = new File((String) yamlInfo.get("agg_stat_output"));
boolean isAppend = false;
if (output.exists() && output.length() > 0) {
isAppend = true;
List<Entry> allModels = null;
for (Field fixedField : fixedVars) {
if ("model".equals(fixedField.getName())) {
allModels = fixedField.getValues();
break;
}
yamlInfo.put("append_to_file", isAppend ? "True" : "False");

try (PrintStream printStream = IoBuilder.forLogger(AggRscriptManager.class)
.setLevel(org.apache.logging.log4j.Level.INFO)
.buildPrintStream()) {
createYamlFile(aggInfoFileName, yamlInfo);
StopWatch stopWatch = new StopWatch();
stopWatch.start();
printStream.println("Running " + python + " " + metCalcpyHome + PYTHON_SCRIPT + " " + aggInfoFileName);


MvResponse mvResponse = MVUtil.runRscript(python,
metCalcpyHome + PYTHON_SCRIPT,
new String[]{aggInfoFileName},
new String[]{"PYTHONPATH=" + metCalcpyHome});
stopWatch.stop();
if (mvResponse.getInfoMessage() != null) {
printStream.println(mvResponse.getInfoMessage());
}
if (allModels != null) {
for (int i = 0; i < allModels.size(); i = i + 2) {
clean();
models = new ArrayList<>(2);
models.add(allModels.get(i));
if (i + 1 < allModels.size()) {
models.add(allModels.get(i + 1));
}
init(mapRow);
initAggBool(yamlInfo, Util.getAggTypeForStat(stat));

//create a template
yamlInfo.put("indy_var", indyVar);
yamlInfo.put("indy_vals", indyList.get(indyVar));

List<String> statList = new ArrayList<>();
statList.add(stat);
yamlInfo.put("list_stat_1", statList);


Map<String, String> list_static_val = new HashMap<>();
list_static_val.put("fcst_var", fcstVar);
yamlInfo.put("list_static_val", list_static_val);
yamlInfo.put("series_val_1", seriesList);

yamlInfo.put("derived_series_1", seriesDiffList);
Map<String, List<String>> fcst_var_val_1 = new HashMap<>();
List<String> fcst_var_val_1_list = new ArrayList<>();
fcst_var_val_1_list.add(stat);
fcst_var_val_1.put(fcstVar, fcst_var_val_1_list);
yamlInfo.put("fcst_var_val_1", fcst_var_val_1);

//check id output file exists and its length not 0
File output = new File((String) yamlInfo.get("agg_stat_output"));
boolean isAppend = false;
if (output.exists() && output.length() > 0) {
isAppend = true;
}
if (mvResponse.getErrorMessage() != null) {
printStream.println(mvResponse.getErrorMessage());
yamlInfo.put("append_to_file", isAppend ? "True" : "False");

try (PrintStream printStream = IoBuilder.forLogger(AggRscriptManager.class)
.setLevel(org.apache.logging.log4j.Level.INFO)
.buildPrintStream()) {
createYamlFile(aggInfoFileName, yamlInfo);
StopWatch stopWatch = new StopWatch();
stopWatch.start();
printStream.println("Running " + python + " " + metCalcpyHome + PYTHON_SCRIPT + " " + aggInfoFileName);


MvResponse mvResponse = MVUtil.runRscript(python,
metCalcpyHome + PYTHON_SCRIPT,
new String[]{aggInfoFileName},
new String[]{"PYTHONPATH=" + metCalcpyHome});
stopWatch.stop();
if (mvResponse.getInfoMessage() != null) {
printStream.println(mvResponse.getInfoMessage());
}
if (mvResponse.getErrorMessage() != null) {
printStream.println(mvResponse.getErrorMessage());
}
printStream.println("Python time " + stopWatch.getFormattedTotalDuration());
} catch (IOException | StopWatchException e) {
logger.error(ERROR_MARKER, e.getMessage());
}
printStream.println("Python time " + stopWatch.getFormattedTotalDuration());
} catch (IOException | StopWatchException e) {
logger.error(ERROR_MARKER, e.getMessage());
}
}
}
Expand Down
Loading

0 comments on commit 930ba33

Please sign in to comment.