Refactor JS metric wrangling to model