How to predict the energy of dangerous solar flares 