2 ##################################
9 from bl_instance
.build_bl
import *
11 from tools
.generic_utils
.time_formats
import *
12 from tools
.generic_utils
.dataPortioning_byTime
import *
15 from tools
.data_processing
.portioningTime_byData
import *
17 from extraction
import *
18 #################################
21 ###############################################
22 startShift_hour
= '07:00:00'
23 endShift_hour
= '07:00:00'
25 extraPeriod_minLength_sec
= 60*10 # = 10 min
26 EXTRAPERIOD_MAXLENGTH_SEC
= 60*60*3 # = 3 hours
27 ###############################################
31 ############################
32 if __name__
== '__main__':
36 print "Correct use: " + sys
.argv
[0] + " startDate_str ('Y-m-d') dest_dir [hdb/tdb]"
39 startDate_str
= sys
.argv
[1]
41 dest_dir
= sys
.argv
[2]
42 if not os
.path
.exists(dest_dir
):
43 print "The directory ", dest_dir
, " does not exist"
45 if dest_dir
[-1] == os
.sep
:
46 dest_dir
= dest_dir
[:-1]
50 if len(sys
.argv
) == 4 and (sys
.argv
[3] == "hdb" or sys
.argv
[3] == "HDB"):
51 extractor
= DeviceProxy("archiving/hdb/hdbextractor.1")
54 extractor
= DeviceProxy("archiving/tdb/tdbextractor.1")
58 extractor
.set_timeout_millis(100000)
59 # ----------------------------------------------------------------------------------------------
61 startShift_str
= startDate_str
+' '+ startShift_hour
62 startShift_sec
= str2sec(startShift_str
)
64 startShift_hour_sec
= hour2sec(startShift_hour
)
65 endShift_hour_sec
= hour2sec(endShift_hour
)
67 if startShift_hour_sec
>= endShift_hour_sec
:
68 startShift_date_sec
= time
.mktime(time
.strptime(startDate_str
, "%Y-%m-%d"))
69 endShift_date_sec
= startShift_date_sec
+ hour2sec("24:00:00")
71 endShift_sec
= endShift_date_sec
+ endShift_hour_sec
72 endShift_str
= sec2str(endShift_sec
)
75 shift_str
= (startShift_str
, endShift_str
)
77 ## print startShift_str # debug
78 ## print endShift_str # debug
79 # ----------------------------------------------------------------------------------------------
82 extractionPeriods_sec
= [(startShift_sec
, endShift_sec
)]
83 extractionPeriods_str
= periodsSec2periodsStr(extractionPeriods_sec
)
84 steadyPeriods_str
= extractionPeriods_str
87 ############################# Main loop #########################
89 for elem
in beam_path
:
90 if isinstance(elem
, beam_monitor
)and not isinstance(elem
, extractable_beamMonitor
):
91 monitor
= elem
# just a notation for a better readability
92 print '\nMonitor: ', monitor
.nickname
94 monitor
.define_blSteadiness(beam_path
)
96 # ------------------------------------------
97 for param
in monitor
.beamAccess_params
:
98 print '\nBeam access: ', param
.name
# debug
100 new_extractionPeriods_str
= []
102 param_data
= extractAttr_relativeTime( param
.attr_fullName
, startShift_sec
,
103 shift_str
, extractor
, dest_dir
)
104 'param_data is in "abs time" but it is saved in the file in relative time !!!'
106 #print len(param_data) # debug
107 if len(param_data
) == 0:
108 print "No data for ", param
.name
110 #subPeriods_str = takeWholeOrEmpty_extendingExtraction(param, time_interval, extractor, dest_dir)
112 # split param_data following the extractionPeriods ---
113 data_portions
= split_paramData( param_data
, extractionPeriods_str
)
114 # in the loop over the extractionPeriods call get_extraPeriods for each data portion
115 # and update new_extractionPeriods_str ---
116 for i
in range (len(data_portions
)):
118 if len(data_portions
[i
]) == 0:
119 subPeriods_str
= takeWholeOrEmpty_extendingTime(param
, periodsStr2periodsSec([extractionPeriods_str
[i
]])[0], param_data
)
121 subPeriods_str
= periodsSec2periodsStr(get_extraPeriods_sec(param
, data_portions
[i
],
122 periodsStr2periodsSec([extractionPeriods_str
[i
]])[0],
123 extraPeriod_minLength_sec
))
125 new_extractionPeriods_str
+= subPeriods_str
126 #print new_extractionPeriods_str # debug
128 extractionPeriods_str
= new_extractionPeriods_str
129 print extractionPeriods_str
# debug
130 print abs2rel(periodsStr2periodsSec(extractionPeriods_str
), startShift_str
) # debug
132 #sys.exit(0) #####################
134 steadyPeriods_str
= extractionPeriods_str
135 #print steadyPeriods_str # debug
137 # ------------------------------------------
138 if len(extractionPeriods_str
):
139 for param
in monitor
.blSteadiness_params
:
140 print '\nSteadiness: ', param
.name
# debug
142 param_data
= extractAttr_relativeTime( param
.attr_fullName
, startShift_sec
,
143 shift_str
, extractor
, dest_dir
)
145 # ------------------------------------------
148 for param
in monitor
.params
:
149 print '\n', param
.name
# debug
151 for steady_period
in steadyPeriods_str
:
152 shortSteadyPeriods_str
= split_longInterval(steady_period
, EXTRAPERIOD_MAXLENGTH_SEC
)
154 for short_steadyPeriod
in shortSteadyPeriods_str
:
156 param_data
= extractAttr_relativeTime( param
.attr_fullName
, startShift_sec
,
157 short_steadyPeriod
, extractor
, dest_dir
)
158 # -------------------------------------------------------
160 print 'beam_path extraction done'
163 env_dir
= dest_dir
+ os
.sep
+'environment'
164 if not os
.path
.exists(env_dir
):
165 os
.mkdir(dest_dir
+ os
.sep
+ 'environment')
167 for elem
in continuous_env
:
168 print '\nContinuous env: ', elem
.nickname
170 for param
in elem
.params
:
171 print '\n', param
.name
# debug
173 shortPeriods_str
= split_longInterval(shift_str
, EXTRAPERIOD_MAXLENGTH_SEC
)
175 for short_period
in shortPeriods_str
:
176 param_data
= extractAttr_relativeTime( param
.attr_fullName
, startShift_sec
,
177 short_period
, extractor
, env_dir
)