Donald Trump woke up mad. Or maybe he got mad before he went to sleep. It's hard to say, but the point is the same. While most American voters were asleep, Trump was up and tweeting about things that were making him angry. Those things were, in ascending order of how mad he was about them: anonymous sources, Hillary Clinton and the beauty queen he once called fat.

My colleague Aaron Blake has done the analysis pointing how excruciatingly terrible the politics of Trump's tweets were. The election is in less than 40 days, and the trailing candidate is still railing about something that his opponent explicitly and strategically wanted to distract him with. Hillary Clinton wanted to show that he could be baited into tweeting, so she baited him, and he is tweeting. It's sort of amazing.

But I was more curious about the timing. Why now? Why is Trump up in the middle of the night at this point, angrily sending 140-character arrows in various directions? What can his past tweeting tell us about what's going on with him at this moment?

A data scientist just analyzed over a thousand tweets from Donald Trump's Twitter account. His findings may help point out when it's actually Trump tweeting. (Jhaan Elker/The Washington Post)

In August of 2015, we looked at when Trump tweeted. It was a fairly broad analysis, finding that Trump didn't tweet much on Friday evenings or on Sunday mornings. This time, though, I decided to break it out a bit more.

I divvied up the campaign into five chunks: The month before he announced, the period between his announcement and the beginning of the Republican primaries, the primaries, the period after the primaries through the Republican convention and the period after that. As a percentage of all tweets sent during those periods, here's how Trump's tweets were distributed.

Normally, there's a gap between about 1 a.m. and 5 a.m. Other than that, fairly even distribution. Not a lot early Monday mornings (Mondays, amirite), but otherwise all over. Interestingly, the post-primary period is dominated by a bunch of tweets he sent after his makeup interview with Fox News's Megyn Kelly. He didn't have as many tweets during that period (it was shorter than most of the others), so that particular investment of energy stands out.

And it tells us a lot about when he tweets late at night.

One thing I was curious about was whether or not Trump tweeted late at night more when he was angry, as he seems to have done this time. I matched his late-night tweets (post-9 p.m., pre-6 a.m.) with his standing against Clinton in the polls, figuring that periods where he was doing worse might see more late-night tweets. (On the chart below, the line is the polling margin and the columns are his late-night tweets.)

They didn't. Comparing each individual day to how Trump's poll numbers had changed relative to the prior week, there was no significant difference in the number of late-night tweets for when he'd improved or when he'd declined. This is a rough metric using a fairly small sample (a few hundred tweets), but no pattern emerged.

So I looked instead at times that Trump had seen a big spike in late-night tweets. For example, that spike at the far right of the graph above. That correlates to the first debate. Which is the pattern: Big news events or, as you might expect, things that happened late at night are when he tweets late at night.

The early morning of July 3, 2015, Trump tweeted a lot, mostly about his feud with Macy's. This was a good example of an angry Trump tweeting. In the same year, on the 21st of that month, he was up late tweeting about his appearances on Fox News. The morning of Aug. 7, 2015, he was retweeting praise for his performance in the first Republican primary debate. In November, two spikes: after his book came out and after his appearance on "Saturday Night Live."

During the primaries he tweeted after late results. He tweeted while flying cross-country. He tweeted, in other words, when he was up and had something to tweet about.

That's the pattern. Trump is a Twitter addict and a night owl. (Editor's note: Same.) He's been tweeting less recently than he did earlier in the campaign, which makes Friday morning's eruption all the more noticeable. But he doesn't tweet late at night because he's mad, he tweets late at night because he tweets late at night. Because he had something he wanted to say right at that minute and so he said it, instead of, say, going to sleep (or going back to sleep).

And that, of course, was Clinton's entire point.