Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
flux management
#1
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)
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
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.
Reply
#4
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...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  code management trix 3 648 Oct-23-2023, 05:29 PM
Last Post: buran
  Keep getting Session management error when running imshow in pycharm pace 0 2,113 Mar-25-2021, 10:06 AM
Last Post: pace
  Can Python Do This? Asset Management mbaker_wv 4 2,251 Oct-28-2020, 01:37 PM
Last Post: mbaker_wv
  User management library? MuntyScruntfundle 0 1,479 Jan-14-2020, 02:01 PM
Last Post: MuntyScruntfundle
  Too big CSV file management CaptainCsaba 3 2,220 Sep-10-2019, 05:52 AM
Last Post: CaptainCsaba

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020