Skip to content
This repository has been archived by the owner on Feb 13, 2022. It is now read-only.

Commit

Permalink
equality for tasks, almost done with reconcile function
Browse files Browse the repository at this point in the history
  • Loading branch information
mvexel committed Jul 20, 2015
1 parent 1240d16 commit 95e4fa5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
4 changes: 4 additions & 0 deletions maproulette/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ def as_payload(self, with_identifier=False):
payload['identifier'] = self.identifier
return payload

def __eq__(self, other):
return (isinstance(other, self.__class__)
and self.__dict__ == other.__dict__)

@classmethod
def from_server(cls, server, slug):
"""Retrieve a task from the server"""
Expand Down
23 changes: 19 additions & 4 deletions maproulette/taskcollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,35 @@ def reconcile(self, server):
if not self.challenge.exists(server):
raise Exception('Challenge does not exist on server')
existing = MapRouletteTaskCollection.from_server(server, self.challenge)
same = []
new = []
changed = []
deleted = []
for task in self.tasks:
if task.identifier in [task.identifier for task in existing.tasks]:
print 'exists'
if task.identifier in [existing_task.identifier for existing_task in existing.tasks]:
if task == existing.get_by_identifier(task.identifier):
same.append(task)
else:
changed.append(task)
else:
print 'new'
new.append(task)
for task in existing.tasks:
if task.identifier not in [task.identifier for task in self.tasks]:
print 'delete'
deleted.append(task)
print '\nsame: {same}\nnew: {new}\nchanged: {changed}\ndeleted: {deleted}'.format(
same=len(same),
new=len(new),
changed=len(changed),
deleted=len(deleted))


def add(self, server):
"""Add task colleciton to the Collection."""
self.tasks.append(task)

def get_by_identifier(self, identifier):
return next((task for task in self.tasks if task.identifier == identifier), None)

def as_payload(self):
payload = [
task.as_payload(with_identifier=True)
Expand Down
3 changes: 3 additions & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ def test_010_reconcile_task_collections(self):
challenge=challenge,
identifier='task-{}'.format(uuid.uuid4()),
geometries=self.__random_point()))
# and finally change one task so it appears 'updated'
task_collection.tasks[0].geometries = self.__random_point()
task_collection.tasks[0].status = 'updated'
task_collection.reconcile(self.server)

def __random_point(self):
Expand Down

0 comments on commit 95e4fa5

Please sign in to comment.