Move coverage into lib file

Summary: Also rewrote the algo for it.  @cramer can you look over the queries?  They're kinda nasty.

Test Plan: viewed the coverage endpoints

Reviewers: cramer

Reviewed By: cramer

Subscribers: cramer

Differential Revision: https://tails.corp.dropbox.com/D48095