Esempio n. 1
0
 def test_byDate_today(self):
     self.assertAlmostEqual(56598000,
                            worldPopulationRankByDate(
                                'unisex', 'World', date(2013, 12, 31),
                                date(2014, 6, 1)),
                            delta=AlgorithmTests.DELTA)
     self.assertAlmostEqual(2541178000,
                            worldPopulationRankByDate(
                                'unisex', 'World', date(1993, 12, 6),
                                date(2014, 6, 1)),
                            delta=AlgorithmTests.DELTA)
     self.assertAlmostEqual(4178250000,
                            worldPopulationRankByDate(
                                'unisex', 'World', date(1980, 1, 1),
                                date(2014, 6, 1)),
                            delta=AlgorithmTests.DELTA)
     self.assertAlmostEqual(5989238000,
                            worldPopulationRankByDate(
                                'unisex', 'World', date(1960, 2, 29),
                                date(2014, 6, 1)),
                            delta=AlgorithmTests.DELTA)
     self.assertAlmostEqual(7233264000,
                            worldPopulationRankByDate(
                                'unisex', 'World', date(1920, 1, 1),
                                date(2014, 6, 1)),
                            delta=AlgorithmTests.DELTA)
Esempio n. 2
0
 def test_byDate_date(self):
     self.assertAlmostEqual(940947000,
                            worldPopulationRankByDate(
                                'unisex', 'World', date(1993, 12, 6),
                                date(2001, 9, 11)),
                            delta=AlgorithmTests.DELTA)
     self.assertAlmostEqual(7198923000,
                            worldPopulationRankByDate(
                                'unisex', 'World', date(1920, 1, 1),
                                date(2014, 1, 1)),
                            delta=AlgorithmTests.DELTA)
Esempio n. 3
0
def world_population_rank_in_future(request, dob, sex, country, offset):
    """ Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by an offset towards the future from today.<p>The world population rank is defined as the position of someone's birthday among the group of living people of the same sex and country of origin, ordered by date of birth increasing. The first person born is assigned rank #1.<p>Today's date is always based on the current time in the timezone UTC.<p>
        Please see <a href="/">the full API browser</a> for more information.
    """
    today = datetime.datetime.utcnow().date()
    rank = worldPopulationRankByDate(sex, country, dob, today + offset)
    return Response({"rank": rank, 'dob': dob, 'sex': sex, 'country': country, 'offset': offset_to_str(offset)})
Esempio n. 4
0
def world_population_rank_by_age(request, dob, sex, country, age):
    """ Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by the person's age.<p>The world population rank is defined as the position of someone's birthday among the group of living people of the same sex and country of origin, ordered by date of birth increasing. The first person born is assigned rank #1.<p>
        Please see <a href="/">the full API browser</a> for more information.
    """
    rank = worldPopulationRankByDate(sex, country, dob, dob + age)
    return Response({
        "rank": rank,
        'dob': dob,
        'sex': sex,
        'country': country,
        'age': offset_to_str(age)
    })
Esempio n. 5
0
 def test_byDate_age(self):
     self.assertAlmostEqual(2541533000,
                            worldPopulationRankByDate(
                                'unisex', 'World', date(1993, 12, 6),
                                date(1993, 12, 6) + timedelta(days=7483)),
                            delta=AlgorithmTests.DELTA)
     self.assertAlmostEqual(1209918000,
                            worldPopulationRankByDate(
                                'unisex', 'World', date(1993, 12, 6),
                                date(1993, 12, 6) + timedelta(days=3650)),
                            delta=AlgorithmTests.DELTA)
     self.assertAlmostEqual(578344100,
                            worldPopulationRankByDate(
                                'unisex', 'World', date(1940, 5, 3),
                                date(1940, 5, 3) + timedelta(days=3530)),
                            delta=AlgorithmTests.DELTA)
     self.assertAlmostEqual(217482,
                            worldPopulationRankByDate(
                                'unisex', 'World', date(1950, 1, 1),
                                date(1950, 1, 1) + timedelta(days=0)),
                            delta=AlgorithmTests.DELTA)
Esempio n. 6
0
def world_population_rank_by_age(request, dob, sex, country, age):
    """ Calculates the world population rank of a person with the given date of birth, sex and country of origin on a certain date as expressed by the person's age.<p>The world population rank is defined as the position of someone's birthday among the group of living people of the same sex and country of origin, ordered by date of birth increasing. The first person born is assigned rank #1.<p>
        Please see <a href="/">the full API browser</a> for more information.
    """
    rank = worldPopulationRankByDate(sex, country, dob, dob + age)
    return Response({"rank": rank, 'dob': dob, 'sex': sex, 'country': country, 'age': offset_to_str(age)})
Esempio n. 7
0
 def test_byDate_date(self):
     self.assertAlmostEqual(940947000,  worldPopulationRankByDate('unisex', 'World', date(1993, 12,  6), date(2001,  9, 11)), delta=TestWorldPopulationRankCalculation.DELTA)
     self.assertAlmostEqual(7198923000, worldPopulationRankByDate('unisex', 'World', date(1920,  1,  1), date(2014,  1,  1)), delta=TestWorldPopulationRankCalculation.DELTA)
Esempio n. 8
0
 def test_byDate_age(self):
     self.assertAlmostEqual(2541533000, worldPopulationRankByDate('unisex', 'World', date(1993, 12,  6), date(1993, 12,  6) + timedelta(days=7483)), delta=TestWorldPopulationRankCalculation.DELTA)
     self.assertAlmostEqual(1209918000, worldPopulationRankByDate('unisex', 'World', date(1993, 12,  6), date(1993, 12,  6) + timedelta(days=3650)), delta=TestWorldPopulationRankCalculation.DELTA)
     self.assertAlmostEqual(578344100,  worldPopulationRankByDate('unisex', 'World', date(1940,  5,  3), date(1940,  5,  3) + timedelta(days=3530)), delta=TestWorldPopulationRankCalculation.DELTA)
     self.assertAlmostEqual(217482,     worldPopulationRankByDate('unisex', 'World', date(1950,  1,  1), date(1950,  1,  1) + timedelta(days=0)),    delta=TestWorldPopulationRankCalculation.DELTA)
Esempio n. 9
0
 def test_byDate_today(self):
     self.assertAlmostEqual(56598000,   worldPopulationRankByDate('unisex', 'World', date(2013, 12, 31), date(2014,  6,  1)), delta=TestWorldPopulationRankCalculation.DELTA)
     self.assertAlmostEqual(2541178000, worldPopulationRankByDate('unisex', 'World', date(1993, 12,  6), date(2014,  6,  1)), delta=TestWorldPopulationRankCalculation.DELTA)
     self.assertAlmostEqual(4178250000, worldPopulationRankByDate('unisex', 'World', date(1980,  1,  1), date(2014,  6,  1)), delta=TestWorldPopulationRankCalculation.DELTA)
     self.assertAlmostEqual(5989238000, worldPopulationRankByDate('unisex', 'World', date(1960,  2, 29), date(2014,  6,  1)), delta=TestWorldPopulationRankCalculation.DELTA)
     self.assertAlmostEqual(7233264000, worldPopulationRankByDate('unisex', 'World', date(1920,  1,  1), date(2014,  6,  1)), delta=TestWorldPopulationRankCalculation.DELTA)
Esempio n. 10
0
 def yourRANKbyDate(self, DoB, refdate):   # Helper function to make this test case look as closely as the R acceptance test as possible
     return worldPopulationRankByDate(self.iSEX, self.CNTRY, DoB, refdate) / 1000
Esempio n. 11
0
 def yourRANKbyAge(self, DoB, iAge):   # Helper function to make this test case look as closely as the R acceptance test as possible
     return worldPopulationRankByDate(self.iSEX, self.CNTRY, DoB, self.TODAY - relativedelta(days=iAge)) / 1000
Esempio n. 12
0
 def yourRANKbyDate(
     self, DoB, refdate
 ):  # Helper function to make this test case look as closely as the R acceptance test as possible
     return worldPopulationRankByDate(self.iSEX, self.CNTRY, DoB,
                                      refdate) / 1000
Esempio n. 13
0
 def yourRANKbyAge(
     self, DoB, iAge
 ):  # Helper function to make this test case look as closely as the R acceptance test as possible
     return worldPopulationRankByDate(self.iSEX, self.CNTRY, DoB, self.TODAY
                                      - relativedelta(days=iAge)) / 1000