Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could you modify my function in python for as this criteria below? The function that I deal with and should fix is display_menu(), cross_reference(files), map_numbers_to_names(numbers,

Could you modify my function in python for as this criteria below?

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedThe function that I deal with and should fix is "display_menu()", "cross_reference(files)", "map_numbers_to_names(numbers, filename)", "display_suspects(names)", and "main()

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Here is my code in Python. I also need to create "main()" function

image text in transcribedimage text in transcribed

- These files (owners , crime scene 1GZ, Gand G.) can be used as an example of how the file with owners mapped to phone numbers and the list of phone numbers from the crime scenes might look like. The one where we help the police (lab3_3_1.txt) \[ \begin{array}{|ll} \longleftrightarrow \text { 1ab3_3_1.txt } \\ 1 & 0709-12345 \\ 2 & 0708-12345 \\ 3 & 0708-23456 \\ 4 & 0709-34567 \\ 5 & 0703-23464 \\ 6 & 0708-56789 \end{array} \] The one where we help the police (lab3_3_2.txt) \begin{tabular}{|cc} \hline 070912345 \\ 2 & 070812345 \\ 3 & 070845678 \\ 4 & 070934567 \\ 5 & 070323464 \\ 6 & 070856789 \\ 7 & 070956789 \end{tabular} The one where we help the police (lab3_3_3.txt) \[ \begin{array}{|ll} \hline \text { lab3_3_3.txt } \\ 1 & 0708-45678 \\ 2 & 0709-34567 \\ 3 & 0703-23464 \\ 4 & 0708-56789 \\ 5 & 0709-56789 \\ 6 & 0709-23456 \\ 7 & 0708-34523 \end{array} \] Task description companies to provide lists of all mobile phones that were in the area where the crime was committed around the time when it was committed. If there is only one crime scene this is not a big problem but if there are several crime scenes then the task of cross referencing the lists gets quite tedious. To combat this the local police department has decided to automate the process by creating a script that automatically does most of the work for them. The script shall work as follows: (Step 1) Start the script (Step 2) Provide one or more paths to files with phone numbers (Step 3) The script finds out what phone numbers occur in all files (Step 4) The script looks up who owns the phone numbers found (Step 5) The script displays the found names To break it all down a little bit further this is what should happen during each step. 1. When starting the script, a path to a file that contains the mapping between name and number shall be given as a command line argument shall contain a pickled dictionary on the following format \{'0709-12345': 'Anna Karlsson'\}. 2. To be able to provide an arbitrary number of files a menu is needed. The menu shall have the following options: 1 . Add file and 2 . Calculate. paths added shall be saved in a list for later use. 3. This step is part of the menu option 2. Calculate. The script shall cross reference the numbers in all the files provided and create a Set with the ones that occur in all files. The files with the phone numbers store one phone number per line and is saved as a regule 4. This step is part of the menu option 2. Calculate. Using the Set of found numbers the script looks up the owner's names using the file sent as a command line argument. The names shall be saved in a list. 5. All the found names located in the set from Step 4 is displayed on the screen. The student must implement the following functions: cross_reference(files) The parameter files shall be a list of filenames (full path). The files shall be files containing one phone number per line. The function shall create, and return, a Set containing all the phone numbers that occurs in all files. If given an invalid filename the function shall raise a FileNotFoundException. map_numbers_to_names(numbers, filename) This function shall match each number from the Set numbers to a name and store the names in a list. To accomplish this, the function shall use a dictionary that is loaded (using pickle) from the file filename. The dictionary shall use the format \{'0709-12345': 'Anna Karlsson'\}. If a number can not be found in the dictionary it shall be listed as Unknown with the phone number attached, like can be seen in this example: Unknown (0709- 11111). The function shall return the list with the names and/or unknown tags. If given an invalid filename the function shall raise a FileNotFoundException. display_suspects(names) As the name of the function suggests this function shall display the names of all suspects sent to the function as a list of strings. The format shall be exactly as shown here: The following persons was present on all crime scenes: Max 0lsson Zara Walthersson Unknown (8703-23464) If the list sent as a parameter is empty the following message shall be shown: The following persons was present on all crime scenes: No matches main() This function shall have a loop that displayed the menu and handles the user input. Depending on the input from the user the function shall either read more filenames or try to find the suspects and print their names using the file from the command line argument for the mapping between numbers and names. Besides having the "main loop" this function shall also be responsible for the error handling in the script and print the error message below if the file given as command line arguments or the files specified while running the script are not valid if \( \underset{\text { main }()}{\text { name }}=={ }^{\prime} \ldots_{\text {main__ }} \) ': Code Structure Options 0% No Summary Score Pass >1 Testing the display_menu function >2 Testing the cross_reference function > Testing the map_numbers_to_names function >4 Testing the display_suspects function test_display_menu Validate that the function prints the meny to the screen TypeError: display_menu() missing 1 required positional argument: 'filename' 1. E TypeError: display_menu() missing 1 required positional argument: 'filename' V 2 Testing the cross_reference function 0/1 Results Output pytest (0/3) test_cross_reference Calling the function using an incorrect filename argument shall result in X test_cross_reference Calling the function with a valid list of filenames shall return a set) with X an FileNotFoundError being raised (have the try-except in main) the phone numbers that occures in all files TypeError: cross_reference() missing 1 required positional argument: TypeError: cross_reference() missing 1 required positional argument: ' common_numbers' ' common_numbers ' 1. E TypeError: cross_reference() missing 1 required positional argument: 'common_numbers' 1. E TypeError: cross_reference() missing 1 required positional argument: 'common_numbers' test_cross_reference Check that the function returns an empty set if there are no matches X TypeError: cross_reference() missing 1 required positional argument: 'common_numbers' 1. E TypeError: cross_reference() missing 1 required positional argument: 'common_numbers' test_display_suspects If the function is called with an empty list the output should be header X test_display_suspects If the function is called with a non-empty list the output should be + "No matches" header + names/unknown TypeError: display_suspects() takes positional arguments but 1 was given TypeError: display_suspects() takes positional arguments but 1 was given 1. E TypeError: display_suspects() takes positional arguments but 1 was given 1. E TypeError: display_suspects() takes positional arguments but 1 was given Results Output pytest (0/3) test_map_numbers_to_names Calling the function using an incorrect filename argument shall test_map_numbers_to_names Check that the function returns the corresponding name given a result in an FileNotFoundError being raised (have the try-except in main) number existing in the unpickled dictionary loaded from the supplied filename TypeError: cross_reference() missing 1 required positional argument: AttributeError: module 'Lab3_3' has no attribute 'map_numbers_to_names' 'common_numbers' 1. E AttributeError: module 'Lab3_3' has no attribute 'map_numbers_to_names' 1. E TypeError: cross_reference() missing 1 required positional argument: 'common_numbers' test_map_numbers_to_names Check that the function returns Unknown (XYZ) given a number X that does NOT exist in the unpickled dictionary loaded from the supplied filename AttributeError: module 'Lab3_3' has no attribute 'map_numbers_to_names' 1. E AttributeError: module 'Lab3_3' has no attribute 'map_numbers_to_names' - These files (owners , crime scene 1GZ, Gand G.) can be used as an example of how the file with owners mapped to phone numbers and the list of phone numbers from the crime scenes might look like. The one where we help the police (lab3_3_1.txt) \[ \begin{array}{|ll} \longleftrightarrow \text { 1ab3_3_1.txt } \\ 1 & 0709-12345 \\ 2 & 0708-12345 \\ 3 & 0708-23456 \\ 4 & 0709-34567 \\ 5 & 0703-23464 \\ 6 & 0708-56789 \end{array} \] The one where we help the police (lab3_3_2.txt) \begin{tabular}{|cc} \hline 070912345 \\ 2 & 070812345 \\ 3 & 070845678 \\ 4 & 070934567 \\ 5 & 070323464 \\ 6 & 070856789 \\ 7 & 070956789 \end{tabular} The one where we help the police (lab3_3_3.txt) \[ \begin{array}{|ll} \hline \text { lab3_3_3.txt } \\ 1 & 0708-45678 \\ 2 & 0709-34567 \\ 3 & 0703-23464 \\ 4 & 0708-56789 \\ 5 & 0709-56789 \\ 6 & 0709-23456 \\ 7 & 0708-34523 \end{array} \] Task description companies to provide lists of all mobile phones that were in the area where the crime was committed around the time when it was committed. If there is only one crime scene this is not a big problem but if there are several crime scenes then the task of cross referencing the lists gets quite tedious. To combat this the local police department has decided to automate the process by creating a script that automatically does most of the work for them. The script shall work as follows: (Step 1) Start the script (Step 2) Provide one or more paths to files with phone numbers (Step 3) The script finds out what phone numbers occur in all files (Step 4) The script looks up who owns the phone numbers found (Step 5) The script displays the found names To break it all down a little bit further this is what should happen during each step. 1. When starting the script, a path to a file that contains the mapping between name and number shall be given as a command line argument shall contain a pickled dictionary on the following format \{'0709-12345': 'Anna Karlsson'\}. 2. To be able to provide an arbitrary number of files a menu is needed. The menu shall have the following options: 1 . Add file and 2 . Calculate. paths added shall be saved in a list for later use. 3. This step is part of the menu option 2. Calculate. The script shall cross reference the numbers in all the files provided and create a Set with the ones that occur in all files. The files with the phone numbers store one phone number per line and is saved as a regule 4. This step is part of the menu option 2. Calculate. Using the Set of found numbers the script looks up the owner's names using the file sent as a command line argument. The names shall be saved in a list. 5. All the found names located in the set from Step 4 is displayed on the screen. The student must implement the following functions: cross_reference(files) The parameter files shall be a list of filenames (full path). The files shall be files containing one phone number per line. The function shall create, and return, a Set containing all the phone numbers that occurs in all files. If given an invalid filename the function shall raise a FileNotFoundException. map_numbers_to_names(numbers, filename) This function shall match each number from the Set numbers to a name and store the names in a list. To accomplish this, the function shall use a dictionary that is loaded (using pickle) from the file filename. The dictionary shall use the format \{'0709-12345': 'Anna Karlsson'\}. If a number can not be found in the dictionary it shall be listed as Unknown with the phone number attached, like can be seen in this example: Unknown (0709- 11111). The function shall return the list with the names and/or unknown tags. If given an invalid filename the function shall raise a FileNotFoundException. display_suspects(names) As the name of the function suggests this function shall display the names of all suspects sent to the function as a list of strings. The format shall be exactly as shown here: The following persons was present on all crime scenes: Max 0lsson Zara Walthersson Unknown (8703-23464) If the list sent as a parameter is empty the following message shall be shown: The following persons was present on all crime scenes: No matches main() This function shall have a loop that displayed the menu and handles the user input. Depending on the input from the user the function shall either read more filenames or try to find the suspects and print their names using the file from the command line argument for the mapping between numbers and names. Besides having the "main loop" this function shall also be responsible for the error handling in the script and print the error message below if the file given as command line arguments or the files specified while running the script are not valid if \( \underset{\text { main }()}{\text { name }}=={ }^{\prime} \ldots_{\text {main__ }} \) ': Code Structure Options 0% No Summary Score Pass >1 Testing the display_menu function >2 Testing the cross_reference function > Testing the map_numbers_to_names function >4 Testing the display_suspects function test_display_menu Validate that the function prints the meny to the screen TypeError: display_menu() missing 1 required positional argument: 'filename' 1. E TypeError: display_menu() missing 1 required positional argument: 'filename' V 2 Testing the cross_reference function 0/1 Results Output pytest (0/3) test_cross_reference Calling the function using an incorrect filename argument shall result in X test_cross_reference Calling the function with a valid list of filenames shall return a set) with X an FileNotFoundError being raised (have the try-except in main) the phone numbers that occures in all files TypeError: cross_reference() missing 1 required positional argument: TypeError: cross_reference() missing 1 required positional argument: ' common_numbers' ' common_numbers ' 1. E TypeError: cross_reference() missing 1 required positional argument: 'common_numbers' 1. E TypeError: cross_reference() missing 1 required positional argument: 'common_numbers' test_cross_reference Check that the function returns an empty set if there are no matches X TypeError: cross_reference() missing 1 required positional argument: 'common_numbers' 1. E TypeError: cross_reference() missing 1 required positional argument: 'common_numbers' test_display_suspects If the function is called with an empty list the output should be header X test_display_suspects If the function is called with a non-empty list the output should be + "No matches" header + names/unknown TypeError: display_suspects() takes positional arguments but 1 was given TypeError: display_suspects() takes positional arguments but 1 was given 1. E TypeError: display_suspects() takes positional arguments but 1 was given 1. E TypeError: display_suspects() takes positional arguments but 1 was given Results Output pytest (0/3) test_map_numbers_to_names Calling the function using an incorrect filename argument shall test_map_numbers_to_names Check that the function returns the corresponding name given a result in an FileNotFoundError being raised (have the try-except in main) number existing in the unpickled dictionary loaded from the supplied filename TypeError: cross_reference() missing 1 required positional argument: AttributeError: module 'Lab3_3' has no attribute 'map_numbers_to_names' 'common_numbers' 1. E AttributeError: module 'Lab3_3' has no attribute 'map_numbers_to_names' 1. E TypeError: cross_reference() missing 1 required positional argument: 'common_numbers' test_map_numbers_to_names Check that the function returns Unknown (XYZ) given a number X that does NOT exist in the unpickled dictionary loaded from the supplied filename AttributeError: module 'Lab3_3' has no attribute 'map_numbers_to_names' 1. E AttributeError: module 'Lab3_3' has no attribute 'map_numbers_to_names

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions