Repository navigation
Statistics
The website's statistics (the map and figures on its front page, and /statistics) count every changeset whose
created_by starts with LaneStudio. A cron job on the web server collects them into a database and writes the
files the pages read, so a page view never touches the database.
| Step | What | Where |
|---|---|---|
| Find | Reads OpenStreetMap's changeset feed (a file a minute) from where it stopped, keeping Lane Studio's changesets | replication.php |
| Read the edits | Downloads each closed changeset's edits from the API and the versions before them: objects created, modified and deleted, tag keys changed, ways with lane tags changed, length of road edited | details.php |
| Country | The country at each changeset's centre, from the borders iD uses |
countries.php, countries.json
|
| Write |
data/statistics.json (figures, latest 5, leaderboard, per day, countries, versions by day with r2, r3 … counted with the day's first, the 20 tag keys changed most) and data/changesets.geojson (the map's points) |
snapshot.php |
| Show | The figures, map (MapLibre GL on OpenFreeMap's dark style), chart, lists (the first 5 versions and tags, the rest under Show more) and leaderboard |
view.php, statistics.php, index.php, assets/js/statistics.js; the hosts it loads from are allowed in .htaccess's Content-Security-Policy |
All in LanesWebsite/includes/statistics/ unless named otherwise. collect.php runs the steps; each run stops after
about 4 minutes, and a lock keeps two runs from overlapping. The first runs catch up from the start day, a few hours
of runs for a month of history; the page says when it is still catching up.
The database has two tables, ls_changesets (one row per changeset) and ls_meta (how far the feed has been read).
They are created on the first run. The collector works with MySQL/MariaDB or, for trying it locally, SQLite.
-
Deploy the website (the Deploy LaneStudio to server workflow, website) so the files are there.
-
Make a database: cPanel → MySQL Databases → create a database (
lanestudio) and a user with a strong password, then Add User To Database with ALL PRIVILEGES. cPanel puts your account name in front of both (CPANELUSER_lanestudio). -
Give the collector its settings: cPanel → File Manager →
public_html/includes/statistics/→ copyconfig.example.phptoconfig.phpand fill in the database name, user and password.config.phpstays on the server: it is never committed, and deploys leave it alone. -
Run it once by hand to check it (cPanel → Terminal, or SSH):
php ~/public_html/includes/statistics/collect.phpIt prints how far it read and how many changesets it found. An error about the database means a wrong name, user or password in
config.php. -
Add the cron job: cPanel → Cron Jobs → Common settings: Once per five minutes (
*/5 * * * *), command:/usr/local/bin/php /home/CPANELUSER/public_html/includes/statistics/collect.php --quiet
Use your account name and the PHP path your host gives (cPanel's Cron Jobs page shows it;
which phpin the Terminal). With--quiet, cron emails you only when something goes wrong.
The pages show the statistics once the first run has written data/statistics.json; until then /statistics says
they are coming and the front page leaves the section out.
collect.php option |
Does |
|---|---|
--quiet |
Prints nothing unless something goes wrong |
--time=SECONDS |
How long a run may take (240) |
--snapshot |
Only writes the data files again |
--changeset=ID |
Adds one changeset by its number (if made with Lane Studio) |
config.php setting |
Is |
|---|---|
dsn, username, password
|
The database (PDO) |
start |
The first day to collect, used once when the database is empty |
hidden_users |
OpenStreetMap user ids (uid) shown as "A mapper" and left off the leaderboard, for anyone who asks |
cp LanesWebsite/includes/statistics/config.example.php LanesWebsite/includes/statistics/config.php
# set 'dsn' => 'sqlite:' . __DIR__ . '/statistics.sqlite' and a recent 'start' day
php LanesWebsite/includes/statistics/collect.php
cd LanesWebsite && php -S localhost:8000 router.phpconfig.php, the SQLite file and LanesWebsite/data/ are ignored by git and left out of deploys. After updating
@rapideditor/country-coder, run node scripts/build_statistics_countries.js to rebuild countries.json.
Copied from docs/ on every change; edit the files there, not here.
Lane Studio
- Guide
- FAQ
-
Tag coverage
- Tags: Accessibility
- Tags: Addresses
- Tags: Advertising
- Tags: Aerialways
- Tags: Aeroways
- Tags: Agriculture
- Tags: Amenities
- Tags: Animals
- Tags: Annotations
- Tags: Barriers
- Tags: Bicycles
- Tags: Boundaries
- Tags: Bridges
- Tags: Buildings
- Tags: Buses
- Tags: Changeset
- Tags: Children
- Tags: Climbing
- Tags: Clubs
- Tags: Communications
- Tags: Crafts
- Tags: Crossings
- Tags: Cycleways
- Tags: Diplomacy
- Tags: Education
- Tags: Emergencies
- Tags: Ferries
- Tags: Food and beverages
- Tags: Government
- Tags: GPS
- Tags: Hazards
- Tags: Health
- Tags: Highways
- Tags: Hiking
- Tags: Historic
- Tags: Import
- Tags: Industrial
- Tags: Infrastructure
- Tags: Landcover
- Tags: Landuse
- Tags: Leisure
- Tags: Lifecycle
- Tags: Man made
- Tags: Marine
- Tags: Marine navigation
- Tags: Maritime
- Tags: Mechanics
- Tags: Military
- Tags: Motorcycles
- Tags: Names
- Tags: NaPTAN
- Tags: Natural
- Tags: Offices
- Tags: Parking
- Tags: Pipelines
- Tags: Places
- Tags: Police
- Tags: Power
- Tags: Products
- Tags: Properties
- Tags: Public transport
- Tags: Railways
- Tags: References
- Tags: Religion
- Tags: Restrictions
- Tags: Riding
- Tags: Routes
- Tags: Shops
- Tags: Social facilities
- Tags: Social networks
- Tags: Sports
- Tags: Swimming and bathing
- Tags: Tourism
- Tags: Transport
- Tags: Vending machines
- Tags: Waste processing
- Tags: Water
- Tags: Water management
- Tags: Waterways
- Tags: Other
- Developers
- API
- Contributing
- Releasing
- Accessibility
- Privacy
- Security
- Code of conduct
- Changelog