def _cal_education(self, oldUserProfile): if self.education != -1 and (not self.educationSchool in [ None, u'' ]) and (self.education != oldUserProfile.education or self.educationSchool != oldUserProfile.educationSchool or self.educationSchool_2 != oldUserProfile.educationSchool_2): from apps.recommend_app.recommend_util import cal_education if self.educationSchool_2 == None: educationscore = cal_education(self.education, self.educationSchool, self.gender, 1) else: SchoolScore1 = cal_education(self.education, self.educationSchool, self.gender, 1) SchoolScore2 = 0 if self.educationSchool_2 != None and self.educationSchool_2.rstrip( ) != u'': SchoolScore2 = cal_education(self.education, self.educationSchool_2, self.gender, 2) if SchoolScore1 > SchoolScore2: educationscore = SchoolScore1 else: educationscore = SchoolScore2 # educationscore=cal_education(self.education,self.educationSchool) if Grade.objects.filter(user=self.user).exists(): Grade.objects.filter(user=self.user).update( educationscore=educationscore) else: Grade(user=self.user, educationscore=educationscore).save()
def _cal_income(self, oldUserProfile): if self.income != None and self.income != oldUserProfile.income: from apps.recommend_app.recommend_util import cal_income incomes = cal_income(self.income, self.gender) if Grade.objects.filter(user=self.user).exists(): Grade.objects.filter(user=self.user).update( incomescore=incomes) else: Grade(user=self.user, incomescore=incomes).save()
def time_task(): userProfileList = UserProfile.objects.all() for user in userProfileList: incomes = cal_income(user.income) from apps.recommend_app.models import Grade if Grade.objects.filter(user_id=user.user.id).exists(): Grade.objects.filter(user_id=user.user.id).update( incomescore=incomes) else: Grade(user_id=user.user.id, incomescore=incomes).save()
def cal_weight(self, userId): ''' 计算权重的值 ''' if Grade.objects.filter(user_id=userId).exists(): grade = Grade.objects.get(user_id=userId) else: grade = Grade(user_id=userId) fieldList = [ 'heightweight', 'incomeweight', 'educationweight', 'characterweight' ] sum, avg = 0, 0 for field in fieldList: sum += self.cleaned_data[field] avg = 1.00 / sum for field in fieldList: setattr(grade, field, avg * self.cleaned_data[field]) grade.appearanceweight = 0 return grade
def init_table_in_register(user_id, username, user_code): #认证表 verification = Verification() verification.username = username verification.verification_code = user_code verification.save() #创建用户验证信息 userVerification = UserVerification() userVerification.user_id = user_id userVerification.save() #用户积分表 from apps.user_score_app.models import UserScore UserScore(user_id=user_id).save() #拼爱币表 from apps.pay_app.models import Charge Charge(user_id=user_id).save() #分数表 from apps.recommend_app.models import Grade Grade(user_id=user_id).save()
def handle(self, *args, **options): #生成测试数据 school = School.objects.all() for i in range(1, 2): if i > 0: user = User(username='******' % ('jin', i), password='******' % ('jin', i)) user.save() userProfile = UserProfile( user=user, gender='M', year_of_birth=random.randint(1880, 1993), month_of_birth=random.randint(1, 12), day_of_birth=random.randint(1, 30), age=random.randint(18, 33), height=random.randint(155, 200), education=random.randint(0, 4), educationSchool=school[random.randint(1, 600)].name, income=random.randint(5, 100), ) else: pass UserExpect( user_id=i, heighty1=random.randint(1, 100), heighty2=random.randint(1, 100), heighty3=random.randint(40, 100), heighty4=random.randint(50, 100), heighty5=random.randint(20, 100), heighty6=random.randint(1, 100), heighty7=random.randint(1, 100), heighty8=random.randint(1, 100), ).save() Grade(user_id=i, heightweight=random.uniform(0, 1), incomeweight=random.uniform(0, 1), edcationscore=random.randint(0, 100), edcationweight=random.uniform(0, 1), appearancescore=random.uniform(30, 100), appearanceweight=random.uniform(0, 1), appearancesvote=random.randint(0, 20)).save() self.stdout.write('score cache reset success!')
UserExpect( user_id=1, heighty1=random.randint(1, 100), heighty2=random.randint(1, 100), heighty3=random.randint(1, 100), heighty4=random.randint(1, 100), heighty5=random.randint(1, 100), heighty6=random.randint(1, 100), heighty7=random.randint(1, 100), heighty8=random.randint(1, 100), ).save() g = Grade(user_id=1, heightweight=random.uniform(0, 1), incomescore=random.uniform(0, 100), incomeweight=random.uniform(0, 1), edcationscore=random.randint(0, 100), edcationweight=random.uniform(0, 1), appearancescore=random.uniform(0, 100), appearanceweight=random.uniform(0, 1), appearancesvote=random.randint(0, 20)).save() for i in range(2, 1000): if i > 500: user = UserProfile( user_id=i, gender='M', year_of_birth=random.randint(1880, 1993), month_of_birth=random.randint(1, 12), day_of_birth=random.randint(1, 30), age=random.randint(18, 33), height=random.randint(155, 200), education=random.randint(0, 4),