예제 #1
0
파일: test_utils.py 프로젝트: ivadim/movies
    def test_calculate_age(self):
        today = datetime.date(2014, 05, 03)
        age = utils.calculate_age('1988-05-03', today)
        self.assertEqual(age, 26)

        today = datetime.date(2014, 05, 02)
        age = utils.calculate_age('1988-05-03', today)
        self.assertEqual(age, 25)

        today = datetime.date(2014, 05, 03)
        age = utils.calculate_age('2015-05-03', today)
        self.assertEqual(age, -1)
예제 #2
0
파일: test_utils.py 프로젝트: ivadim/movies
    def test_calculate_age(self):
        today = datetime.date(2014, 05, 03)
        age = utils.calculate_age('1988-05-03', today)
        self.assertEqual(age, 26)

        today = datetime.date(2014, 05, 02)
        age = utils.calculate_age('1988-05-03', today)
        self.assertEqual(age, 25)

        today = datetime.date(2014, 05, 03)
        age = utils.calculate_age('2015-05-03', today)
        self.assertEqual(age, -1)
예제 #3
0
파일: main.py 프로젝트: ivadim/movies
def process_movie(movie, min_accuracy, use_freebase):
    cast, crew = tmdb_api.get_movie_credits(movie.id)
    none_number = 0;
    total_age = 0;
    if len(cast) == 0:
        #Didn't find any actors in film
        return
    for person_id in cast:
        if person_id in actors_cache:
            person = actors_cache[person_id]
        else:
            person = tmdb_api.get_person_info(person_id)
            if not person.birthday and use_freebase:
                person.birthday = try_find_birthday_in_freebase(person.name)
            actors_cache[person_id] = person
        if not person.birthday:
            none_number += 1;
        else:
            total_age += utils.calculate_age(person.birthday)
    accuracy = utils.calc_accuracy(len(cast), none_number)
    average = utils.calc_average(total_age, len(cast), none_number)
    if accuracy >= min_accuracy:
        print "'{}' average age is {:.4} with accuracy {:.4}%".format(movie.title.encode('utf-8'), average, accuracy)
예제 #4
0
def process_movie(movie, min_accuracy, use_freebase):
    cast, crew = tmdb_api.get_movie_credits(movie.id)
    none_number = 0
    total_age = 0
    if len(cast) == 0:
        #Didn't find any actors in film
        return
    for person_id in cast:
        if person_id in actors_cache:
            person = actors_cache[person_id]
        else:
            person = tmdb_api.get_person_info(person_id)
            if not person.birthday and use_freebase:
                person.birthday = try_find_birthday_in_freebase(person.name)
            actors_cache[person_id] = person
        if not person.birthday:
            none_number += 1
        else:
            total_age += utils.calculate_age(person.birthday)
    accuracy = utils.calc_accuracy(len(cast), none_number)
    average = utils.calc_average(total_age, len(cast), none_number)
    if accuracy >= min_accuracy:
        print "'{}' average age is {:.4} with accuracy {:.4}%".format(
            movie.title.encode('utf-8'), average, accuracy)
예제 #5
0
파일: test_utils.py 프로젝트: ivadim/movies
 def test_calculate_age_year_and_month(self):
     today = datetime.date(2014, 05, 03)
     age = utils.calculate_age('2000-06', today)
     self.assertEqual(age, 13)
예제 #6
0
파일: test_utils.py 프로젝트: ivadim/movies
 def test_calculate_age_only_year(self):
     today = datetime.date(2014, 05, 03)
     age = utils.calculate_age('2000', today)
     self.assertEqual(age, 14)
예제 #7
0
파일: test_utils.py 프로젝트: ivadim/movies
 def test_calculate_age_none(self):
     age = utils.calculate_age(None)
     self.assertEqual(age, None)
예제 #8
0
파일: test_utils.py 프로젝트: ivadim/movies
 def test_calculate_age_year_and_month(self):
     today = datetime.date(2014, 05, 03)
     age = utils.calculate_age('2000-06', today)
     self.assertEqual(age, 13)
예제 #9
0
파일: test_utils.py 프로젝트: ivadim/movies
 def test_calculate_age_only_year(self):
     today = datetime.date(2014, 05, 03)
     age = utils.calculate_age('2000', today)
     self.assertEqual(age, 14)
예제 #10
0
파일: test_utils.py 프로젝트: ivadim/movies
 def test_calculate_age_none(self):
     age = utils.calculate_age(None)
     self.assertEqual(age, None)