Jump to content

Template:Xviews/doc

From Wikipedia, the free encyclopedia

May be used to generate a bar chart showing page views for a given article or page from a pageviews file downloaded from the pageviews tool. Mock-up; see § Notes.

Usage

[edit]

{{xviews}}
{{xviews|pageviews file}}

Parameters

[edit]

There are three optional parameters:

  • |1= – the pageviews file.(Default: {{SUBJECTPAGENAME}}; place on Talk page to get pageviews for the article.) See § Instructions.
  • |ct= – the count of page view bars to display (optional; default: 75; max: 150.) Large values may cause failure, see § Notes.
  • |stale= – number of days when a pageviews file becomes stale. Stale files will not generate a chart; a link to the § Update instructions is provided instead. (optional; default: 30).

Hooks are in place for additional parameters, not yet implemented:

  • |log= – use logarithmic data points; ideal for spiky or highly variable page view data   (not implemented)
  • |mode= – flips the chart from horizontal to vertical   (not implemented)

Examples

[edit]
Example 1. page views for World War II

{{xviews|Talk:World War II/pageviews}}

07-2817492
07-2922065
07-3015410
07-3114414
08-0114765
08-0214319
08-0314910
08-0416761
08-0515195
08-0615074
08-0714352
08-0814872
08-0914028
08-1014893
08-1116612
08-1217183
08-1315369
08-1415974
08-1515341
08-1615894
08-1716571
08-1817052
08-1917177
08-2015807
08-2116478
08-2217245
08-2316188
08-2415856
08-2517127
08-2618046
08-2716013
08-2817527
08-2916276
08-3015215
08-3114623
09-0117237
09-0216936
09-0316240
09-0415391
09-0516129
09-0615726
09-0715118
09-0815791
09-0916711
09-1015917
0
2210
4420
6630
8840
11050
13260
15470
17680
19890
page views for World War II

Instructions

[edit]

How-to

Displaying an experimental pageviews bar chart for a given article involves these steps:

  1. add {{Xreadership}} to the Talk page below the rest of the banners; hit Preview, and click [show].
  2. open tabs for the /pageviews page (edit it if blue), and for the pageviews tool
  3. download the pageviews data from the tool (three months's worth recommended) and copy it to the open /pageviews tab (overwriting any former data), but do not save it yet;
  4. test in Preview mode (important!). If there are problems, replace the call with {{Xreadership|ct=45}} and preview again. Publish when the bar chart *and* the rest of the page are displayed properly.
  5. Optional: to view as much pageviews data as possible without blowing up the rest of the page, fine tune the value of |ct= to keep template usage high, but within bounds; i.e. PEIS below 2Mb; 1.7 is better. Be aware that if someone later adds complex templates in a discussion, they may not work if insufficient resources are left after the chart; keep the page on your watchlist and monitor changes.

Pageviews file

This template requires a pageviews file in CSV format, which by default is expected to be available as a subpage of the article Talk page where the template is placed. Positional param 1 is available as an override, to point somewhere else. The pageviews file may be placed by bot, or manually by an editor.

Contents of the pageviews file may be downloaded manually from the pageviews tool. Request output in CSV format, and copy it to a Talk subpage whose subpagename is pageviews; e.g., Talk:Cleopatra/pageviews. A good amount of data to request is three months' worth. Any amount of data may be copied to the subpage, but the template will only display at most the last 150 lines in the file to avoid issues caused by technical limitations with templates.The template has to read the whole pageviews file even if less data is displayed, and long files may exceed some technical limitations and cause the template to fail; reducing the pageviews file size may permit more of it to be displayed, than when the total filesize is larger. Empirically, the optimal amount appears to be 90 or 100 days, for Talk pages with an average number of other templates on them. Some pages will show as many as 150 days' worth; rarely more. However much data is downloaded to the file, you may always display less than the full amount using param |ct= in order to avoid exceeding template limits.

Maintenance

If the pageviews file is not updated, it will eventually reach the staleness threshold (currently, 30 days) and after that will not be displayed. To display it again, repeat download step 1 above. You may download and save the pageviews file for a given page as often as you like; just save it on top of the old one.

Notes

[edit]

This template is a mockup of a replacement for the non-working {{annual readership}} based on {{Graph:Chart}} which was withdrawn for security reasons. It is a proof of concept and if approved, is designed to be replaced by a Lua module.

Technical limitations

There are various limitations in the template which will disappear in a Lua version, such as reaching the PEIS limit if too many statistics are charted at once. The default value of param |ct= is a throttle to help avoid this. If there are a lot of other templates on the page, you may need do reduce the value of that parameter to stay within limits. See Help:Template limits.

Troubleshooting

  • Chart does not display – some cases are recognized by the template and trapped with an error message; others are not.
    • recognized errors:
    1. missing file – if the pageviews file is missing, you should see a red error message.
    2. stale data – if the data in the pageviews file is older than the 'stale' age, then a message about stale data should be emitted.
    • unrecognized:
    1. template limits exceeded – if there is no chart and no error message, you may have exceeded one of the template limits. In this case, you may see just the template name instead of any output; this is a sign that PEIS has been exceeded. Try running it in preview mode; if PEIS is exceeded, you may see the message, Warning: Post-expand include size is too large. Some templates will not be included. in a pink box at the top, and the parser profiling data will show the PEIS maxed out at "2,097,152 of 2,097,152 bytes". If you see that, try reducing the value of |ct= until it shows output in preview mode, then save it. Reducing the pagefile size will also help; the template reads and processes all the data (multiple times, which a module won't), and if your pagefile has a year's worth of data, you may only be able to display 30 days of it, whereas if you reduce it to three months of data, you can probably display all of it.

Known issues

  • Wrapping – in some cases, the page views in the right margin wraps to the next line; this usually only happens with the longest bar in the chart, and especially when the values are greater than 1,000 (and thus require 4 or more characters)
  • length of longest bar – by design, the bar representing the page view statistic with the highest value should be close to the right margin (allowing space for date on the left and view statistic on the right); all other bars are positioned as a fraction of the longest one. Currently, the longest bar will display close to the right margin if all data in the pageviews file is displayed, but if less than all data is displayed (due to use of |ct= or default value) and the largest value in the pageviews file happens to belong to a non-displayed statistic (i.e., one more than three months ago, in the default chart), then it's possible that the displayed bars will appear shorter, as they are still displayed relative to the largest page view statistic in the file, even if it is not displayed. The fix is to display the longest *displayed* statistic close to the right margin, and other bars proportional to it. In practice, this means a rewrite of {{xviews/max views}} to return the value of the largest displayed statistic, not the largest one in the pageviews file.

Performance

[edit]

This is a mockup intended to be replaced in the medium term by a Lua module, and ultimately by repair to the Graphs problem, so performance of the template isn't really a major issue. Check WP:Parser profiling data for performance data. One chart with three months of data (92 bars) took 2.32 seconds (real) and 1.86 of 2.09Mb PEIS. Templates don't have local storage, and one upshot is that the template does a great deal of repetitive accesses (> 100) to the pageviews file that would turn into one access in Lua, so performance improvement in a module should be dramatic.

See also

[edit]