本文整理匯總了Python中serializer.Serializer.parse_units方法的典型用法代碼示例。如果您正苦於以下問題:Python Serializer.parse_units方法的具體用法?Python Serializer.parse_units怎麽用?Python Serializer.parse_units使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類serializer.Serializer
的用法示例。
在下文中一共展示了Serializer.parse_units方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __push_data_from_obj
# 需要導入模塊: from serializer import Serializer [as 別名]
# 或者: from serializer.Serializer import parse_units [as 別名]
def __push_data_from_obj(self, obj):
""" saves array data to disk in HDF5s and uploads new datafiles to the
server according to the arrays of the given obj. Saves datafile objects
to cache """
data_refs = {} # collects all references to the related data - output
model_name = self._meta.get_type_by_obj( obj )
data_attrs = self._meta.get_array_attr_names( model_name )
attrs_to_sync = self._cache.detect_changed_data_fields( obj )
for attr in data_attrs: # attr is like 'times', 'signal' etc.
arr = None
if attr in attrs_to_sync:
# 1. get current array and units
fname = self._meta.app_definitions[model_name]['data_fields'][attr][2]
if fname == 'self':
arr = obj # some NEO objects like signal inherit array
else:
arr = getattr(obj, fname)
if not type(arr) == type(None): # because of NEO __eq__
units = Serializer.parse_units(arr)
datapath = self._cache.save_data(arr)
json_obj = self._remote.save_data(datapath)
# update cache data map
datalink = json_obj['permalink']
fid = str(get_id_from_permalink( datalink ))
folder, tempname = os.path.split(datapath)
new_path = os.path.join(folder, fid + tempname[tempname.find('.'):])
os.rename(datapath, new_path)
self._cache.update_data_map(fid, new_path)
data_refs[ attr ] = {'data': datalink, 'units': units}
else:
data_refs[ attr ] = None
return data_refs