Electronic structure of tetragonal tungsten bronzes and electrochromic oxides