Ignore:
Timestamp:
Feb 22, 2010, 6:35:37 PM (13 years ago)
Author:
duh
Message:
  • added events, eventDescriptions, etc
Location:
trunk/grails-app/domain/dbnp/studycapturing
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/grails-app/domain/dbnp/studycapturing/Event.groovy

    r201 r209  
    77 * to multiple subjects at the same time. That is why the actual description of the event is factored out into a more
    88 * general EventDescription class. Events that also lead to sample(s) should be instantiated as SamplingEvents.
     9 *
     10 * Revision information:
     11 * $Rev$
     12 * $Author$
     13 * $Date$
    914 */
    10 class Event {
    11 
     15class Event implements Serializable {
    1216        Subject subject
    1317        EventDescription eventDescription
     
    1923
    2024        static hasMany = [
    21                 parameterStringValues : String, // stores both STRING and STRINGLIST items (latter should be checked against the list)
    22                 parameterIntegerValues : int,
    23                 parameterFloatValues : float
     25                parameterStringValues: String, // stores both STRING and STRINGLIST items (latter should be checked against the list)
     26                parameterIntegerValues: int,
     27                parameterFloatValues: float,
    2428        ]
    2529
     30        static constraints = {
     31                subject(nullable: true, blank: true)    // TODO: subject is to be removed from Event, and into EventGroup
     32                startTime(nullable:false)
     33                endTime(validator: {val, obj ->
     34           if (val && val.before(obj.startTime)) {
     35                return 'endTimeshouldbegreater'
     36           }
     37        })
     38        }
    2639
    2740        // time diff between end and start date
    2841        // thus, do this manually as follows
    29         def getDuration( date1, date2 ) {
     42
     43        def getDuration(date1, date2) {
    3044                def timeMillis = (date2.getTime() - date1.getTime()).abs()
    3145                def days = (timeMillis / (1000 * 60 * 60 * 24)).toInteger()
     
    3852        }
    3953
    40 
    4154        def getDuration() {
    4255                return getDuration(startTime, endTime)
    4356        }
    4457
    45 
    4658        // return a string that prints the duration sensibly.
    4759        // the largest date unit (sec, min, h, day, week, month, or year)
    4860        // is output
    49         def getPrettyDuration( duration ) {
    50              def handleNumerus = { number ,string ->
    51                      return number.toString() + (number==1 ? string : string + 's' )
    52              }
    53              if( duration.getYears()   > 0 ) return handleNumerus( duration.getYears(), " year" )
    54              if( duration.getMonths()  > 0 ) return handleNumerus( duration.getMonths(), " month" )
    55              if( duration.getDays()    > 0 ) return handleNumerus( duration.getDays(), " day" )
    56              if( duration.getHours()   > 0 ) return handleNumerus( duration.getHours(), " hour" )
    57              if( duration.getMinutes() > 0 ) return handleNumerus( duration.getMinutes(), " minute" )
    58                                              return handleNumerus( duration.getSeconds(), " second" )
     61
     62        def getPrettyDuration(duration) {
     63                def handleNumerus = {number, string ->
     64                        return number.toString() + (number == 1 ? string : string + 's')
     65                }
     66                if (duration.getYears() > 0) return handleNumerus(duration.getYears(), " year")
     67                if (duration.getMonths() > 0) return handleNumerus(duration.getMonths(), " month")
     68                if (duration.getDays() > 0) return handleNumerus(duration.getDays(), " day")
     69                if (duration.getHours() > 0) return handleNumerus(duration.getHours(), " hour")
     70                if (duration.getMinutes() > 0) return handleNumerus(duration.getMinutes(), " minute")
     71                return handleNumerus(duration.getSeconds(), " second")
    5972        }
    60 
    6173
    6274        // convenience method. gives formatted string output for a duration
    6375        def getPrettyDuration() {
    64              getPrettyDuration( getDuration() )
     76                getPrettyDuration(getDuration())
    6577        }
    6678
    67 
    6879        // convenience method. gives formatted string output for a duration
    69         def getPrettyDuration( date1, date2 )
    70         {
    71              return  getPrettyDuration( getDuration( date1, date2 ) )
     80        def getPrettyDuration(date1, date2) {
     81                return getPrettyDuration(getDuration(date1, date2))
    7282        }
    73 
    7483
    7584        def getDurationString() {
     
    7887        }
    7988
     89        def getShortDuration() {
     90                def d = getDuration()
     91                def days = d.days
     92                def hours = d.hours - (24 * days)
     93                def minutes = d.minutes - (24 * 60 * days) - (60 * hours)
     94                return "${days}d ${hours}:${minutes}"
     95        }
    8096
    8197        def isSamplingEvent() {
    82                 return ( this instanceof SamplingEvent )
    83         }
    84 
     98                return (this instanceof SamplingEvent)
     99        }
    85100
    86101        def String toString() {
    87102                return eventDescription ? eventDescription.name : ""
    88103        }
    89 
    90104}
  • trunk/grails-app/domain/dbnp/studycapturing/EventDescription.groovy

    r190 r209  
    2121
    2222        static constraints = {
     23                name(nullable: false, blank: false)
     24                description(nullable: false, blank: false)
    2325                classification(nullable: true, blank: true)
     26                protocol(nullable: true, blank: true)
     27        }
     28
     29        def String toString() {
     30                return name
    2431        }
    2532}
  • trunk/grails-app/domain/dbnp/studycapturing/EventGroup.groovy

    r208 r209  
    11package dbnp.studycapturing
    22
    3 class EventGroup {
    4 
     3/**
     4 * EventGroup groups events
     5 *
     6 * Revision information:
     7 * $Rev$
     8 * $Author$
     9 * $Date$
     10 */
     11class EventGroup implements Serializable {
    512        String name
    613
    714        static hasMany = [
    8                 subjects : Subject,
    9                 events : Event
     15                subjects: Subject,
     16                events: Event
    1017        ]
    1118
    12     static constraints = {
    13     }
     19        static constraints = {
     20        }
    1421}
Note: See TracChangeset for help on using the changeset viewer.