Skip to content

Commit

Permalink
Merge pull request eee555#173 from putianyi889/patch-94
Browse files Browse the repository at this point in the history
解决bvs的除0错误
  • Loading branch information
eee555 authored Dec 8, 2024
2 parents 5ee62b3 + e1db032 commit 5806ca5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,8 @@ jobs:
- name: Flags
run: python -m unittest tests.py -v

- name: Video Manager
run: python manage.py test videomanager

- name: Account Link
run: python manage.py test accountlink
2 changes: 1 addition & 1 deletion back_end/saolei/videomanager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class VideoModel(models.Model):
timems = models.PositiveIntegerField(default=DefaultRankingScores["timems"]) # 整数形式存储的毫秒数。
# 0-32767
bv = models.PositiveSmallIntegerField()
bvs = models.GeneratedField(expression = models.F('bv') / models.F('timems') * models.Value(1000), output_field = models.FloatField(), db_persist = True)
bvs = models.GeneratedField(expression = models.Case(models.When(timems=0,then=models.Value(0.0)), default=models.F('bv') / models.F('timems') * models.Value(1000), output_field = models.FloatField()), output_field = models.FloatField(), db_persist = True)

# 暂时的解决方案
def __getattr__(self, name):
Expand Down
11 changes: 11 additions & 0 deletions back_end/saolei/videomanager/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
from django.test import TestCase
from userprofile.models import UserProfile
from .models import VideoModel, ExpandVideoModel

# Create your tests here.

class VideoManagerTestCase(TestCase):
def setUp(self):
self.user = UserProfile.objects.create(username='setUp', email='[email protected]')

def test_zero_time(self):
expandvideo = ExpandVideoModel.objects.create(identifier='test', left=1, right=0, double=0, cl=1, left_s=0, right_s=0, double_s=0, cl_s=0, path=0, flag=0, flag_s=0, stnb=0, rqp=0, ioe=1, thrp=1, corr=1, ce=1, ce_s=0, op=1, isl=0, cell0=0, cell1=0, cell2=0, cell3=0, cell4=0, cell5=0, cell6=0, cell7=0, cell8=0)
video = VideoModel.objects.create(player=self.user, file='test.evf', video=expandvideo, state='a', software='e', level='b', mode='00', timems=0, bv=1)
self.assertEqual(video.bvs, 0)

0 comments on commit 5806ca5

Please sign in to comment.