# PopulationCounter

Summary: Produces a linear estimate of a number, for example the population of an area, when given two data points and their corresponding times.
Version: 1.0
Prerequisites:
Status:
Maintainer: Ben Stallings
Categories: Markup

## Questions answered by this recipe

How can I include an estimate of current world population or some other time-dependent statistic in my wiki?

## Description

Given two values and times in the wiki markup, this recipe displays an estimate of the current value.

Include the following in your config.php or a page's or group's .php file:

```Markup('popcount', 'directives', "/\(:popcount[ 	]*(.*?):\)\s*/e", "PopCount(PSS('\$1'))");

function PopCount(\$params) {
extract(ParseArgs(\$params));
if ((\$pop1) and (\$pop2) and (\$date1) and (\$date2)) {
\$time1 = strtotime(\$date1); \$time2 = strtotime(\$date2);
\$rate = (\$pop2 - \$pop1) / (\$time2 - \$time1);
return number_format(\$pop1 + (\$rate * (time() - \$time1)));
} else return "(:popcount \$params:)";
}
```

The syntax is (:popcount pop1=1234 date1=1/2/1934 pop2=2345 date2=2/3/1945:)

The four parameters can be typed in any order, and the dates can be provided in any format, though if your dates include spaces you will need to put quotes around them. Date2 is assumed to be later than date1.

The markup extrapolates from the two data points and produces an estimate of the value at the current time.

## Notes

Note that this is a linear extrapolation, not exponential, so you should use this markup with phenomena that approximate linear growth during the relevant time period, and update the data points frequently.

For example, if you enter two population data points from [(approve links) edit diff] , you will find that the estimate produced by this recipe is slightly lower than the live one on that site. That is because the population curve is not linear (as the recipe assumes it is) but is currently decreasing in slope.

## Release Notes

If the recipe has multiple releases, then release notes can be placed here. Note that it's often easier for people to work with "release dates" instead of "version numbers".