z_2026-08-traffic-spike.html
001| """The Giant File Room post read spike (August 20-27)."""
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\blog\lcc'
011|
012|
013| DefaultData = {
014| 'The Giant File Room': [
015| (dttm.date(2026, 8, 16), 0),
016| (dttm.date(2026, 8, 17), 0),
017| (dttm.date(2026, 8, 18), 0),
018| (dttm.date(2026, 8, 19), 0),
019| (dttm.date(2026, 8, 20), 5),
020| (dttm.date(2026, 8, 21), 7),
021| (dttm.date(2026, 8, 22), 21),
022| (dttm.date(2026, 8, 23), 11),
023| (dttm.date(2026, 8, 24), 52),
024| (dttm.date(2026, 8, 25), 74),
025| (dttm.date(2026, 8, 26),114),
026| (dttm.date(2026, 8, 27), 40),
027| (dttm.date(2026, 8, 28), 0),
028| (dttm.date(2026, 8, 29), 0),
029|
030| ],
031| 'Is Reality Determined': [
032| (dttm.date(2026, 8, 16), 0),
033| (dttm.date(2026, 8, 17), 0),
034| (dttm.date(2026, 8, 18), 0),
035| (dttm.date(2026, 8, 19), 0),
036| (dttm.date(2026, 8, 20), 6),
037| (dttm.date(2026, 8, 21), 10),
038| (dttm.date(2026, 8, 22), 5),
039| (dttm.date(2026, 8, 23), 15),
040| (dttm.date(2026, 8, 24), 25),
041| (dttm.date(2026, 8, 25), 37),
042| (dttm.date(2026, 8, 26), 69),
043| (dttm.date(2026, 8, 27), 37),
044| (dttm.date(2026, 8, 28), 0),
045| (dttm.date(2026, 8, 29), 0),
046|
047| ],
048| 'What is Consciousness?': [
049| (dttm.date(2026, 8, 16), 1),
050| (dttm.date(2026, 8, 17), 0),
051| (dttm.date(2026, 8, 18), 0),
052| (dttm.date(2026, 8, 19), 0),
053| (dttm.date(2026, 8, 20), 0),
054| (dttm.date(2026, 8, 21), 2),
055| (dttm.date(2026, 8, 22), 2),
056| (dttm.date(2026, 8, 23), 4),
057| (dttm.date(2026, 8, 24), 12),
058| (dttm.date(2026, 8, 25), 19),
059| (dttm.date(2026, 8, 26), 28),
060| (dttm.date(2026, 8, 27), 13),
061| (dttm.date(2026, 8, 28), 0),
062| (dttm.date(2026, 8, 29), 0),
063| ],
064| 'Entropy Isn’t Fundamental!': [
065| (dttm.date(2026, 8, 16), 0),
066| (dttm.date(2026, 8, 17), 0),
067| (dttm.date(2026, 8, 18), 0),
068| (dttm.date(2026, 8, 19), 0),
069| (dttm.date(2026, 8, 20), 2),
070| (dttm.date(2026, 8, 21), 1),
071| (dttm.date(2026, 8, 22), 0),
072| (dttm.date(2026, 8, 23), 3),
073| (dttm.date(2026, 8, 24), 4),
074| (dttm.date(2026, 8, 25), 10),
075| (dttm.date(2026, 8, 26), 20),
076| (dttm.date(2026, 8, 27), 12),
077| (dttm.date(2026, 8, 28), 0),
078| (dttm.date(2026, 8, 29), 0),
079| ],
080|
081| }
082|
083|
084|
085|
086|
087|
088|
089|
090|
091| def create_chart (chart_data:list, fname:str, fpath:str) -> str:
092| """Create chart(s)."""
093|
094|
095| c0_lab, c0_xs, c0_ys = chart_data[0]
096| c1_lab, c1_xs, c1_ys = chart_data[1]
097| c2_lab, c2_xs, c2_ys = chart_data[2]
098| c3_lab, c3_xs, c3_ys = chart_data[3]
099|
100| print(c0_ys)
101| print(c1_ys)
102| print(c2_ys)
103| print(c3_ys)
104| print()
105|
106|
107| filename = path.join(fpath,fname) if fpath else fname
108|
109| margin = dttm.timedelta(1.0)
110|
111| def round_up (n:int, interval=20) -> int:
112| """Round number up to tens."""
113| return int(((n//interval)+1)*interval)
114|
115| def create_axis (ax, xs, ys, label, color='#ff6633'):
116| """Create and plot an axis."""
117|
118| ax.xaxis_date()
119| ax.set_xlim(xs[0]-margin, xs[-1]+margin)
120| ax.xaxis.set_major_locator(mldates.DayLocator(bymonthday=range(16,30)))
121| ax.xaxis.set_major_formatter(mldates.DateFormatter('%m/%d'))
122|
123| ax.set_ylim(0, round_up(max(ys)))
124| ax.yaxis.set_major_locator(mlticks.MultipleLocator(20))
125| ax.yaxis.set_major_formatter(mlticks.FormatStrFormatter('%d'))
126|
127| ax.grid(which='major', axis='both', color='#dfdfef', lw=1.2,ls='-',zorder=1, alpha=1.0)
128| ax.tick_params(which='major', axis='both', direction='out', color='#000000')
129|
130| ax.bar(xs,ys, label=label, color=color, alpha=1.00, zorder=11)
131|
132| fig, axes = plt.subplots(nrows=4, ncols=1, squeeze=False)
133| fig.suptitle('Traffic spike in late August 2026', fontsize=14, fontweight='bold')
134| fig.set_figwidth(10.0)
135| fig.set_figheight(8.0)
136| fig.subplots_adjust(left=0.055, right=0.98, bottom=0.050, top=0.95)
137|
138|
139| create_axis(axes[0][0], c0_xs, c0_ys, c0_lab, color='#ff6633')
140|
141|
142| create_axis(axes[1][0], c1_xs, c1_ys, c1_lab, color='#33cc66')
143|
144|
145| create_axis(axes[2][0], c2_xs, c2_ys, c2_lab, color='#3366ff')
146|
147|
148| create_axis(axes[3][0], c3_xs, c3_ys, c3_lab, color='#cc33cc')
149|
150| fig.legend(ncols=1, fontsize=10, loc='upper left', bbox_to_anchor=(0.055,0.95))
151|
152| fig.savefig(filename)
153| print('wrote: %s' % filename)
154| print()
155|
156| return filename
157|
158|
159| def process_data (input_data) -> list:
160| """Convert input data to chart data; return chart data."""
161|
162| chart_data = []
163|
164| for ix,name in enumerate(input_data, start=1):
165| print(f'{ix}: {name}')
166|
167|
168| dates,counts = list(zip(*input_data[name]))
169|
170|
171| post_data = [name]
172| post_data.append(dates)
173| post_data.append(counts)
174|
175|
176| chart_data.append(post_data)
177|
178| print()
179|
180| return chart_data
181|
182|
183|
184| def test (input_data):
185| """Test function."""
186| test_data = []
187| return test_data
188|
189|
190| def main (input_data, fname:str="2026-08-traffic-spike.png", fpath:str=BasePath):
191|
192|
193|
194|
195|
196|
197| chart_data = process_data(input_data)
198|
199|
200| file_name = create_chart(chart_data, fname, fpath)
201|
202|
203| return (file_name, chart_data, input_data)
204|
205| if __name__ == '__main__':
206| print(f'running: {argv[0]}...')
207| print()
208|
209| rv = main(DefaultData)
210| print()
211|
212| """eof"""
213|