I don't have an answer for you, but I have a very similar experience. some days I wake up and it's "go time", sifting through source files and crushing multiple bugs in eight hours, often forgetting to eat lunch! other days I'll try over and over to start working, but every time I look at a line of code, I feel an immense pressure to alt-tab to the browser or get out of my chair and pace around my apartment. if nothing else, it's good to know other people are like this.
I've tried to examine correlations between my focus at work and my sleep schedule, diet, social life, etc. and I don't really see anything. sometimes my best weeks of work will coincide with eating bad takeout and staying up til 2am playing factorio every night. sometimes I go to bed at 10pm, eat three healthy meals a day, and accomplish absolutely nothing at work.