source: trunk/grails-app/domain/dbnp/studycapturing/Event.groovy @ 162

Last change on this file since 162 was 162, checked in by duh, 10 years ago
  • set keyword expansion
  • Property svn:keywords set to
    Date
    Author
    Rev
File size: 1.7 KB
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        // static constraints = { }
27
28        def getDuration() {
29                // time diff between end and start date
30                // thus, do this manually as follows
31
32                def timeMillis = (endTime.getTime() - startTime.getTime()).abs()
33                def days = (timeMillis / (1000 * 60 * 60 * 24)).toInteger()
34                def hours = (timeMillis / (1000 * 60 * 60)).toInteger()
35                def minutes = (timeMillis / (1000 * 60)).toInteger()
36                def seconds = (timeMillis / 1000).toInteger()
37                def millis = (timeMillis % 1000).toInteger()
38
39                return new Duration(days, hours, minutes, seconds, millis)
40        }
41
42
43        def getPrettyDuration() {
44             // return a string that prints the duration sensibly.
45             // the largest date unit (sec, min, h, day, month, or year)
46             // is output
47        }
48
49
50        def getDurationString() {
51                def d = getDuration()
52                return "${d.days} days, ${d.hours} hrs, ${d.minutes} min, ${d.seconds} sec."
53        }
54
55
56        def isSamplingEvent() {
57                return ( this instanceof SamplingEvent )
58        }
59}
Note: See TracBrowser for help on using the repository browser.