Sep-09-2018, 08:46 AM
(This post was last modified: Sep-09-2018, 08:47 AM by chris_thibault.)
Hi everyone,
I would like to fill surface A and surface B (A = Entrepot(15)
B = Entrepot(100) 15 and 100 are available surfaces) with some squares which have attributs : id, surface, date_arrival, date_departure.
I get a csv like that (each row is a square):
id,surface,date_arr,date_depart
0,11,01/01/2018,02/11/2020
1,1.6,02/02/2018,06/06/2018
2,5,03/02/2018,10/10/2019
etc...
I'm starting to fill surface A with squares and when surface A is at 100%, I'll fill the surface B.
I put a square at a certain date(date_arrival) and I remove this square at date_Departure. I have to check that (and update the surface of A or B) before putting a new square.
At the end, I will get the available surface of A and B.
Here is my code :
I would like to fill surface A and surface B (A = Entrepot(15)
B = Entrepot(100) 15 and 100 are available surfaces) with some squares which have attributs : id, surface, date_arrival, date_departure.
I get a csv like that (each row is a square):
id,surface,date_arr,date_depart
0,11,01/01/2018,02/11/2020
1,1.6,02/02/2018,06/06/2018
2,5,03/02/2018,10/10/2019
etc...
I'm starting to fill surface A with squares and when surface A is at 100%, I'll fill the surface B.
I put a square at a certain date(date_arrival) and I remove this square at date_Departure. I have to check that (and update the surface of A or B) before putting a new square.
At the end, I will get the available surface of A and B.
Here is my code :
class Square(object): global df def __init__(self, id): self.surface = df['surface'][id] self.date_arr = df['date_arrive'][id] self.date_dep = df['date_depart'][id] class Entrepot(object): def __init__(self, surface_tot): self.surface_tot = surface_tot def maj_surface(self, surface): self.surface_tot -= surface return self.surface_tot def depart_square(self, surface): self.surface_tot += surface
A = Entrepot(15) B = Entrepot(100)
def remplissage(): # on commence par remplir A - si A est plein on remplit B global df for i in range(0, len(df['id'])): if A.surface_tot >= 0: A.maj_surface(Square(i).surface) for j in range(0, len(df['id'])): if Square(j).date_dep <= Square(i).date_arr and i > j: A.depart_square(Square(j).surface) df.drop(df.index[j]) else: B.maj_surface(Square(i).surface) for j in range(0, len(df['id'])): if Square(j).date_dep <= Square(i).date_arr and i > j: B.depart_square(Square(j).surface) df.drop(df.index[j])
remplissage() print(A.surface_tot) print(B.surface_tot)