Ok, my go at the solution:
When to activate:
a) use saints rules to activate the mixing on round end
b) admin command or vote
Who to mix up:
The factors should be if the players stacks regularly and he if is a top scoring player of his team.
Never mix up all of the players, but lets say 65% of the teams.
Almost never move those that have selected random team - those should not be punished!
Keep a history of team choices for each player (red, blue, and if possible random).
If a player has more than 20% difference in red/blue (or low random % if possible) selection we assume he is a stacker.
First see the player's team choices for the last week/month/total and move the serial stackers first. The regular stackers should be the first to be moved and might even be moved in the middle of the round if the admin command is executed (if not only team medic, medic with uber >5% (if possible), or engie with sentry built (if possible). The medic can be moved later on death as well as engie on sentry destroyed but this only complicates things
)...
If the teams are still stacked (or eg. if we have not shuffled 65% of the teams or some criteria based on total team points difference is not satisfied) then check the current game and move those that haven't selected random at the beginning (if possible). Note, that if we have shuffled 65% of the teams and you have stacked only this time you can continue playing with your favorite medic (this time
).
How to do it from a technical perspective:
Well, stats do it already -
the example of the serial stacker and he should always be the first to be mixed
.
This for example is obviously not a stacker so he should not be moved and should be allowed to chose his team once in a while.
What we need is a the above for the last X days or/and current game but it should be possible for your tech team to collect that data...