Packages

  • package root
    Definition Classes
    root
  • package molecule
    Definition Classes
    root
  • package boilerplate
    Definition Classes
    molecule
  • package api
    Definition Classes
    boilerplate
  • trait KeywordsStable extends AnyRef

    Keywords to mark aggregate expressions on and unifications of attributes.

    Keywords to mark aggregate expressions on and unifications of attributes.

    // Aggregates on any attribute type
    Person.age(count).get.map(_.head ==> 3)         // count of asserted `age` attribute values
    Person.age(countDistinct).get.map(_.head ==> 3) // count of asserted distinct `age` attribute values
    Person.age(max).get.map(_.head ==> 38)          // maximum `age` value (using `compare`)
    Person.age(min).get.map(_.head ==> 5)           // maximum `age` value (using `compare`)
    Person.age(rand).get.map(_.head ==> 25)         // single random `age` value
    Person.age(sample).get.map(_.head ==> 27)       // single sample `age` value (when single value, same as random)
    
    // Aggregates on any attribute type, returning multiple values
    Person.age(distinct).get.map(_.head ==> Vector(5, 7, 38)) // distinct `age` values
    Person.age(max(2)).get.map(_.head ==> Vector(38, 7))      // 2 maximum `age` values
    Person.age(min(2)).get.map(_.head ==> Vector(5, 7))       // 2 minimum `age` values
    Person.age(rand(2)).get.map(_.head ==> Stream(5, ?))      // 2 random `age` values (values can re-occur)
    Person.age(sample(2)).get.map(_.head ==> Vector(7, 38))   // 2 sample `age` values
    
    // Aggregates on number attributes
    Person.age(sum).get.map(_.head ==> 50)                  // sum of all `age` numbers
    Person.age(avg).get.map(_.head ==> 16.66666667)         // average of all `age` numbers
    Person.age(median).get.map(_.head ==> 7)                // median of all `age` numbers
    Person.age(stddev).get.map(_.head ==> 15.107025591499)  // standard deviation of all `age` numbers
    Person.age(variance).get.map(_.head ==> 228.2222222222) // variance of all `age` numbers
    Definition Classes
    api
  • AggrCoalesce
  • AggrInt
  • AggrKw
  • Kw
  • avg
  • bi
  • count
  • countDistinct
  • distinct
  • max
  • maxs
  • median
  • min
  • mins
  • rand
  • rands
  • sample
  • samples
  • stddev
  • sum
  • unify
  • v1
  • variance

trait median extends AggrCoalesce

Median of attribute values.

Apply median keyword to attribute to return median of attribute values of entities matching the molecule.

for {
  _ <- Match.sKeywords.insert(1, 2, 4)
  _ <- Match.score(median).get.map(_.head ==> 2)
} yield ()

OBS: When it comes to an even number of values, Datomic has a special implementation of median that is different from the one described on the Wiki entry on the median function.

Datomic calculates the median of even number of values as the average of the two middle numbers rounded down to nearest whole number

for {
  _ <- Match.sKeywords.insert(1, 2, 3, 4)
  _ <- Match.score(median).get.map(_.head ==> 2) // (2 + 3) / 2 = 2.5 rounded down to 2
} yield ()

With decimal numbers this can go wrong:

for {
  _ <- Match.sKeywords.insert(1.0, 2.5, 2.5, 3.0)
  _ <- Match.score(median).get.map(_.head ==> 2) // (2.5 + 2.5) / 2 = 2.5 rounded down to 2 (This is wrong and bug report has been filed)
} yield ()
returns

Value of Attribute type

Source
Keywords.scala
Linear Supertypes
AggrCoalesce, AggrKw, Kw, AnyRef, Any
Known Subclasses
Type Hierarchy
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. median
  2. AggrCoalesce
  3. AggrKw
  4. Kw
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native() @IntrinsicCandidate()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @IntrinsicCandidate()
  9. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @IntrinsicCandidate()
  10. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  11. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  12. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @IntrinsicCandidate()
  13. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @IntrinsicCandidate()
  14. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  15. def toString(): String
    Definition Classes
    AnyRef → Any
  16. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  17. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] ) @Deprecated
    Deprecated

Inherited from AggrCoalesce

Inherited from AggrKw

Inherited from Kw

Inherited from AnyRef

Inherited from Any

Ungrouped