It is calculated on the CP of your highest CP mon of your entire team, in comparison to any mons you attack.
You get max (1000) for keeping at or below 50% CP of the mons you attack...and decreases the higher the CP of your toughest mon is compared to the defenders.
Best explained by the pro's, here...
https://pokemongo.gamepress.gg/gym-combat-mechanics