本文整理汇总了Python中models.Activity.duration方法的典型用法代码示例。如果您正苦于以下问题:Python Activity.duration方法的具体用法?Python Activity.duration怎么用?Python Activity.duration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Activity
的用法示例。
在下文中一共展示了Activity.duration方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: filterActivityData
# 需要导入模块: from models import Activity [as 别名]
# 或者: from models.Activity import duration [as 别名]
def filterActivityData(dayOfActivityData):
#filter
walkingArray = []
runningArray = []
stationaryArray = []
carArray = []
unknownArray = []
lastobj = Activity(duration=0,type=1)
sumDuration = 0
for actobj in dayOfActivityData:
if actobj.type == 1:
if lastobj.type == 1:
if len(walkingArray) > 0:
sumDuration = actobj.duration + walkingArray[len(walkingArray)-1]
else:
sumDuration = actobj.duration
walkingArray.append(sumDuration)
elif actobj.type == 2:
if lastobj.type == 2:
if len(runningArray) > 0:
sumDuration = actobj.duration + runningArray[len(runningArray)-1]
else:
sumDuration = actobj.duration
runningArray.append(sumDuration)
elif actobj.type == 3:
if lastobj.type == 3:
if len(stationaryArray) > 0:
sumDuration = actobj.duration + stationaryArray[len(stationaryArray)-1]
else:
sumDuration = actobj.duration
stationaryArray.append(sumDuration)
elif actobj.type == 4:
if lastobj.type == 4:
if len(carArray) > 0:
sumDuration = actobj.duration + carArray[len(carArray)-1]
else:
sumDuration = actobj.duration
carArray.append(sumDuration)
else:
if lastobj.type == 5:
if len(unknownArray) > 0:
sumDuration = actobj.duration + unknownArray[len(unknownArray)-1]
else:
sumDuration = actobj.duration
unknownArray.append(sumDuration)
lastobj = actobj
lastobj.duration = actobj.duration
lastobj.type = actobj.type
filteredData = {"walking":walkingArray,"running":runningArray,"stationary":stationaryArray,"car":carArray,"unknown":unknownArray}
return filteredData