def test_create_challenge(self, mock_request, api_instance=api):
     test_challenge_model = maproulette.ChallengeModel(
         name='Test_Challenge_Name',
         instruction='Do something',
         description='This is a test challenge',
         overpassQL=test_overpassQL_query)
     mock_request.return_value.status_code = '200'
     response = api_instance.create_challenge(test_challenge_model)
     self.assertEqual(response['status'], '200')
Пример #2
0
 def test_create_challenge(self, mock_request, api_instance=api):
     test_challenge_model = maproulette.ChallengeModel(name='Test_Challenge_Name',
                                                       instruction='Do something',
                                                       description='This is a test challenge',
                                                       overpassQL=test_overpassQL_query)
     api_instance.create_challenge(test_challenge_model)
     mock_request.assert_called_once_with(
         f'{self.url}/challenge',
         json=json.loads(create_challenge_output),
         params=None)
 def test_create_virtual_challenge(self, mock_request, api_instance=api):
     # TODO: add model for virtual challenge to aid in posting
     test_challenge_model = maproulette.ChallengeModel(
         name='Test_Challenge_Name',
         instruction='Do something',
         description='This is a test challenge',
         overpassQL=test_overpassQL_query)
     api_instance.create_virtual_challenge(test_challenge_model)
     mock_request.assert_called_once_with(f'{self.url}/virtualchallenge',
                                          json=test_challenge_model,
                                          params=None)
 def test_add_challenge_to_project(self, mock_request, api_instance=api):
     test_virtual_project_model = maproulette.ProjectModel(
         name='Test Virtual Project Name', id=1234)
     test_challenge_model = maproulette.ChallengeModel(
         name='Test Challenge Name', id=246)
     test_virtual_project_id = test_virtual_project_model.id
     test_challenge_id = test_challenge_model.id
     mock_request.return_value.status_code = '200'
     response = api_instance.add_challenge_to_project(
         test_virtual_project_id, test_challenge_id)
     self.assertEqual(response['status'], '200')
 def test_add_challenge_to_project(self, mock_request, api_instance=api):
     test_virtual_project_model = maproulette.ProjectModel(
         name='Test Virtual Project Name', id=1234)
     test_challenge_model = maproulette.ChallengeModel(
         name='Test Challenge Name', id=246)
     test_virtual_project_id = test_virtual_project_model.id
     test_challenge_id = test_challenge_model.id
     api_instance.add_challenge_to_project(test_virtual_project_id,
                                           test_challenge_id)
     mock_request.assert_called_once_with(
         f'{self.url}/project/{test_virtual_project_id}/challenge/{test_challenge_id}/add',
         json=None,
         params=None)
project_id = '2491'
print(json.dumps(api.get_challenge_by_name(project_id=project_id,
                                           challenge_name=challenge_name), indent=4, sort_keys=True))

# We can also use challenges' set tags to retrieve them:
challenge_tags = 'River'
print(json.dumps(api.get_challenges_by_tags(challenge_tags=challenge_tags), indent=4, sort_keys=True))

# We can access challenge statistics as well:
print(json.dumps(api.get_challenge_statistics_by_id(challenge_id)))

# Accessing a challenge's tasks is easy too. Specify the ID of the challenge you want:
print(json.dumps(api.get_challenge_tasks(challenge_id), indent=4, sort_keys=True))

# In order to create a new challenge, we can make our lives easier by using the Challenge Model
challenge_data = maproulette.ChallengeModel(name='Test_Challenge_Name')

# Adding example description
challenge_data.description = "This is a test challenge"

# Adding required instruction
challenge_data.instruction = "Do something"

# Let's create a basic rule to classify features with tags 'highway' = 'footway' to be high priority
rule_1 = maproulette.PriorityRule(priority_value='highway.footway',
                                  priority_type=maproulette.priority_rule.Types.STRING,
                                  priority_operator=maproulette.priority_rule.StringOperators.EQUAL)

# Create a formal priority rule for the challenge
challenge_data.high_priority_rule = maproulette.PriorityRuleModel(condition=maproulette.priority_rule.Conditions.OR,
                                                                  rules=rule_1
Пример #7
0
for cat_id in range(59):
    chal_file = open("cat_id_%d.geojsonl" % cat_id)
    cat_name = json.loads(
        chal_file.readline())["features"][0]["properties"][CATEGORY]
    chal_file.seek(0)
    if cat_name not in presets:
        cat_name = "Other"
    if cat_name == "Other, please specify":
        print("Run add-other-category.py on cat_id_%d.geojsonl first" % cat_id)
        continue
    chal_name = "SDP import: " + cat_name
    if chal_name in challengeNameToData:
        data = challengeNameToData[chal_name]
        chal = maproulette.ChallengeModel(name=data["name"],
                                          id=data["id"],
                                          parent=proj.id)
        existing = True
        print("Using existing challenge ID", chal.id)
    else:
        chal = maproulette.ChallengeModel(name=chal_name, parent=proj.id)
        existing = False
        print("Creating new challenge", repr(chal_name))

    if not existing:
        chal.description = proj.description
        chal.instruction = """Follow the directions [here](https://docs.google.com/document/d/1vnR8xpxZlOPvMibsPX0TqFy99k_BaFs5aiszIDedgPo/preview). In short: Verify the business address and location (skip addresses that are the owner's house), then add a point for that business using the provided name and address."""
        if cat_name in presets:
            chal.instruction += " For this type of business we recommend the presets " + presets[
                cat_name] + "."
        chal.enabled = True