root/trunk/grails-app/domain/dbnp/studycapturing/Event.groovy @ 190

Revision 190, 2.2 KB (checked in by duh, 4 years ago)

- set keyword expansion

  • Property svn:keywords set to Rev Date Author
Line 
1package dbnp.studycapturing
2
3import groovy.time.*
4
5/**
6 * The Event class describes an actual event, as it has happened to a certain subject. Often, the same event occurs
7 * to multiple subjects at the same time. That is why the actual description of the event is factored out into a more
8 * general EventDescription class. Events that also lead to sample(s) should be instantiated as SamplingEvents.
9 */
10class Event {
11
12        Subject subject
13        EventDescription eventDescription
14        Date startTime
15        Date endTime
16        Map parameterStringValues
17        Map parameterIntegerValues
18        Map parameterFloatValues
19
20        static hasMany = [
21                parameterStringValues : String, // stores both STRING and STRINGLIST items (latter should be checked against the list)
22                parameterIntegerValues : int,
23                parameterFloatValues : float
24        ]
25
26
27                // time diff between end and start date
28                // thus, do this manually as follows
29        def getDuration() {
30                def timeMillis = (endTime.getTime() - startTime.getTime()).abs()
31                def days = (timeMillis / (1000 * 60 * 60 * 24)).toInteger()
32                def hours = (timeMillis / (1000 * 60 * 60)).toInteger()
33                def minutes = (timeMillis / (1000 * 60)).toInteger()
34                def seconds = (timeMillis / 1000).toInteger()
35                def millis = (timeMillis % 1000).toInteger()
36
37                return new Duration(days, hours, minutes, seconds, millis)
38        }
39
40
41             // return a string that prints the duration sensibly.
42             // the largest date unit (sec, min, h, day, week, month, or year)
43             // is output
44        def getPrettyDuration() {
45             def duration = getDuration()
46             if( duration.getYears()   > 0 ) return duration.getYears()   + " years"
47             if( duration.getMonths()  > 0 ) return duration.getMonths()  + " months"
48             if( duration.getWeeks()   > 0 ) return duration.getWeeks()   + " weeks"
49             if( duration.getDays()    > 0 ) return duration.getDays()    + " days"
50             if( duration.getHours()   > 0 ) return duration.getHours()   + " minutes"
51                                             return duration.getSeconds() + " seconds"
52        }
53
54
55        def getDurationString() {
56                def d = getDuration()
57                return "${d.days} days, ${d.hours} hrs, ${d.minutes} min, ${d.seconds} sec."
58        }
59
60
61        def isSamplingEvent() {
62                return ( this instanceof SamplingEvent )
63        }
64}
Note: See TracBrowser for help on using the browser.