Changeset 209 for trunk/grails-app/domain
- Timestamp:
- Feb 22, 2010, 6:35:37 PM (13 years ago)
- Location:
- trunk/grails-app/domain/dbnp/studycapturing
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/grails-app/domain/dbnp/studycapturing/Event.groovy
r201 r209 7 7 * to multiple subjects at the same time. That is why the actual description of the event is factored out into a more 8 8 * 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$ 9 14 */ 10 class Event { 11 15 class Event implements Serializable { 12 16 Subject subject 13 17 EventDescription eventDescription … … 19 23 20 24 static hasMany = [ 21 parameterStringValues: String, // stores both STRING and STRINGLIST items (latter should be checked against the list)22 parameterIntegerValues 23 parameterFloatValues : float25 parameterStringValues: String, // stores both STRING and STRINGLIST items (latter should be checked against the list) 26 parameterIntegerValues: int, 27 parameterFloatValues: float, 24 28 ] 25 29 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 } 26 39 27 40 // time diff between end and start date 28 41 // thus, do this manually as follows 29 def getDuration( date1, date2 ) { 42 43 def getDuration(date1, date2) { 30 44 def timeMillis = (date2.getTime() - date1.getTime()).abs() 31 45 def days = (timeMillis / (1000 * 60 * 60 * 24)).toInteger() … … 38 52 } 39 53 40 41 54 def getDuration() { 42 55 return getDuration(startTime, endTime) 43 56 } 44 57 45 46 58 // return a string that prints the duration sensibly. 47 59 // the largest date unit (sec, min, h, day, week, month, or year) 48 60 // 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") 59 72 } 60 61 73 62 74 // convenience method. gives formatted string output for a duration 63 75 def getPrettyDuration() { 64 getPrettyDuration( getDuration())76 getPrettyDuration(getDuration()) 65 77 } 66 78 67 68 79 // 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)) 72 82 } 73 74 83 75 84 def getDurationString() { … … 78 87 } 79 88 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 } 80 96 81 97 def isSamplingEvent() { 82 return ( this instanceof SamplingEvent ) 83 } 84 98 return (this instanceof SamplingEvent) 99 } 85 100 86 101 def String toString() { 87 102 return eventDescription ? eventDescription.name : "" 88 103 } 89 90 104 } -
trunk/grails-app/domain/dbnp/studycapturing/EventDescription.groovy
r190 r209 21 21 22 22 static constraints = { 23 name(nullable: false, blank: false) 24 description(nullable: false, blank: false) 23 25 classification(nullable: true, blank: true) 26 protocol(nullable: true, blank: true) 27 } 28 29 def String toString() { 30 return name 24 31 } 25 32 } -
trunk/grails-app/domain/dbnp/studycapturing/EventGroup.groovy
r208 r209 1 1 package dbnp.studycapturing 2 2 3 class EventGroup { 4 3 /** 4 * EventGroup groups events 5 * 6 * Revision information: 7 * $Rev$ 8 * $Author$ 9 * $Date$ 10 */ 11 class EventGroup implements Serializable { 5 12 String name 6 13 7 14 static hasMany = [ 8 subjects: Subject,9 events 15 subjects: Subject, 16 events: Event 10 17 ] 11 18 12 13 19 static constraints = { 20 } 14 21 }
Note: See TracChangeset
for help on using the changeset viewer.