コード例 #1
0
ファイル: sampledata.py プロジェクト: xrile/fjord
def create_basic_sampledata():
    print 'Generating 100 happy and 100 sad responses...'
    happy_feedback = sentence_generator(HAPPY_FEEDBACK)
    sad_feedback = sentence_generator(SAD_FEEDBACK)

    # Note: We're abusing sentence_generator to just return random
    # choice from a tuple of things.
    products = sentence_generator(PRODUCT_TUPLES)
    locales = locale_generator()
    urls = sentence_generator(URLS)

    # Create 100 happy responses.
    now = time.time()
    objs = []
    for i in range(100):
        product = products.next()
        now = now - random.randint(500, 2000)
        if product[0] in ALWAYS_API:
            api = '1'
        elif product[0] in NEVER_API:
            api = None
        else:
            api = random.choice(('1', None))

        objs.append(
            ResponseFactory.build(happy=True,
                                  description=happy_feedback.next(),
                                  product=product[0],
                                  version=product[1],
                                  platform=product[2],
                                  user_agent=product[3],
                                  locale=locales.next(),
                                  created=datetime.datetime.fromtimestamp(now),
                                  api=api))

    # Create 100 sad responses.
    now = time.time()
    for i in range(100):
        product = products.next()
        now = now - random.randint(500, 2000)
        if product[0] in ALWAYS_API:
            api = '1'
        elif product[0] in NEVER_API:
            api = None
        else:
            api = random.choice(('1', None))
        objs.append(
            ResponseFactory.build(happy=False,
                                  description=sad_feedback.next(),
                                  product=product[0],
                                  version=product[1],
                                  platform=product[2],
                                  locale=locales.next(),
                                  user_agent=product[3],
                                  url=urls.next(),
                                  created=datetime.datetime.fromtimestamp(now),
                                  api=api))

    Response.objects.bulk_create(objs)
コード例 #2
0
ファイル: test_models.py プロジェクト: rlr/fjord
    def test_happy_to_rating(self):
        """Test we don't populate rating from happy"""
        resp = ResponseFactory.build(happy=True, rating=None)
        resp.save()
        eq_(resp.rating, None)

        resp = ResponseFactory.build(happy=False, rating=None)
        resp.save()
        eq_(resp.rating, None)
コード例 #3
0
    def test_happy_to_rating(self):
        """Test we don't populate rating from happy"""
        resp = ResponseFactory.build(happy=True, rating=None)
        resp.save()
        eq_(resp.rating, None)

        resp = ResponseFactory.build(happy=False, rating=None)
        resp.save()
        eq_(resp.rating, None)
コード例 #4
0
 def test_rating_to_happy(self):
     """Test that we do populate happy from rating"""
     data = {1: False, 2: False, 3: False, 4: True, 5: True}
     for rat, expected in data.items():
         # Create the response, but DON'T save it to the db.
         resp = ResponseFactory.build(happy=None, rating=rat)
         resp.save()
         eq_(resp.happy, expected)
コード例 #5
0
ファイル: sampledata.py プロジェクト: ANKIT-KS/fjord
def create_basic_sampledata():
    happy_feedback = sentence_generator(HAPPY_FEEDBACK)
    sad_feedback = sentence_generator(SAD_FEEDBACK)

    products = sentence_generator(PRODUCTS)
    platforms = sentence_generator(PLATFORMS)
    locales = sentence_generator(settings.DEV_LANGUAGES)
    urls = sentence_generator(URLS)

    # Create 100 happy responses.
    now = time.time()
    objs = []
    for i in range(100):
        product = products.next()
        now = now - random.randint(500, 2000)
        objs.append(
            ResponseFactory.build(
                happy=True,
                description=happy_feedback.next(),
                product=product[0],
                version=product[1],
                platform=platforms.next(),
                locale=locales.next(),
                created=datetime.datetime.fromtimestamp(now)
            )
        )

    # Create 100 sad responses.
    now = time.time()
    for i in range(100):
        product = products.next()
        now = now - random.randint(500, 2000)
        objs.append(
            ResponseFactory.build(
                happy=False,
                description=sad_feedback.next(),
                product=product[0],
                version=product[1],
                platform=platforms.next(),
                locale=locales.next(),
                url=urls.next(),
                created=datetime.datetime.fromtimestamp(now)
            )
        )

    Response.objects.bulk_create(objs)
コード例 #6
0
ファイル: sampledata.py プロジェクト: Givemore/fjord
def create_additional_sampledata(samplesize="1000"):
    samplesize = int(samplesize)

    print "Generating {0} feedback responses...".format(samplesize)

    happy_feedback = sentence_generator(HAPPY_FEEDBACK)
    sad_feedback = sentence_generator(SAD_FEEDBACK)
    products = sentence_generator(PRODUCT_TUPLES)
    urls = sentence_generator(URLS)
    locales = locale_generator()

    objs = []

    now = time.time()
    for i in range(samplesize):
        now = now - random.randint(500, 2000)

        happy = random.choice([True, False])
        if happy:
            description = happy_feedback.next()
            url = u""
        else:
            description = sad_feedback.next()
            url = urls.next()

        product = products.next()
        if product[0] in ALWAYS_API:
            api = "1"
        elif product[0] in NEVER_API:
            api = None
        else:
            api = random.choice(("1", None))
        objs.append(
            ResponseFactory.build(
                happy=happy,
                description=description,
                product=product[0],
                version=product[1],
                platform=product[2],
                url=url,
                user_agent=product[3],
                locale=locales.next(),
                created=datetime.datetime.fromtimestamp(now),
                api=api,
            )
        )

        # Bulk-save the objects to the db 500 at a time and
        # print something to stdout about it.
        if i % 500 == 0:
            Response.objects.bulk_create(objs)
            objs = []
            print "  {0}...".format(i)

    if objs:
        print "  {0}...".format(samplesize)
        Response.objects.bulk_create(objs)
        objs = []
コード例 #7
0
ファイル: sampledata.py プロジェクト: xrile/fjord
def create_additional_sampledata(samplesize='1000'):
    samplesize = int(samplesize)

    print 'Generating {0} feedback responses...'.format(samplesize)

    happy_feedback = sentence_generator(HAPPY_FEEDBACK)
    sad_feedback = sentence_generator(SAD_FEEDBACK)
    products = sentence_generator(PRODUCT_TUPLES)
    urls = sentence_generator(URLS)
    locales = locale_generator()

    objs = []

    now = time.time()
    for i in range(samplesize):
        now = now - random.randint(500, 2000)

        happy = random.choice([True, False])
        if happy:
            description = happy_feedback.next()
            url = u''
        else:
            description = sad_feedback.next()
            url = urls.next()

        product = products.next()
        if product[0] in ALWAYS_API:
            api = '1'
        elif product[0] in NEVER_API:
            api = None
        else:
            api = random.choice(('1', None))
        objs.append(
            ResponseFactory.build(happy=happy,
                                  description=description,
                                  product=product[0],
                                  version=product[1],
                                  platform=product[2],
                                  url=url,
                                  user_agent=product[3],
                                  locale=locales.next(),
                                  created=datetime.datetime.fromtimestamp(now),
                                  api=api))

        # Bulk-save the objects to the db 500 at a time and
        # print something to stdout about it.
        if i % 500 == 0:
            Response.objects.bulk_create(objs)
            objs = []
            print '  {0}...'.format(i)

    if objs:
        print '  {0}...'.format(samplesize)
        Response.objects.bulk_create(objs)
        objs = []
コード例 #8
0
ファイル: sampledata.py プロジェクト: deshraj/fjord
def create_basic_sampledata():
    happy_feedback = sentence_generator(HAPPY_FEEDBACK)
    sad_feedback = sentence_generator(SAD_FEEDBACK)

    products = sentence_generator(PRODUCTS)
    platforms = sentence_generator(PLATFORMS)
    locales = sentence_generator(settings.DEV_LANGUAGES)
    urls = sentence_generator(URLS)

    # Create 100 happy responses.
    now = time.time()
    objs = []
    for i in range(100):
        product = products.next()
        now = now - random.randint(500, 2000)
        objs.append(
            ResponseFactory.build(
                happy=True,
                description=happy_feedback.next(),
                product=product[0],
                version=product[1],
                platform=platforms.next(),
                locale=locales.next(),
                created=datetime.datetime.fromtimestamp(now)))

    # Create 100 sad responses.
    now = time.time()
    for i in range(100):
        product = products.next()
        now = now - random.randint(500, 2000)
        objs.append(
            ResponseFactory.build(
                happy=False,
                description=sad_feedback.next(),
                product=product[0],
                version=product[1],
                platform=platforms.next(),
                locale=locales.next(),
                url=urls.next(),
                created=datetime.datetime.fromtimestamp(now)))

    Response.objects.bulk_create(objs)
コード例 #9
0
ファイル: sampledata.py プロジェクト: ANKIT-KS/fjord
def create_additional_sampledata(samplesize):
    samplesize = int(samplesize)

    print 'Working on generating {0} feedback responses....'.format(
        samplesize)

    happy_feedback = sentence_generator(HAPPY_FEEDBACK)
    sad_feedback = sentence_generator(SAD_FEEDBACK)
    products = sentence_generator(PRODUCTS)
    urls = sentence_generator(URLS)
    user_agents = sentence_generator(USER_AGENTS)
    locales = sentence_generator(settings.DEV_LANGUAGES)

    objs = []

    now = time.time()
    for i in range(samplesize):
        now = now - random.randint(500, 2000)

        happy = random.choice([True, False])
        if happy:
            description = happy_feedback.next()
            url = u''
        else:
            description = sad_feedback.next()
            url = urls.next()

        product = products.next()
        objs.append(
            ResponseFactory.build(
                happy=happy,
                description=description,
                product=product[0],
                version=product[1],
                url=url,
                user_agent=user_agents.next(),
                locale=locales.next(),
                created=datetime.datetime.fromtimestamp(now)
            )
        )

        # Bulk-save the objects to the db 500 at a time and
        # print something to stdout about it.
        if i % 500 == 0:
            Response.objects.bulk_create(objs)
            objs = []
            print '  {0}...'.format(i)

    if objs:
        print '  {0}...'.format(samplesize)
        Response.objects.bulk_create(objs)
        objs = []
コード例 #10
0
ファイル: test_models.py プロジェクト: rlr/fjord
 def test_rating_to_happy(self):
     """Test that we do populate happy from rating"""
     data = {
         1: False,
         2: False,
         3: False,
         4: True,
         5: True
     }
     for rat, expected in data.items():
         # Create the response, but DON'T save it to the db.
         resp = ResponseFactory.build(happy=None, rating=rat)
         resp.save()
         eq_(resp.happy, expected)
コード例 #11
0
ファイル: sampledata.py プロジェクト: deshraj/fjord
def create_additional_sampledata(samplesize):
    samplesize = int(samplesize)

    print 'Working on generating {0} feedback responses....'.format(samplesize)

    happy_feedback = sentence_generator(HAPPY_FEEDBACK)
    sad_feedback = sentence_generator(SAD_FEEDBACK)
    products = sentence_generator(PRODUCTS)
    urls = sentence_generator(URLS)
    user_agents = sentence_generator(USER_AGENTS)
    locales = sentence_generator(settings.DEV_LANGUAGES)

    objs = []

    now = time.time()
    for i in range(samplesize):
        now = now - random.randint(500, 2000)

        happy = random.choice([True, False])
        if happy:
            description = happy_feedback.next()
            url = u''
        else:
            description = sad_feedback.next()
            url = urls.next()

        product = products.next()
        objs.append(
            ResponseFactory.build(
                happy=happy,
                description=description,
                product=product[0],
                version=product[1],
                url=url,
                user_agent=user_agents.next(),
                locale=locales.next(),
                created=datetime.datetime.fromtimestamp(now)))

        # Bulk-save the objects to the db 500 at a time and
        # print something to stdout about it.
        if i % 500 == 0:
            Response.objects.bulk_create(objs)
            objs = []
            print '  {0}...'.format(i)

    if objs:
        print '  {0}...'.format(samplesize)
        Response.objects.bulk_create(objs)
        objs = []
コード例 #12
0
ファイル: sampledata.py プロジェクト: Givemore/fjord
def create_basic_sampledata():
    print "Generating 100 happy and 100 sad responses..."
    happy_feedback = sentence_generator(HAPPY_FEEDBACK)
    sad_feedback = sentence_generator(SAD_FEEDBACK)

    # Note: We're abusing sentence_generator to just return random
    # choice from a tuple of things.
    products = sentence_generator(PRODUCT_TUPLES)
    locales = locale_generator()
    urls = sentence_generator(URLS)

    # Create 100 happy responses.
    now = time.time()
    objs = []
    for i in range(100):
        product = products.next()
        now = now - random.randint(500, 2000)
        if product[0] in ALWAYS_API:
            api = "1"
        elif product[0] in NEVER_API:
            api = None
        else:
            api = random.choice(("1", None))

        objs.append(
            ResponseFactory.build(
                happy=True,
                description=happy_feedback.next(),
                product=product[0],
                version=product[1],
                platform=product[2],
                user_agent=product[3],
                locale=locales.next(),
                created=datetime.datetime.fromtimestamp(now),
                api=api,
            )
        )

    # Create 100 sad responses.
    now = time.time()
    for i in range(100):
        product = products.next()
        now = now - random.randint(500, 2000)
        if product[0] in ALWAYS_API:
            api = "1"
        elif product[0] in NEVER_API:
            api = None
        else:
            api = random.choice(("1", None))
        objs.append(
            ResponseFactory.build(
                happy=False,
                description=sad_feedback.next(),
                product=product[0],
                version=product[1],
                platform=product[2],
                locale=locales.next(),
                user_agent=product[3],
                url=urls.next(),
                created=datetime.datetime.fromtimestamp(now),
                api=api,
            )
        )

    Response.objects.bulk_create(objs)