I'm coming from Java so I am used to performing calculations I require in separate functions. I would like to know if the below code makes sense in my Django model especially the loop and calling functions from within functions.
The aim of this is to create a backend for multiple Litecoin miners (L3's). Every miner will contribute to the same pool but be plugged in at different times. Therefore each will get its own time stamp. Each month I will pull the total pool amount (pulled from api) and use the total amount of hours contributed to the pool to calculate the litecoins-to-hour ratio. This ratio I can then multiply to each miners' hours worked for the month to determine that particular miners Litecoin earned.
class L3(models.Model): user = models.ForeignKey(User, related_name="L3") MachineID = models.CharField(max_length=256) TimeOnline = models.DateTimeField() Commission = models.IntegerField(default='10') TimeOffline = models.IntegerField(default='0') def indivMachineHoursWorked(self): this_month = datetime.now().month if self.TimeOnline == this_month: x = datetime.now() - self.TimeOnline else: x = datetime.now() - datetime.today().replace(day=1) #need to update hour to 0 too i.e. start of month return x def totalMachineHoursWorked(self): L3_total = L3.objects.all() hrs=0 for l3 in L3_total: hrs =+ l3.indivMachineHoursWorked() return hrs def btcToHour(self): main_api = 'https://api.nicehash.com/api?method=balance&id=123456&key=01234567-abcd-dcba-abcd-0123456789abc' url = main_api json_data = requests.get(url).json() print(json_data) balance1 = json_data['result']['balance_confirmed'] print(balance1) btc2hour = balance1/self.totalMachineHoursWorked() return btc2hour def indivMachineTurnover(self): return self.indivMachineHoursWorked()*self.btcToHour() def __str__(self): return self.user.get_full_name()