本文整理汇总了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