From 5d9cadc0ffc5e792250a9dc297f4c97a12a2a106 Mon Sep 17 00:00:00 2001 From: Jonathan Herrewijnen Date: Sun, 8 Sep 2024 23:13:28 +0200 Subject: [PATCH] Adding readplan_generator for creating a Bible reading plan --- .vscode/launch.json | 9 +++ debug.py | 7 +- herrewebpy/christianity/__init__.py | 1 + herrewebpy/christianity/readplan_generator.py | 69 +++++++++++++++++++ requirements.txt | 3 +- 5 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 herrewebpy/christianity/__init__.py create mode 100644 herrewebpy/christianity/readplan_generator.py diff --git a/.vscode/launch.json b/.vscode/launch.json index 71f426b..2fd7972 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -19,6 +19,15 @@ ], "console": "integratedTerminal", "justMyCode": false + }, + { + "name": "C-ReadPlanGenerator", + "type": "debugpy", + "request": "launch", + "program": "herrewebpy/christianity/readplan_generator.py", + "args": [], + "console": "integratedTerminal", + "justMyCode": false } ] } \ No newline at end of file diff --git a/debug.py b/debug.py index 555e15d..5d10591 100644 --- a/debug.py +++ b/debug.py @@ -1,5 +1,8 @@ #from herrewebpy.bioinformatics import sequence_alignment #sequence_alignment.SequenceAlignment(['aa', 'bb', 'cc'],['bb','aa','cc'], ['1','2','3'], ['1','2','3']) -from herrewebpy.firmware_forensics import function_extractor -function_extractor.FunctionExtractor('', 'ARM_AARCH64') \ No newline at end of file +#from herrewebpy.firmware_forensics import function_extractor +#function_extractor.FunctionExtractor('', 'ARM_AARCH64') + +from herrewebpy.christianity import readplan_generator +readplan_generator.generate_readplan() \ No newline at end of file diff --git a/herrewebpy/christianity/__init__.py b/herrewebpy/christianity/__init__.py new file mode 100644 index 0000000..b974282 --- /dev/null +++ b/herrewebpy/christianity/__init__.py @@ -0,0 +1 @@ +from . import * \ No newline at end of file diff --git a/herrewebpy/christianity/readplan_generator.py b/herrewebpy/christianity/readplan_generator.py new file mode 100644 index 0000000..bdda400 --- /dev/null +++ b/herrewebpy/christianity/readplan_generator.py @@ -0,0 +1,69 @@ +import pythonbible as bible +import random, argparse, datetime +import pandas as pd + +def generate_readplan(start_date): + book_groups = bible.BOOK_GROUPS + reading_list = [] + + # Drop OLD TESTAMENT and NEW TESTAMENT from book_groups + all_books = list(set(book_groups['Old Testament'])) + list(set(book_groups['New Testament'])) + book_groups.pop('Old Testament', 'New Testament') + + # Randomly order book groups + book_groups = dict(sorted(book_groups.items(), key=lambda x: random.random())) + + for group in book_groups.keys(): + reading_list.extend(book_groups[group]) + reading_list = list(set(reading_list)) + + # Find missing books in reading_list + missing_books = list(set(all_books) - set(reading_list)) + + # Randomly order missing books + missing_books = sorted(missing_books, key=lambda x: random.random()) + + # Insert missing books in reading_list + for book in missing_books: + reading_list.insert(random.randint(0, len(reading_list)), book) + + total_chapters = sum([bible.get_number_of_chapters(reading_list[i]) for i in range(len(reading_list))]) + chapters_per_day = total_chapters // 365 + 1 + + df = pd.DataFrame(columns=['Book', 'Chapters']) + for book in reading_list: + df = pd.concat([df, pd.DataFrame({'Book': [book.title], 'Chapters': [bible.get_number_of_chapters(book)]})]) + + # Generate a reading plan, by reading 4 chapters per day, until the reading list is empty. Read 4 chapters per day + reading_plan_df = pd.DataFrame(columns=['Date', 'Book', 'Start Chapter', 'End Chapter']) + date = pd.Timestamp(start_date) # Start date + + for row in df.iterrows(): + book = row[1]['Book'] + chapters = row[1]['Chapters'] + start_chapter = 1 + end_chapter = min(chapters, start_chapter + chapters_per_day - 1) + + while start_chapter <= chapters: + reading_plan_df = pd.concat([reading_plan_df, pd.DataFrame({'Date': [date], 'Book': [book], 'Start Chapter': [start_chapter], 'End Chapter': [end_chapter]})]) + date += pd.Timedelta(days=1) + start_chapter = end_chapter + 1 + end_chapter = min(chapters, start_chapter + chapters_per_day - 1) + + # Set date as index + reading_plan_df.set_index('Date', inplace=True) + + return reading_plan_df + + +if __name__ == '__main__': + # Add start date as argument + parser = argparse.ArgumentParser() + parser.add_argument('--start_date', help='Start date of the reading plan (YYYY-MM-DD)', required=False, type=str) + args = parser.parse_args() + + if not args.start_date: + args.start_date = datetime.datetime.now().strftime('%Y-%m-%d') + + reading_list = generate_readplan(start_date=args.start_date) + reading_list.to_csv(f'reading_plan_{args.start_date}.csv', index=True) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 7a8035d..bd78d78 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,4 +7,5 @@ scikit-learn capstone keystone plotly -BioPython \ No newline at end of file +BioPython +pythonbible \ No newline at end of file