7 from paramdata_filename
import timeInterval2paramdataFilename
8 #############################################################################
10 def attrData_fromTimeToTime(attr_name
, startTime_str
, endTime_str
, extractor
):
13 extraction_args
.append( attr_name
)
14 extraction_args
.append( startTime_str
)
15 extraction_args
.append( endTime_str
)
18 if ( extractor
.GetAttDataBetweenDatesCount(extraction_args
) ):
20 attrData_pointer
= extractor
.GetAttDataBetweenDates( extraction_args
)
22 valsNb
= attrData_pointer
[0][0]
23 buffer_id
= attrData_pointer
[1][0]
25 #print 'attrData_fromTimeToTime: valsNb = ' + str(valsNb)
26 #print 'attrData_fromTimeToTime: buffer_id = ' + str(buffer_id)
28 for data_item
in extractor
.attribute_history( buffer_id
, valsNb
):
29 attr_data
.append( (data_item
.value
.time
.tv_sec
, data_item
.value
.value
) )
31 attr_data
.sort() # !!!!!!!!!
34 "The dynamic attribute created by the GetAttDataBetweenDates commande is to be removed"
35 if attrData_pointer
!= []:
36 extractor
.RemoveDynamicAttribute( buffer_id
)
41 ##################################################################################################
42 def extractAttr_fromTimeToTime(attr_name
, startTime_str
, endTime_str
, extractor
, output_filename
):
44 output_file
= open(output_filename
, 'w')
46 attr_data
= attrData_fromTimeToTime(attr_name
, startTime_str
, endTime_str
, extractor
)
48 start_time
= time
.mktime(time
.strptime(startTime_str
, "%Y-%m-%d %H:%M:%S"))
50 for i
in range (len(attr_data
)):
51 output_file
.write( str(attr_data
[i
][0]-start_time
) + " " + str(attr_data
[i
][1]) + "\n")
54 #################################################################################################
55 def extractAttr_relativeTime(attr_name
, zeroTime_sec
, extraPeriod_str
, extractor
, dest_dir
= '.' ):
57 attr_data
= attrData_fromTimeToTime(attr_name
,
58 extraPeriod_str
[0], extraPeriod_str
[1], extractor
)
61 #-------------------- filename --------------------
62 ## date_str = extraPeriod_str[0][8:10]
63 ## startHour_str = extraPeriod_str[0][11:].replace(':', '.')
64 ## endHour_str = extraPeriod_str[1][11:].replace(':', '.')
66 ## dev_name = attr_name.split('/')[-2]
67 ## attr_shortName = attr_name.split('/')[-1]
69 ## output_filename = ( dest_dir + os.sep + date_str +'_'+ startHour_str + '-' + endHour_str + '_'
70 ## + dev_name + '.' + attr_shortName )
71 #----------------------------------------------------
73 output_filename
= dest_dir
+ os
.sep
+ timeInterval2paramdataFilename(attr_name
, extraPeriod_str
)
75 output_file
= open(output_filename
, 'w')
77 for i
in range (len(attr_data
)):
78 output_file
.write( str(attr_data
[i
][0]-zeroTime_sec
) + " "
79 + str(attr_data
[i
][1]) + "\n")
83 ##################################################################################################
84 ##def extractData_fromTimeToTime(attr_list, startTime_str, endTime_str, extractor, baseOutputName):
86 ## for i in range ( len(attr_list) ):
87 ## attr_fulName = attr_list[i]
88 ## devName = attr_fulName.split('/')[-2]
89 ## attr_shortName = attr_fulName.split('/')[-1]
90 ## #print attr_shortName
91 ## filename_i = baseOutputName + devName + '.' + attr_shortName
92 ## extractAttr_fromTimeToTime(attr_fulName, startTime_str, endTime_str, extractor, filename_i)
98 ##################################################################################################
99 if __name__
== '__main__':
102 if len(sys
.argv
) < 4:
103 print "Correct use: " + sys
.argv
[0] + " archi_filename startTime_str ('Y-m-d H:M:S') endTime_str ('Y-m-d H:M:S') dest_dir [hdb/tdb]"
106 archi_filename
= sys
.argv
[1]
107 startTime_str
= sys
.argv
[2]
108 endTime_str
= sys
.argv
[3]
109 dest_dir
= sys
.argv
[4]
113 if len(sys
.argv
) == 6 and (sys
.argv
[5] == "hdb" or sys
.argv
[5] == "HDB"):
114 extractor
= DeviceProxy("archiving/hdb/hdbextractor.1")
117 extractor
= DeviceProxy("archiving/tdb/tdbextractor.1")
121 extractor
.set_timeout_millis(100000)
123 # TEST 1 -------------------------------------------
124 attr_list
= reading_txtac
.attrs_fromDevList(archi_filename
)
125 #print attr_list # DEBUG
126 date_string
= startTime_str
[:10]
127 startHour_string
= startTime_str
[11:].replace(':', '.')
128 endHour_string
= endTime_str
[11:].replace(':', '.')
130 baseOutputName
= dest_dir
+ os
.sep
+ date_string
+ '_' + startHour_string
+ '-' + endHour_string
+ '_'
132 extractData_fromTimeToTime( attr_list
, startTime_str
, endTime_str
, extractor
, baseOutputName
)
135 # TEST 2 -------------------------------------------
136 #extractData_archivedPeriods(archi_filename, startTime_str, endTime_str, extractor, dest_dir)