TL;DR
Shift clicking modules into machines should be checking the boost % amount.What?
You can shift click and replace modules in machines only with a higher either quality or stage of the module.You can't go from normally quality 3 modules to uncommon quality 2 modules by shift clicking (which would be a % increase from 2.5% per module to 2.6% per module) but you can go from uncommon quality 2 to quality 3 modules (which would be a % decrease)
Instead of just looking at the stage and quality of the modules it would be better if the logic looks at the boost % that the said module gives. With speed and prod modules for it would be also nice to prefer lower penalty bonus for example preferring the 50% of legendary speed 1 module that has +50% energy consumption over then 50% of the normal speed 3 module that has +70% energy consumption.