Changeset 3556


Ignore:
Timestamp:
Jul 16, 2007, 8:43:56 AM (14 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #648 and #650

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

Legend:

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

    r3528 r3556  
    8585    ev.setExternalId(externalId);
    8686    ev.setValueType(valueType);
    87     ev.setAverageMethod(AverageMethod.ARITHMETIC_MEAN);
     87    ev.setAverageMethod(valueType.isNumerical() ? AverageMethod.ARITHMETIC_MEAN : AverageMethod.NONE);
    8888    return ev;
    8989  }
     
    319319    Get the average method for this extra value type.
    320320    @return A {@link AverageMethod} object
     321    @since 2.4
    321322   */
    322323  public Formula.AverageMethod getAverageMethod()
     
    330331      write permission
    331332    @throws InvalidDataException If the averageMethod is null
     333    @since 2.4
    332334  */
    333335  public void setAverageMethod(Formula.AverageMethod averageMethod)
  • trunk/src/core/net/sf/basedb/core/Formula.java

    r3528 r3556  
    181181    Get the average method for this formula.
    182182    @return A {@link AverageMethod} object
    183    */
     183    @since 2.4
     184  */
    184185  public Formula.AverageMethod getAverageMethod()
    185186  {
     
    192193      write permission
    193194    @throws InvalidDataException If the averageMethod is null
     195    @since 2.4
    194196  */
    195197  public void setAverageMethod(Formula.AverageMethod averageMethod)
     
    370372    The average method used for the values of this formula. The average
    371373    is only useful with a {@link Type#COLUMN_EXPRESSION}.
    372    */
     374    @version 2.4
     375  */
    373376  public enum AverageMethod
    374377  {
    375     NONE(0, "None"),
    376     GEOMETRIC_MEAN(1, "Geometric mean"),
    377     ARITHMETIC_MEAN(2, "Arithmetic mean"),
    378     MIN(3, "Min"),
    379     MAX(4, "Max");
     378    NONE(0, "None")
     379    {
     380      public Expression getAverageExpression(Expression e)
     381      {
     382        return null;
     383      }
     384    },
     385    GEOMETRIC_MEAN(1, "Geometric mean")
     386    {
     387      public Expression getAverageExpression(Expression e)
     388      {
     389        return Aggregations.geometricMean(e);
     390      }     
     391    },
     392    ARITHMETIC_MEAN(2, "Arithmetic mean")
     393    {
     394      public Expression getAverageExpression(Expression e)
     395      {
     396        return Aggregations.mean(e);
     397      }
     398     
     399    },
     400    MIN(3, "Min")
     401    {
     402      public Expression getAverageExpression(Expression e)
     403      {
     404        return Aggregations.min(e);
     405      }
     406       
     407    },
     408    MAX(4, "Max")
     409    {
     410      public Expression getAverageExpression(Expression e)
     411      {
     412        return Aggregations.max(e);
     413      }
     414     
     415    };
    380416   
    381417    /**
     
    415451    }
    416452   
    417     public Expression getAverageExpression(Expression e)
    418     {
    419       Expression avg;
    420       switch (this)
    421       {
    422         case GEOMETRIC_MEAN :
    423           avg = Aggregations.geometricMean(e);
    424           break;
    425         case ARITHMETIC_MEAN :
    426           avg = Aggregations.mean(e);
    427           break;
    428         case MIN :
    429           avg = Aggregations.min(e);
    430           break;
    431         case MAX:
    432           avg = Aggregations.max(e);
    433           break;
    434         case NONE:
    435         default:
    436           avg = Expressions.string("");
    437           break;
    438       }
    439 
    440       return avg;
    441     }
    442    
    443     /**
    444      * Get the integer value that is used when storing a
    445      * <code>Formula.AverageMethod</code> in the database.
    446      *
    447      * @return The integer value of this type
    448      */
     453    /**
     454      Given an expression, create an expression that takes the correct
     455      average of it.
     456      @param e The expression, null is not allowed
     457      @return The average expression, or null if it is not possible
     458        to create an average expression
     459    */
     460    public abstract Expression getAverageExpression(Expression e);
     461   
     462    /**
     463      Get the integer value that is used when storing a
     464      <code>Formula.AverageMethod</code> in the database.
     465      @return The integer value of this type
     466    */
    449467    public int getValue()
    450468    {
  • trunk/src/core/net/sf/basedb/core/data/ExtraValueTypeData.java

    r3528 r3556  
    134134    The average method for thid formula:
    135135    <ul>
    136     <li>0 = none, {@link net.sf.basedb.core.Formula.AverageMethod#NONE}; no average is defined for this formula
    137     <li>1 = geometric mean, {@link net.sf.basedb.core.Formula.AverageMethod#GEOMETRIC_MEAN}; this formula uses geometric mean
    138     <li>2 = arithmetic mean, {@link net.sf.basedb.core.Formula.AverageMethod#ARITHMETIC_MEAN}; this formula uses arithmetic mean
    139     <li>3 = min, {@link net.sf.basedb.core.Formula.AverageMethod#MIN}; this formula uses the min value as a "mean"
    140     <li>4 = max, {@link net.sf.basedb.core.Formula.AverageMethod#MAX}; this formula uses the max value as a "mean"
     136    <li>0 = none, {@link net.sf.basedb.core.Formula.AverageMethod#NONE};
     137      no average is defined for this formula
     138    <li>1 = geometric mean, {@link net.sf.basedb.core.Formula.AverageMethod#GEOMETRIC_MEAN};
     139      this formula uses geometric mean
     140    <li>2 = arithmetic mean, {@link net.sf.basedb.core.Formula.AverageMethod#ARITHMETIC_MEAN};
     141      this formula uses arithmetic mean
     142    <li>3 = min, {@link net.sf.basedb.core.Formula.AverageMethod#MIN};
     143      this formula uses the min value as a "mean"
     144    <li>4 = max, {@link net.sf.basedb.core.Formula.AverageMethod#MAX};
     145      this formula uses the max value as a "mean"
    141146    </ul>
    142147   
    143148    @hibernate.property column="`average_method`" type="int" not-null="true"
     149    @since 2.4
    144150  */
    145151  public int getAverageMethod()
  • trunk/src/core/net/sf/basedb/core/data/FormulaData.java

    r3528 r3556  
    4848    The average method for thid formula:
    4949    <ul>
    50     <li>0 = none, {@link net.sf.basedb.core.Formula.AverageMethod#NONE}; no average is defined for this formula
    51     <li>1 = geometric mean, {@link net.sf.basedb.core.Formula.AverageMethod#GEOMETRIC_MEAN}; this formula uses geometric mean
    52     <li>2 = arithmetic mean, {@link net.sf.basedb.core.Formula.AverageMethod#ARITHMETIC_MEAN}; this formula uses arithmetic mean
    53     <li>3 = min, {@link net.sf.basedb.core.Formula.AverageMethod#MIN}; this formula uses the min value as a "mean"
    54     <li>4 = max, {@link net.sf.basedb.core.Formula.AverageMethod#MAX}; this formula uses the max value as a "mean"
     50    <li>0 = none, {@link net.sf.basedb.core.Formula.AverageMethod#NONE};
     51      no average is defined for this formula
     52    <li>1 = geometric mean, {@link net.sf.basedb.core.Formula.AverageMethod#GEOMETRIC_MEAN};
     53      this formula uses geometric mean
     54    <li>2 = arithmetic mean, {@link net.sf.basedb.core.Formula.AverageMethod#ARITHMETIC_MEAN};
     55      this formula uses arithmetic mean
     56    <li>3 = min, {@link net.sf.basedb.core.Formula.AverageMethod#MIN};
     57      this formula uses the min value as a "mean"
     58    <li>4 = max, {@link net.sf.basedb.core.Formula.AverageMethod#MAX};
     59      this formula uses the max value as a "mean"
    5560    </ul>
    5661   
    5762    @hibernate.property column="`average_method`" type="int" not-null="true"
     63    @since 2.4
    5864  */
    5965  public int getAverageMethod()
  • trunk/src/core/net/sf/basedb/core/query/Aggregations.java

    r3522 r3556  
    5151    Calculates the geometric mean of all values for an expression: new expression =
    5252    EXP(AVG(LN(e))). Note that this method can handle values less then or equal with
    53     0 due although the mathematical definition of geometric mean doesn't alow it.
     53    0 although the mathematical definition of geometric mean doesn't allow it.
    5454    This is caused by the way that sql handle null values in aggregated operations.
    5555    The geometric mean of the numbers [2, -5, 8] is therefor 4 (because ln(-5) is
     
    6060    @return The new Expression
    6161    @throws InvalidDataException If the expression is null
     62    @since 2.4
    6263  */
    6364  public static Expression geometricMean(Expression e)
  • trunk/src/core/net/sf/basedb/core/query/GeometricMeanExpression.java

    r3530 r3556  
    3434
    3535  @author Johan Enell
    36   @version 2.0
     36  @version 2.4
    3737  @see Aggregations#geometricMean(Expression)
    3838  @base.modified $Date$
Note: See TracChangeset for help on using the changeset viewer.