import logging


def get_completed_assignments(project, workers):
    """
    Get's the completed assignments
    :param project: (Project) The project to use
    :param workers: (List<String>) The list of worker usernames to get completed assignments for
    :return: List<Assignment> The list of completed assignments
    """
    if not workers:
        workers = project.workers.search()

    worker_query = "{} in ({})".format(project._worker_schema.user_id,
                                       ",".join(["'{}'".format(w) for w in workers]))
    worker_ids = [w.object_id for w in
                  project.workers.search(where=worker_query)]
    if not worker_ids:
        logging.getLogger().info("No assignments completed by specified workers")
        return []
    logging.getLogger().info("Querying source features...")
    assignment_query = "{} in ({}) AND {} is not NULL".format(project._assignment_schema.worker_id,
                                                              ",".join(["'{}'".format(w) for w in worker_ids]),
                                                              project._assignment_schema.completed_date)
    completed_assignments = project.assignments.search(assignment_query)
    return completed_assignments