def handle(self, *args, **options): project_stubs = ProjectStub.objects.filter(active=True) for ps in project_stubs: try: u = ProjectUtilization.objects.get(name=ps.name) updated_util = calculate_utilization_for_project(ps) u.su = updated_util["su"] u.active_users = updated_util["active_users"] except ProjectUtilization.DoesNotExist: u = ProjectUtilization(**calculate_utilization_for_project(ps)) u.save() self.stdout.write("Successfully updated project utilization values.")
def handle(self, *args, **options): project_stubs = ProjectStub.objects.filter(active=True) curr_date = datetime.datetime.now().strftime('%s') # Prevent db cursor timeout stubs = [ps.name for ps in project_stubs] for s in stubs: ps = ProjectStub.objects.get(name=s) util_per_month = [] i = 0 while True: i += 1 d = add_months(ps.start_date,i) slice_date = d.strftime('%s') if slice_date < curr_date: mutil = calculate_utilization_for_project(ps,end_date=slice_date) del mutil['name'] mutil['date'] = d util_per_month.append(mutil) else: mutil = calculate_utilization_for_project(ps) del mutil['name'] mutil['date'] = d util_per_month.append(mutil) break try: u = MonthlyUtilization.objects.get(name=ps.name) u.utilizations_to_date = util_per_month except MonthlyUtilization.DoesNotExist: u = MonthlyUtilization( name=ps.name, utilizations_to_date=util_per_month ) u.save() self.stdout.write('Successfully updated monthly project utilization values.')