<commit_before>import datetime
from django.db import models

from pleniere.models import Pleniere

# in seconds
OK_THRESHOLD = 5

class Video(models.Model):
    pleniere = models.ForeignKey(Pleniere)

    # len are in seconds
    mms_len = models.IntegerField(null=True)
    wmv_len = models.IntegerField(null=True)
    mp4_len = models.IntegerField(null=True)
    webm_len = models.IntegerField(null=True)

    def __unicode__(self):
        return "Videos of '%s'" % (self.pleniere.chambre_id)

    # format len
    def _format_len(self, l):
        return str(datetime.timedelta(seconds=l))

    def format_mms_len(self):
        return self._format_len(self.mms_len)

    def format_wmv_len(self):
        return self._format_len(self.wmv_len)

    def format_mp4_len(self):
        return self._format_len(self.mp4_len)

    def format_webm_len(self):
        return self._format_len(self.webm_len)

    # is the video considered as 'ok'
    def wmv_is_ok(self):
        # WMV seems to be longer than MMS for some reason
        return self.wmv_len >= self.mms_len

    def mp4_is_ok(self):
        return abs(self.mp4_len - self.mms_len) <= OK_THRESHOLD

    def webm_is_ok(self):
        return abs(self.webm_len - self.mms_len) <= OK_THRESHOLD
<commit_msg>videos_tools: check if mp4/webm are None<commit_after>import datetime
from django.db import models

from pleniere.models import Pleniere

# in seconds
OK_THRESHOLD = 5

class Video(models.Model):
    pleniere = models.ForeignKey(Pleniere)

    # len are in seconds
    mms_len = models.IntegerField(null=True)
    wmv_len = models.IntegerField(null=True)
    mp4_len = models.IntegerField(null=True)
    webm_len = models.IntegerField(null=True)

    def __unicode__(self):
        return "Videos of '%s'" % (self.pleniere.chambre_id)

    # format len
    def _format_len(self, l):
        return str(datetime.timedelta(seconds=l))

    def format_mms_len(self):
        return self._format_len(self.mms_len)

    def format_wmv_len(self):
        return self._format_len(self.wmv_len)

    def format_mp4_len(self):
        return self._format_len(self.mp4_len)

    def format_webm_len(self):
        return self._format_len(self.webm_len)

    # is the video considered as 'ok'
    def wmv_is_ok(self):
        # WMV seems to be longer than MMS for some reason
        return self.wmv_len >= self.mms_len

    def mp4_is_ok(self):
        if self.mp4_len is None:
            return False

        return abs(self.mp4_len - self.mms_len) <= OK_THRESHOLD

    def webm_is_ok(self):
        if self.webm_len is None:
            return False

        return abs(self.webm_len - self.mms_len) <= OK_THRESHOLD

{'fraction_non_alphanumeric': 0.0912490650710546, 'fraction_numerical': 0.005235602094240838, 'mean_word_length': 3.0591805766312596, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5897556', 'n_tokens_mistral': 965, 'n_tokens_neox': 935, 'n_words': 203}