|
[HepData-svn] r1899 - trunk/hepdata-webapp/src/main/java/cedar/hepdata/formatsblackhole at projects.hepforge.org blackhole at projects.hepforge.orgTue Oct 6 13:03:18 BST 2015
Author: watt Date: Tue Oct 6 13:03:17 2015 New Revision: 1899 Log: Don't write independent or dependent variables in YAML formatter if no data points 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 Mon Oct 5 20:34:25 2015 (r1898) +++ trunk/hepdata-webapp/src/main/java/cedar/hepdata/formats/YamlFormatter.java Tue Oct 6 13:03:17 2015 (r1899) @@ -233,15 +233,15 @@ else {s.append(", ");} } } -// if(p.getKeywords().size() > 0) { -// s.append(sp+"{name: keywords, values: ["); -// int np=0; -// for (String pkey : p.getKeywords()){ -// s.append("'"+pkey+"'"); -// if(++np==p.getKeywords().size()){s.append("]}\n"); } -// else {s.append(", ");} -// } -// } + // if(p.getKeywords().size() > 0) { + // s.append(sp+"{name: keywords, values: ["); + // int np=0; + // for (String pkey : p.getKeywords()){ + // s.append("'"+pkey+"'"); + // if(++np==p.getKeywords().size()){s.append("]}\n"); } + // else {s.append(", ");} + // } + // } Double ecmlow=99999.0; @@ -326,248 +326,250 @@ String location = ""; Paper p = ds.getPaper(); + int npoints=ds.getNumPoints(); + //s.append("name: 'Table "+ds.getId()+"'\n"); s.append("independent_variables:\n"); - 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(); - } - 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+"{"); - // if(bin.getId() != null ) { - // s.append("id: "+bin.getId()); - // first=false; - // } + 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(); + } + 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+"{"); + // 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()); + 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; } - 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()); - } + 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.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()+"'"); - first=false; - } - if (bin.getDescription() == null && bin.getFocus() == null && bin.getLowValue() == null && bin.getHighValue() == null) { - s.append("value: '-'"); + } + 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()+"'"); + 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"); } - if(bin.getId() < xax.getBins().size()) { - s.append("}"); - } - else{s.append("}");} - s.append("\n"); - } - } + } + } s.append("dependent_variables:\n"); - int npoints=ds.getNumPoints(); - - for (YAxis yax : ds.getYAxes()){ - String name=yax.getHeader(); - String unit=""; - if(yax.getHeader().contains(" IN ")){ - name=yax.getHeader().substring(0,yax.getHeader().indexOf(" IN ")).trim(); - unit=yax.getHeader().substring(yax.getHeader().indexOf(" IN ")+4).trim(); - } - if (npoints > 0) { + if (npoints > 0) { + for (YAxis yax : ds.getYAxes()){ + String name=yax.getHeader(); + String unit=""; + if(yax.getHeader().contains(" IN ")){ + name=yax.getHeader().substring(0,yax.getHeader().indexOf(" IN ")).trim(); + unit=yax.getHeader().substring(yax.getHeader().indexOf(" IN ")+4).trim(); + } s.append(sp+"header: {name: '"+name.replaceAll("'","''")+"'"); if(!unit.equals("")){ s.append(", units: '"+unit+"'"); } s.append("}\n"); - } - boolean first=true; - for (Property prop : yax.getProperties()){ - if(first) { s.append(s4+"qualifiers:\n"); } - first=false; + boolean first=true; + for (Property prop : yax.getProperties()){ + if(first) { s.append(s4+"qualifiers:\n"); } + first=false; - s.append(s4+sp+"{name: '"+prop.getName().replaceAll("'","''")+"'"); + s.append(s4+sp+"{name: '"+prop.getName().replaceAll("'","''")+"'"); - if(prop.getFocus()!=null || prop.getLowValue()!=null || prop.getHighValue()!=null){ - s.append(", value: '"); - } - if (prop.getFocus() != null){ - s.append(prop.getFocus()); - } + if(prop.getFocus()!=null || prop.getLowValue()!=null || prop.getHighValue()!=null){ + s.append(", value: '"); + } + if (prop.getFocus() != null){ + s.append(prop.getFocus()); + } - if (prop.getLowValue() != null && prop.getHighValue() != null && - prop.getLowValue().equals(prop.getHighValue())) { - s.append(prop.getLowValue()); - } else { - if(prop.getFocus() != null) { s.append(" ("); } - s.append(prop.getLowValue()); - s.append("-"); - s.append(prop.getHighValue()); - if(prop.getFocus() != null) { s.append(")"); } - } - if(prop.getFocus()!=null || prop.getLowValue()!=null || prop.getHighValue()!=null){ - s.append("'"); - } + if (prop.getLowValue() != null && prop.getHighValue() != null && + prop.getLowValue().equals(prop.getHighValue())) { + s.append(prop.getLowValue()); + } else { + if(prop.getFocus() != null) { s.append(" ("); } + s.append(prop.getLowValue()); + s.append("-"); + s.append(prop.getHighValue()); + if(prop.getFocus() != null) { s.append(")"); } + } + if(prop.getFocus()!=null || prop.getLowValue()!=null || prop.getHighValue()!=null){ + s.append("'"); + } - if (prop.getUnit().toString().equals("") || !prop.getUnit().isDimensionless()) { - s.append(", units: '"); - s.append(prop.getUnit().toString()+"'"); - } + if (prop.getUnit().toString().equals("") || !prop.getUnit().isDimensionless()) { + s.append(", units: '"); + s.append(prop.getUnit().toString()+"'"); + } - s.append("}\n"); - } - for (String comment : yax.getComments()){ - if(first) { s.append(s4+"qualifiers:\n"); } - first=false; - unit=""; - String type=comment.substring(0,comment.indexOf(":")-1).trim(); - String value=comment.substring(comment.indexOf(":")+1).trim(); -// String type="SYS"; -// String value=comment; -// if(comment.indexOf(":")>-1) { -// type=comment.substring(0,comment.indexOf(":")-1).trim(); -// value=comment.substring(comment.indexOf(":")+1).trim(); -// } - if(type.contains(" IN ")){ - unit=type.substring(type.indexOf(" IN ")+4).trim(); - type=type.substring(0,type.indexOf(" IN ")).trim(); - } - s.append(s4+sp+"{name: '"+type.replaceAll("'","''")+"'"); - s.append(", value: '"+ value.replaceAll("'","''")+"'"); -// if(type.equals("SYS") && value.indexOf("//")>-1){ -// String comments[] = value.replaceAll("////","//").split("//"); -// for( int i=0; i<comments.length; i++) { -// s.append(s4+sp+"{name: '"+type.replaceAll("'","''")+"'"); -// s.append(", value: '"+ comments[i].replaceAll("'","''")+"'"); -// if(i!=comments.length-1) { s.append("}\n"); } -// } -// } -// else { -// s.append(s4+sp+"{name: '"+type.replaceAll("'","''")+"'"); -// s.append(", value: '"+ value.replaceAll("'","''")+"'"); -// } - if(!unit.equals("")){ - s.append(", units: '"+ unit+"'"); - } - s.append("}\n"); - } + s.append("}\n"); + } + for (String comment : yax.getComments()){ + if(first) { s.append(s4+"qualifiers:\n"); } + first=false; + unit=""; + String type=comment.substring(0,comment.indexOf(":")-1).trim(); + String value=comment.substring(comment.indexOf(":")+1).trim(); + // String type="SYS"; + // String value=comment; + // if(comment.indexOf(":")>-1) { + // type=comment.substring(0,comment.indexOf(":")-1).trim(); + // value=comment.substring(comment.indexOf(":")+1).trim(); + // } + if(type.contains(" IN ")){ + unit=type.substring(type.indexOf(" IN ")+4).trim(); + type=type.substring(0,type.indexOf(" IN ")).trim(); + } + s.append(s4+sp+"{name: '"+type.replaceAll("'","''")+"'"); + s.append(", value: '"+ value.replaceAll("'","''")+"'"); + // if(type.equals("SYS") && value.indexOf("//")>-1){ + // String comments[] = value.replaceAll("////","//").split("//"); + // for( int i=0; i<comments.length; i++) { + // s.append(s4+sp+"{name: '"+type.replaceAll("'","''")+"'"); + // s.append(", value: '"+ comments[i].replaceAll("'","''")+"'"); + // if(i!=comments.length-1) { s.append("}\n"); } + // } + // } + // else { + // s.append(s4+sp+"{name: '"+type.replaceAll("'","''")+"'"); + // s.append(", value: '"+ value.replaceAll("'","''")+"'"); + // } + if(!unit.equals("")){ + s.append(", units: '"+ unit+"'"); + } + s.append("}\n"); + } - for(Uncertainty error : ds.getErrors()){ - if(error.getPlus()==0.0 && npoints > 0){ - s.append(s4+sp+"{name: 'SYS', value: '"+error.getComment()+"'}\n"); - } - } - for(Uncertainty error : yax.getErrors()){ - if(error.getPlus()==0.0 && npoints > 0){ - s.append(s4+sp+"{name: 'SYS', value: '"+error.getComment()+"'}\n"); - } - } + for(Uncertainty error : ds.getErrors()){ + if(error.getPlus()==0.0){ + s.append(s4+sp+"{name: 'SYS', value: '"+error.getComment()+"'}\n"); + } + } + for(Uncertainty error : yax.getErrors()){ + if(error.getPlus()==0.0){ + s.append(s4+sp+"{name: 'SYS', value: '"+error.getComment()+"'}\n"); + } + } - if (npoints > 0) { s.append(s4+"values:\n"); } + s.append(s4+"values:\n"); - for (int ip=1; ip<npoints+1; ip++){ - Point point = yax.getPoint(ip); - if(point==null){ - // s.append(s4+sp+"id: "+ip+"\n"); - // s.append(s4+s4+"value: '-'\n"); - s.append(s4+sp+"value: '-'\n"); - } - else{ - // s.append(s4+sp+"id: "+point.getId()+"\n"); - // s.append(s4+s4+"value: "); - s.append(s4+sp+"value: "); - if(point.getRelation() != Relation.EQUALS){ - s.append("'"+point.getRelation()); - } - // s.append(point.getValue()+" "+point.getValueLength()+"\n"); - if (point.getDescription() != null) { - if(point.getRelation() == Relation.EQUALS){ + for (int ip=1; ip<npoints+1; ip++){ + Point point = yax.getPoint(ip); + if(point==null){ + // s.append(s4+sp+"id: "+ip+"\n"); + // s.append(s4+s4+"value: '-'\n"); + s.append(s4+sp+"value: '-'\n"); + } + else{ + // s.append(s4+sp+"id: "+point.getId()+"\n"); + // s.append(s4+s4+"value: "); + s.append(s4+sp+"value: "); + if(point.getRelation() != Relation.EQUALS){ + s.append("'"+point.getRelation()); + } + // s.append(point.getValue()+" "+point.getValueLength()+"\n"); + if (point.getDescription() != null) { + if(point.getRelation() == Relation.EQUALS){ + s.append("'"); + } + s.append(point.getDescription()+"'"); + } else { + s.append(point.getValue()); + } + if (point.getRelation() != Relation.EQUALS) { s.append("'"); } - s.append(point.getDescription()+"'"); - } else { - s.append(point.getValue()); - } - if (point.getRelation() != Relation.EQUALS) { - s.append("'"); - } - s.append("\n"); - if (point.getErrors().size() > 0 - || yax.getErrors().size() > 0 - || ds.getErrors().size() > 0) { - s.append(s4+s4+"errors:\n"); - } - if(point.getErrors().size()>0){ - for(Uncertainty error : point.getErrors()){ - s.append(_formatError(error,"point")); + s.append("\n"); + if (point.getErrors().size() > 0 + || yax.getErrors().size() > 0 + || ds.getErrors().size() > 0) { + s.append(s4+s4+"errors:\n"); } - } - if(yax.getErrors().size()>0){ - for(Uncertainty error : yax.getErrors()){ - if(error.getPlus()!=0.0) s.append(_formatError(error,"axis")); + if(point.getErrors().size()>0){ + for(Uncertainty error : point.getErrors()){ + s.append(_formatError(error,"point")); + } } - } - if(ds.getErrors().size()>0){ - for(Uncertainty error : ds.getErrors()){ - if(error.getPlus()!=0.0) s.append(_formatError(error,"dataset")); + if(yax.getErrors().size()>0){ + for(Uncertainty error : yax.getErrors()){ + if(error.getPlus()!=0.0) s.append(_formatError(error,"axis")); + } + } + if(ds.getErrors().size()>0){ + for(Uncertainty error : ds.getErrors()){ + if(error.getPlus()!=0.0) s.append(_formatError(error,"dataset")); + } } } - } - } - } + } + } + } return s.toString(); } - + public static String _formatError(Uncertainty error, String which) { String s4=" ";
More information about the HepData-svn mailing list |