<commit_before>from VIPSystem.models import VIP, VIPPackage
from datetime import datetime, timedelta
from django.utils import timezone

def changePackage(vip):
	#No need to flush
	vip.headPackage.days = 0
	vip.headPackage.save()
	if vip.headPackage.nextPackage:
		vip.headPackage.nextPackage.start_date = timezone.now()
		vip.headPackage.nextPackage.save()
	vip.headPackage = vip.headPackage.nextPackage
	vip.save()
	return vip

def flushVip(vip):
	if vip:
		total_timedelta = timezone.now() - vip.headPackage.start_date
		difference = total_timedelta - timedelta(vip.headPackage.days)
		while difference >= timedelta(0):
			total_timedelta = difference
			vip = changePackage(vip)	
			difference = total_timedelta - timedelta(vip.headPackage.days)
		vip.headPackage.days = vip.headPackage.days - total_timedelta.days
		vip.headPackage.save()
		return vip
	else:
		return vip

def addNewHeadPackage(vip, newPackage):
	vip = flushVip(vip)
	vip.headPackage.days = vip.headPackage.days - (timezone.now() - vip.headPackage.start_date)
	vip.headPackage.save()
	newPackage.nextPackage = vip.headPackage
	newPackage.start_date = timezone.now()
	newPackage.save()
	vip.headPackage = newPackage
	vip.save()
	return vip

def addNewPackage(month, typeid, vip=None, user=None):
	vip = flushVip(vip)
	if vip:
		currentPackage = vip.headPackage
		if currentPackage.level == typeid:
			currentPackage.days = currentPackage.days + month*31
			currentPackage.save()<commit_msg>small issue fixed<commit_after>from VIPSystem.models import VIP, VIPPackage
from datetime import datetime, timedelta
from django.utils import timezone

def changePackage(vip):
	#No need to flush
	vip.headPackage.days = 0
	vip.headPackage.save()
	if vip.headPackage.nextPackage:
		vip.headPackage.nextPackage.start_date = timezone.now()
		vip.headPackage.nextPackage.save()
	vip.headPackage = vip.headPackage.nextPackage
	vip.save()
	return vip

def flushVip(vip):
	if vip:
		total_timedelta = timezone.now() - vip.headPackage.start_date
		difference = total_timedelta - timedelta(vip.headPackage.days)
		while difference >= timedelta(0):
			total_timedelta = difference
			vip = changePackage(vip)	
			difference = total_timedelta - timedelta(vip.headPackage.days)
		vip.headPackage.days = vip.headPackage.days - total_timedelta.days
		vip.headPackage.save()
		return vip
	else:
		return vip

def addNewHeadPackage(vip, newPackage):
	vip = flushVip(vip)
	vip.headPackage.days = vip.headPackage.days - (timezone.now() - vip.headPackage.start_date).days
	vip.headPackage.save()
	newPackage.nextPackage = vip.headPackage
	newPackage.start_date = timezone.now()
	newPackage.save()
	vip.headPackage = newPackage
	vip.save()
	return vip

def addNewPackage(month, typeid, vip=None, user=None):
	vip = flushVip(vip)
	if vip:
		currentPackage = vip.headPackage
		if currentPackage.level == typeid:
			currentPackage.days = currentPackage.days + month*31
			currentPackage.save()
{'fraction_non_alphanumeric': 0.10344827586206896, 'fraction_numerical': 0.0027313076135199728, 'mean_word_length': 4.883534136546185, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4798103', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1031, 'n_words': 201}