1 | ''' |
---|
2 | BSD Licence |
---|
3 | Copyright (c) 2012, Science & Technology Facilities Council (STFC) |
---|
4 | All rights reserved. |
---|
5 | |
---|
6 | Redistribution and use in source and binary forms, with or without modification, |
---|
7 | are permitted provided that the following conditions are met: |
---|
8 | |
---|
9 | * Redistributions of source code must retain the above copyright notice, |
---|
10 | this list of conditions and the following disclaimer. |
---|
11 | * Redistributions in binary form must reproduce the above copyright notice, |
---|
12 | this list of conditions and the following disclaimer in the documentation |
---|
13 | and/or other materials provided with the distribution. |
---|
14 | * Neither the name of the Science & Technology Facilities Council (STFC) |
---|
15 | nor the names of its contributors may be used to endorse or promote |
---|
16 | products derived from this software without specific prior written permission. |
---|
17 | |
---|
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
---|
20 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
---|
21 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
---|
22 | BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
---|
23 | OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
---|
25 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
---|
26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
---|
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
28 | |
---|
29 | Created on 31 Jul 2012 |
---|
30 | |
---|
31 | @author: mnagni |
---|
32 | ''' |
---|
33 | from cedaMoles.MolesManager.views.moles2gui import CedaMolesGuiAdapter, unicodeToString |
---|
34 | from ea_model.iso_19108_2006_temporal_schema.temporal_objects.tm_period import TM_Period |
---|
35 | |
---|
36 | class Period(CedaMolesGuiAdapter): |
---|
37 | """ |
---|
38 | Simplifies for the GUI an instance |
---|
39 | from ea_model.iso_19108_2006_temporal_schema.temporal_objects.tm_period.TM_Period |
---|
40 | |
---|
41 | **Parameters** |
---|
42 | * `TM_Period` **period** |
---|
43 | an TM_Period instance |
---|
44 | """ |
---|
45 | |
---|
46 | mapper = {'startDate': '', |
---|
47 | 'endDate': '' |
---|
48 | } |
---|
49 | acceptedTypes = [TM_Period] |
---|
50 | |
---|
51 | dataFormat = '%04d-%02d-%02d %02d:%02d:%02d' |
---|
52 | |
---|
53 | def postCedaObjToAdapterMapping(self, cedaObject): |
---|
54 | position = cedaObject.begin.position.date8601 |
---|
55 | self.startDate = self.dataFormat \ |
---|
56 | % (position.year, position.month, position.day, \ |
---|
57 | getattr(position, 'hour', 0), getattr(position, 'minute', 0), getattr(position, 'second', 0)) |
---|
58 | |
---|
59 | position = cedaObject.end.position.date8601 |
---|
60 | self.endDate = self.dataFormat \ |
---|
61 | % (position.year, position.month, position.day, \ |
---|
62 | getattr(position, 'hour', 0), getattr(position, 'minute', 0), getattr(position, 'second', 0)) |
---|
63 | |
---|
64 | def _mapPosition(self, position, dateTuple): |
---|
65 | setattr(position, 'year', dateTuple[0]) |
---|
66 | setattr(position, 'month', dateTuple[1]) |
---|
67 | setattr(position, 'day', dateTuple[2]) |
---|
68 | setattr(position, 'hour', dateTuple[3]) |
---|
69 | setattr(position, 'minute', dateTuple[4]) |
---|
70 | setattr(position, 'second', dateTuple[5]) |
---|
71 | |
---|
72 | def _parseDate(self, dateString): |
---|
73 | d, t = unicodeToString(dateString).split() |
---|
74 | year, month, day = d.split("-") |
---|
75 | hour, minute, second = t.split(":") |
---|
76 | return (year, month, day, hour, minute, second) |
---|
77 | |
---|
78 | def postAdapterToCedaObjMapping(self, cedaObject): |
---|
79 | self._mapPosition(cedaObject.begin.position.date8601, \ |
---|
80 | self._parseDate(self.startDate)) |
---|
81 | |
---|
82 | self._mapPosition(cedaObject.end.position.date8601, \ |
---|
83 | self._parseDate(self.endDate)) |
---|