Now You Code 5: Syracuse Weather

Write a program to load the Syracuse weather data from Dec 2015 in JSON format into a Python list of dictionary.

The file with the weather data is: "NYC5-syr-weather-dec-2015.json"

You should load this data into a Python list of dictionary using the json package.

After you load this data, loop over the list of weather items and record each of the different weather events (found under the "Events") key into another Python dictionary, talling the different types of weather events across the 31 days of December.

When done correctly your output should be:

{'Rain': 14, None: 7, 'Fog': 2, 'Snow': 2, 'Fog-Rain': 3, 'Rain-Snow': 3}

Write the dictionary to a Python file called dec-2015-events.json.

Problem Simplification

This is a conceptually difficult problem and the solution is classic Python: 10 lines of code and quite cryptic looking. The best approach is to use problem simplifcation to once again arrive at the answer. This program is too complicated to write all at once! Let's break it up into parts.

Parts:

  1. Write a program to read "NYC5-syr-weather-dec-2015.json" into a python list of dict variable named weather
  2. With the weather variable print all the `"Events" keys. There should be 31 weather events one for each day in December
  3. Now that you know how to write the loop, modify the loop to add keys to another dictionary events where the value is the number of occurences of the event
  4. write the events Python dictionary as JSON to a file called dec-2015-events.json.
  5. Assemble parts 1 through 4 into a single program.

NOTE: In the problem analysis sections, the inputs and outputs are provided, but you must write the algorithms.

Part 1: Step 1: Problem Analysis

Write a program to read "NYC5-syr-weather-dec-2015.json" into a python list of dictionary.

Inputs: text in the file "NYC5-syr-weather-dec-2015.json"

Outputs: a python variable named weather of type list with each element of type dict

Algorithm (Steps in Program):


In [12]:
# Part 1 : Step 2 Write Code

Part 2: Step 1: Problem Analysis

Contine the program, looping over the weather list and printing the "Events" keys.

Inputs: weather variable from previous step

Outputs: 31 "Events" (one for each day of weather in December)

Algorithm (Steps in Program):


In [13]:
# part 2:  step 2 write code

Part 3: Step 1: Problem Analysis

Now that you know how to write the loop, modify the loop to add keys to another dictionary events where the value is the number of occurences of the event

Inputs: weather variable from previous step, empty dictionary named events

Outputs: events dictionary where they keys are the event names and the value is the number of times the event occured in December

Algorithm (Steps in Program):


In [14]:
# Part 3: Step 2 write code

Part 4: Step 1: Problem Analysis

write the events Python dictionary as JSON to a file called dec-2015-events.json

Inputs: events Python dictionary

Outputs: print the dictionary, then write to the file dec-2015-events.json in JSON format.

Algorithm (Steps in Program):


In [15]:
# Part 4: Step 2: write code

Part 5 Write the final program

Take parts 1 through 4 and create a running program in a single cell! Don't just copy and paste it all THINK about what you really need.


In [16]:
# part 5 re-write code here

Step 3: Questions

  1. What are the advantages to storing the weather events in a Python dictionary?

Answer:

  1. What is the data type of the weather data as it is read from the file NYC5-syr-weather-dec-2015.json ?

Answer:

  1. Could this same program work for weather at other times in other cities? What conditions would need to be met for this to happen?

Answer:

Step 4: Reflection

Reflect upon your experience completing this assignment. This should be a personal narrative, in your own voice, and cite specifics relevant to the activity as to help the grader understand how you arrived at the code you submitted. Things to consider touching upon: Elaborate on the process itself. Did your original problem analysis work as designed? How many iterations did you go through before you arrived at the solution? Where did you struggle along the way and how did you overcome it? What did you learn from completing the assignment? What do you need to work on to get better? What was most valuable and least valuable about this exercise? Do you have any suggestions for improvements?

To make a good reflection, you should journal your thoughts, questions and comments while you complete the exercise.

Keep your response to between 100 and 250 words.

--== Write Your Reflection Below Here ==--


In [ ]:
# RUN THIS CODE CELL TO TURN IN YOUR WORK!
from ist256.submission import Submission
Submission().submit()