When sorting Draco and Ron It seems the hat didn't waste time to find out their character traits . In Ron's case he even says:
"Another Weasley! I know just what to do with you."
It seems as if the first priority is by family alliances/political fractions and only in cases of the 'neutrals' (Luna, the Patil twins) and newcomers (like the Creevy brothers) is when the hat puts in some effort to try to sort by character traits. But it still seems completely random to me. Hermione is ambitious, cunning and can be ruthless (keeping Rita Skeeter in a bottle for months then blackmailing her, hexing Marietta in fifth year) she is loyal, intelligent and brave. So why Gryffindor? Because she's a muggleborn, would she have a hard time in Slytherin?
So what is the function of the sorting hat and the houses? To keep the wizarding society static? Not put kids in houses their families wont like unless the kid specifically asks?
And why on earth did the hat try to put Harry in Slytherin? Sure, he had a piece of Voldemort in him, but it was dormant. Harry himself barely demonstrated any character traits fit for a Slytherin.
Here is that hat, sitting all year long in the headmaster's office, probably listening to pretty intriquing conversations, then sorting the kids and shaping the wizarding society. Is it supposed to be apolitical? Or is it supposed to obey and be loyal the Headmaster, like the paintings?
How that thing works? ??