I like to look ahead in the music to see what the highest note is that needs to be played, and then to look for opportunities to get into a position where that note can be played efficiently and without a sudden long jump in positions.
Here is an example from a show I recently played.
The red Roman numerals on the bottom are the position I played in (V = 1st finger on the fifth fret, VII = 1st finger on the seventh fret). The black numbers on the top are the fingers I used to play the notes (I play Simandl style, with fingers 124, even up in position VII unless I'm playing something that specifically calls for one finger per fret).
For this particular example, I saw that the highest note in measure 74a was an E, two ledger lines above the staff. There are two places on my bass where I can realistically play that note: the ninth fret of the G string, or the 14th fret of the D string. I will usually default to the lowest available position unless there is a need to use a higher position, so I would play that note on the ninth fret of the G string.
But what finger to use to play that high E? Well, look at the highest note and determine how to get to it efficiently without a big jump for that note and with the fewest position shifts. For example, I could have played the notes leading up to it on the second and fourth frets of the D and G strings, but then I would have had to make a large, quick jump up to the E. I could have played the high E with my first finger, and the B preceding it with my first finger, but the A before that would not have been within reach. But, looking at the figure, I recognized that if I played the highest E with my fourth finger, the five notes leading up to it could all be played in the same position.
Working backwards, I recognized that I could play the first two notes that measure and the third note (B) on the second fret of the A string, but then there would be a big jump to get to VII for the rest of the measure. So I saw that if I played the first three notes in position V, I would need to shift only two frets to get to the higher notes. I think the first time I played this measure, when I was sight-reading, I played the first E A B E E in position 5, and then shifted to position seven during the tied note. After that, I realized it would be more efficient to shift after playing the low B.
This explanation makes it sounded more complicated than it is. In reality, I've been playing and reading long enough that I recognize that the second half of the measure is root fourth fifth octave fifth fourth root, and I know from experience that I can play the root with my first finger and the octave with my fourth, so it didn't take more than a glance at the measure as I was sight-reading to recognize that my fourth finger needed to be on that high E, and the rest of the figure just fell into place. But as you're learning, you just need to sit down and work through as many examples as possible, and keep saying to yourself, "what is the most efficient way to play this?"