Adding readplan_generator for creating a Bible reading plan

This commit is contained in:
Jonathan Herrewijnen 2024-09-08 23:13:28 +02:00
parent 3680b94d17
commit 5d9cadc0ff
5 changed files with 86 additions and 3 deletions

9
.vscode/launch.json vendored
View File

@ -19,6 +19,15 @@
], ],
"console": "integratedTerminal", "console": "integratedTerminal",
"justMyCode": false "justMyCode": false
},
{
"name": "C-ReadPlanGenerator",
"type": "debugpy",
"request": "launch",
"program": "herrewebpy/christianity/readplan_generator.py",
"args": [],
"console": "integratedTerminal",
"justMyCode": false
} }
] ]
} }

View File

@ -1,5 +1,8 @@
#from herrewebpy.bioinformatics import sequence_alignment #from herrewebpy.bioinformatics import sequence_alignment
#sequence_alignment.SequenceAlignment(['aa', 'bb', 'cc'],['bb','aa','cc'], ['1','2','3'], ['1','2','3']) #sequence_alignment.SequenceAlignment(['aa', 'bb', 'cc'],['bb','aa','cc'], ['1','2','3'], ['1','2','3'])
from herrewebpy.firmware_forensics import function_extractor #from herrewebpy.firmware_forensics import function_extractor
function_extractor.FunctionExtractor('', 'ARM_AARCH64') #function_extractor.FunctionExtractor('', 'ARM_AARCH64')
from herrewebpy.christianity import readplan_generator
readplan_generator.generate_readplan()

View File

@ -0,0 +1 @@
from . import *

View File

@ -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)

View File

@ -7,4 +7,5 @@ scikit-learn
capstone capstone
keystone keystone
plotly plotly
BioPython BioPython
pythonbible