Weeks 7-8

In my previous post I discussed making graphs, or rather redrawing existing graphs using a new library. Since I was only redrawing the graphs, I only discussed the final step for making a graph: feeding the data to the graph library. I have also been making new graphs from scratch, however, which is a bit more complicated. I’ll first describe how a graphing tool works in crash-stats:

1. First some parameters are chosen (either by the user, or by whoever set the default parameters), such as dates of crashes, products that crashed, versions of those products, etc.

What the user sees during step 1.

Screenshot from 2015-08-06 14:19:25

2. These parameters are encoded in a URL and sent off to the server. Since we are using Django, the URL also specifies which Django view to send our parameters to.

What the user sees during steps 2 – 4.

Screenshot from 2015-08-06 14:49:22

3. The view function specified by the URL is called. The view does some processing of the parameters and sends them to the middleware API. The view then returns the data it gets back from the middleware as a JSON object.

4. The JavaScript processes this returned data into the format required by the graph library.

5. Now we are ready to do everything in my previous post: hand the data over to Metrics Graphics and receive back a beautifully drawn graph.

What the user sees after step 5.

Screenshot from 2015-08-06 14:21:33

So, code-wise, making a new graphing tool involves writing: a form so the user can choose parameters, an AJAX request to be performed when the form is submitted, a new Django view (which will (a) process the parameters, (b) talk to the middleware and (c) return the data), and some functionality to format the data for the graph, draw the graph, and add it to the DOM.

A final note about testing Django views, in particular mocking. The idea of the test is that you check that your view does everything it is supposed to: that it processes the parameters and sends them in the correct form to the middleware, and that it processes the data that it gets back from the middleware correctly. What you don’t want to do here is test the middleware, so you define a function that mocks the call to the middleware. Inside this function you can check that your parameters have been passed through correctly, and you can also ask it to return some data in place of what the middleware would have returned, and then check that the view processes it correctly.


3 thoughts on “Weeks 7-8

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s