leamare / D2-LRG-lrg2

Dota 2 League stats Report Generator - a collection of simple (not anymore) scripts to fetch match data, generate, display and backup reports. DEPRECATED.
https://stats.spectral.gg/lrg2/
GNU General Public License v3.0
9 stars 2 forks source link
cli dota-stats dota2 mysql-database php

Dota 2 League Report Generator (D2-LRG-lrg2)

Current version: 2.25.1

This is the lrg2 version that won't be updated any further.

Well, kind of. I guess it will be updated eventually and the repo will be renamed, but for now it's a huge mess.

D2-LRG (for short) is a tool for fetching stats for dota matches and forming fancy stats pages with every data you may need.

Before we start

So, first of all, I do not recommend using this project for yourself. Like at all.

It was created just as three (four) simple PHP scripts to gather detailed match data for Dota and generate JSON report blobs and HTML pages for them. It was pretty simple initially and it just became a much bigger thing I initially intended it to be. As you may understand, it's pretty hard to understand what's going on in this code and it's hard to modify it. It doesn't follow any PSR suggestions. It doesn't use Composer. It's pretty simple in its functionality and it was written mostly for myself.

The reason why it's open source project is pretty simple: I just thought "why not"?

So technically you can use if you want. Altho you need to keep in mind some things:

  1. It's pretty ugly inside, it's hard to modify and some things are just illogical.
  2. I abandoned it a long time ago. I released some fixes relatively recently and I will release some hotfixes later on (probably), but the thing is it won't be usable at some point.

Around Jan 2019 I switched to part-time development of a D2-LRG-Simon project that should've effectively replace this project and it would be much cleaner and easier to use/modify. However I ended up switching to another project with closed source (D2-LRG-Guame) that's using a lot of Simon ideas and code inside. Guame is still in PHP and it's using ReactPHP, the fetcher is server that's listening for orders all the time, and there's just WebAPI for all the stuff.

I could've develop Simon in this same repo, but it's so defferent in it's core so it's easier to write everything from scratch. And the final nail is Simon will probably be a JavaScript based project.

So what does it mean in context of this repository:

  1. It doesn't show how I would actually write a decent PHP code. I will write some showcase projects later on for that.
  2. As soon as I finish the first working version of D2-Simon, this repo will be abandoned completely.
    • However, Simon will be able to transform lrg2 JSON reports into its own reports format. So technically (if you want) you can use this collection of scripts and make your reports and then reuse it here
  3. Simon will be somewhat ready sometime around Feb 2020 (maybe even later) and then I will be working on an interface for all this, so this one will be completely shut down around June 2020.

Features

Thanks to custom leagues, it can be used as a tool for teams as well. It is possible to fetch data for enemy teams before tournaments, as well as forming stats reports for your own team to make analysis for that.

Working prototype: http://stats.spectral.gg/

How does it work

D2LRG is made of four scripts, divided into smaller modules:

Why PHP and Why migrate to LRG-Simon

  1. The project was created as a proof-of-concept collection of scripts. Initially it should be working on a cheapest web server possible with minimal effort. It became much bigger than intended, but it still can be used that way.
  2. PHP5 and PHP7 are easy and fast tools to work with
  3. LRG-Simon (LRG3) will be rebuilt from scratch. A lot of features and ideas will be backported from LRG2, but the code will be much easier to read and to work with. It will also be harder to work with, but it will be more powerful too.

What do I need to use it?

MySQL database server and PHP interpreter. Nothing really special, you can use regular XAMPP for it.

I also recommend using PHPMyAdmin for manual data change.

It would be nice to have bash on your system. For Windows it's recommended to have git bash or cygwin with ConEmu.

Dependencies:

After getting D2LRG code to your computer, run php setup.php. It will install the rest of dependencies:

Setup

Use php setup.php to install, setup and update all the things.

You can also specify special parameters:

It's recommended to use php setup.php -ds to update.

How to use

LRG is made of these modules:

Beforehand you should use setup.php to initialise settings (like database credentials or Steam API key) file and download dependencies. Just run it and follow instructions.

You can also use setup.php to update dependencies or settings. It has special parameters to skip unnecessary parts:

rg_init

Creates database from template and saves leaguefile.

Parameters:

rg_backup

Creates/restores backup. Backups are saved to backups folder.

Parameters:

rg_fetcher

Fetches data for matches in matchlist.

Parameters:

Fetcher has two modes: "listen" mode and the regular one. Fetcher is using matchlist from matchlists follder by default, listen mode changes it to STDIN. It's not async because of time limitation on OpenDota side (basically you can't be too fast with your requests anyway, so there's no need to be asynchronous).

Matchlist is basically a line delimited text file, each line is a new match string. It's using following rules:

Listen mode accepts lines in the same format.

Fetcher matchrule string is a string matching following format: {matchid}::{rule_type}:{search}:{value}::...rules, where {search} is replaced by {value} following specific {rule_type} rules. Any matchrule string may have an unlmited number of rules.

Rules types:

Additional parameters to inject in league json descriptor:

And some things about the listen mode:

rg_analyzer

Analyzes and requests data, forms report file.

Parameters:

rg_report_web

This file (and rg_report_out_settings.php) should be put on your webserver, as well as "reports/" folder with all the reports in it and "res/", "modules/functions" and "modules/view". You will also need to use .htaccess to disable access to modules and settings files.

Settings you can change in it:

If cache file is specified, it will be generated at first page load and then every time any report changes. While generating, it opens every report and creates a descriptor for it, so it may take a while at first.

GET parameters:

It can use custom styles. To use them you need to put a .css file to "res/custom_styles" directory. You can also get some additional information from custom styles library repository: https://github.com/leamare/D2-LRG-Custom-Styles

Categories file is a simple JSON configuration file. If it is specified and it exists, categories will be loaded and then applied to every report on instance. There is an example of categories config available, but essentially it looks like this:

{
  "category_tag": {
    "name": "Category Name",
    "names_locales": { "ru": "Category name for a specific locale" },
    "desc": "Category Description",
    "desc_locales": { "ru": "Category description for a specific locale" },
    "filters": [
      [ [ 0, "value" ] ]
    ],
    "custom_style": "custom style",
    "custom_logo": "custom logo"
  }
}

All category filters types are listed in modules/view/functions/check_filters.php. First level filters are applied with logical OR, second level filters are applied with logical AND.

Tools

Tools are additional scripts that can be used for specific things. All of them should be executed from the main directory with command similar to php tools/%TOOL%.php %PARAMETERS%.