Assigning Values of Objects by iterating through a list only returns last value

Viewed 25

Here I have a ClientCallback class:

class ClientCallback:
    def __init__(self, client_id, preconditioning, referenceYear, yearDay, hour, minute, totalEnergy, Coolingcoil1,airTemperature):
        self.client_id = client_id
        self.preconditioning = preconditioning
        self.referenceYear = referenceYear
        self.yearDay = yearDay
        self.hour = hour
        self.minute = minute
        self.totalEnergy = totalEnergy
        self.Coolingcoil1 = Coolingcoil1
        self.airTemperature = airTemperature

Now I want to assign value to the Coolingcoil1 by looping through a list, which is in factor_new

def __call__(self):
    if self.client_id == 1027:
       for index, row in factor_new.iterrows():
            self.Coolingcoil1.value = row['Coolingcoil1']
    print(f"Client ID {self.client_id} , {self.date_time} ,Coolingcoil1 {self.Coolingcoil1.value}, total Energy {self.totalEnergy.value} , airTemperature{self.airTemperature.value}")

    

But the client 1028 only grabs the last loop list value(0.3375433382862803) instead of looping values in the factor_new when calling the ClientCallback

sub_clients: list = []

    for client_num, client in enumerate(clients):
        client_id = ports[client_num]
        callback = ClientCallback(
            client_id, preconditioning, referenceYear, yearDay, hour, minute, totalEnergy, Coolingcoil1, airTemperature)

        sub_clients.append((client, callback))

For example:

Client ID 1028 , 2020-02-01 23:15:00 ,Coolingcoil1 0.3375433382862803, total Energy 25746.003173828125 , airTemperature24.1041259765625

Client ID 1028 , 2020-02-01 23:45:00 ,Coolingcoil1 0.3375433382862803, total Energy 29757.621948242188 , airTemperature24.791654586791992

I'm quite new to python, is there anywhere needs to be modified? Thanks a lot.

0 Answers
Related