Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #38 from dpriskorn/remove_picked_subject_from_list
Browse files Browse the repository at this point in the history
Improve handling of results
  • Loading branch information
dpriskorn authored Feb 9, 2022
2 parents 4e370a1 + ee453fc commit 934636d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
9 changes: 6 additions & 3 deletions src/helpers/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,12 @@ def print_finished():
def print_job_statistics(jobs: List[BatchJob] = None):
if jobs is None:
raise ValueError("jobs was None")
console.print(f"The jobs list now contain a total of {len(jobs)} "
f"jobs with a total of "
f"{sum(len(job.items.list) for job in jobs)} items")
if len(jobs) == 0:
console.print("The jobs list is empty")
else:
console.print(f"The jobs list now contain a total of {len(jobs)} "
f"jobs with a total of "
f"{sum(len(job.items.list) for job in jobs)} items")


def ask_discard_existing_job_pickle():
Expand Down
37 changes: 22 additions & 15 deletions src/helpers/jobs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import argparse
import logging
import random
from datetime import datetime
from typing import Union, List, TYPE_CHECKING
Expand Down Expand Up @@ -145,7 +146,7 @@ def get_validated_main_subjects_as_jobs(
jobs: List[BatchJob] = None
) -> List[BatchJob]:
"""This function randomly picks a subject and present it for validation"""
# logger = logging.getLogger(__name__)
logger = logging.getLogger(__name__)
if jobs is None:
raise ValueError("jobs was None")
if not isinstance(jobs, List):
Expand All @@ -154,33 +155,39 @@ def get_validated_main_subjects_as_jobs(
raise ValueError("args was None")
if main_subjects is None:
raise ValueError("main subjects was None")
subjects_not_picked_yet = main_subjects
task: Task = select_task()
if task is None:
raise ValueError("Got no task")
if not isinstance(task, Task):
raise ValueError("task was not a Task object")
# TODO implement better check for duplicates to avoid wasting resources
picked_before = []
while True:
console.print(f"Picking a random main subject")
qid = random.choice(main_subjects)
if qid not in picked_before:
# Check if we have any subjects left in the list
if len(subjects_not_picked_yet) > 0:
console.print(f"Picking a random main subject")
qid = random.choice(subjects_not_picked_yet)
subjects_not_picked_yet.remove(qid)
job = process_qid_into_job(qid=qid,
# The scientific article task is hardcoded for now
task=task,
args=args,
confirmation=args.no_confirmation)
if job is not None:
jobs.append(job)
picked_before.append(qid)
logger.debug(f"joblist now has {len(jobs)} jobs")
print_job_statistics(jobs=jobs)
if (
args.no_ask_match_more_limit is None or
args.no_ask_match_more_limit < sum(len(job.items.list) for job in jobs)
):
answer = ask_yes_no_question("Match one more?")
if not answer:
break
if len(subjects_not_picked_yet) > 0:
if (
args.no_ask_match_more_limit is None or
args.no_ask_match_more_limit < sum(len(job.items.list) for job in jobs)
):
answer_was_yes = ask_yes_no_question("Match one more?")
if not answer_was_yes:
break
else:
console.print("No more subjects in the list.")
break
else:
console.print("Skipping already picked qid")
console.print("No more subjects in the list. Exiting.")
break
return jobs

0 comments on commit 934636d

Please sign in to comment.