User:Mathglot/Charts replacement project

This page is about brainstorming ideas to replace the charts and graphs that were disabled in 2022, and among other things, caused the {{Annual readership}} template to stop displaying a graph of page views of an article.

Input

edit

The input for the project is the output of the download function of the Toolforge page views tool, copied to an article subpage with subpagename /pageviews. As an example, the first ten rows of Talk:Liberation of France/pageviews are:

Date,"Liberation of France"
2024-06-01,533
2024-06-02,767
2024-06-03,825
2024-06-04,1049
2024-06-05,2133
2024-06-06,6184
2024-06-07,3233
2024-06-08,1751
2024-06-09,1345

Data structures

edit

I've been thinking of various data structures, and they might be different for the mockup and the module, at least the envelope for it. Some structures I've been thinking of are month based. One, following your general design for example, might be

["2024-01"] = 500, 750, 1000,500, -, 650, ..., 850, 900, ...     (up to 31 data points)

but in the end, if/when it is designed as a bot it would be up to the bot writer as far as what the best structure would be (although I would like to be part of that discussion).

However, for the mockup, rather than building my own parsing to analyze a lua structure (which I could do) I plan to reuse off-the-shelf stuff as much as possible, since the mockup would be a throwaway, so I thought that an easy data structure for a mockup could be simply a template written as a big #switch: whose parameters I could grab, either by month, or whatever way. Following the previous example, one would grab January like this:

{{pageviews get|year=2024|month=1}}

and the page data structure would either have a csv structure similar to the one above, and grab the items with {{Array}}. Another way, is that the data page itself would be coded as template calls (to a template that needn't even exist) and we could grab the values of them using {{template parameter value}}:

Example of using Tmpv to grab page data
  • {{Tmpv|User:Mathglot/sandbox|void|1|month}} → January
  • {{Tmpv|User:Mathglot/sandbox|void|1|data}} → 1500, 1750, 1000, 1500
  • {{Tmpv|User:Mathglot/sandbox|void|2|data}} → 2500, 2750, 2000, 2500
  • {{Tmpv|User:Mathglot/sandbox|void|3|data}} → 3500, 3750, 3000, 3500
  • {{Tmpv|User:Mathglot/sandbox|void|3|month}} → March
  • {{Tmpv|User:Mathglot/sandbox|nonesuch|1|a}}
  • {{Tmpv|User:Mathglot/sandbox|nonesuch|1|c}}
  • {{Tmpv|User:Mathglot/sandbox|nonesuch|2|a}}
  • {{Tmpv|User:Mathglot/sandbox|nonesuch|2|c}}

At the outset, the bot would emit the data in mockup style, but have hooks to switch easily to Lua style. (Or possibly it could emit both styles on the page from the start: the mockup would see only what it needs, and likewise for the module, making the transition seamless.)

As far as bot frequency, whether it is daily, weekly, or something else will depend, I imagine, on performance considerations, how expensive it is, and how many pages need it. Currently there are 52,886 transclusions of {{annual readership}}. If we did them weekly, we could run 7555 per day. I'm thinking that once we have a mockup and a bot, if all looks good, we just redirect {{annual readership}} to the mockup, and then at some point, a Module would replace the mockup, and then down the road at some point, hopefully, Module:Graph:Chart will be back.

Data

edit

Try these

  • French colonial empire
  • Regency of Algiers
  • Talk:Marie Curie‎
  • Wikipedia talk:WikiProject Catalonia‎

Design

edit

Patterns

edit

Some needed patterns:

  • .202%d%-%d%d%-%d%d – replace a date in the form 'yyyy-mm-dd' preceded by newline with null (remove dates and newlines):
    • {{#invoke:String|replace|source={{<pageviews subpage>}}|pattern=.202%d%-%d%d%-%d%d|replace=|plain=false}}
  • ^Date,"[^"]+" - strip first line column headers:
    • {{#invoke:String|replace|source={{<pageviews subpage>}}|pattern=^Date,"[^"]+"|replace=|plain=false}}
  • .?(202%d%-%d%d%-%d%d)%,(%d+) – create comma-sep date:views items after stripping col headers
    • {{#invoke:String|replace|source={{#invoke:String|replace|source={{Talk:Liberation of France/pageviews}}|pattern=^Date,"[^"]+"|replace=|plain=false}}|pattern=.?(202%d%-%d%d%-%d%d)%,(%d+)|replace=%1:%2,|plain=false}}

Templates

edit
  • {{Xreadership}}, tmbox for placement on article talk pages; calls Xviews.
  1. {{xviews}}, page views charting template; entry point and user param handling.
  2. {{xviews/age}}, return the age in days of the given pageviews file
  3. {{xviews/xvmain}}, main loop: calls item_bar in a loop to generate the chart.
  4. {{xviews/item bar}}, Emits one progress bar-style graphic corresponding to a given line number of a page views download file created by the pageviews tool
  5. {{xviews/vbar}}, generates a single page views bar, currently horizontal only
  6. {{xviews/max views}}, return the maximum value from downloaded pageviews data.
  7. {{xviews/view count}}, return the count of page view statistics in downloaded pageviews data
  8. {{xviews/nth view}}, returns the nth view item (date:value) from downloaded pageviews data.
  9. {{xviews/xlabel}}, returns a normalized form of the date for bar id currently, just drops year and bolds day 1.
  10. {{xviews/x-axis}}, generates an x-axis legend with labeled tick marks for a horizontal page views chart

Pseudo-globals:

Categories

edit

Examples

edit
06-26251
06-27252
06-28221
06-29258
06-30253
07-01304
07-02241
07-03249
07-04306
07-05254
07-06285
07-07297
07-08311
07-09290
07-10281
07-11274
07-12254
07-13285
07-14288
07-15300
07-16300
07-17306
07-180
07-19273
void<span class="vbar-h" alt="Page views for (date) = (views)." style="; width:Expression error: Unrecognized word "outrange".%; ">outrange
05-21298
05-22275
05-23298
05-24271
05-25353
05-26395
05-27360
05-28396
05-29339
05-30313
05-31311
06-01360
06-02359
06-03349
06-04299
06-05415
06-061482
06-07790
06-08525
06-09402
06-10370
06-11343
06-12319
06-13320
06-14291
06-15284
06-16298
06-17285
06-18282
06-19251
06-20278
06-21320
06-22269
06-23288
06-24266
06-25326
06-26251
06-27252
06-28221
06-29258
06-30253
07-01304
07-02241
07-03249
07-04306
07-05254
07-06285
07-07297
07-08311
07-09290
07-10281
07-11274
07-12254
07-13285
07-14288
07-15300
07-16300
07-17306
07-180
07-19273
0
150
300
450
600
750
900
1050
1200
1350
page views for Liberation of France


See also

edit