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

Last change on this file since 139 was 139, checked in by keesvb, 11 years ago

changed domain model for events and protocol parameters, and for template field storage, added NuGO PPS3 events, added searchable plugin for full text queries, corrected a few HTML errors in create study

File size: 1.5 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                //endTime - startTime  // this is not documented and does not work either
30                // so, it's useless.
31                // thus, do this manually as follows
32
33                def timeMillis = (endTime.getTime() - startTime.getTime()).abs()
34                def days = (timeMillis / (1000 * 60 * 60 * 24)).toInteger()
35                def hours = (timeMillis / (1000 * 60 * 60)).toInteger()
36                def minutes = (timeMillis / (1000 * 60)).toInteger()
37                def seconds = (timeMillis / 1000).toInteger()
38                def millis = (timeMillis % 1000).toInteger()
39
40                return new Duration(days, hours, minutes, seconds, millis)
41        }
42
43
44        def getDurationString() {
45                def d = getDuration()
46                return "${d.days} days, ${d.hours} hrs, ${d.minutes} min, ${d.seconds} sec."
47        }
48
49
50}
Note: See TracBrowser for help on using the repository browser.