Postgresql Window Function Count Python Function