ready to implement one of our menu items

Please help! We’re ready to implement one of our menu items, and a couple ofthe instance methods of our class. We will be importing a file thatcontains thousands of temperature readings taken during a week atthe STEM Center. Download the file in today’s module and place it in the samedirectory as your python files. The file is in .csv format (commaseparated value). Each line represents one “report” from a sensorin the STEM center, most of which are temperature readings. The format of each line is: Day of Week, Time of Day, Sensor Number, Reading Type, Value Day of Week is an int where 0 representsSunday, 1 represents Monday, etc. Time of Day is a float between 0 and 1. 0 is12:00AM and 1 is 11:59PM. The rest of the times are scaledlinearly. We will covert this value to an hour of day value. Sensor Number is an int between 0 and 5, andmaps to the sensors we coded in a previous assignment. Reading Type is a string that contains”BATTERY”, “TEMP”, “AWAKE” or “SLEEPING”. We will only use thelines with “TEMP”. Value is the value related of the reading. ForTEMP type, this is degrees Celsius. Steps to Implementation This is a pretty complex project, but here’s a roadmap to whatneeds to be done: First, open a new file for this assignment. Copy in your codefrom assignment seven, including its main (make sure that you fixany issues that were noted by your professor!). Then copy the classfrom assignment eight. Make sure you do not include the unit testfrom assignment eight. Just before your main, instantiate an objectcurrent_set of type TempDataset(). Finally, we’ll fix all thefunction calls in our menu that pass the argumentNone – we can now pass current_set instead. Runthis code to make sure you have no stray lines. Your menu shouldrun just as in assignment seven. Now we are ready to build on thiscode! We will start with process_file(). This method has filename as one of its parameters. We need totry (hint) to open this file for reading.If we can’t open it, we need to return False. Once you have thatcoded, you can test it by callingprocess_file(“Temperatures2017-08-06.csv”) andprocess_file(“Blah”). Remember, these are instance methods in ourclass, so you need to call them using the current_set object wecreated. The first should quietly succeed, if you have downloadedthe datafile and put it in the correct directory. The second shouldreturn False. Continuing in process_file(), recall that we have a variabledata_set in our class that was initialized to None. We want toreinitialize this as an empty list. Remember that this variable isan instance attribute in the class, be careful not to createanother variable that is local to process_file()! In a loop, we read in each line from the file. We’ll need to dotype conversions to make day and sensor as ints and temp as afloat. We also must convert Time of Day to a number that representsthe hour of the day. Multiply the given time by 24, and then usemath.floor to round the result down to an integer between 0 and 23(you will need to import math at the top of your module touse the floor function). We want to discard anything other than a temp reading (how?).For temperature readings, we will make a tuple: (day, time, sensor, temp) and add the tuple to the list data_set. We’ll make the assumption that the data in the file is correct.We should be handling errors in the reading of the data, but forour purposes if we get past opening the file, we’ll assume thateverything else will go smoothly. Feel free to improve on this byreturning False if any kind of load error happens throughout theprocess. Continue until we are done with the list, and return True! Next we implement get_loaded_temps() This method is simple. If we have not successfully loaded a datafile, it should return None. Otherwise it should return the numberof samples that were loaded (an int). Think of how we can check ifa data file has ever been loaded, by looking at data_set. Finally, new_file() Recall that our menu item 1 calls newFile(). This functionshould ask for a filename and then use process_file() to load thedata. If process_file() fails to load data, the program shouldcomplain (from new_file(), not from process_file!) to the user thatit is unable to load a file. new_file() should then fall back tomain. If process_file() succeeds, then new_file() should report thenumber of samples that were loaded. new_file() should then ask for a 3 to 20 character name for thedata. Use the set_name() method in TempDataset() to validate andset the name. Tell the user if the name is bad, and don’t let themleave until they input a good name.   You are notchanging set_name() at all, we already verified that it works. Allof this functionality should happen in new_file(). Remember to change the menu routine, replace None in the call tonew_file() with the appropriate object. Note that process_file() and set_name() should notprint anything. Test out the functionality of your loop, the number of samplesretrieved should be the same as my sample run below (11,724). One last thing. For testing, add these lines in main right afteryour call to print_menu(): if current_set.data_set is not None: print([current_set.data_set[k] for k in range(0, 5000, 1000)]) After you run and load the file, you should see a list thatlooks (exactly) like this. The loop pulls out item 0, 1000, 2000,3000 and 4000, and you can use this to verify that the data isloaded correctly. I will be adding this line to your code andchecking that you have the correct data. [(0, 18, 0, 17.5), (0, 2, 3, 21.59), (1, 9, 0, 19.55), (1, 12, 2, 23.23), (2, 4, 1, 22.05)] We’re breaking the rules by directly accessing object data. Soquickly take these lines out after you verify the data! We wouldn’twant to get caught. That’s it! Make sure your sample run shows a failed load as wellas a successful one. Sample run: STEM Center Temperature ProjectEric ReedMain Menu———1 – Process a new data file2 – Choose units3 – Edit room filter4 – Show summary statistics5 – Show temperature by date and time6 – Show histogram of temperatures7 – QuitWhat is your choice? 1Please enter the filename of the new dataset: Temperatures2017-08-06.csvLoaded 11724 samplesPlease provide a 3 to 20 character name for the dataset My Data SetMain Menu———1 – Process a new data file2 – Choose units3 – Edit room filter4 – Show summary statistics5 – Show temperature by date and time6 – Show histogram of temperatures7 – QuitWhat is your choice? Grading: 5 points – Menu functionality successfully updated in main (userinput should happen in the new_file() function, not in the class).Number of samples loaded correctly reported using get_loaded_temps.Code is elegant and simple. 1 point – Function calls that were passing None as an argumentnow pass current_set. 2 points – Accurate implementation of process_file() methodaccording to spec. Nothing should be printed by this method.total_samples_loaded is correctly updated. Code is elegant andsimple. 2 points – Data checks correctly as described in the assignment(doesn’t need to be in your sample run, I will add this to yourprogram when I run it). 3 points – Run included and matches spec. Correct number ofsamples loaded 1 point – Formatting 1 point – Updated docstr Below is CSV file: 0,0.0291087962962963,1,BATTERY,2.58 0,0.0637731481481481,1,BATTERY,2.58 0,0.0984375000000000,1,BATTERY,2.58 0,0.1331134259259260,1,BATTERY,2.58 0,0.1677893518518520,1,BATTERY,2.58 0,0.2024652777777780,1,BATTERY,2.58 0,0.2371296296296300,1,BATTERY,2.58 0,0.2718055555555560,1,BATTERY,2.59 0,0.3064814814814810,1,BATTERY,2.59 0,0.3411689814814820,1,BATTERY,2.59 0,0.3758333333333330,1,BATTERY,2.59 0,0.4104976851851850,1,BATTERY,2.59 0,0.4451620370370370,1,BATTERY,2.59 0,0.4798379629629630,1,BATTERY,2.59 0,0.5145023148148150,1,BATTERY,2.59 0,0.5838541666666670,1,BATTERY,2.59 0,0.8958912037037040,1,BATTERY,2.59 0,0.9305555555555550,1,BATTERY,2.59 0,0.9998958333333330,1,BATTERY,2.59 0,0.5491782407407410,1,BATTERY,2.6 0,0.6185185185185190,1,BATTERY,2.6 0,0.6531944444444440,1,BATTERY,2.6 0,0.6878587962962960,1,BATTERY,2.6 0,0.7572222222222220,1,BATTERY,2.6 0,0.7918750000000000,1,BATTERY,2.6 0,0.8265509259259260,1,BATTERY,2.6 0,0.8612268518518520,1,BATTERY,2.6 0,0.6584606481481480,3,BATTERY,2.79 0,0.6931481481481480,3,BATTERY,2.79 0,0.7278240740740740,3,BATTERY,2.79 0,0.7625115740740740,3,BATTERY,2.79 0,0.7971990740740740,3,BATTERY,2.79 0,0.8318865740740740,3,BATTERY,2.79 0,0.8665625000000000,3,BATTERY,2.79 0,0.9012500000000000,3,BATTERY,2.79 0,0.9359259259259260,3,BATTERY,2.79 0,0.9706134259259260,3,BATTERY,2.79 0,0.4503587962962960,3,BATTERY,2.8 0,0.4850347222222220,3,BATTERY,2.8 0,0.5197106481481480,3,BATTERY,2.8 0,0.5544097222222220,3,BATTERY,2.8 0,0.5890972222222220,3,BATTERY,2.8 0,0.6237731481481480,3,BATTERY,2.8 0,0.2422453703703700,3,BATTERY,2.81 0,0.2769212962962960,3,BATTERY,2.81 0,0.3116203703703700,3,BATTERY,2.81 0,0.3463078703703700,3,BATTERY,2.81 0,0.3809837962962960,3,BATTERY,2.81 0,0.4156712962962960,3,BATTERY,2.81 0,0.0341319444444444,3,BATTERY,2.82 0,0.0688194444444444,3,BATTERY,2.82 0,0.1035069444444440,3,BATTERY,2.82 0,0.1381944444444440,3,BATTERY,2.82 0,0.1728703703703700,3,BATTERY,2.82 Please save this data to csv file in order to read from thecode. . . .

Leave a Reply

Your email address will not be published. Required fields are marked *