@BoredEngineer
It figures out a predicted score based on the difficulty, enemy deployment and your deployment.
Then it uses the difference between that score and your actual score (based on damage dealt, damage received, healing, deaths and the percentage of possible XP gained) to modify the enemy deployment budgets on every threat level.
It does smooth the modification somewhat by using the average of your last few battles.
Also you should take threat levels seriously. Unmodified Low threat caps out at a budget of 1000, but extreme caps out at 3000. Those caps are then modified by the difficulty:
Rookie: 1.0 x
Veteran: 1.15 x
Heroic: 1.3x
Legendary: 1.5x
All the deployment budgets start out much smaller, but they’ll trend towards max as you exceed expectations or trends towards min as you under-perform.
This is why you get swarmed if you save scum, because you are performing far better than you should be and the game is ramping up numbers to try and challenge what it perceives to be a god tier player.