|
[HepData-svn] r1903 - trunk/hepdata-webapp/src/main/java/cedar/hepdata/formatsblackhole at projects.hepforge.org blackhole at projects.hepforge.orgMon Nov 9 12:13:26 GMT 2015
Author: whalley Date: Mon Nov 9 12:13:26 2015 New Revision: 1903 Log: fix bug with missing empty x bins Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java Modified: trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java ============================================================================== --- trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java Thu Nov 5 09:58:41 2015 (r1902) +++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java Mon Nov 9 12:13:26 2015 (r1903) @@ -332,93 +332,99 @@ s.append("independent_variables:\n"); if (npoints > 0) { for (XAxis xax : ds.getXAxes()){ - String name=xax.getHeader(); - String unit=""; - if(xax.getHeader().contains(" IN ")){ - name=xax.getHeader().substring(0,xax.getHeader().indexOf(" IN ")).trim(); - unit=xax.getHeader().substring(xax.getHeader().indexOf(" IN ")+4).trim(); - } else if (xax.getHeader().contains(" in ")) { - name=xax.getHeader().substring(0,xax.getHeader().indexOf(" in ")).trim(); - unit=xax.getHeader().substring(xax.getHeader().indexOf(" in ")+4).trim(); - } - s.append(sp+"header: {name: '"+name.replaceAll("'","''")+"'"); - if(!unit.equals("")){ s.append(", units: '"+unit+"'"); } - s.append("}\n"); - s.append(s4+"values:\n"); - for (Bin bin : xax.getBins()){ - boolean first=true; - s.append(s4+sp+"{"); + String name=xax.getHeader(); + String unit=""; + if(xax.getHeader().contains(" IN ")){ + name=xax.getHeader().substring(0,xax.getHeader().indexOf(" IN ")).trim(); + unit=xax.getHeader().substring(xax.getHeader().indexOf(" IN ")+4).trim(); + } else if (xax.getHeader().contains(" in ")) { + name=xax.getHeader().substring(0,xax.getHeader().indexOf(" in ")).trim(); + unit=xax.getHeader().substring(xax.getHeader().indexOf(" in ")+4).trim(); + } + s.append(sp+"header: {name: '"+name.replaceAll("'","''")+"'"); + if(!unit.equals("")){ s.append(", units: '"+unit+"'"); } + s.append("}\n"); + s.append(s4+"values:\n"); + for (int ip=1; ip<npoints+1; ip++){ + Bin bin = xax.getBin(ip); + if(bin == null) { + s.append(s4+sp+"{value: '-'}\n"); + } + else { + boolean first=true; + s.append(s4+sp+"{"); // if(bin.getId() != null ) { // s.append("id: "+bin.getId()); // first=false; // } - boolean asymmfocus = false; - if (bin.getLowValue() != null && bin.getHighValue() != null && bin.getFocus() != null) { - double diff = bin.getFocus() - (bin.getLowValue() + bin.getHighValue()) / 2.0; - if (Math.abs(diff/bin.getFocus()) > 1E-6) { asymmfocus = true; } - } - boolean haswidth = false; - if (bin.getLowValue() != null && bin.getHighValue() != null) { - double diff = bin.getHighValue() - bin.getLowValue(); - double mean = (bin.getLowValue() + bin.getHighValue()) / 2.0; - if((Math.abs(diff/mean) > 1E-6) || (mean == 0.0 && Math.abs(diff) > 1E-6)){ haswidth = true;} - } + boolean asymmfocus = false; + if (bin.getLowValue() != null && bin.getHighValue() != null && bin.getFocus() != null) { + double diff = bin.getFocus() - (bin.getLowValue() + bin.getHighValue()) / 2.0; + if (Math.abs(diff/bin.getFocus()) > 1E-6) { asymmfocus = true; } + } + boolean haswidth = false; + if (bin.getLowValue() != null && bin.getHighValue() != null) { + double diff = bin.getHighValue() - bin.getLowValue(); + double mean = (bin.getLowValue() + bin.getHighValue()) / 2.0; + if((Math.abs(diff/mean) > 1E-6) || (mean == 0.0 && Math.abs(diff) > 1E-6)){ haswidth = true;} + } - if(bin.getRelation() != null && bin.getRelation() != Relation.EQUALS ) { - if(!first) { s.append(", "); } - s.append("value: '"+bin.getRelation()+" "); - if (bin.getLowValue() != null) { - s.append(bin.getLowValue()); - } else if (bin.getHighValue() != null) { - s.append(bin.getHighValue()); - } - s.append("'"); - first=false; - } - else if(bin.getFocus() != null) { - if(asymmfocus || !haswidth) { - if(!first) {s.append(", "); } - if(bin.getFocusLength()!=null) { - s.append("value: "+forms(bin.getFocus(),bin.getFocusLength())); - } else { - s.append("value: "+bin.getFocus()); - } - first=false; - } - } - if(bin.getLowValue() != null && haswidth) { - if(!first) { s.append(", "); } - if(bin.getLowValueLength()!=null) { - s.append("low: "+forms(bin.getLowValue(),bin.getLowValueLength())); - } else { - s.append("low: "+bin.getLowValue()); - } - first=false; - } - if(bin.getHighValue() != null && haswidth) { - if(!first) {s.append(", "); } - if(bin.getHighValueLength()!=null) { - s.append("high: "+forms(bin.getHighValue(),bin.getHighValueLength())); - } else { - s.append("high: "+bin.getHighValue()); - } - first=false; - } - if(bin.getDescription() != null ) { - if(!first) { s.append(", "); } - s.append("value: '"+bin.getDescription().replaceAll("'","''")+"'"); - first=false; - } - if (bin.getDescription() == null && bin.getFocus() == null && bin.getLowValue() == null && bin.getHighValue() == null) { - s.append("value: '-'"); - } - if(bin.getId() < xax.getBins().size()) { - s.append("}"); + if(bin.getRelation() != null && bin.getRelation() != Relation.EQUALS ) { + if(!first) { s.append(", "); } + s.append("value: '"+bin.getRelation()+" "); + if (bin.getLowValue() != null) { + s.append(bin.getLowValue()); + } else if (bin.getHighValue() != null) { + s.append(bin.getHighValue()); + } + s.append("'"); + first=false; + } + else if(bin.getFocus() != null) { + if(asymmfocus || !haswidth) { + if(!first) {s.append(", "); } + if(bin.getFocusLength()!=null) { + s.append("value: "+forms(bin.getFocus(),bin.getFocusLength())); + } else { + s.append("value: "+bin.getFocus()); + } + first=false; + } + } + if(bin.getLowValue() != null && haswidth) { + if(!first) { s.append(", "); } + if(bin.getLowValueLength()!=null) { + s.append("low: "+forms(bin.getLowValue(),bin.getLowValueLength())); + } else { + s.append("low: "+bin.getLowValue()); + } + first=false; + } + if(bin.getHighValue() != null && haswidth) { + if(!first) {s.append(", "); } + if(bin.getHighValueLength()!=null) { + s.append("high: "+forms(bin.getHighValue(),bin.getHighValueLength())); + } else { + s.append("high: "+bin.getHighValue()); + } + first=false; + } + if(bin.getDescription() != null ) { + if(!first) { s.append(", "); } + s.append("value: '"+bin.getDescription().replaceAll("'","''")+"'"); + first=false; + } + if (bin.getDescription() == null && bin.getFocus() == null && bin.getLowValue() == null && bin.getHighValue() == null) { + s.append("value: '-'"); + } + if(bin.getId() < xax.getBins().size()) { + s.append("}"); + } + else{s.append("}");} + s.append("\n"); + } } - else{s.append("}");} - s.append("\n"); - } } }
More information about the HepData-svn mailing list |