Changeset 3556
- Timestamp:
- Jul 16, 2007, 8:43:56 AM (16 years ago)
- 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 85 85 ev.setExternalId(externalId); 86 86 ev.setValueType(valueType); 87 ev.setAverageMethod( AverageMethod.ARITHMETIC_MEAN);87 ev.setAverageMethod(valueType.isNumerical() ? AverageMethod.ARITHMETIC_MEAN : AverageMethod.NONE); 88 88 return ev; 89 89 } … … 319 319 Get the average method for this extra value type. 320 320 @return A {@link AverageMethod} object 321 @since 2.4 321 322 */ 322 323 public Formula.AverageMethod getAverageMethod() … … 330 331 write permission 331 332 @throws InvalidDataException If the averageMethod is null 333 @since 2.4 332 334 */ 333 335 public void setAverageMethod(Formula.AverageMethod averageMethod) -
trunk/src/core/net/sf/basedb/core/Formula.java
r3528 r3556 181 181 Get the average method for this formula. 182 182 @return A {@link AverageMethod} object 183 */ 183 @since 2.4 184 */ 184 185 public Formula.AverageMethod getAverageMethod() 185 186 { … … 192 193 write permission 193 194 @throws InvalidDataException If the averageMethod is null 195 @since 2.4 194 196 */ 195 197 public void setAverageMethod(Formula.AverageMethod averageMethod) … … 370 372 The average method used for the values of this formula. The average 371 373 is only useful with a {@link Type#COLUMN_EXPRESSION}. 372 */ 374 @version 2.4 375 */ 373 376 public enum AverageMethod 374 377 { 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 }; 380 416 381 417 /** … … 415 451 } 416 452 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 */ 449 467 public int getValue() 450 468 { -
trunk/src/core/net/sf/basedb/core/data/ExtraValueTypeData.java
r3528 r3556 134 134 The average method for thid formula: 135 135 <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" 141 146 </ul> 142 147 143 148 @hibernate.property column="`average_method`" type="int" not-null="true" 149 @since 2.4 144 150 */ 145 151 public int getAverageMethod() -
trunk/src/core/net/sf/basedb/core/data/FormulaData.java
r3528 r3556 48 48 The average method for thid formula: 49 49 <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" 55 60 </ul> 56 61 57 62 @hibernate.property column="`average_method`" type="int" not-null="true" 63 @since 2.4 58 64 */ 59 65 public int getAverageMethod() -
trunk/src/core/net/sf/basedb/core/query/Aggregations.java
r3522 r3556 51 51 Calculates the geometric mean of all values for an expression: new expression = 52 52 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. 54 54 This is caused by the way that sql handle null values in aggregated operations. 55 55 The geometric mean of the numbers [2, -5, 8] is therefor 4 (because ln(-5) is … … 60 60 @return The new Expression 61 61 @throws InvalidDataException If the expression is null 62 @since 2.4 62 63 */ 63 64 public static Expression geometricMean(Expression e) -
trunk/src/core/net/sf/basedb/core/query/GeometricMeanExpression.java
r3530 r3556 34 34 35 35 @author Johan Enell 36 @version 2. 036 @version 2.4 37 37 @see Aggregations#geometricMean(Expression) 38 38 @base.modified $Date$
Note: See TracChangeset
for help on using the changeset viewer.