pedrolbacelar / Digital_Twin

6 stars 0 forks source link

[Synchronization] Fix with replicated digital db #259

Closed pedrolbacelar closed 1 year ago

pedrolbacelar commented 1 year ago

Fix Sync:

# --- For Local Test
        if copied_realDB == True:
            #--- Update the timestamp ---

            #--- before copying, we delete the previous one
            try:
                os.remove(self.real_database_path)
            except FileNotFoundError:
                self.helper.printer(f"[WARNING][Digital_Twin.py/init()] The file '{self.real_database_path}' does not exist")
                print(f"copying file {self.database_path} in the path {self.real_database_path}")

            #--- Copy the whole database
            try:
                shutil.copy2(self.database_path, self.real_database_path)
            except FileNotFoundError:
                self.helper.printer(f"[ERROR][Digital_Twin.py/__init__()] It was not possible to find the digital database in the path '{self.database_path}'. Make sure that you runned the a simulation before trying to copy it (mydt.run_digital_model() or if are working directly with the digital_model object: digital_model.run())", 'red')
                self.helper.kill()

            #--- Create a temporary real db object for initial fix
            self.temporary_real_database = Database(database_path= self.real_database_path, event_table= 'real_log', copied_realDB= copied_realDB)

            #--- Copy the column timestamp into timestamp_real and clean the previous one
            #self.temporary_real_database.copy_timestamp_to_timestamp_real()

            #--- Update the timestamp according to the current real time
            #self.temporary_real_database.update_real_time_now()
pedrolbacelar commented 1 year ago

we don-t do this more when initiating the DT just when you specify in the Syn run.

pedrolbacelar commented 1 year ago

This was also with a bug in the alternating allocation

#---------------- Reset the counter if it's at maximum ----------------
                        if self.allocation_counter >= (len(self.queue_out)):
                            self.allocation_counter = 0 # minus 1 because we're going to increase 1 anyways
                        #-----------------------------------------------------------------------

Now we don-t subtract one because we put the increase of the counter

pedrolbacelar commented 1 year ago

Always check the allocation of the machine 2

image