Changeset 3562 for trunk/src/core/net/sf


Ignore:
Timestamp:
Jul 16, 2007, 2:35:29 PM (15 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #649 and #674

Location:
trunk/src/core/net/sf/basedb/core
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/ExtendedProperties.java

    r2747 r3562  
    205205      if (type == Type.STRING && length > 255) type = Type.TEXT;
    206206      boolean nullable = XMLUtil.getBooleanAttribute(property, "null", true);
    207       boolean insertable = XMLUtil.getBooleanAttribute(property, "insert", true);;
    208       boolean updateable = XMLUtil.getBooleanAttribute(property, "update", true);;
     207      boolean insertable = XMLUtil.getBooleanAttribute(property, "insert", true);
     208      boolean updateable = XMLUtil.getBooleanAttribute(property, "update", true);
    209209      boolean averagable = XMLUtil.getBooleanAttribute(property, "averagable", type.isNumerical());
     210      String avgMethod = property.getAttributeValue("averagemethod");
     211      Formula.AverageMethod averageMethod = null;
     212      if (avgMethod != null)
     213      {
     214        averageMethod = Formula.AverageMethod.valueOf(avgMethod.toUpperCase());
     215      }
     216      else if (averagable)
     217      {
     218        averageMethod = Formula.AverageMethod.ARITHMETIC_MEAN;
     219      }
     220      else
     221      {
     222        averageMethod = Formula.AverageMethod.NONE;       
     223      }
    210224     
    211225      List<Element> links = (List<Element>)property.getChildren("link");
     
    221235        }
    222236      }
    223       properties.add(new ExtendedProperty(name, title, description, column, type, length, nullable, insertable, updateable, averagable, epLinks));
     237      properties.add(new ExtendedProperty(name, title, description, column, type, length, nullable, insertable, updateable, averageMethod, epLinks));
    224238    }
    225239    return properties;
  • trunk/src/core/net/sf/basedb/core/ExtendedProperty.java

    r3472 r3562  
    4646  private final boolean insertable;
    4747  private final boolean updateable;
    48   private final boolean isAveragable;
     48  private final Formula.AverageMethod averageMethod;
    4949  private final List<ExtendedPropertyLinker> linkers;
    5050
     
    5555  ExtendedProperty(String name, String title, String description, String column,
    5656    Type type, int length, boolean nullable, boolean insertable, boolean updateable,
    57     boolean isAveragable, List<ExtendedPropertyLinker> linkers)
     57    Formula.AverageMethod averageMethod, List<ExtendedPropertyLinker> linkers)
    5858  {
    5959    this.name = name;
     
    6666    this.insertable = insertable;
    6767    this.updateable = updateable;
    68     this.isAveragable = type.isNumerical() && isAveragable;
     68    this.averageMethod = averageMethod;
    6969    this.linkers = linkers;
    7070  }
     
    161161    values. By default all numerical values are averagable.
    162162    @return TRUE if it makes sense to take the average, FALSE otherwise
     163    @see #getAverageMethod()
    163164  */
    164165  public boolean isAveragable()
    165166  {
    166     return isAveragable;
     167    return averageMethod != null && averageMethod != Formula.AverageMethod.NONE;
     168  }
     169 
     170  /**
     171    Which method to use when calculating the average of a set of values.
     172    Prior to 2.4 only arithmetic mean was supported.
     173    @return The average method to use
     174    @since 2.4
     175  */
     176  public Formula.AverageMethod getAverageMethod()
     177  {
     178    return averageMethod;
    167179  }
    168180 
  • trunk/src/core/net/sf/basedb/core/RawDataProperty.java

    r2535 r3562  
    4242  */
    4343  RawDataProperty(String name, String title, String description, String column,
    44     Type type, int length, boolean nullable, boolean averagable, int channel)
     44    Type type, int length, boolean nullable, Formula.AverageMethod averageMethod, int channel)
    4545  {
    46     super(name, title, description, column, type, length, nullable, true, false, averagable, null);
     46    super(name, title, description, column, type, length, nullable, true, false, averageMethod, null);
    4747    this.channel = channel;
    4848  }
  • trunk/src/core/net/sf/basedb/core/RawDataTypes.java

    r2535 r3562  
    177177      boolean nullable = XMLUtil.getBooleanAttribute(property, "null", true);
    178178      boolean averagable = XMLUtil.getBooleanAttribute(property, "averagable", type.isNumerical());
     179      String avgMethod = property.getAttributeValue("averagemethod");
     180      Formula.AverageMethod averageMethod = null;
     181      if (avgMethod != null)
     182      {
     183        averageMethod = Formula.AverageMethod.valueOf(avgMethod.toUpperCase());
     184      }
     185      else if (averagable)
     186      {
     187        averageMethod = Formula.AverageMethod.ARITHMETIC_MEAN;
     188      }
     189      else
     190      {
     191        averageMethod = Formula.AverageMethod.NONE;       
     192      }
    179193      int channel = XMLUtil.getIntAttribute(property, "channel", 0);
    180       properties.add(new RawDataProperty(name, title, description, column, type, length, nullable, averagable, channel));
     194      properties.add(new RawDataProperty(name, title, description, column, type, length, nullable, averageMethod, channel));
    181195    }
    182196    return properties;
  • trunk/src/core/net/sf/basedb/core/data/ExtendableData.java

    r2601 r3562  
    4545         update="true"
    4646         insert="true"
    47          averagable="false"
     47         averagemethod="geometric_mean"
    4848         description="An extra property for all reporters"
    4949      /&gt;
     
    156156    <td>averagable</td>
    157157    <td>
     158      <b>This attribute has been deprecated and is replaced by <code>averagemethod</code>!</b>
     159      <br>
    158160      If it makes sense to take the average of multiple values for this
    159161      property. By default all numerical columns are averagable. For non-numerical
    160       columns, this attribute is ignored.
     162      columns, this attribute is ignored. The default method is to calculate the
     163      arithmetic mean.
    161164      <ul>
    162165      <li>true
     
    164167      </ul>
    165168      See {@link net.sf.basedb.core.ExtendedProperty#isAveragable()}.
     169    </td>
     170  </tr>
     171  <tr valign="top">
     172    <td>averagemethod</td>
     173    <td>
     174      The method to use when calculating the average of a set of values.
     175      This attribute replaces the <code>averagable</code> attribute.
     176      The following values can be used:
     177      <ul>
     178      <li>none: do not use this property when calculating averages
     179      <li>arithmetic_mean: calculate the arithmetic mean
     180      <li>geometric_mean: calculate the geometric mean
     181      <li>min: use the minimum value among the values in the set
     182      <li>max: use the maximum value among the values in the set
     183      </ul>
     184      If no value is given to this attribute the default is to use arithmetic
     185      mean for all numerical value types.
     186      See {@link net.sf.basedb.core.ExtendedProperty#getAverageMethod()}.
    166187    </td>
    167188  </tr>
  • trunk/src/core/net/sf/basedb/core/dtd/extended-properties.dtd

    r2535 r3562  
    4343  update (true|false) "true"
    4444  averagable (true|false) #IMPLIED
     45  averagemethod (none|arithmetic_mean|geometric_mean|min|max) #IMPLIED
    4546>
    4647
  • trunk/src/core/net/sf/basedb/core/dtd/raw-data-types.dtd

    r2535 r3562  
    4646  null (true|false) "true"
    4747  averagable (true|false) #IMPLIED
     48  averagemethod (none|arithmetic_mean|geometric_mean|min|max) #IMPLIED
    4849  channel CDATA #IMPLIED
    4950>
Note: See TracChangeset for help on using the changeset viewer.