traffic-spike-2026-08.html
001| """The Giant File Room post read spike (August 20-27).
001|
001| This is a single-use program to generate a nice chart showing the weird traffic spike
001| on my blog in late August 2026. Out of the blue, four posts, which usually received
001| almost no traffic, suddenly spiked in views. Especially weird was that, although the
001| spike was synchronized among the four posts, those posts don't seem related. None of
001| them link to each other, so I'm not sure why all four spiked in concert.
001|
001| Of course, as usual, no one commented, so it'll always be a mystery.
001|
001| """
002|
003| from sys import argv
004| from os import path
005| import datetime as dttm
006| import matplotlib.pyplot as plt
007| import matplotlib.ticker as mlticks
008| import matplotlib.dates as mldates
009|
010| BasePath = r'C:\CJS\prj\Python\ws\tutorial'
011|
012|
013| """Hits data for four posts that experienced a traffic spike in late August 2026."""
014| PostHitsData = {
015| 'The Giant File Room': [
016| (dttm.date(2026, 8, 16), 0),
017| (dttm.date(2026, 8, 17), 0),
018| (dttm.date(2026, 8, 18), 0),
019| (dttm.date(2026, 8, 19), 0),
020| (dttm.date(2026, 8, 20), 5),
021| (dttm.date(2026, 8, 21), 7),
022| (dttm.date(2026, 8, 22), 21),
023| (dttm.date(2026, 8, 23), 11),
024| (dttm.date(2026, 8, 24), 52),
025| (dttm.date(2026, 8, 25), 74),
026| (dttm.date(2026, 8, 26),114),
027| (dttm.date(2026, 8, 27), 40),
028| (dttm.date(2026, 8, 28), 0),
029| (dttm.date(2026, 8, 29), 0),
030|
031| ],
032| 'Is Reality Determined': [
033| (dttm.date(2026, 8, 16), 0),
034| (dttm.date(2026, 8, 17), 0),
035| (dttm.date(2026, 8, 18), 0),
036| (dttm.date(2026, 8, 19), 0),
037| (dttm.date(2026, 8, 20), 6),
038| (dttm.date(2026, 8, 21), 10),
039| (dttm.date(2026, 8, 22), 5),
040| (dttm.date(2026, 8, 23), 15),
041| (dttm.date(2026, 8, 24), 25),
042| (dttm.date(2026, 8, 25), 37),
043| (dttm.date(2026, 8, 26), 69),
044| (dttm.date(2026, 8, 27), 37),
045| (dttm.date(2026, 8, 28), 0),
046| (dttm.date(2026, 8, 29), 0),
047|
048| ],
049| 'What is Consciousness?': [
050| (dttm.date(2026, 8, 16), 1),
051| (dttm.date(2026, 8, 17), 0),
052| (dttm.date(2026, 8, 18), 0),
053| (dttm.date(2026, 8, 19), 0),
054| (dttm.date(2026, 8, 20), 0),
055| (dttm.date(2026, 8, 21), 2),
056| (dttm.date(2026, 8, 22), 2),
057| (dttm.date(2026, 8, 23), 4),
058| (dttm.date(2026, 8, 24), 12),
059| (dttm.date(2026, 8, 25), 19),
060| (dttm.date(2026, 8, 26), 28),
061| (dttm.date(2026, 8, 27), 13),
062| (dttm.date(2026, 8, 28), 0),
063| (dttm.date(2026, 8, 29), 0),
064| ],
065| 'Entropy Isn’t Fundamental!': [
066| (dttm.date(2026, 8, 16), 0),
067| (dttm.date(2026, 8, 17), 0),
068| (dttm.date(2026, 8, 18), 0),
069| (dttm.date(2026, 8, 19), 0),
070| (dttm.date(2026, 8, 20), 2),
071| (dttm.date(2026, 8, 21), 1),
072| (dttm.date(2026, 8, 22), 0),
073| (dttm.date(2026, 8, 23), 3),
074| (dttm.date(2026, 8, 24), 4),
075| (dttm.date(2026, 8, 25), 10),
076| (dttm.date(2026, 8, 26), 20),
077| (dttm.date(2026, 8, 27), 12),
078| (dttm.date(2026, 8, 28), 0),
079| (dttm.date(2026, 8, 29), 0),
080| ],
081| }
082|
083|
084|
085| def create_chart (chart_data:list, fname:str, fpath:str) -> str:
086| """Create chart with four sub-charts.
086|
086| Inputs:
086| chart_data
086| A list with (at least) four sub-lists, one for each sub-chart.
086| Each sub-list has three items: name (str); dates (list); hit counts (list).
086|
086| Returns:
086| Name of the chart PNG image file.
086|
086| """
087|
088| c0_lab, c0_xs, c0_ys = chart_data[0]
089| c1_lab, c1_xs, c1_ys = chart_data[1]
090| c2_lab, c2_xs, c2_ys = chart_data[2]
091| c3_lab, c3_xs, c3_ys = chart_data[3]
092|
093| print(c0_ys)
094| print(c1_ys)
095| print(c2_ys)
096| print(c3_ys)
097| print()
098|
099|
100| filename = path.join(fpath,fname) if fpath else fname
101|
102|
103| margin = dttm.timedelta(1.0)
104|
105| def create_axis (ax, xs, ys, label, color):
106| """Create and plot an axis."""
107| round_up = lambda ns, interval=20: int(((max(ns)//interval)+1)*interval)
108|
109|
110| ax.xaxis_date()
111| ax.set_xlim(xs[0]-margin, xs[-1]+margin)
112| ax.xaxis.set_major_locator(mldates.DayLocator(bymonthday=range(16,30)))
113| ax.xaxis.set_major_formatter(mldates.DateFormatter('%m/%d'))
114|
115|
116| ax.set_ylim(0, round_up(ys))
117| ax.yaxis.set_major_locator(mlticks.MultipleLocator(20))
118| ax.yaxis.set_major_formatter(mlticks.FormatStrFormatter('%d'))
119|
120|
121| ax.grid(which='major', axis='both', color='#dfdfef', lw=1.2,ls='-',zorder=1, alpha=1.0)
122| ax.tick_params(which='major', axis='both', direction='out', color='#000000')
123|
124|
125| ax.bar(xs,ys, label=label, color=color, alpha=1.00, zorder=11)
126|
127|
128| fig, axes = plt.subplots(nrows=4, ncols=1)
129|
130|
131| fig.set_figwidth(10.0)
132| fig.set_figheight(8.0)
133|
134|
135| fig.subplots_adjust(left=0.055, right=0.98, bottom=0.050, top=0.95)
136|
137|
138| fig.suptitle('Traffic spike in late August 2026', fontsize=14, fontweight='bold')
139|
140|
141| create_axis(axes[0], c0_xs, c0_ys, c0_lab, color='#ff6633')
142|
143|
144| create_axis(axes[1], c1_xs, c1_ys, c1_lab, color='#33cc66')
145|
146|
147| create_axis(axes[2], c2_xs, c2_ys, c2_lab, color='#3366ff')
148|
149|
150| create_axis(axes[3], c3_xs, c3_ys, c3_lab, color='#cc33cc')
151|
152|
153| fig.legend(ncols=1, loc='upper left', bbox_to_anchor=(0.055,0.95))
154|
155|
156| fig.savefig(filename)
157| print('wrote: %s' % filename)
158| print()
159|
160| return filename
161|
162|
163| def process_data (input_data:dict) -> list:
164| """Convert input data to chart data.
164|
164| Inputs:
164| input_data
164| A dictionary with blog post names as keys and lists of tuples as values.
164| Each tuple has two values: a date; the number of hits on the post.
164|
164| Returns:
164| A list containing sub-lists.
164| Each sub-list has three items: name (str); dates (list); hit counts (list).
164|
164| """
165| chart_data = []
166|
167|
168| for ix,name in enumerate(input_data, start=1):
169| print(f'{ix}: {name}')
170|
171|
172| dates,counts = list(zip(*input_data[name]))
173|
174|
175| post_data = [name]
176| post_data.append(dates)
177| post_data.append(counts)
178|
179|
180| chart_data.append(post_data)
181|
182| print()
183|
184| return chart_data
185|
186|
187|
188| def test (input_data=PostHitsData):
189| """Test function. Print the Doc Strings and the input data."""
190|
191| print(f'{__name__ = }')
192| print(f'{__doc__ = }')
193| print(f'{create_chart.__doc__ = }')
194| print(f'{process_data.__doc__ = }')
195| print()
196|
197| for name in input_data:
198| print(f'{name}:')
199| for dt,n in input_data[name]:
200| print(f'{dt:%b %d}: {n:3d}')
201| print()
202| print()
203|
204| return input_data
205|
206|
207| def main (input_data=PostHitsData, fname:str="2026-08-traffic-spike.png", fpath:str=BasePath):
208| """Main function. Process the data and create the chart."""
209|
210|
211| chart_data = process_data(input_data)
212|
213|
214| file_name = create_chart(chart_data, fname, fpath)
215|
216|
217| return (file_name, chart_data, input_data)
218|
219|
220| if __name__ == '__main__':
221| print(f'running: {argv[0]}...')
222| print()
223| rv = test()
224| rv = main()
225| print()
226|
227| """eof"""
228|