@@ -55,42 +55,49 @@ def valid_options(self) -> tuple:
5555 option_tuple += id ['type' ]
5656 return option_tuple
5757
58- def process_report (self , filename : str ):
59- """Function to process calculate and generate report of man hour saved .
58+ def compute_total_words (self , filename : str ) -> int :
59+ """Function to compute total words in a file .
6060 Args:
6161 filename (str): File to count the words
6262
6363 Returns:
64- Creates a report on estimated man hours/minutes saved.
64+ total_words (int): total words in file
6565 """
66+ total_words = 0
67+ word_length = 5
6668 try :
67- # Open a file read pointer as target_file
6869 with open (filename , encoding = "utf-8" ) as target_file :
6970 text_chunk = target_file .read ()
70-
71- # Words per minute
72- WPM = 75
73-
74- word_length = 5
75- total_words = 0
7671 for current_text in text_chunk :
7772 total_words += len (current_text )/ word_length
73+ except UnicodeDecodeError :
74+ sys .exit ("[-] Unable to read target file" )
75+ return math .ceil (total_words )
7876
79- total_words = math .ceil (total_words )
77+ def compute_reading_minutes (self , total_words : int ) -> int :
78+ # Words per minute
79+ WPM = 75
80+ return math .ceil (total_words / WPM )
8081
81- # Divide total words by words per minute read to get minutes and hour estimate.
82- reading_minutes = math .ceil (total_words / WPM )
83- reading_hours = math .floor (reading_minutes / 60 )
82+ def compute_reading_hours (self , reading_minutes : int ) -> int :
83+ return math .floor (reading_minutes / 60 )
8484
85- word_report = f"[+] Estimated total words : { total_words } "
86- minutes_saved = f"[+] Estimated total minutes saved : { reading_minutes } "
87- man_hours_saved = f"[+] Estimated total man hours saved : { reading_hours } "
85+ def process_report (self , filename : str ):
86+ """Function to process calculate and generate report of man hour saved.
87+ Args:
88+ filename (str): File to count the words
89+
90+ Returns:
91+ Creates a report on estimated man hours/minutes saved.
92+ """
93+ total_words = self .compute_total_words (filename )
94+ reading_minutes = self .compute_reading_minutes (total_words )
95+ reading_hours = self .compute_reading_hours (reading_minutes )
8896
89- print ( word_report )
90- print ( minutes_saved )
91- print ( man_hours_saved )
97+ word_report = f"[+] Estimated total words : { total_words } "
98+ minutes_saved = f"[+] Estimated total minutes saved : { reading_minutes } "
99+ man_hours_saved = f"[+] Estimated total man hours saved : { reading_hours } "
92100
93- except UnicodeDecodeError :
94- os .remove (f"manhour_saved_report_{ os .path .basename (filename )} " )
95- print ("[-] Removed incomplete report" )
96- sys .exit ("[-] Unable to read target file" )
101+ print (word_report )
102+ print (minutes_saved )
103+ print (man_hours_saved )
0 commit comments