UPS with intelligent charging algorithm