Python Forum

Full Version: flux management
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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 :



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)
First, I would say don't use global. Pass df as a parameter to remplissage and Square.__init__. Beyond that, I'm not sure what your question is.
Thx for the global variable. The goal is : find the values of available surface of A and B (surface_tot) when all the things have been put.
Or the available surface for each date. Do you think that use of classes/objects is the easiest way to do that or no ? Because in the future I have to add a lot of surfaces and constraints...