Пример #1
0
 def setUp(self):
     self.survey = Survey.objects.get(slug='reef-fish-market-survey')
     self.question = self.survey.questions.get(slug='survey-site')
     self.respondant_user = User.objects.get(username='******')
     self.ts = datetime.datetime(2013, 11, 30).replace(tzinfo=utc)
     self.respondant = Respondant(survey=self.survey,
                                  ts=self.ts,
                                  surveyor=self.respondant_user)
     response = Response(question=self.question, respondant=self.respondant)
     response.answer_raw = json.dumps({'text': 'Fishing Village'})
     self.respondant.save()
     response.save()
Пример #2
0
    def create_respondant(self, when, market, prices):
        respondant = Respondant(survey=self.survey,
                                ts=when,
                                surveyor=self.user)

        respondant.save()

        response_a = self.create_text_response(self.question_a,
                                               respondant, when, market)
        respondant.response_set.add(response_a)

        response_b = self.create_grid_response(self.question_b,
                                               respondant, when, prices)
        respondant.response_set.add(response_b)
        respondant.save()
        return respondant
Пример #3
0
    def create_respondant(self,
                          vendor,
                          fishes,
                          market=None,
                          status=None,
                          when=None):
        if when is None:
            when = datetime.datetime.utcnow().replace(tzinfo=utc)
        respondant = Respondant(survey=self.survey,
                                ts=when,
                                surveyor=self.user)
        if status is not None:
            respondant.review_status = status

        respondant.save()

        if market is not None:
            response_market = self.create_text_response(
                self.question_market, respondant, when, market)
            respondant.response_set.add(response_market)

        response_vendor = self.create_text_response(self.question_vendor,
                                                    respondant, when, vendor)
        respondant.response_set.add(response_vendor)

        response_fishes = self.create_multi_select_response(
            self.question_fishes, respondant, when, fishes)
        respondant.response_set.add(response_fishes)
        respondant.save()
        return respondant
Пример #4
0
class BaseSurveyorStatsCase(TestCase):
    fixtures = ['reef.json', 'users.json']

    def setUp(self):
        self.survey = Survey.objects.get(slug='reef-fish-market-survey')
        self.question = self.survey.questions.get(slug='survey-site')
        self.respondant_user = User.objects.get(username='******')
        self.ts = datetime.datetime(2013, 11, 30).replace(tzinfo=utc)
        self.respondant = Respondant(survey=self.survey,
                                     ts=self.ts,
                                     surveyor=self.respondant_user)
        response = Response(question=self.question, respondant=self.respondant)
        response.answer_raw = json.dumps({'text': 'Fishing Village'})
        self.respondant.save()
        response.save()

    def login(self):
        self.client.login(username=self.respondant_user.username,
                          password='******')
Пример #5
0
class BaseSurveyorStatsCase(TestCase):
    fixtures = ['reef.json', 'users.json']

    def setUp(self):
        self.survey = Survey.objects.get(slug='reef-fish-market-survey')
        self.question = self.survey.questions.get(slug='survey-site')
        self.respondant_user = User.objects.get(username='******')
        self.ts = datetime.datetime(2013, 11, 30).replace(tzinfo=utc)
        self.respondant = Respondant(survey=self.survey,
                                     ts=self.ts,
                                     surveyor=self.respondant_user)
        response = Response(question=self.question,
                            respondant=self.respondant)
        response.answer_raw = json.dumps({'text': 'Fishing Village'})
        self.respondant.save()
        response.save()

    def login(self):
        self.client.login(username=self.respondant_user.username,
                          password='******')
Пример #6
0
    def create_respondant(self, vendor, fishes, market=None, status=None,
                          when=None):
        if when is None:
            when = datetime.datetime.utcnow().replace(tzinfo=utc)
        respondant = Respondant(survey=self.survey,
                                ts=when,
                                surveyor=self.user)
        if status is not None:
            respondant.review_status = status

        respondant.save()

        if market is not None:
            response_market = self.create_text_response(self.question_market,
                                                        respondant, when, market)
            respondant.response_set.add(response_market)

        response_vendor = self.create_text_response(self.question_vendor,
                                                    respondant, when, vendor)
        respondant.response_set.add(response_vendor)

        response_fishes = self.create_multi_select_response(self.question_fishes,
                                                            respondant, when, fishes)
        respondant.response_set.add(response_fishes)
        respondant.save()
        return respondant
Пример #7
0
 def setUp(self):
     self.survey = Survey.objects.get(slug='reef-fish-market-survey')
     self.question = self.survey.questions.get(slug='survey-site')
     self.respondant_user = User.objects.get(username='******')
     self.ts = datetime.datetime(2013, 11, 30).replace(tzinfo=utc)
     self.respondant = Respondant(survey=self.survey,
                                  ts=self.ts,
                                  surveyor=self.respondant_user)
     response = Response(question=self.question,
                         respondant=self.respondant)
     response.answer_raw = json.dumps({'text': 'Fishing Village'})
     self.respondant.save()
     response.save()
Пример #8
0
    def create_respondant(self, when, market, prices):
        respondant = Respondant(survey=self.survey,
                                ts=when,
                                surveyor=self.user)

        response_a = Response(question=self.question_a,
                              respondant=respondant,
                              ts=when)
        response_a.answer_raw = json.dumps({'text': market})

        response_b = Response(question=self.question_b,
                              respondant=respondant,
                              ts=when)
        response_b.answer_raw = self.cost_grid.format(*prices)

        respondant.save()
        response_a.save()
        response_b.save()
        respondant.responses.add(response_a)
        respondant.responses.add(response_b)
        respondant.save()
        return respondant
Пример #9
0
    def create_respondant(self, when, prices, market=None, status=None):
        respondant = Respondant(survey=self.survey,
                                ts=when,
                                surveyor=self.user)
        if status is not None:
            respondant.review_status = status

        respondant.save()

        grid_response = self.create_grid_response(self.question, respondant,
                                                  when, prices)
        respondant.response_set.add(grid_response)
        if market is not None:
            market_response = self.create_text_response(
                self.market_question, respondant, when, market)
            respondant.response_set.add(market_response)
        respondant.save()
Пример #10
0
    def create_respondant(self, when, market, answers, status=None):
        respondant = Respondant(survey=self.survey,
                                ts=when,
                                surveyor=self.user)
        if status is not None:
            respondant.review_status = status

        respondant.save()

        response_a = self.create_text_response(self.question_a, respondant,
                                               when, market)
        respondant.response_set.add(response_a)

        response_b = self.create_multi_select_response(self.question_b,
                                                       respondant, when,
                                                       answers)
        respondant.response_set.add(response_b)
        respondant.save()
        return respondant
Пример #11
0
    def create_respondant(self, when, market, prices):
        respondant = Respondant(survey=self.survey,
                                ts=when,
                                surveyor=self.user)

        respondant.save()

        response_a = self.create_text_response(self.question_a, respondant,
                                               when, market)
        respondant.response_set.add(response_a)

        response_b = self.create_grid_response(self.question_b, respondant,
                                               when, prices)
        respondant.response_set.add(response_b)
        respondant.save()
        return respondant
Пример #12
0
    def create_respondant(self, when, prices, market=None, status=None):
        respondant = Respondant(survey=self.survey,
                                ts=when,
                                surveyor=self.user)
        if status is not None:
            respondant.review_status = status

        respondant.save()

        grid_response = self.create_grid_response(self.question, respondant,
                                                  when, prices)
        respondant.response_set.add(grid_response)
        if market is not None:
            market_response = self.create_text_response(self.market_question,
                                                        respondant, when, market)
            respondant.response_set.add(market_response)
        respondant.save()
Пример #13
0
    def create_respondant(self, when, market, answers, status=None):
        respondant = Respondant(survey=self.survey,
                                ts=when,
                                surveyor=self.user)
        if status is not None:
            respondant.review_status = status

        respondant.save()

        response_a = self.create_text_response(self.question_a,
                                               respondant, when, market)
        respondant.response_set.add(response_a)

        response_b = self.create_multi_select_response(self.question_b,
                                                       respondant, when, answers)
        respondant.response_set.add(response_b)
        respondant.save()
        return respondant
Пример #14
0
    def handle(self, *args, **options):
        respondants = Respondant.objects.filter(test_data=True)
        Response.objects.filter(respondant__in=respondants).delete()
        respondants.delete()
        survey = Survey.objects.get(slug='reef-fish-market-survey')
        market_question = Question.objects.get(slug='survey-site',
                                               survey=survey)
        volume_question = Question.objects.get(slug='total-weight',
                                               survey=survey)
        origin_question = Question.objects.get(
            slug='province-purchased-caught', survey=survey)
        cost_question = Question.objects.get(slug='cost', survey=survey)
        date_question = Question.objects.get(slug='survey-date', survey=survey)
        users = []
        for i in range(7):
            try:
                user = User.objects.get(username='******'.format(i))
                users.append(user)
            except User.DoesNotExist:
                users.append(
                    User.objects.create_user(username='******'.format(i),
                                             first_name='user',
                                             last_name=i,
                                             password='******'))

        for i in range(100):
            date = datetime.datetime.utcnow()
            date = datetime.date(
                year=date.year, month=date.month,
                day=date.day) + datetime.timedelta(-randint(0, 365))
            respondant = Respondant(survey=survey,
                                    test_data=True,
                                    ts=date,
                                    surveyor=choice(users))
            market_response = Response(question=market_question,
                                       respondant=respondant)
            volume_response = Response(question=volume_question,
                                       respondant=respondant,
                                       ts=date)
            origin_response = Response(question=origin_question,
                                       respondant=respondant)
            date_response = Response(question=date_question,
                                     respondant=respondant)
            cost_response = Response(question=cost_question,
                                     respondant=respondant)
            volume_response.answer_raw = simplejson.dumps(randint(1, 1000))
            date_response.answer_raw = simplejson.dumps(
                date.strftime('%d/%m/%Y'))
            market_response.answer_raw = simplejson.dumps(
                {'text': centers[randint(0,
                                         len(centers) - 1)]})
            origin_response.answer_raw = simplejson.dumps(
                {'text': provinces[randint(0,
                                           len(provinces) - 1)]})
            cost_response.answer_raw = cost_grid % (randint(
                1, 20), randint(1, 20), randint(1, 20), randint(
                    1, 20), randint(1, 20), randint(1, 20), randint(1, 20))
            print date
            respondant.save()
            market_response.save()
            volume_response.save()
            origin_response.save()
            date_response.save()
            cost_response.save()
            volume_response.ts = date
            volume_response.save()
            respondant.response_set.add(market_response)
            respondant.response_set.add(volume_response)
            respondant.response_set.add(origin_response)
            respondant.response_set.add(date_response)
            respondant.response_set.add(cost_response)
            respondant.save()
Пример #15
0
    def handle(self, *args, **options):
        respondants = Respondant.objects.filter(test_data=True)
        Response.objects.filter(respondant__in=respondants).delete()
        respondants.delete()
        survey = Survey.objects.get(slug='reef-fish-market-survey')
        market_question = Question.objects.get(
            slug='survey-site', survey=survey)
        volume_question = Question.objects.get(
            slug='total-weight', survey=survey)
        origin_question = Question.objects.get(
            slug='province-purchased-caught', survey=survey)
        cost_question = Question.objects.get(slug='cost', survey=survey)
        date_question = Question.objects.get(
            slug='survey-date', survey=survey)
        users = []
        for i in range(7):
            try:
                user = User.objects.get(username='******'.format(i))
                users.append(user)
            except User.DoesNotExist:
                users.append(User.objects.create_user(username='******'.format(i),
                                                      first_name='user',
                                                      last_name=i,
                                                      password='******'))

        for i in range(100):
            date = datetime.datetime.utcnow()
            date = datetime.date(year=date.year, month=date.month, day=date.day) + datetime.timedelta(-randint(0, 365))
            respondant = Respondant(survey=survey, test_data=True, ts=date, surveyor=choice(users))
            market_response = Response(
                question=market_question, respondant=respondant)
            volume_response = Response(
                question=volume_question, respondant=respondant, ts=date)
            origin_response = Response(
                question=origin_question, respondant=respondant)
            date_response = Response(
                question=date_question, respondant=respondant)
            cost_response = Response(
                question=cost_question, respondant=respondant)
            volume_response.answer_raw = simplejson.dumps(randint(1, 1000))
            date_response.answer_raw = simplejson.dumps(date.strftime('%d/%m/%Y'))
            market_response.answer_raw = simplejson.dumps(
                {'text': centers[randint(0, len(centers) - 1)]})
            origin_response.answer_raw = simplejson.dumps(
                {'text': provinces[randint(0, len(provinces) - 1)]})
            cost_response.answer_raw = cost_grid % (randint(1, 20), randint(1, 20), randint(
                1, 20), randint(1, 20), randint(1, 20), randint(1, 20), randint(1, 20))
            print date
            respondant.save()
            market_response.save()
            volume_response.save()
            origin_response.save()
            date_response.save()
            cost_response.save()
            volume_response.ts = date
            volume_response.save()
            respondant.response_set.add(market_response)
            respondant.response_set.add(volume_response)
            respondant.response_set.add(origin_response)
            respondant.response_set.add(date_response)
            respondant.response_set.add(cost_response)
            respondant.save()