Beispiel #1
0
 def test_has_point_values(self):
     location = LocationBuilder(self.organization).with_long_lat(
         a_float(), a_float()).create()
     url = '/v1/locations/'
     response = self.client.get(url)
     self.assertEqual(response.json()[0]['latitude'], location.point.x)
     self.assertEqual(response.json()[0]['longitude'], location.point.y)
 def __init__(self, organization):
     self.location_id = a_string()
     self.organization = organization
     self.name = a_string()
     self.latitude = a_float()
     self.longitude = a_float()
     self.description = a_string()
    def test_saves_all_scores_if_number_of_scores_to_save_is_large(self):
        scores = scipy.sparse.csr_matrix([[a_float() for i in range(6)]
                                          for j in range(6)])

        too_many_records_to_save = 2000
        save_task_service_similarity_scores(self.three_task_ids,
                                            self.three_service_ids, scores,
                                            too_many_records_to_save)

        scores_saved_in_all = 3 * 3
        self.assertEqual(TaskServiceSimilarityScore.objects.count(),
                         scores_saved_in_all)
    def test_saves_required_number_of_records_for_each_row(self):
        ids = [a_string() for i in range(5)]
        create_tasks(ids)
        scores = scipy.sparse.csr_matrix([[a_float() for i in range(5)]
                                          for j in range(5)])

        scores_to_save_per_row = 2
        save_task_similarities(ids, scores, scores_to_save_per_row)

        scores_saved_in_all = 5 * 2
        self.assertEqual(TaskSimilarityScore.objects.count(),
                         scores_saved_in_all)
    def test_deletes_existing_records(self):
        task_id = a_string()
        Task(id=task_id, name=a_string(), description=a_string()).save()
        service = ServiceBuilder(self.organization).create()
        record = TaskServiceSimilarityScore(task_id=task_id,
                                            service=service,
                                            similarity_score=a_float())
        record.save()

        save_task_service_similarity_scores([], [], [], 0)

        self.assertEqual(TaskServiceSimilarityScore.objects.count(), 0)
    def test_saves_required_number_of_records_for_each_row(self):
        scores = scipy.sparse.csr_matrix([[a_float() for i in range(6)]
                                          for j in range(6)])

        scores_to_save_per_row = 2
        save_task_service_similarity_scores(self.three_task_ids,
                                            self.three_service_ids, scores,
                                            scores_to_save_per_row)

        scores_saved_in_all = 3 * 2
        self.assertEqual(TaskServiceSimilarityScore.objects.count(),
                         scores_saved_in_all)
    def test_deletes_existing_records(self):
        first_task_id = a_string()
        second_task_id = a_string()
        create_tasks([first_task_id, second_task_id])
        record = TaskSimilarityScore(first_task_id=first_task_id,
                                     second_task_id=second_task_id,
                                     similarity_score=a_float())
        record.save()

        save_task_similarities([], [], 0)

        self.assertEqual(TaskSimilarityScore.objects.count(), 0)
Beispiel #8
0
    def test_can_create_row(self):
        first_id = a_string()
        second_id = a_string()
        score = a_float()
        create_tasks([first_id, second_id])
        score_record = TaskSimilarityScore(first_task_id=first_id,
                                           second_task_id=second_id,
                                           similarity_score=score)
        score_record_from_db = validate_save_and_reload(score_record)

        self.assertEqual(score_record_from_db.first_task_id, first_id)
        self.assertEqual(score_record_from_db.second_task_id, second_id)
        self.assertAlmostEqual(score_record_from_db.similarity_score, score)
    def test_saves_all_off_diagonal_scores_if_number_of_scores_to_save_is_large(
            self):
        ids = [a_string() for i in range(5)]
        create_tasks(ids)
        scores = scipy.sparse.csr_matrix([[a_float() for i in range(5)]
                                          for j in range(5)])

        too_many_records_to_save = 2000
        save_task_similarities(ids, scores, too_many_records_to_save)

        number_of_off_diagonal_elements = 5 * 4
        self.assertEqual(TaskSimilarityScore.objects.count(),
                         number_of_off_diagonal_elements)
Beispiel #10
0
    def test_can_create_row(self):
        organization = OrganizationBuilder().create()
        service = ServiceBuilder(organization).create()
        task_id = a_string()
        score = a_float()

        create_tasks([task_id])
        score_record = TaskServiceSimilarityScore(task_id=task_id,
                                                  service=service,
                                                  similarity_score=score)
        score_record_from_db = validate_save_and_reload(score_record)

        self.assertEqual(score_record_from_db.task_id, task_id)
        self.assertEqual(score_record_from_db.service_id, service.id)
        self.assertAlmostEqual(score_record_from_db.similarity_score, score)
Beispiel #11
0
    def test_does_not_return_unrelated_services(self):
        task_id = 'the-task-id'
        create_tasks([task_id])
        related_service = ServiceBuilder(self.organization).with_location(
            self.location).create()
        self.set_service_similarity_score(task_id, related_service.id,
                                          a_float())

        unrelated_service = ServiceBuilder(self.organization).with_location(
            self.location).create()

        url = '/v1/services_at_location/?related_to_task={0}'.format(task_id)
        json = self.client.get(url).json()

        self.assertEqual(len(json), 1)
        self.assertEqual(json[0]['service']['name'], related_service.name)
Beispiel #12
0
    def setUp(self):
        translation.activate('en')
        self.task_id = a_string()

        self.task = Task(id=self.task_id,
                         name=a_string(),
                         description=a_string())
        self.task.save()

        organization = OrganizationBuilder().create()
        self.service = ServiceBuilder(organization).create()

        self.similarity_score = a_float()
        TaskServiceSimilarityScore(
            task=self.task,
            service=self.service,
            similarity_score=self.similarity_score).save()
Beispiel #13
0
    def setUp(self):
        translation.activate('en')
        self.first_task_id = a_string()

        self.second_task_id = a_string()
        self.second_task_name = a_string()
        self.second_task_description = a_string()

        self.first_task = Task(id=self.first_task_id,
                               name=a_string(),
                               description=a_string())
        self.first_task.save()

        self.second_task = Task(id=self.second_task_id,
                                name=self.second_task_name,
                                description=self.second_task_description)
        self.second_task.save()

        self.similarity_score = a_float()
        TaskSimilarityScore(first_task=self.first_task,
                            second_task=self.second_task,
                            similarity_score=self.similarity_score).save()
Beispiel #14
0
 def test_can_create_and_retrieve_point(self):
     location = LocationBuilder(self.organization).with_long_lat(
         a_float(), a_float()).build()
     location_from_db = validate_save_and_reload(location)
     self.assertEqual(location_from_db.point, location.point)