Problems in re-computing distributions to use in main.py file
first of all, I had an old which worked great as it were, i call this for distributions_v1.py. This file is generating random distributions using probabilities.
What was the problem with this file? The problem was that this was a bad code, and it only generated distributions once! so when I am running simulations in main.py, the simulation
is using the same distributions everyday, instead of computing new ones for each day.
So what did I try to do, Well I tried the reloading module(recalling the file), but that doest not work because of this method:
def distribute_faster(cars, totals):
counts = {total: 0 for total in range(totals)}
while cars > 0:
adjust = cars > 5000 # totally arbitrary
change = 1
if adjust:
change = 5
choice = randint(0, totals - 1)
counts[choice] += change
cars -= change
return counts
So after this didnt work, I tried reformatting the code, this I named for distributions_v2.py. I have added functions etc, but the error I get in the main.py file because of the changes
are: for hotspot in hotspot_districts:
TypeError: 'int' object is not iterable
PS: here is the old code(distributions_v1.py):
from random import randint
total_amount_of_cars_that_are_driving_to_work_districts = 26904
total_amount_of_cars_that_are_driving_to_main_districts = 21528
total_amount_of_cars_that_are_driving_to_hotspot_districts = 5376
"----Work districts setup----"
distributed_cars_to_work =
cars_per_hour_to_work_districts =
total_work_districts =
all_working_districts_used =
for amount_of_working_districts in range(0,7):
all_working_districts_used.append(amount_of_working_districts)
for work_districts in all_working_districts_used:
total_work_districts.append(work_districts)
"----Main districts setup----"
distributed_cars_to_main =
cars_per_hour_to_main_districts =
total_main_districts =
all_the_main_districts =
for amount_of_main_districts in range (0,45):
all_the_main_districts.append(amount_of_main_districts)
for main_districts in all_the_main_districts:
total_main_districts.append(main_districts)
"----Hotspot district setup----"
distributed_cars_to_hotspot =
cars_per_hour_to_hotspot_districts =
total_hotspot_districts =
all_the_hotspot_districts =
for amount_of_hotspot_districts in range(0,4):
all_the_hotspot_districts.append(amount_of_hotspot_districts)
for hotspot_districts in all_the_hotspot_districts:
total_hotspot_districts.append(hotspot_districts)
class CarsDistribution:
all_probabilities = {
"work":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.01, 0.05, 0.11, 0.19, 0.23, 0.2, 0.14, 0.05, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
"main":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.02, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.08, 0.08, 0.08, 0.07, 0.06, 0.06, 0.05, 0.04),
"hotspot":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.02, 0.03, 0.04, 0.08, 0.1, 0.12, 0.13, 0.13, 0.11, 0.07, 0.05, 0.04, 0.03, 0.02, 0.01)
}
def __init__(self, type, cars):
total_length = len(cars)
self.cars_per_hour = {}
for hour, p in enumerate(self.all_probabilities[type]):
try:
self.cars_per_hour[hour] = [cars.pop() for i in range(int(p * total_length))]
except IndexError:
print('cars already exhausted at hour {}'.format(hour))
if cars:
print('{} left after distributing is finished'.format(len(cars)))
def distribute_faster(cars, totals):
counts = {total: 0 for total in range(totals)}
while cars > 0:
adjust = cars > 5000 # totally arbitrary
change = 1
if adjust:
change = 5
choice = randint(0, totals - 1)
counts[choice] += change
cars -= change
return counts
random_distribution_to_work = distribute_faster(total_amount_of_cars_that_are_driving_to_work_districts, 8)
print("Amount of cars distributed to work stations: {}".format(random_distribution_to_work))
print(".............................................................................................................")
for key, value in random_distribution_to_work.items():
distributed_cars_to_work.append(value)
(work_districts) = (CarsDistribution('work', [distributed_cars_to_work for x in range(num_cars)]) for num_cars in distributed_cars_to_work)
for randomWork in work_districts:
cars_per_hour_to_work_districts.append([len(c) for c in randomWork.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_work in cars_per_hour_to_work_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)
print("Total amount of car that got distributed to this work station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)))
print("--------------------------------------------------------------------------------------------------")
print("===============================WORK DISTRIBUTION FINISHED=========================================")
random_distribution_to_main = distribute_faster(total_amount_of_cars_that_are_driving_to_main_districts, 46) #46!!
print("Amount of cars distributed to main stations: {}".format(random_distribution_to_main))
print(".............................................................................................................")
for key, value in random_distribution_to_main.items():
distributed_cars_to_main.append(value)
(main_districts) = (CarsDistribution('main', [distributed_cars_to_main for x in range(num_cars)]) for num_cars in
distributed_cars_to_main)
for randomMain in main_districts:
cars_per_hour_to_main_districts.append([len(c) for c in randomMain.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_main in cars_per_hour_to_main_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)
print("Total amount of car that got distributed to this main station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)))
print("--------------------------------------------------------------------------------------------------")
print("===============================MAIN DISTRIBUTION FINISHED=========================================")
random_distribution_to_hotspot = distribute_faster(total_amount_of_cars_that_are_driving_to_hotspot_districts, 5)
print("Amount of cars distributed to hotspot stations: {}".format(random_distribution_to_hotspot))
print(".............................................................................................................")
for key, value in random_distribution_to_hotspot.items():
distributed_cars_to_hotspot.append(value)
(hotspot_districts) = (CarsDistribution('hotspot', [distributed_cars_to_hotspot for x in range(num_cars)]) for num_cars in
distributed_cars_to_hotspot)
for randomHotspot in hotspot_districts:
cars_per_hour_to_hotspot_districts.append([len(c) for c in randomHotspot.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot in cars_per_hour_to_hotspot_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)
print("Total amount of car that got distributed to this hotspot station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)))
print("--------------------------------------------------------------------------------------------------")
print("============================HOTSPOT DISTRIBUTION FINISHED=========================================")
and here is the reformatted code with functions(distributions_v2.py):
from random import randint
total_amount_of_cars_that_are_driving_to_work_districts = 26904
total_amount_of_cars_that_are_driving_to_main_districts = 21528
total_amount_of_cars_that_are_driving_to_hotspot_districts = 5376
"----Work districts setup----"
distributed_cars_to_work =
cars_per_hour_to_work_districts =
total_work_districts =
all_working_districts_used =
for amount_of_working_districts in range(0,7):
all_working_districts_used.append(amount_of_working_districts)
for work_districts in all_working_districts_used:
total_work_districts.append(work_districts)
"----Main districts setup----"
distributed_cars_to_main =
cars_per_hour_to_main_districts =
total_main_districts =
all_the_main_districts =
for amount_of_main_districts in range (0,45):
all_the_main_districts.append(amount_of_main_districts)
for main_districts in all_the_main_districts:
total_main_districts.append(main_districts)
"----Hotspot district setup----"
distributed_cars_to_hotspot =
cars_per_hour_to_hotspot_districts =
total_hotspot_districts =
all_the_hotspot_districts =
for amount_of_hotspot_districts in range(0,4):
all_the_hotspot_districts.append(amount_of_hotspot_districts)
for hotspot_districts in all_the_hotspot_districts:
total_hotspot_districts.append(hotspot_districts)
def distribute_faster(cars, totals):
counts = {total: 0 for total in range(totals)}
while cars > 0:
adjust = cars > 5000 # totally arbitrary
change = 1
if adjust:
change = 5
choice = randint(0, totals - 1)
counts[choice] += change
cars -= change
return counts
class CarsDistribution:
all_probabilities = {
"work":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.01, 0.05, 0.11, 0.19, 0.23, 0.2, 0.14, 0.05, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
"main":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.02, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.08, 0.08, 0.08, 0.07, 0.06, 0.06, 0.05, 0.04),
"hotspot":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.02, 0.03, 0.04, 0.08, 0.1, 0.12, 0.13, 0.13, 0.11, 0.07, 0.05, 0.04, 0.03, 0.02, 0.01)
}
def __init__(self, type, cars):
total_length = len(cars)
self.cars_per_hour = {}
for hour, p in enumerate(self.all_probabilities[type]):
try:
self.cars_per_hour[hour] = [cars.pop() for i in range(int(p * total_length))]
except IndexError:
print('cars already exhausted at hour {}'.format(hour))
if cars:
print('{} left after distributing is finished'.format(len(cars)))
def generate_work_districts_distribution():
random_distribution_to_work = distribute_faster(total_amount_of_cars_that_are_driving_to_work_districts, 8)
print("Amount of cars distributed to work stations: {}".format(random_distribution_to_work))
print(
".............................................................................................................")
for key, value in random_distribution_to_work.items():
distributed_cars_to_work.append(value)
(work_districts) = (CarsDistribution('work', [distributed_cars_to_work for x in range(num_cars)]) for num_cars in
distributed_cars_to_work)
for randomWork in work_districts:
cars_per_hour_to_work_districts.append([len(c) for c in randomWork.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_work in cars_per_hour_to_work_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)
print("Total amount of car that got distributed to this work station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)))
print("--------------------------------------------------------------------------------------------------")
print("===============================WORK DISTRIBUTION FINISHED=========================================")
def generate_distributions_to_main():
random_distribution_to_main = distribute_faster(total_amount_of_cars_that_are_driving_to_main_districts, 46) # 46!!
print("Amount of cars distributed to main stations: {}".format(random_distribution_to_main))
print(
".............................................................................................................")
for key, value in random_distribution_to_main.items():
distributed_cars_to_main.append(value)
(main_districts) = (CarsDistribution('main', [distributed_cars_to_main for x in range(num_cars)]) for num_cars in
distributed_cars_to_main)
for randomMain in main_districts:
cars_per_hour_to_main_districts.append([len(c) for c in randomMain.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_main in cars_per_hour_to_main_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)
print("Total amount of car that got distributed to this main station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)))
print("--------------------------------------------------------------------------------------------------")
print("===============================MAIN DISTRIBUTION FINISHED=========================================")
def generate_hotspot_distributions():
random_distribution_to_hotspot = distribute_faster(total_amount_of_cars_that_are_driving_to_hotspot_districts, 5)
print("Amount of cars distributed to hotspot stations: {}".format(random_distribution_to_hotspot))
print(
".............................................................................................................")
for key, value in random_distribution_to_hotspot.items():
distributed_cars_to_hotspot.append(value)
(hotspot_districts) = (CarsDistribution('hotspot', [distributed_cars_to_hotspot for x in range(num_cars)]) for
num_cars in
distributed_cars_to_hotspot)
for randomHotspot in hotspot_districts:
cars_per_hour_to_hotspot_districts.append([len(c) for c in randomHotspot.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot in cars_per_hour_to_hotspot_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)
print("Total amount of car that got distributed to this hotspot station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)))
print("--------------------------------------------------------------------------------------------------")
print("============================HOTSPOT DISTRIBUTION FINISHED=========================================")
"---Reset the lists after used ---"
distributed_cars_to_work =
cars_per_hour_to_work_districts =
total_work_districts =
all_working_districts_used =
distributed_cars_to_main =
cars_per_hour_to_main_districts =
total_main_districts =
all_the_main_districts =
distributed_cars_to_hotspot =
cars_per_hour_to_hotspot_districts =
total_hotspot_districts =
all_the_hotspot_districts =
Could someone help me please? the new code looks great, but now in the main.py file i get Typerror"int object is not iterable"
If I dont see any solution I may perhaps just move all into main.py, but as I wanna have good structure I want to keep the distributions.py file.
Thank you.
python numpy
add a comment |
first of all, I had an old which worked great as it were, i call this for distributions_v1.py. This file is generating random distributions using probabilities.
What was the problem with this file? The problem was that this was a bad code, and it only generated distributions once! so when I am running simulations in main.py, the simulation
is using the same distributions everyday, instead of computing new ones for each day.
So what did I try to do, Well I tried the reloading module(recalling the file), but that doest not work because of this method:
def distribute_faster(cars, totals):
counts = {total: 0 for total in range(totals)}
while cars > 0:
adjust = cars > 5000 # totally arbitrary
change = 1
if adjust:
change = 5
choice = randint(0, totals - 1)
counts[choice] += change
cars -= change
return counts
So after this didnt work, I tried reformatting the code, this I named for distributions_v2.py. I have added functions etc, but the error I get in the main.py file because of the changes
are: for hotspot in hotspot_districts:
TypeError: 'int' object is not iterable
PS: here is the old code(distributions_v1.py):
from random import randint
total_amount_of_cars_that_are_driving_to_work_districts = 26904
total_amount_of_cars_that_are_driving_to_main_districts = 21528
total_amount_of_cars_that_are_driving_to_hotspot_districts = 5376
"----Work districts setup----"
distributed_cars_to_work =
cars_per_hour_to_work_districts =
total_work_districts =
all_working_districts_used =
for amount_of_working_districts in range(0,7):
all_working_districts_used.append(amount_of_working_districts)
for work_districts in all_working_districts_used:
total_work_districts.append(work_districts)
"----Main districts setup----"
distributed_cars_to_main =
cars_per_hour_to_main_districts =
total_main_districts =
all_the_main_districts =
for amount_of_main_districts in range (0,45):
all_the_main_districts.append(amount_of_main_districts)
for main_districts in all_the_main_districts:
total_main_districts.append(main_districts)
"----Hotspot district setup----"
distributed_cars_to_hotspot =
cars_per_hour_to_hotspot_districts =
total_hotspot_districts =
all_the_hotspot_districts =
for amount_of_hotspot_districts in range(0,4):
all_the_hotspot_districts.append(amount_of_hotspot_districts)
for hotspot_districts in all_the_hotspot_districts:
total_hotspot_districts.append(hotspot_districts)
class CarsDistribution:
all_probabilities = {
"work":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.01, 0.05, 0.11, 0.19, 0.23, 0.2, 0.14, 0.05, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
"main":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.02, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.08, 0.08, 0.08, 0.07, 0.06, 0.06, 0.05, 0.04),
"hotspot":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.02, 0.03, 0.04, 0.08, 0.1, 0.12, 0.13, 0.13, 0.11, 0.07, 0.05, 0.04, 0.03, 0.02, 0.01)
}
def __init__(self, type, cars):
total_length = len(cars)
self.cars_per_hour = {}
for hour, p in enumerate(self.all_probabilities[type]):
try:
self.cars_per_hour[hour] = [cars.pop() for i in range(int(p * total_length))]
except IndexError:
print('cars already exhausted at hour {}'.format(hour))
if cars:
print('{} left after distributing is finished'.format(len(cars)))
def distribute_faster(cars, totals):
counts = {total: 0 for total in range(totals)}
while cars > 0:
adjust = cars > 5000 # totally arbitrary
change = 1
if adjust:
change = 5
choice = randint(0, totals - 1)
counts[choice] += change
cars -= change
return counts
random_distribution_to_work = distribute_faster(total_amount_of_cars_that_are_driving_to_work_districts, 8)
print("Amount of cars distributed to work stations: {}".format(random_distribution_to_work))
print(".............................................................................................................")
for key, value in random_distribution_to_work.items():
distributed_cars_to_work.append(value)
(work_districts) = (CarsDistribution('work', [distributed_cars_to_work for x in range(num_cars)]) for num_cars in distributed_cars_to_work)
for randomWork in work_districts:
cars_per_hour_to_work_districts.append([len(c) for c in randomWork.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_work in cars_per_hour_to_work_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)
print("Total amount of car that got distributed to this work station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)))
print("--------------------------------------------------------------------------------------------------")
print("===============================WORK DISTRIBUTION FINISHED=========================================")
random_distribution_to_main = distribute_faster(total_amount_of_cars_that_are_driving_to_main_districts, 46) #46!!
print("Amount of cars distributed to main stations: {}".format(random_distribution_to_main))
print(".............................................................................................................")
for key, value in random_distribution_to_main.items():
distributed_cars_to_main.append(value)
(main_districts) = (CarsDistribution('main', [distributed_cars_to_main for x in range(num_cars)]) for num_cars in
distributed_cars_to_main)
for randomMain in main_districts:
cars_per_hour_to_main_districts.append([len(c) for c in randomMain.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_main in cars_per_hour_to_main_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)
print("Total amount of car that got distributed to this main station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)))
print("--------------------------------------------------------------------------------------------------")
print("===============================MAIN DISTRIBUTION FINISHED=========================================")
random_distribution_to_hotspot = distribute_faster(total_amount_of_cars_that_are_driving_to_hotspot_districts, 5)
print("Amount of cars distributed to hotspot stations: {}".format(random_distribution_to_hotspot))
print(".............................................................................................................")
for key, value in random_distribution_to_hotspot.items():
distributed_cars_to_hotspot.append(value)
(hotspot_districts) = (CarsDistribution('hotspot', [distributed_cars_to_hotspot for x in range(num_cars)]) for num_cars in
distributed_cars_to_hotspot)
for randomHotspot in hotspot_districts:
cars_per_hour_to_hotspot_districts.append([len(c) for c in randomHotspot.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot in cars_per_hour_to_hotspot_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)
print("Total amount of car that got distributed to this hotspot station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)))
print("--------------------------------------------------------------------------------------------------")
print("============================HOTSPOT DISTRIBUTION FINISHED=========================================")
and here is the reformatted code with functions(distributions_v2.py):
from random import randint
total_amount_of_cars_that_are_driving_to_work_districts = 26904
total_amount_of_cars_that_are_driving_to_main_districts = 21528
total_amount_of_cars_that_are_driving_to_hotspot_districts = 5376
"----Work districts setup----"
distributed_cars_to_work =
cars_per_hour_to_work_districts =
total_work_districts =
all_working_districts_used =
for amount_of_working_districts in range(0,7):
all_working_districts_used.append(amount_of_working_districts)
for work_districts in all_working_districts_used:
total_work_districts.append(work_districts)
"----Main districts setup----"
distributed_cars_to_main =
cars_per_hour_to_main_districts =
total_main_districts =
all_the_main_districts =
for amount_of_main_districts in range (0,45):
all_the_main_districts.append(amount_of_main_districts)
for main_districts in all_the_main_districts:
total_main_districts.append(main_districts)
"----Hotspot district setup----"
distributed_cars_to_hotspot =
cars_per_hour_to_hotspot_districts =
total_hotspot_districts =
all_the_hotspot_districts =
for amount_of_hotspot_districts in range(0,4):
all_the_hotspot_districts.append(amount_of_hotspot_districts)
for hotspot_districts in all_the_hotspot_districts:
total_hotspot_districts.append(hotspot_districts)
def distribute_faster(cars, totals):
counts = {total: 0 for total in range(totals)}
while cars > 0:
adjust = cars > 5000 # totally arbitrary
change = 1
if adjust:
change = 5
choice = randint(0, totals - 1)
counts[choice] += change
cars -= change
return counts
class CarsDistribution:
all_probabilities = {
"work":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.01, 0.05, 0.11, 0.19, 0.23, 0.2, 0.14, 0.05, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
"main":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.02, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.08, 0.08, 0.08, 0.07, 0.06, 0.06, 0.05, 0.04),
"hotspot":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.02, 0.03, 0.04, 0.08, 0.1, 0.12, 0.13, 0.13, 0.11, 0.07, 0.05, 0.04, 0.03, 0.02, 0.01)
}
def __init__(self, type, cars):
total_length = len(cars)
self.cars_per_hour = {}
for hour, p in enumerate(self.all_probabilities[type]):
try:
self.cars_per_hour[hour] = [cars.pop() for i in range(int(p * total_length))]
except IndexError:
print('cars already exhausted at hour {}'.format(hour))
if cars:
print('{} left after distributing is finished'.format(len(cars)))
def generate_work_districts_distribution():
random_distribution_to_work = distribute_faster(total_amount_of_cars_that_are_driving_to_work_districts, 8)
print("Amount of cars distributed to work stations: {}".format(random_distribution_to_work))
print(
".............................................................................................................")
for key, value in random_distribution_to_work.items():
distributed_cars_to_work.append(value)
(work_districts) = (CarsDistribution('work', [distributed_cars_to_work for x in range(num_cars)]) for num_cars in
distributed_cars_to_work)
for randomWork in work_districts:
cars_per_hour_to_work_districts.append([len(c) for c in randomWork.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_work in cars_per_hour_to_work_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)
print("Total amount of car that got distributed to this work station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)))
print("--------------------------------------------------------------------------------------------------")
print("===============================WORK DISTRIBUTION FINISHED=========================================")
def generate_distributions_to_main():
random_distribution_to_main = distribute_faster(total_amount_of_cars_that_are_driving_to_main_districts, 46) # 46!!
print("Amount of cars distributed to main stations: {}".format(random_distribution_to_main))
print(
".............................................................................................................")
for key, value in random_distribution_to_main.items():
distributed_cars_to_main.append(value)
(main_districts) = (CarsDistribution('main', [distributed_cars_to_main for x in range(num_cars)]) for num_cars in
distributed_cars_to_main)
for randomMain in main_districts:
cars_per_hour_to_main_districts.append([len(c) for c in randomMain.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_main in cars_per_hour_to_main_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)
print("Total amount of car that got distributed to this main station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)))
print("--------------------------------------------------------------------------------------------------")
print("===============================MAIN DISTRIBUTION FINISHED=========================================")
def generate_hotspot_distributions():
random_distribution_to_hotspot = distribute_faster(total_amount_of_cars_that_are_driving_to_hotspot_districts, 5)
print("Amount of cars distributed to hotspot stations: {}".format(random_distribution_to_hotspot))
print(
".............................................................................................................")
for key, value in random_distribution_to_hotspot.items():
distributed_cars_to_hotspot.append(value)
(hotspot_districts) = (CarsDistribution('hotspot', [distributed_cars_to_hotspot for x in range(num_cars)]) for
num_cars in
distributed_cars_to_hotspot)
for randomHotspot in hotspot_districts:
cars_per_hour_to_hotspot_districts.append([len(c) for c in randomHotspot.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot in cars_per_hour_to_hotspot_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)
print("Total amount of car that got distributed to this hotspot station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)))
print("--------------------------------------------------------------------------------------------------")
print("============================HOTSPOT DISTRIBUTION FINISHED=========================================")
"---Reset the lists after used ---"
distributed_cars_to_work =
cars_per_hour_to_work_districts =
total_work_districts =
all_working_districts_used =
distributed_cars_to_main =
cars_per_hour_to_main_districts =
total_main_districts =
all_the_main_districts =
distributed_cars_to_hotspot =
cars_per_hour_to_hotspot_districts =
total_hotspot_districts =
all_the_hotspot_districts =
Could someone help me please? the new code looks great, but now in the main.py file i get Typerror"int object is not iterable"
If I dont see any solution I may perhaps just move all into main.py, but as I wanna have good structure I want to keep the distributions.py file.
Thank you.
python numpy
2
Can you distill this to something less than 8 screens long? See Minimal, Complete, and Verifiable example on creating good examples. Also, please add the full exception traceback. Currently no one can know where in your code that TypeError is happening.
– Norrius
Jan 19 at 14:00
Well, you could still see if the version 2 file is done correctly or not
– giroud13
Jan 19 at 14:18
add a comment |
first of all, I had an old which worked great as it were, i call this for distributions_v1.py. This file is generating random distributions using probabilities.
What was the problem with this file? The problem was that this was a bad code, and it only generated distributions once! so when I am running simulations in main.py, the simulation
is using the same distributions everyday, instead of computing new ones for each day.
So what did I try to do, Well I tried the reloading module(recalling the file), but that doest not work because of this method:
def distribute_faster(cars, totals):
counts = {total: 0 for total in range(totals)}
while cars > 0:
adjust = cars > 5000 # totally arbitrary
change = 1
if adjust:
change = 5
choice = randint(0, totals - 1)
counts[choice] += change
cars -= change
return counts
So after this didnt work, I tried reformatting the code, this I named for distributions_v2.py. I have added functions etc, but the error I get in the main.py file because of the changes
are: for hotspot in hotspot_districts:
TypeError: 'int' object is not iterable
PS: here is the old code(distributions_v1.py):
from random import randint
total_amount_of_cars_that_are_driving_to_work_districts = 26904
total_amount_of_cars_that_are_driving_to_main_districts = 21528
total_amount_of_cars_that_are_driving_to_hotspot_districts = 5376
"----Work districts setup----"
distributed_cars_to_work =
cars_per_hour_to_work_districts =
total_work_districts =
all_working_districts_used =
for amount_of_working_districts in range(0,7):
all_working_districts_used.append(amount_of_working_districts)
for work_districts in all_working_districts_used:
total_work_districts.append(work_districts)
"----Main districts setup----"
distributed_cars_to_main =
cars_per_hour_to_main_districts =
total_main_districts =
all_the_main_districts =
for amount_of_main_districts in range (0,45):
all_the_main_districts.append(amount_of_main_districts)
for main_districts in all_the_main_districts:
total_main_districts.append(main_districts)
"----Hotspot district setup----"
distributed_cars_to_hotspot =
cars_per_hour_to_hotspot_districts =
total_hotspot_districts =
all_the_hotspot_districts =
for amount_of_hotspot_districts in range(0,4):
all_the_hotspot_districts.append(amount_of_hotspot_districts)
for hotspot_districts in all_the_hotspot_districts:
total_hotspot_districts.append(hotspot_districts)
class CarsDistribution:
all_probabilities = {
"work":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.01, 0.05, 0.11, 0.19, 0.23, 0.2, 0.14, 0.05, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
"main":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.02, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.08, 0.08, 0.08, 0.07, 0.06, 0.06, 0.05, 0.04),
"hotspot":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.02, 0.03, 0.04, 0.08, 0.1, 0.12, 0.13, 0.13, 0.11, 0.07, 0.05, 0.04, 0.03, 0.02, 0.01)
}
def __init__(self, type, cars):
total_length = len(cars)
self.cars_per_hour = {}
for hour, p in enumerate(self.all_probabilities[type]):
try:
self.cars_per_hour[hour] = [cars.pop() for i in range(int(p * total_length))]
except IndexError:
print('cars already exhausted at hour {}'.format(hour))
if cars:
print('{} left after distributing is finished'.format(len(cars)))
def distribute_faster(cars, totals):
counts = {total: 0 for total in range(totals)}
while cars > 0:
adjust = cars > 5000 # totally arbitrary
change = 1
if adjust:
change = 5
choice = randint(0, totals - 1)
counts[choice] += change
cars -= change
return counts
random_distribution_to_work = distribute_faster(total_amount_of_cars_that_are_driving_to_work_districts, 8)
print("Amount of cars distributed to work stations: {}".format(random_distribution_to_work))
print(".............................................................................................................")
for key, value in random_distribution_to_work.items():
distributed_cars_to_work.append(value)
(work_districts) = (CarsDistribution('work', [distributed_cars_to_work for x in range(num_cars)]) for num_cars in distributed_cars_to_work)
for randomWork in work_districts:
cars_per_hour_to_work_districts.append([len(c) for c in randomWork.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_work in cars_per_hour_to_work_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)
print("Total amount of car that got distributed to this work station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)))
print("--------------------------------------------------------------------------------------------------")
print("===============================WORK DISTRIBUTION FINISHED=========================================")
random_distribution_to_main = distribute_faster(total_amount_of_cars_that_are_driving_to_main_districts, 46) #46!!
print("Amount of cars distributed to main stations: {}".format(random_distribution_to_main))
print(".............................................................................................................")
for key, value in random_distribution_to_main.items():
distributed_cars_to_main.append(value)
(main_districts) = (CarsDistribution('main', [distributed_cars_to_main for x in range(num_cars)]) for num_cars in
distributed_cars_to_main)
for randomMain in main_districts:
cars_per_hour_to_main_districts.append([len(c) for c in randomMain.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_main in cars_per_hour_to_main_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)
print("Total amount of car that got distributed to this main station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)))
print("--------------------------------------------------------------------------------------------------")
print("===============================MAIN DISTRIBUTION FINISHED=========================================")
random_distribution_to_hotspot = distribute_faster(total_amount_of_cars_that_are_driving_to_hotspot_districts, 5)
print("Amount of cars distributed to hotspot stations: {}".format(random_distribution_to_hotspot))
print(".............................................................................................................")
for key, value in random_distribution_to_hotspot.items():
distributed_cars_to_hotspot.append(value)
(hotspot_districts) = (CarsDistribution('hotspot', [distributed_cars_to_hotspot for x in range(num_cars)]) for num_cars in
distributed_cars_to_hotspot)
for randomHotspot in hotspot_districts:
cars_per_hour_to_hotspot_districts.append([len(c) for c in randomHotspot.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot in cars_per_hour_to_hotspot_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)
print("Total amount of car that got distributed to this hotspot station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)))
print("--------------------------------------------------------------------------------------------------")
print("============================HOTSPOT DISTRIBUTION FINISHED=========================================")
and here is the reformatted code with functions(distributions_v2.py):
from random import randint
total_amount_of_cars_that_are_driving_to_work_districts = 26904
total_amount_of_cars_that_are_driving_to_main_districts = 21528
total_amount_of_cars_that_are_driving_to_hotspot_districts = 5376
"----Work districts setup----"
distributed_cars_to_work =
cars_per_hour_to_work_districts =
total_work_districts =
all_working_districts_used =
for amount_of_working_districts in range(0,7):
all_working_districts_used.append(amount_of_working_districts)
for work_districts in all_working_districts_used:
total_work_districts.append(work_districts)
"----Main districts setup----"
distributed_cars_to_main =
cars_per_hour_to_main_districts =
total_main_districts =
all_the_main_districts =
for amount_of_main_districts in range (0,45):
all_the_main_districts.append(amount_of_main_districts)
for main_districts in all_the_main_districts:
total_main_districts.append(main_districts)
"----Hotspot district setup----"
distributed_cars_to_hotspot =
cars_per_hour_to_hotspot_districts =
total_hotspot_districts =
all_the_hotspot_districts =
for amount_of_hotspot_districts in range(0,4):
all_the_hotspot_districts.append(amount_of_hotspot_districts)
for hotspot_districts in all_the_hotspot_districts:
total_hotspot_districts.append(hotspot_districts)
def distribute_faster(cars, totals):
counts = {total: 0 for total in range(totals)}
while cars > 0:
adjust = cars > 5000 # totally arbitrary
change = 1
if adjust:
change = 5
choice = randint(0, totals - 1)
counts[choice] += change
cars -= change
return counts
class CarsDistribution:
all_probabilities = {
"work":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.01, 0.05, 0.11, 0.19, 0.23, 0.2, 0.14, 0.05, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
"main":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.02, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.08, 0.08, 0.08, 0.07, 0.06, 0.06, 0.05, 0.04),
"hotspot":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.02, 0.03, 0.04, 0.08, 0.1, 0.12, 0.13, 0.13, 0.11, 0.07, 0.05, 0.04, 0.03, 0.02, 0.01)
}
def __init__(self, type, cars):
total_length = len(cars)
self.cars_per_hour = {}
for hour, p in enumerate(self.all_probabilities[type]):
try:
self.cars_per_hour[hour] = [cars.pop() for i in range(int(p * total_length))]
except IndexError:
print('cars already exhausted at hour {}'.format(hour))
if cars:
print('{} left after distributing is finished'.format(len(cars)))
def generate_work_districts_distribution():
random_distribution_to_work = distribute_faster(total_amount_of_cars_that_are_driving_to_work_districts, 8)
print("Amount of cars distributed to work stations: {}".format(random_distribution_to_work))
print(
".............................................................................................................")
for key, value in random_distribution_to_work.items():
distributed_cars_to_work.append(value)
(work_districts) = (CarsDistribution('work', [distributed_cars_to_work for x in range(num_cars)]) for num_cars in
distributed_cars_to_work)
for randomWork in work_districts:
cars_per_hour_to_work_districts.append([len(c) for c in randomWork.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_work in cars_per_hour_to_work_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)
print("Total amount of car that got distributed to this work station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)))
print("--------------------------------------------------------------------------------------------------")
print("===============================WORK DISTRIBUTION FINISHED=========================================")
def generate_distributions_to_main():
random_distribution_to_main = distribute_faster(total_amount_of_cars_that_are_driving_to_main_districts, 46) # 46!!
print("Amount of cars distributed to main stations: {}".format(random_distribution_to_main))
print(
".............................................................................................................")
for key, value in random_distribution_to_main.items():
distributed_cars_to_main.append(value)
(main_districts) = (CarsDistribution('main', [distributed_cars_to_main for x in range(num_cars)]) for num_cars in
distributed_cars_to_main)
for randomMain in main_districts:
cars_per_hour_to_main_districts.append([len(c) for c in randomMain.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_main in cars_per_hour_to_main_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)
print("Total amount of car that got distributed to this main station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)))
print("--------------------------------------------------------------------------------------------------")
print("===============================MAIN DISTRIBUTION FINISHED=========================================")
def generate_hotspot_distributions():
random_distribution_to_hotspot = distribute_faster(total_amount_of_cars_that_are_driving_to_hotspot_districts, 5)
print("Amount of cars distributed to hotspot stations: {}".format(random_distribution_to_hotspot))
print(
".............................................................................................................")
for key, value in random_distribution_to_hotspot.items():
distributed_cars_to_hotspot.append(value)
(hotspot_districts) = (CarsDistribution('hotspot', [distributed_cars_to_hotspot for x in range(num_cars)]) for
num_cars in
distributed_cars_to_hotspot)
for randomHotspot in hotspot_districts:
cars_per_hour_to_hotspot_districts.append([len(c) for c in randomHotspot.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot in cars_per_hour_to_hotspot_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)
print("Total amount of car that got distributed to this hotspot station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)))
print("--------------------------------------------------------------------------------------------------")
print("============================HOTSPOT DISTRIBUTION FINISHED=========================================")
"---Reset the lists after used ---"
distributed_cars_to_work =
cars_per_hour_to_work_districts =
total_work_districts =
all_working_districts_used =
distributed_cars_to_main =
cars_per_hour_to_main_districts =
total_main_districts =
all_the_main_districts =
distributed_cars_to_hotspot =
cars_per_hour_to_hotspot_districts =
total_hotspot_districts =
all_the_hotspot_districts =
Could someone help me please? the new code looks great, but now in the main.py file i get Typerror"int object is not iterable"
If I dont see any solution I may perhaps just move all into main.py, but as I wanna have good structure I want to keep the distributions.py file.
Thank you.
python numpy
first of all, I had an old which worked great as it were, i call this for distributions_v1.py. This file is generating random distributions using probabilities.
What was the problem with this file? The problem was that this was a bad code, and it only generated distributions once! so when I am running simulations in main.py, the simulation
is using the same distributions everyday, instead of computing new ones for each day.
So what did I try to do, Well I tried the reloading module(recalling the file), but that doest not work because of this method:
def distribute_faster(cars, totals):
counts = {total: 0 for total in range(totals)}
while cars > 0:
adjust = cars > 5000 # totally arbitrary
change = 1
if adjust:
change = 5
choice = randint(0, totals - 1)
counts[choice] += change
cars -= change
return counts
So after this didnt work, I tried reformatting the code, this I named for distributions_v2.py. I have added functions etc, but the error I get in the main.py file because of the changes
are: for hotspot in hotspot_districts:
TypeError: 'int' object is not iterable
PS: here is the old code(distributions_v1.py):
from random import randint
total_amount_of_cars_that_are_driving_to_work_districts = 26904
total_amount_of_cars_that_are_driving_to_main_districts = 21528
total_amount_of_cars_that_are_driving_to_hotspot_districts = 5376
"----Work districts setup----"
distributed_cars_to_work =
cars_per_hour_to_work_districts =
total_work_districts =
all_working_districts_used =
for amount_of_working_districts in range(0,7):
all_working_districts_used.append(amount_of_working_districts)
for work_districts in all_working_districts_used:
total_work_districts.append(work_districts)
"----Main districts setup----"
distributed_cars_to_main =
cars_per_hour_to_main_districts =
total_main_districts =
all_the_main_districts =
for amount_of_main_districts in range (0,45):
all_the_main_districts.append(amount_of_main_districts)
for main_districts in all_the_main_districts:
total_main_districts.append(main_districts)
"----Hotspot district setup----"
distributed_cars_to_hotspot =
cars_per_hour_to_hotspot_districts =
total_hotspot_districts =
all_the_hotspot_districts =
for amount_of_hotspot_districts in range(0,4):
all_the_hotspot_districts.append(amount_of_hotspot_districts)
for hotspot_districts in all_the_hotspot_districts:
total_hotspot_districts.append(hotspot_districts)
class CarsDistribution:
all_probabilities = {
"work":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.01, 0.05, 0.11, 0.19, 0.23, 0.2, 0.14, 0.05, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
"main":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.02, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.08, 0.08, 0.08, 0.07, 0.06, 0.06, 0.05, 0.04),
"hotspot":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.02, 0.03, 0.04, 0.08, 0.1, 0.12, 0.13, 0.13, 0.11, 0.07, 0.05, 0.04, 0.03, 0.02, 0.01)
}
def __init__(self, type, cars):
total_length = len(cars)
self.cars_per_hour = {}
for hour, p in enumerate(self.all_probabilities[type]):
try:
self.cars_per_hour[hour] = [cars.pop() for i in range(int(p * total_length))]
except IndexError:
print('cars already exhausted at hour {}'.format(hour))
if cars:
print('{} left after distributing is finished'.format(len(cars)))
def distribute_faster(cars, totals):
counts = {total: 0 for total in range(totals)}
while cars > 0:
adjust = cars > 5000 # totally arbitrary
change = 1
if adjust:
change = 5
choice = randint(0, totals - 1)
counts[choice] += change
cars -= change
return counts
random_distribution_to_work = distribute_faster(total_amount_of_cars_that_are_driving_to_work_districts, 8)
print("Amount of cars distributed to work stations: {}".format(random_distribution_to_work))
print(".............................................................................................................")
for key, value in random_distribution_to_work.items():
distributed_cars_to_work.append(value)
(work_districts) = (CarsDistribution('work', [distributed_cars_to_work for x in range(num_cars)]) for num_cars in distributed_cars_to_work)
for randomWork in work_districts:
cars_per_hour_to_work_districts.append([len(c) for c in randomWork.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_work in cars_per_hour_to_work_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)
print("Total amount of car that got distributed to this work station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)))
print("--------------------------------------------------------------------------------------------------")
print("===============================WORK DISTRIBUTION FINISHED=========================================")
random_distribution_to_main = distribute_faster(total_amount_of_cars_that_are_driving_to_main_districts, 46) #46!!
print("Amount of cars distributed to main stations: {}".format(random_distribution_to_main))
print(".............................................................................................................")
for key, value in random_distribution_to_main.items():
distributed_cars_to_main.append(value)
(main_districts) = (CarsDistribution('main', [distributed_cars_to_main for x in range(num_cars)]) for num_cars in
distributed_cars_to_main)
for randomMain in main_districts:
cars_per_hour_to_main_districts.append([len(c) for c in randomMain.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_main in cars_per_hour_to_main_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)
print("Total amount of car that got distributed to this main station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)))
print("--------------------------------------------------------------------------------------------------")
print("===============================MAIN DISTRIBUTION FINISHED=========================================")
random_distribution_to_hotspot = distribute_faster(total_amount_of_cars_that_are_driving_to_hotspot_districts, 5)
print("Amount of cars distributed to hotspot stations: {}".format(random_distribution_to_hotspot))
print(".............................................................................................................")
for key, value in random_distribution_to_hotspot.items():
distributed_cars_to_hotspot.append(value)
(hotspot_districts) = (CarsDistribution('hotspot', [distributed_cars_to_hotspot for x in range(num_cars)]) for num_cars in
distributed_cars_to_hotspot)
for randomHotspot in hotspot_districts:
cars_per_hour_to_hotspot_districts.append([len(c) for c in randomHotspot.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot in cars_per_hour_to_hotspot_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)
print("Total amount of car that got distributed to this hotspot station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)))
print("--------------------------------------------------------------------------------------------------")
print("============================HOTSPOT DISTRIBUTION FINISHED=========================================")
and here is the reformatted code with functions(distributions_v2.py):
from random import randint
total_amount_of_cars_that_are_driving_to_work_districts = 26904
total_amount_of_cars_that_are_driving_to_main_districts = 21528
total_amount_of_cars_that_are_driving_to_hotspot_districts = 5376
"----Work districts setup----"
distributed_cars_to_work =
cars_per_hour_to_work_districts =
total_work_districts =
all_working_districts_used =
for amount_of_working_districts in range(0,7):
all_working_districts_used.append(amount_of_working_districts)
for work_districts in all_working_districts_used:
total_work_districts.append(work_districts)
"----Main districts setup----"
distributed_cars_to_main =
cars_per_hour_to_main_districts =
total_main_districts =
all_the_main_districts =
for amount_of_main_districts in range (0,45):
all_the_main_districts.append(amount_of_main_districts)
for main_districts in all_the_main_districts:
total_main_districts.append(main_districts)
"----Hotspot district setup----"
distributed_cars_to_hotspot =
cars_per_hour_to_hotspot_districts =
total_hotspot_districts =
all_the_hotspot_districts =
for amount_of_hotspot_districts in range(0,4):
all_the_hotspot_districts.append(amount_of_hotspot_districts)
for hotspot_districts in all_the_hotspot_districts:
total_hotspot_districts.append(hotspot_districts)
def distribute_faster(cars, totals):
counts = {total: 0 for total in range(totals)}
while cars > 0:
adjust = cars > 5000 # totally arbitrary
change = 1
if adjust:
change = 5
choice = randint(0, totals - 1)
counts[choice] += change
cars -= change
return counts
class CarsDistribution:
all_probabilities = {
"work":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.01, 0.05, 0.11, 0.19, 0.23, 0.2, 0.14, 0.05, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0),
"main":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.02, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.08, 0.08, 0.08, 0.07, 0.06, 0.06, 0.05, 0.04),
"hotspot":
#Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.02, 0.03, 0.04, 0.08, 0.1, 0.12, 0.13, 0.13, 0.11, 0.07, 0.05, 0.04, 0.03, 0.02, 0.01)
}
def __init__(self, type, cars):
total_length = len(cars)
self.cars_per_hour = {}
for hour, p in enumerate(self.all_probabilities[type]):
try:
self.cars_per_hour[hour] = [cars.pop() for i in range(int(p * total_length))]
except IndexError:
print('cars already exhausted at hour {}'.format(hour))
if cars:
print('{} left after distributing is finished'.format(len(cars)))
def generate_work_districts_distribution():
random_distribution_to_work = distribute_faster(total_amount_of_cars_that_are_driving_to_work_districts, 8)
print("Amount of cars distributed to work stations: {}".format(random_distribution_to_work))
print(
".............................................................................................................")
for key, value in random_distribution_to_work.items():
distributed_cars_to_work.append(value)
(work_districts) = (CarsDistribution('work', [distributed_cars_to_work for x in range(num_cars)]) for num_cars in
distributed_cars_to_work)
for randomWork in work_districts:
cars_per_hour_to_work_districts.append([len(c) for c in randomWork.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_work in cars_per_hour_to_work_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)
print("Total amount of car that got distributed to this work station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)))
print("--------------------------------------------------------------------------------------------------")
print("===============================WORK DISTRIBUTION FINISHED=========================================")
def generate_distributions_to_main():
random_distribution_to_main = distribute_faster(total_amount_of_cars_that_are_driving_to_main_districts, 46) # 46!!
print("Amount of cars distributed to main stations: {}".format(random_distribution_to_main))
print(
".............................................................................................................")
for key, value in random_distribution_to_main.items():
distributed_cars_to_main.append(value)
(main_districts) = (CarsDistribution('main', [distributed_cars_to_main for x in range(num_cars)]) for num_cars in
distributed_cars_to_main)
for randomMain in main_districts:
cars_per_hour_to_main_districts.append([len(c) for c in randomMain.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_main in cars_per_hour_to_main_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)
print("Total amount of car that got distributed to this main station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)))
print("--------------------------------------------------------------------------------------------------")
print("===============================MAIN DISTRIBUTION FINISHED=========================================")
def generate_hotspot_distributions():
random_distribution_to_hotspot = distribute_faster(total_amount_of_cars_that_are_driving_to_hotspot_districts, 5)
print("Amount of cars distributed to hotspot stations: {}".format(random_distribution_to_hotspot))
print(
".............................................................................................................")
for key, value in random_distribution_to_hotspot.items():
distributed_cars_to_hotspot.append(value)
(hotspot_districts) = (CarsDistribution('hotspot', [distributed_cars_to_hotspot for x in range(num_cars)]) for
num_cars in
distributed_cars_to_hotspot)
for randomHotspot in hotspot_districts:
cars_per_hour_to_hotspot_districts.append([len(c) for c in randomHotspot.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot in cars_per_hour_to_hotspot_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)
print("Total amount of car that got distributed to this hotspot station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)))
print("--------------------------------------------------------------------------------------------------")
print("============================HOTSPOT DISTRIBUTION FINISHED=========================================")
"---Reset the lists after used ---"
distributed_cars_to_work =
cars_per_hour_to_work_districts =
total_work_districts =
all_working_districts_used =
distributed_cars_to_main =
cars_per_hour_to_main_districts =
total_main_districts =
all_the_main_districts =
distributed_cars_to_hotspot =
cars_per_hour_to_hotspot_districts =
total_hotspot_districts =
all_the_hotspot_districts =
Could someone help me please? the new code looks great, but now in the main.py file i get Typerror"int object is not iterable"
If I dont see any solution I may perhaps just move all into main.py, but as I wanna have good structure I want to keep the distributions.py file.
Thank you.
python numpy
python numpy
asked Jan 19 at 13:52
giroud13giroud13
114
114
2
Can you distill this to something less than 8 screens long? See Minimal, Complete, and Verifiable example on creating good examples. Also, please add the full exception traceback. Currently no one can know where in your code that TypeError is happening.
– Norrius
Jan 19 at 14:00
Well, you could still see if the version 2 file is done correctly or not
– giroud13
Jan 19 at 14:18
add a comment |
2
Can you distill this to something less than 8 screens long? See Minimal, Complete, and Verifiable example on creating good examples. Also, please add the full exception traceback. Currently no one can know where in your code that TypeError is happening.
– Norrius
Jan 19 at 14:00
Well, you could still see if the version 2 file is done correctly or not
– giroud13
Jan 19 at 14:18
2
2
Can you distill this to something less than 8 screens long? See Minimal, Complete, and Verifiable example on creating good examples. Also, please add the full exception traceback. Currently no one can know where in your code that TypeError is happening.
– Norrius
Jan 19 at 14:00
Can you distill this to something less than 8 screens long? See Minimal, Complete, and Verifiable example on creating good examples. Also, please add the full exception traceback. Currently no one can know where in your code that TypeError is happening.
– Norrius
Jan 19 at 14:00
Well, you could still see if the version 2 file is done correctly or not
– giroud13
Jan 19 at 14:18
Well, you could still see if the version 2 file is done correctly or not
– giroud13
Jan 19 at 14:18
add a comment |
1 Answer
1
active
oldest
votes
Solved, I have an function that calls all the other functions!
here is my code:
from random import randint
total_amount_of_cars_that_are_driving_to_work_districts = 26904
total_amount_of_cars_that_are_driving_to_main_districts = 21528
total_amount_of_cars_that_are_driving_to_hotspot_districts = 5376
cars_per_hour_to_hotspot_districts = None
cars_per_hour_to_work_districts = None
cars_per_hour_to_main_districts = None
def generate_new_data():
create_days()
generate_work_districts_distribution()
generate_hotspot_distributions()
generate_distributions_to_main()
def distribute_faster(cars, totals):
counts = {total: 0 for total in range(totals)}
while cars > 0:
adjust = cars > 5000 # totally arbitrary
change = 1
if adjust:
change = 5
choice = randint(0, totals - 1)
counts[choice] += change
cars -= change
return counts
def create_days():
"----Work districts setup----"
global distributed_cars_to_work
distributed_cars_to_work =
global cars_per_hour_to_work_districts
cars_per_hour_to_work_districts =
total_work_districts =
all_working_districts_used =
for amount_of_working_districts in range(0, 7):
all_working_districts_used.append(amount_of_working_districts)
for work_districts in all_working_districts_used:
total_work_districts.append(work_districts)
"----Main districts setup----"
global distributed_cars_to_main
distributed_cars_to_main =
global cars_per_hour_to_main_districts
cars_per_hour_to_main_districts =
total_main_districts =
all_the_main_districts =
for amount_of_main_districts in range(0, 45):
all_the_main_districts.append(amount_of_main_districts)
for main_districts in all_the_main_districts:
total_main_districts.append(main_districts)
"----Hotspot district setup----"
global distributed_cars_to_hotspot
distributed_cars_to_hotspot =
global cars_per_hour_to_hotspot_districts
cars_per_hour_to_hotspot_districts =
total_hotspot_districts =
all_the_hotspot_districts =
for amount_of_hotspot_districts in range(0, 4):
all_the_hotspot_districts.append(amount_of_hotspot_districts)
for hotspot_districts in all_the_hotspot_districts:
total_hotspot_districts.append(hotspot_districts)
def generate_work_districts_distribution():
random_distribution_to_work = distribute_faster(total_amount_of_cars_that_are_driving_to_work_districts, 8)
print("Amount of cars distributed to work stations: {}".format(random_distribution_to_work))
print(
".............................................................................................................")
for key, value in random_distribution_to_work.items():
distributed_cars_to_work.append(value)
(work_districts) = (CarsDistribution('work', [distributed_cars_to_work for x in range(num_cars)]) for num_cars in
distributed_cars_to_work)
for randomWork in work_districts:
cars_per_hour_to_work_districts.append([len(c) for c in randomWork.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_work in cars_per_hour_to_work_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)
print("Total amount of car that got distributed to this work station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)))
print("--------------------------------------------------------------------------------------------------")
print("===============================WORK DISTRIBUTION FINISHED=========================================")
def generate_distributions_to_main():
random_distribution_to_main = distribute_faster(total_amount_of_cars_that_are_driving_to_main_districts, 46) # 46!!
print("Amount of cars distributed to main stations: {}".format(random_distribution_to_main))
print(
".............................................................................................................")
for key, value in random_distribution_to_main.items():
distributed_cars_to_main.append(value)
(main_districts) = (CarsDistribution('main', [distributed_cars_to_main for x in range(num_cars)]) for num_cars in
distributed_cars_to_main)
for randomMain in main_districts:
cars_per_hour_to_main_districts.append([len(c) for c in randomMain.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_main in cars_per_hour_to_main_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)
print("Total amount of car that got distributed to this main station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)))
print("--------------------------------------------------------------------------------------------------")
print("===============================MAIN DISTRIBUTION FINISHED=========================================")
def generate_hotspot_distributions():
random_distribution_to_hotspot = distribute_faster(total_amount_of_cars_that_are_driving_to_hotspot_districts, 5)
print("Amount of cars distributed to hotspot stations: {}".format(random_distribution_to_hotspot))
print(
".............................................................................................................")
for key, value in random_distribution_to_hotspot.items():
distributed_cars_to_hotspot.append(value)
(hotspot_districts) = (CarsDistribution('hotspot', [distributed_cars_to_hotspot for x in range(num_cars)]) for
num_cars in distributed_cars_to_hotspot)
for randomHotspot in hotspot_districts:
cars_per_hour_to_hotspot_districts.append([len(c) for c in randomHotspot.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot in cars_per_hour_to_hotspot_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)
print("Total amount of car that got distributed to this hotspot station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)))
print("--------------------------------------------------------------------------------------------------")
print("============================HOTSPOT DISTRIBUTION FINISHED=========================================")
class CarsDistribution:
all_probabilities = {
"work":
# Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.01, 0.05, 0.11, 0.19, 0.23, 0.2, 0.14, 0.05, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0),
"main":
# Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.02, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.08, 0.08,
0.08, 0.07, 0.06, 0.06, 0.05, 0.04),
"hotspot":
# Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.02, 0.03, 0.04, 0.08, 0.1, 0.12, 0.13, 0.13, 0.11,
0.07, 0.05, 0.04, 0.03, 0.02, 0.01)
}
def __init__(self, type, cars):
total_length = len(cars)
self.cars_per_hour = {}
for hour, p in enumerate(self.all_probabilities[type]):
try:
self.cars_per_hour[hour] = [cars.pop() for i in range(int(p * total_length))]
except IndexError:
print('cars already exhausted at hour {}'.format(hour))
if cars:
print('{} left after distributing is finished'.format(len(cars)))
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54267787%2fproblems-in-re-computing-distributions-to-use-in-main-py-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Solved, I have an function that calls all the other functions!
here is my code:
from random import randint
total_amount_of_cars_that_are_driving_to_work_districts = 26904
total_amount_of_cars_that_are_driving_to_main_districts = 21528
total_amount_of_cars_that_are_driving_to_hotspot_districts = 5376
cars_per_hour_to_hotspot_districts = None
cars_per_hour_to_work_districts = None
cars_per_hour_to_main_districts = None
def generate_new_data():
create_days()
generate_work_districts_distribution()
generate_hotspot_distributions()
generate_distributions_to_main()
def distribute_faster(cars, totals):
counts = {total: 0 for total in range(totals)}
while cars > 0:
adjust = cars > 5000 # totally arbitrary
change = 1
if adjust:
change = 5
choice = randint(0, totals - 1)
counts[choice] += change
cars -= change
return counts
def create_days():
"----Work districts setup----"
global distributed_cars_to_work
distributed_cars_to_work =
global cars_per_hour_to_work_districts
cars_per_hour_to_work_districts =
total_work_districts =
all_working_districts_used =
for amount_of_working_districts in range(0, 7):
all_working_districts_used.append(amount_of_working_districts)
for work_districts in all_working_districts_used:
total_work_districts.append(work_districts)
"----Main districts setup----"
global distributed_cars_to_main
distributed_cars_to_main =
global cars_per_hour_to_main_districts
cars_per_hour_to_main_districts =
total_main_districts =
all_the_main_districts =
for amount_of_main_districts in range(0, 45):
all_the_main_districts.append(amount_of_main_districts)
for main_districts in all_the_main_districts:
total_main_districts.append(main_districts)
"----Hotspot district setup----"
global distributed_cars_to_hotspot
distributed_cars_to_hotspot =
global cars_per_hour_to_hotspot_districts
cars_per_hour_to_hotspot_districts =
total_hotspot_districts =
all_the_hotspot_districts =
for amount_of_hotspot_districts in range(0, 4):
all_the_hotspot_districts.append(amount_of_hotspot_districts)
for hotspot_districts in all_the_hotspot_districts:
total_hotspot_districts.append(hotspot_districts)
def generate_work_districts_distribution():
random_distribution_to_work = distribute_faster(total_amount_of_cars_that_are_driving_to_work_districts, 8)
print("Amount of cars distributed to work stations: {}".format(random_distribution_to_work))
print(
".............................................................................................................")
for key, value in random_distribution_to_work.items():
distributed_cars_to_work.append(value)
(work_districts) = (CarsDistribution('work', [distributed_cars_to_work for x in range(num_cars)]) for num_cars in
distributed_cars_to_work)
for randomWork in work_districts:
cars_per_hour_to_work_districts.append([len(c) for c in randomWork.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_work in cars_per_hour_to_work_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)
print("Total amount of car that got distributed to this work station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)))
print("--------------------------------------------------------------------------------------------------")
print("===============================WORK DISTRIBUTION FINISHED=========================================")
def generate_distributions_to_main():
random_distribution_to_main = distribute_faster(total_amount_of_cars_that_are_driving_to_main_districts, 46) # 46!!
print("Amount of cars distributed to main stations: {}".format(random_distribution_to_main))
print(
".............................................................................................................")
for key, value in random_distribution_to_main.items():
distributed_cars_to_main.append(value)
(main_districts) = (CarsDistribution('main', [distributed_cars_to_main for x in range(num_cars)]) for num_cars in
distributed_cars_to_main)
for randomMain in main_districts:
cars_per_hour_to_main_districts.append([len(c) for c in randomMain.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_main in cars_per_hour_to_main_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)
print("Total amount of car that got distributed to this main station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)))
print("--------------------------------------------------------------------------------------------------")
print("===============================MAIN DISTRIBUTION FINISHED=========================================")
def generate_hotspot_distributions():
random_distribution_to_hotspot = distribute_faster(total_amount_of_cars_that_are_driving_to_hotspot_districts, 5)
print("Amount of cars distributed to hotspot stations: {}".format(random_distribution_to_hotspot))
print(
".............................................................................................................")
for key, value in random_distribution_to_hotspot.items():
distributed_cars_to_hotspot.append(value)
(hotspot_districts) = (CarsDistribution('hotspot', [distributed_cars_to_hotspot for x in range(num_cars)]) for
num_cars in distributed_cars_to_hotspot)
for randomHotspot in hotspot_districts:
cars_per_hour_to_hotspot_districts.append([len(c) for c in randomHotspot.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot in cars_per_hour_to_hotspot_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)
print("Total amount of car that got distributed to this hotspot station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)))
print("--------------------------------------------------------------------------------------------------")
print("============================HOTSPOT DISTRIBUTION FINISHED=========================================")
class CarsDistribution:
all_probabilities = {
"work":
# Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.01, 0.05, 0.11, 0.19, 0.23, 0.2, 0.14, 0.05, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0),
"main":
# Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.02, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.08, 0.08,
0.08, 0.07, 0.06, 0.06, 0.05, 0.04),
"hotspot":
# Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.02, 0.03, 0.04, 0.08, 0.1, 0.12, 0.13, 0.13, 0.11,
0.07, 0.05, 0.04, 0.03, 0.02, 0.01)
}
def __init__(self, type, cars):
total_length = len(cars)
self.cars_per_hour = {}
for hour, p in enumerate(self.all_probabilities[type]):
try:
self.cars_per_hour[hour] = [cars.pop() for i in range(int(p * total_length))]
except IndexError:
print('cars already exhausted at hour {}'.format(hour))
if cars:
print('{} left after distributing is finished'.format(len(cars)))
add a comment |
Solved, I have an function that calls all the other functions!
here is my code:
from random import randint
total_amount_of_cars_that_are_driving_to_work_districts = 26904
total_amount_of_cars_that_are_driving_to_main_districts = 21528
total_amount_of_cars_that_are_driving_to_hotspot_districts = 5376
cars_per_hour_to_hotspot_districts = None
cars_per_hour_to_work_districts = None
cars_per_hour_to_main_districts = None
def generate_new_data():
create_days()
generate_work_districts_distribution()
generate_hotspot_distributions()
generate_distributions_to_main()
def distribute_faster(cars, totals):
counts = {total: 0 for total in range(totals)}
while cars > 0:
adjust = cars > 5000 # totally arbitrary
change = 1
if adjust:
change = 5
choice = randint(0, totals - 1)
counts[choice] += change
cars -= change
return counts
def create_days():
"----Work districts setup----"
global distributed_cars_to_work
distributed_cars_to_work =
global cars_per_hour_to_work_districts
cars_per_hour_to_work_districts =
total_work_districts =
all_working_districts_used =
for amount_of_working_districts in range(0, 7):
all_working_districts_used.append(amount_of_working_districts)
for work_districts in all_working_districts_used:
total_work_districts.append(work_districts)
"----Main districts setup----"
global distributed_cars_to_main
distributed_cars_to_main =
global cars_per_hour_to_main_districts
cars_per_hour_to_main_districts =
total_main_districts =
all_the_main_districts =
for amount_of_main_districts in range(0, 45):
all_the_main_districts.append(amount_of_main_districts)
for main_districts in all_the_main_districts:
total_main_districts.append(main_districts)
"----Hotspot district setup----"
global distributed_cars_to_hotspot
distributed_cars_to_hotspot =
global cars_per_hour_to_hotspot_districts
cars_per_hour_to_hotspot_districts =
total_hotspot_districts =
all_the_hotspot_districts =
for amount_of_hotspot_districts in range(0, 4):
all_the_hotspot_districts.append(amount_of_hotspot_districts)
for hotspot_districts in all_the_hotspot_districts:
total_hotspot_districts.append(hotspot_districts)
def generate_work_districts_distribution():
random_distribution_to_work = distribute_faster(total_amount_of_cars_that_are_driving_to_work_districts, 8)
print("Amount of cars distributed to work stations: {}".format(random_distribution_to_work))
print(
".............................................................................................................")
for key, value in random_distribution_to_work.items():
distributed_cars_to_work.append(value)
(work_districts) = (CarsDistribution('work', [distributed_cars_to_work for x in range(num_cars)]) for num_cars in
distributed_cars_to_work)
for randomWork in work_districts:
cars_per_hour_to_work_districts.append([len(c) for c in randomWork.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_work in cars_per_hour_to_work_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)
print("Total amount of car that got distributed to this work station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)))
print("--------------------------------------------------------------------------------------------------")
print("===============================WORK DISTRIBUTION FINISHED=========================================")
def generate_distributions_to_main():
random_distribution_to_main = distribute_faster(total_amount_of_cars_that_are_driving_to_main_districts, 46) # 46!!
print("Amount of cars distributed to main stations: {}".format(random_distribution_to_main))
print(
".............................................................................................................")
for key, value in random_distribution_to_main.items():
distributed_cars_to_main.append(value)
(main_districts) = (CarsDistribution('main', [distributed_cars_to_main for x in range(num_cars)]) for num_cars in
distributed_cars_to_main)
for randomMain in main_districts:
cars_per_hour_to_main_districts.append([len(c) for c in randomMain.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_main in cars_per_hour_to_main_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)
print("Total amount of car that got distributed to this main station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)))
print("--------------------------------------------------------------------------------------------------")
print("===============================MAIN DISTRIBUTION FINISHED=========================================")
def generate_hotspot_distributions():
random_distribution_to_hotspot = distribute_faster(total_amount_of_cars_that_are_driving_to_hotspot_districts, 5)
print("Amount of cars distributed to hotspot stations: {}".format(random_distribution_to_hotspot))
print(
".............................................................................................................")
for key, value in random_distribution_to_hotspot.items():
distributed_cars_to_hotspot.append(value)
(hotspot_districts) = (CarsDistribution('hotspot', [distributed_cars_to_hotspot for x in range(num_cars)]) for
num_cars in distributed_cars_to_hotspot)
for randomHotspot in hotspot_districts:
cars_per_hour_to_hotspot_districts.append([len(c) for c in randomHotspot.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot in cars_per_hour_to_hotspot_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)
print("Total amount of car that got distributed to this hotspot station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)))
print("--------------------------------------------------------------------------------------------------")
print("============================HOTSPOT DISTRIBUTION FINISHED=========================================")
class CarsDistribution:
all_probabilities = {
"work":
# Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.01, 0.05, 0.11, 0.19, 0.23, 0.2, 0.14, 0.05, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0),
"main":
# Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.02, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.08, 0.08,
0.08, 0.07, 0.06, 0.06, 0.05, 0.04),
"hotspot":
# Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.02, 0.03, 0.04, 0.08, 0.1, 0.12, 0.13, 0.13, 0.11,
0.07, 0.05, 0.04, 0.03, 0.02, 0.01)
}
def __init__(self, type, cars):
total_length = len(cars)
self.cars_per_hour = {}
for hour, p in enumerate(self.all_probabilities[type]):
try:
self.cars_per_hour[hour] = [cars.pop() for i in range(int(p * total_length))]
except IndexError:
print('cars already exhausted at hour {}'.format(hour))
if cars:
print('{} left after distributing is finished'.format(len(cars)))
add a comment |
Solved, I have an function that calls all the other functions!
here is my code:
from random import randint
total_amount_of_cars_that_are_driving_to_work_districts = 26904
total_amount_of_cars_that_are_driving_to_main_districts = 21528
total_amount_of_cars_that_are_driving_to_hotspot_districts = 5376
cars_per_hour_to_hotspot_districts = None
cars_per_hour_to_work_districts = None
cars_per_hour_to_main_districts = None
def generate_new_data():
create_days()
generate_work_districts_distribution()
generate_hotspot_distributions()
generate_distributions_to_main()
def distribute_faster(cars, totals):
counts = {total: 0 for total in range(totals)}
while cars > 0:
adjust = cars > 5000 # totally arbitrary
change = 1
if adjust:
change = 5
choice = randint(0, totals - 1)
counts[choice] += change
cars -= change
return counts
def create_days():
"----Work districts setup----"
global distributed_cars_to_work
distributed_cars_to_work =
global cars_per_hour_to_work_districts
cars_per_hour_to_work_districts =
total_work_districts =
all_working_districts_used =
for amount_of_working_districts in range(0, 7):
all_working_districts_used.append(amount_of_working_districts)
for work_districts in all_working_districts_used:
total_work_districts.append(work_districts)
"----Main districts setup----"
global distributed_cars_to_main
distributed_cars_to_main =
global cars_per_hour_to_main_districts
cars_per_hour_to_main_districts =
total_main_districts =
all_the_main_districts =
for amount_of_main_districts in range(0, 45):
all_the_main_districts.append(amount_of_main_districts)
for main_districts in all_the_main_districts:
total_main_districts.append(main_districts)
"----Hotspot district setup----"
global distributed_cars_to_hotspot
distributed_cars_to_hotspot =
global cars_per_hour_to_hotspot_districts
cars_per_hour_to_hotspot_districts =
total_hotspot_districts =
all_the_hotspot_districts =
for amount_of_hotspot_districts in range(0, 4):
all_the_hotspot_districts.append(amount_of_hotspot_districts)
for hotspot_districts in all_the_hotspot_districts:
total_hotspot_districts.append(hotspot_districts)
def generate_work_districts_distribution():
random_distribution_to_work = distribute_faster(total_amount_of_cars_that_are_driving_to_work_districts, 8)
print("Amount of cars distributed to work stations: {}".format(random_distribution_to_work))
print(
".............................................................................................................")
for key, value in random_distribution_to_work.items():
distributed_cars_to_work.append(value)
(work_districts) = (CarsDistribution('work', [distributed_cars_to_work for x in range(num_cars)]) for num_cars in
distributed_cars_to_work)
for randomWork in work_districts:
cars_per_hour_to_work_districts.append([len(c) for c in randomWork.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_work in cars_per_hour_to_work_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)
print("Total amount of car that got distributed to this work station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)))
print("--------------------------------------------------------------------------------------------------")
print("===============================WORK DISTRIBUTION FINISHED=========================================")
def generate_distributions_to_main():
random_distribution_to_main = distribute_faster(total_amount_of_cars_that_are_driving_to_main_districts, 46) # 46!!
print("Amount of cars distributed to main stations: {}".format(random_distribution_to_main))
print(
".............................................................................................................")
for key, value in random_distribution_to_main.items():
distributed_cars_to_main.append(value)
(main_districts) = (CarsDistribution('main', [distributed_cars_to_main for x in range(num_cars)]) for num_cars in
distributed_cars_to_main)
for randomMain in main_districts:
cars_per_hour_to_main_districts.append([len(c) for c in randomMain.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_main in cars_per_hour_to_main_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)
print("Total amount of car that got distributed to this main station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)))
print("--------------------------------------------------------------------------------------------------")
print("===============================MAIN DISTRIBUTION FINISHED=========================================")
def generate_hotspot_distributions():
random_distribution_to_hotspot = distribute_faster(total_amount_of_cars_that_are_driving_to_hotspot_districts, 5)
print("Amount of cars distributed to hotspot stations: {}".format(random_distribution_to_hotspot))
print(
".............................................................................................................")
for key, value in random_distribution_to_hotspot.items():
distributed_cars_to_hotspot.append(value)
(hotspot_districts) = (CarsDistribution('hotspot', [distributed_cars_to_hotspot for x in range(num_cars)]) for
num_cars in distributed_cars_to_hotspot)
for randomHotspot in hotspot_districts:
cars_per_hour_to_hotspot_districts.append([len(c) for c in randomHotspot.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot in cars_per_hour_to_hotspot_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)
print("Total amount of car that got distributed to this hotspot station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)))
print("--------------------------------------------------------------------------------------------------")
print("============================HOTSPOT DISTRIBUTION FINISHED=========================================")
class CarsDistribution:
all_probabilities = {
"work":
# Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.01, 0.05, 0.11, 0.19, 0.23, 0.2, 0.14, 0.05, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0),
"main":
# Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.02, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.08, 0.08,
0.08, 0.07, 0.06, 0.06, 0.05, 0.04),
"hotspot":
# Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.02, 0.03, 0.04, 0.08, 0.1, 0.12, 0.13, 0.13, 0.11,
0.07, 0.05, 0.04, 0.03, 0.02, 0.01)
}
def __init__(self, type, cars):
total_length = len(cars)
self.cars_per_hour = {}
for hour, p in enumerate(self.all_probabilities[type]):
try:
self.cars_per_hour[hour] = [cars.pop() for i in range(int(p * total_length))]
except IndexError:
print('cars already exhausted at hour {}'.format(hour))
if cars:
print('{} left after distributing is finished'.format(len(cars)))
Solved, I have an function that calls all the other functions!
here is my code:
from random import randint
total_amount_of_cars_that_are_driving_to_work_districts = 26904
total_amount_of_cars_that_are_driving_to_main_districts = 21528
total_amount_of_cars_that_are_driving_to_hotspot_districts = 5376
cars_per_hour_to_hotspot_districts = None
cars_per_hour_to_work_districts = None
cars_per_hour_to_main_districts = None
def generate_new_data():
create_days()
generate_work_districts_distribution()
generate_hotspot_distributions()
generate_distributions_to_main()
def distribute_faster(cars, totals):
counts = {total: 0 for total in range(totals)}
while cars > 0:
adjust = cars > 5000 # totally arbitrary
change = 1
if adjust:
change = 5
choice = randint(0, totals - 1)
counts[choice] += change
cars -= change
return counts
def create_days():
"----Work districts setup----"
global distributed_cars_to_work
distributed_cars_to_work =
global cars_per_hour_to_work_districts
cars_per_hour_to_work_districts =
total_work_districts =
all_working_districts_used =
for amount_of_working_districts in range(0, 7):
all_working_districts_used.append(amount_of_working_districts)
for work_districts in all_working_districts_used:
total_work_districts.append(work_districts)
"----Main districts setup----"
global distributed_cars_to_main
distributed_cars_to_main =
global cars_per_hour_to_main_districts
cars_per_hour_to_main_districts =
total_main_districts =
all_the_main_districts =
for amount_of_main_districts in range(0, 45):
all_the_main_districts.append(amount_of_main_districts)
for main_districts in all_the_main_districts:
total_main_districts.append(main_districts)
"----Hotspot district setup----"
global distributed_cars_to_hotspot
distributed_cars_to_hotspot =
global cars_per_hour_to_hotspot_districts
cars_per_hour_to_hotspot_districts =
total_hotspot_districts =
all_the_hotspot_districts =
for amount_of_hotspot_districts in range(0, 4):
all_the_hotspot_districts.append(amount_of_hotspot_districts)
for hotspot_districts in all_the_hotspot_districts:
total_hotspot_districts.append(hotspot_districts)
def generate_work_districts_distribution():
random_distribution_to_work = distribute_faster(total_amount_of_cars_that_are_driving_to_work_districts, 8)
print("Amount of cars distributed to work stations: {}".format(random_distribution_to_work))
print(
".............................................................................................................")
for key, value in random_distribution_to_work.items():
distributed_cars_to_work.append(value)
(work_districts) = (CarsDistribution('work', [distributed_cars_to_work for x in range(num_cars)]) for num_cars in
distributed_cars_to_work)
for randomWork in work_districts:
cars_per_hour_to_work_districts.append([len(c) for c in randomWork.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_work in cars_per_hour_to_work_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)
print("Total amount of car that got distributed to this work station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_work)))
print("--------------------------------------------------------------------------------------------------")
print("===============================WORK DISTRIBUTION FINISHED=========================================")
def generate_distributions_to_main():
random_distribution_to_main = distribute_faster(total_amount_of_cars_that_are_driving_to_main_districts, 46) # 46!!
print("Amount of cars distributed to main stations: {}".format(random_distribution_to_main))
print(
".............................................................................................................")
for key, value in random_distribution_to_main.items():
distributed_cars_to_main.append(value)
(main_districts) = (CarsDistribution('main', [distributed_cars_to_main for x in range(num_cars)]) for num_cars in
distributed_cars_to_main)
for randomMain in main_districts:
cars_per_hour_to_main_districts.append([len(c) for c in randomMain.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_main in cars_per_hour_to_main_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)
print("Total amount of car that got distributed to this main station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_main)))
print("--------------------------------------------------------------------------------------------------")
print("===============================MAIN DISTRIBUTION FINISHED=========================================")
def generate_hotspot_distributions():
random_distribution_to_hotspot = distribute_faster(total_amount_of_cars_that_are_driving_to_hotspot_districts, 5)
print("Amount of cars distributed to hotspot stations: {}".format(random_distribution_to_hotspot))
print(
".............................................................................................................")
for key, value in random_distribution_to_hotspot.items():
distributed_cars_to_hotspot.append(value)
(hotspot_districts) = (CarsDistribution('hotspot', [distributed_cars_to_hotspot for x in range(num_cars)]) for
num_cars in distributed_cars_to_hotspot)
for randomHotspot in hotspot_districts:
cars_per_hour_to_hotspot_districts.append([len(c) for c in randomHotspot.cars_per_hour.values()])
for if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot in cars_per_hour_to_hotspot_districts:
print(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)
print("Total amount of car that got distributed to this hotspot station: {}".format(
sum(if_i_want_to_see_cars_per_hour_in_24_hours_to_hotspot)))
print("--------------------------------------------------------------------------------------------------")
print("============================HOTSPOT DISTRIBUTION FINISHED=========================================")
class CarsDistribution:
all_probabilities = {
"work":
# Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.01, 0.05, 0.11, 0.19, 0.23, 0.2, 0.14, 0.05, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
0.0, 0.0, 0.0, 0.0, 0.0),
"main":
# Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.01, 0.02, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.08, 0.08,
0.08, 0.07, 0.06, 0.06, 0.05, 0.04),
"hotspot":
# Hour:0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01, 0.02, 0.03, 0.04, 0.08, 0.1, 0.12, 0.13, 0.13, 0.11,
0.07, 0.05, 0.04, 0.03, 0.02, 0.01)
}
def __init__(self, type, cars):
total_length = len(cars)
self.cars_per_hour = {}
for hour, p in enumerate(self.all_probabilities[type]):
try:
self.cars_per_hour[hour] = [cars.pop() for i in range(int(p * total_length))]
except IndexError:
print('cars already exhausted at hour {}'.format(hour))
if cars:
print('{} left after distributing is finished'.format(len(cars)))
answered Jan 19 at 16:01
giroud13giroud13
114
114
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54267787%2fproblems-in-re-computing-distributions-to-use-in-main-py-file%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Can you distill this to something less than 8 screens long? See Minimal, Complete, and Verifiable example on creating good examples. Also, please add the full exception traceback. Currently no one can know where in your code that TypeError is happening.
– Norrius
Jan 19 at 14:00
Well, you could still see if the version 2 file is done correctly or not
– giroud13
Jan 19 at 14:18