Here's my guess for how finding overall keys works:
Multi-Movement Works
The name is probably the definitive, canon indicator for the key the multi-movement work is in. For example, Chopin's Piano Sonata No. 3 in B Minor, Op. 58 is in B minor, despite one of its movements being in B major and another in E flat major. Heck, the last movement ends in B major (and starts in B minor)! Another example is Mendelssohn's Symphony No. 4 in A Major, Op. 90, "Italian" is in A major, despite one of its movements being in D minor and its last movement being in A minor. Yet another example is Beethoven's Piano Sonata No. 27 in E Minor, Op. 90, which is in E minor despite being only 2 movements long--the 1st movement is in E minor and the last is in E major.
Once you've found enough multi-movement works with names that reveal their keys, you can sketch out some rough rules for determining the overall key of a multi-movement work. I generally agree with your proposed factors, except that I agree more strongly with the first key of the final movement being a major factor. This is because minor-key works often end in the tonic major.
I'll have to provide some caveats--some multi-movement works have no overall key, and some movements have no overall key. Your rough rules must be flexible enough to accommodate this. For example, whatever the key of Bartok's fifth string quartet is, it hasn't been widely published.
Single Movements
From listening to a LOT of music, here are my rough factors for finding what overall key a piece has, if any:
- The key of the first motive
- The key of the last motive
- The most often used key
- The percentage of the piece that is atonal
- All keys that are playing simultaneously (in the case of polytonal music)
- The key in the piece that has the closest relationships with all other keys in the piece (dominant/subdominant/tonic major are closer relationships than chromatic mediant, for example)
- The assigned key of other pieces with the same form as this piece (e.g. marches tend to be assigned their 1st key as their overall key, even though they often don't end in the same key as they start with)
You can also figure out the overall keys of contemporary music with these guidelines.
Gary P. Gilroy's Heart of the City should be a fairly straightforward example--it starts in F minor, it ends in F minor, and it's in F minor the most often, so its overall key is F minor. It doesn't matter much that some of its phrases are in F major or A flat major.
A less straightforward example is C-R-O-W-N-E-D from Kirby's Return to Dream Land. It also starts in F minor and ends in F minor. However, portions of it are also in A flat minor, E minor, and C minor, and it quite possibly ends up in A flat minor the most often. Despite C minor arguably having the closest relationships to all the other keys (it's the dominant of F minor and chromatic mediants of all the other keys, while F minor has a very loose relationship with E minor), I'd still say the overall key of this piece is F minor. This piece still begins and ends in that key, after all.
For me at least, overall keys get more tenuous the higher percentage of the piece is atonal. While The Defender from Shovel Knight is in D minor overall (it arguably starts in D minor and is in D minor the most often), large portions of that piece are chromatic to the point of atonality, and a phrase of it is even in B minor.
Eventually, pieces stop having overall keys. Half or more of Ginastera's Danza del gaucho matrero, Op. 2, No. 3 from his Danzas Argentinas is atonal, and the rest is desperately trying to cling onto a C major-like tonic. Some of it is actually in C major (with an interlude in A flat major), but I'd hesitate to say this piece has any overall key.
By the way, given these tips, can you help me find the overall key (if any) of Mind in a PROGRAM from Kirby: Planet Robobot? Portions of it are in C minor, F# minor, B minor, D minor, G# minor, C# minor, and E minor, and whatever key the intro is in, it probably isn't any of those. But I cannot determine which of those keys is the overall one. Even though the largest percentage of this piece is in E minor, that's its ending, non-starting key. I'm starting to give up on determining whether this piece has an overall key. Does this piece have an overall key?