Needs to be in Python

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Needs to be in Python

Post by answerhappygod »

Needs to be in Python
Needs To Be In Python 1
Needs To Be In Python 1 (150.08 KiB) Viewed 21 times
Functional Requirements/Specifications You need to create two program files: doses.py; analyze_doses.py. Each of these files will write to another file: ● doses.py writes to doses.csv; analyze_doses.py writes to vaccine_stats.txt. All of the above files are described in detail below. A General Note on Reading Files When you need to read .csv files into your program, you will use the csv module. Documentation can be found here: https://docs.python.org/3/library/csv.html. This module is made use of in section 8.7 of zyBooks and in the labs for Chapter 8 of zyBooks. You can use the reader method from the csv module to read the file into your program. It may take some playing around with to get the data structures working properly. You will likely want to use quite a few print() statements for debugging while you work. The doses.py File This file will contain two functions: Function Name: main() ● This function prompts the user to enter a .csv file to read (e.g., doses_data_mar_30.csv). This file contains vaccination information. The function should read the file's contents into a dictionary of lists. Each list in the dictionary contains the doses given at each location on a given date. The dictionary keys should be the dates on which the doses were administered, and the value should be the list of doses by location. Example: {'2020-12-20': [0, 0, 0, 0, 206], '2020-12-27': [0, 0, 0, 0, '1,799'], ...} 2 Assignment #3 CS 1026 Summer 2022

Be careful: the data contains multiple entries for some of the dates, so you'll have to check to see if a key already exists before storing information. You also must consider that some numbers are stored as strings, while others are stored as integers and handle this. Hints: 1. setdefault(string, []) can help create the basic dictionary structure. This sets the default key as a string, and the default value as a list. 2. You can use the following line of code to skip the column headers before writing to the dictionary, as the column headers will break your dictionary: next(reader, None). The main() function processes data and then outputs that data to doses.csv. ● Function Name: count_doses_by_date() This function adds up the number of vaccine doses administered at different locations on each date. You will need to do some minor processing of strings here to count them, as the file has numbers that contain commas and entries with empty values. Hint: remove the commas from the numbers and replace the empty values with zeroes. o Parameter: a list containing the dose number for each. location on a given date. O Return Value: a total vaccination count for that date. This file will output a file named doses.csv, which will contain entries that look like this: 2020-12-20, 206 2020-12-27, 1799 2021-01-03, 3787 2021-01-10, 4073 The first value is the date (technically, it's the first day of the week from which the vaccination numbers were taken), and the second value is the total vaccination count Assignment #3 3 CS 1026 Summer 2022

for that date (an integer). For the doses_data_mar_20.csv file, your output file should contain 66 entries, and, depending on how you write your output, it may have a 67th entry that is just an empty line). The result of running the program will look like this: Which data would like to consider? doses_dato_mar_20.csv Date: 2020-12-20 Doses: ['0', '8', '0', '8', '206¹] Date: 2020-12-27 Doses: ['0', '8', '0', '0', '1,799'] Date: 2021-01-03 Doses: ['0', '8', '0', '0', '3,787'] Date: 2021-01-10 Doses: ['198', '0', '0', '0', '3,875'] D Date: 2021-01-17 Doses: ['2,098', '47', '8', '0', '1,588'] Date: 2021-01-24 Doses: ['645', '0', '0', '0', '127'] Date: 2021-01-31 Doses: ['918', '54', '0', '0', ''] Date: 2021-82-87 Doses: ['1,954', '42', '8', '0', '2,548'] Date: 2021-02-14 Doses: ['917', 'e', '0', '0', '5,042¹] Date: 2021-02-21 Doses: ['1,232', '0', '0', '0', '5,700'] Date: 2021-02-28 Doses: ['156', '938', '0', '8', '7,517'] The analyze_doses.py File This file will contain (at least) four functions: Function Name: main() This function reads the doses.csv file you created with your doses.py file. It should store that data in a list of tuples. Example: [('2020-12-20', 206), ('2020-12-27', 1799), ('2021- 01-03', 3787) The function processes data and then outputs that data to vaccine_stats.txt. 4 Assignment #3 CS 1026 Summer 2022

. . Function Name: minimum() This function identifies the date with the fewest vaccinations. o Parameter: the list containing the number of vaccinations by date. o Return Value: a tuple containing the date of the fewest vaccinations and the total number of vaccinations that took place on that date. Function Name: maximum() This function identifies the date with the most vaccinations. O Parameter: the list containing the number of vaccinations by date. O Return Value: a tuple containing the date of the most vaccinations and the total number of vaccinations that took place on that date. . Function Name: total_vaccinations() This function adds up the number of vaccine doses delivered by different locations on the same date to get a total number of vaccinations. o Parameter: the list containing the number of vaccinations by date. O Return Value: an integer containing the total number of vaccinations that took place. You may also include any helper functions you wish to include. Remember that the aim is to generalize your code wherever possible so that you aren't repeating the same code over and over again. If you find that you are repeating sections of code, see if you can encapsulate that code in a generalized way. This file will output a file named vaccine_stats.txt, which should look exactly like this: Total doses: 1116678 Minimum date: 2020-12-20, Doses: 206 Maximum date: 2021-06-27, Doses: 56999 This information should also be printed out for a user to see when the program runs. 5 Assignment #3 CS 1026 Summer 2022

Non-Functional Requirements/Specifications 1. Include brief comments in your code identifying yourself (i.e., include your student number in a comment at the beginning of your program) and describing what the program does. Include docstrings describing what each function does. Place these comments in the appropriate places in the program.

A B 1 Week start date Congregate settings Other (e.g., mobile clinics) 2 2020-12-20 0 0 3 2020-12-27 0 0 4 2021-01-03 0 0 5 2021-01-10 198 0 6 2021-01-17 2,098 47 7 2021-01-24 645 2021-01-31 918 2021-02-07 1,954 10 2021-02-14 917 11 2021-02-21 1,232 12 2021-02-28 156 13 2021-03-07 451 14 2021-03-14 1,049 15 2021-03-21 228 16 2021-03-28 174 17 2021-04-04 126 18 2021-04-11 36 19 2021-04-18 0 20 2021-04-25 21 2021-05-02 22 2021-05-09 23 2021-05-16 24 2021-05-23 C 326 30 11 31 91 D doses_data_mar_20 E Pharmacies Primary care 0 0 0 0 0 0 54 42 0 0 938 214 0 1,013 275 130 110 793 229 172 199 357 459 0 0 0 0 0 0 0 0 0 0 0 0 0 0 644 1,573 7,551 6,322 3,566 809 2,383 2,328 0 0 0 0 0 0 0 0 0 0 0 265 928 1,854 2,136 481 1,278 1,605 1,650 F Mass immunization clinics 206 1,799 3,787 3,875 1,588 127 2,548 5,042 5,700 7,517 10,840 9,997 11,110 14,544 14,039 16,367 19,446 18,271 18,692 18,420 21,065 26,371 G

O A 24 2021-05-23 25 2021-05-30 26 2021-06-06 27 2021-06-13 28 2021-06-20 2021-06-27 29 30 2021-07-04 31 2021-07-11 32 2021-07-18 33 2021-07-25 34 2021-08-01 35 2021-08-08 36 2021-08-15 37 2021-08-22 38 2021-08-29 39 2021-09-05 40 2021-09-12 41 2021-09-19 42 2021-09-26 43 2021-10-03 44 2021-10-10 45 2021-10-17 46 2021-10-24 47 2021-10-31 48 2021-11-07 49 2021-11-14 Actual 0 B 91 40 60 42 32 68 76 62 23 33 11 19 135 230 215 865 549 217 84 2191 2328 1745 2056 2615 2640 C 459 569 1,099 792 2,659 1,537 2,186 2,632 3,113 2,022 1,154 1,317 1,206 1,029 2,281 2,098 2,172 3,350 2,286 2,006 37 126 295 690 228 71 D 2,328 6,731 7,800 8,175 8,670 9,250 8,943 6,432 5,044 3,708 2,549 3,032 2,394 2,760 3,381 2,803 2,923 4,095 3,209 3,141 2705 2892 2581 2090 2063 2182 E 1,650 334 141 785 1,838 1,848 1,259 1,167 656 271 29 202 52 136 66 82 42 93 93 89 122 70 75 69 90 49 F 26,371 27,026 29,362 29,494 37,923 44,296 44,149 41,395 23,190 15,711 11,263 10,903 8,317 5,996 5,917 3,719 3,665 4,007 3,063 2,383 586 342 535 291 237 108 G

O, 49 2021-11-14 50 2021-11-21 51 2021-11-28 52 2021-12-05 53 2021-12-12 54 2021-12-19 2021-12-26 55 56 2022-01-02 2022-01-09 57 58 2022-01-16 59 2022-01-23 60 2022-01-30 61 2022-02-06 62 2022-02-13 63 2022-02-20 64 2022-02-27 65 2022-03-06 66 2022-03-13 67 2022-03-20 (F) Actual 0 B 2640 4378 10425 10176 15362 18867 17687 20369 21776 17942 14491 8201 4007 3181 3131 2139 1555 1572 1168 C 71 48 93 222 508 394 239 378 815 703 420 443 210 154 257 212 143 24 192 D 2182 2584 4359 5291 10762 13459 10508 12081 11208 7346 4519 3607 2412 1720 1343 1078 846 828 776 49 181 274 433 974 2957 1302 1173 1201 588 417 387 225 91 84 34 47 39 42 F 108 160 1123 1676 2895 2771 1412 1233 3288 2085 1321 977 465 233 261 251 154 252 249 G I
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply