本文整理汇总了Python中Statistics.Statistics.getList方法的典型用法代码示例。如果您正苦于以下问题:Python Statistics.getList方法的具体用法?Python Statistics.getList怎么用?Python Statistics.getList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Statistics.Statistics
的用法示例。
在下文中一共展示了Statistics.getList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Statistics import Statistics [as 别名]
# 或者: from Statistics.Statistics import getList [as 别名]
class Road:
def __init__(self):
# all variables here
self.TOTAL_TIME = 15000
self.NUM_OF_CARS = 200000
self.DELTA_TIME = 0.05
self.PERCENT_OF_CARS = [0.3,0.7]
# Units: m/delta_t
self.AVG_SPEED_OF_CARS = {'s': 30, 'm': 25, 'b': 20}
self.STD_DEV_OF_CARS = {'s': 10, 'm':10, 'b': 10}
# Units: m
self.LENGTHS_OF_CARS = {'s': 5, 'm': 7, 'b': 10}
self.VISIBLE_DISTANCE_OF_CARS = {'s': 70, 'm': 80, 'b': 90}
# Units: m/delta_t
self.MIN_SPEED = 15
self.MAX_SPEED = 60
# Units: m
self.ROAD_LENGTH = 5000
self.SAFE_DISTANCE_BETWEEN_CARS = 20
''' this affects accident rate a lot'''
self.INITIAL_DISTANCE_BETWEEN_CARS = 80
self._recycledIndexes = set()
self.all_cars = []
self.current_num_of_cars = 0
self.stat = Statistics()
self.generateCar(self.generateIndex())
for time in range(self.TOTAL_TIME):
if self.needToGenerateCars():
self.generateCar(self.generateIndex())
## print("New Car generated")
## print(self._recycledIndexes)
## print()
num_of_cars_on_r = 0
num_of_cars_on_l = 0
total_speed_on_r = 0
total_speed_on_l = 0
for i in range(len(self.all_cars)):
each = self.all_cars[i]
if each == None:
self._recycledIndexes.add(i)
continue
if each.position > self.ROAD_LENGTH:
self.all_cars[i] = None
self._recycledIndexes.add(i)
## print(each.index, "th car reaches the end of the road!")
## print(self._recycledIndexes)
continue
## print(each.index, "th car: ", each.position, " lane: ", each.lane)
## print()
each.move(self.all_cars)
###################################################Statistics################################
if each.lane == 'r':
num_of_cars_on_r += 1
total_speed_on_r += each.Vcurrent
elif each.lane == 'l':
num_of_cars_on_l += 1
total_speed_on_l += each.Vcurrent
self.stat.listIncrease("density_of_r", time, num_of_cars_on_r / self.ROAD_LENGTH)
self.stat.listIncrease("density_of_l", time, num_of_cars_on_l / self.ROAD_LENGTH)
if num_of_cars_on_r == 0:
self.stat.listIncrease("avg_speed_on_r", time, 0)
else:
self.stat.listIncrease("avg_speed_on_r", time, total_speed_on_r / num_of_cars_on_r)
if num_of_cars_on_l == 0:
self.stat.listIncrease("avg_speed_on_l", time, 0)
else:
self.stat.listIncrease("avg_speed_on_l", time, total_speed_on_l / num_of_cars_on_l)
time += self.DELTA_TIME
print("accident rate: ", self.stat.getRate("num_of_accidents", "num_of_cars_generated"))
print("succussful passing rate: ", self.stat.getRate("successful_passings", "passing_intents"))
writeToFile(self.stat.getList("density_of_r"), "density_of_r.txt")
writeToFile(self.stat.getList("density_of_l"), "density_of_l.txt")
writeToFile(self.stat.getList("avg_speed_on_r"), "avg_speed_on_r.txt")
writeToFile(self.stat.getList("avg_speed_on_l"), "avg_speed_on_l.txt")
## print("density of lane r: ", self.stat.getList("density_of_r"))
## print("density of lane l: ", self.stat.getList("density_of_l"))
## print("Average speed on lane r: ", self.stat.getList("avg_speed_on_r"))
## print("Average speed on lane l: ", self.stat.getList("avg_speed_on_l"))
#############
## f.write(s)
#.........这里部分代码省略.........