<commit_before># xonotic-server-list

Provide server list front-end and display player count stats over time.

## Frontend

Coming soon.

## Backend/Middleware

### Installation

Setup a venv and install the requirements

```
virtualenv -p /usr/bin/python3 venv
ln -s venv/bin/activate
source activate
pip install -r requirements.txt
```

### Configuration

Create a configuration file:

```
cp config/example.config.ini config/config.ini
```

Its contents should appear similar to below:

```
[default]
master_server = dpmaster.deathmask.net
stats_file = resources/data/stats.json
ip_location_db = resources/data/GeoLite2-Country.mmdb
```

### Usage

Print current stats to output:

```
./bin/players2json.py -o
```

Write current stats to output (appends to file):

```
./bin/players2json.py -w
```


See help for additional options:

```
./bin/players2json.py -h
```

The generated json is an array of objects padded by a `data` object.

```
{
    data: [
        {
            time: unixtime,
            total_players: 30,
            countries: {
                EUR: 20,
                AUS: 2,
                USA: 8
            }
        },
        …
    ]
}
```

#### Development

The object looks similar to the example below:

**Note: the players value returns `None`, this is a bug. numplayers is used instead.**

```
{'@type': 'Q3S',
 '@address': '172.16.31.10:26010',
 '@status': 'UP',
 'hostname': '172.16.31.10:26010',
 'name': '(SMB) '
         'USA '
         'Instagib+Hook '
         'CTF/DM '
         '[DALLAS]',
 'gametype': None,
 'map': 'concrete_space_xon',
 'numplayers': '9',<commit_msg>added syntax highlighting<commit_after># xonotic-server-list

Provide server list front-end and display player count stats over time.

## Frontend

Coming soon.

## Backend/Middleware

### Installation

Setup a venv and install the requirements

```
virtualenv -p /usr/bin/python3 venv
ln -s venv/bin/activate
source activate
pip install -r requirements.txt
```

### Configuration

Create a configuration file:

```
cp config/example.config.ini config/config.ini
```

Its contents should appear similar to below:

```ini
[default]
master_server = dpmaster.deathmask.net
stats_file = resources/data/stats.json
ip_location_db = resources/data/GeoLite2-Country.mmdb
```

### Usage

Print current stats to output:

```
./bin/players2json.py -o
```

Write current stats to output (appends to file):

```
./bin/players2json.py -w
```


See help for additional options:

```
./bin/players2json.py -h
```

The generated json is an array of objects padded by a `data` object.

```json
{
    "data": [
        {
            "time": 1460344051,
            "total_players": 30,
            "countries": {
                "EUR": 20,
                "AUS": 2,
                "USA": 8
            }
        },
        …
    ]
}
```

#### Development

The object looks similar to the example below:

**Note: the players value returns `None`, this is a bug. numplayers is used instead.**

```
{'@type': 'Q3S',
 '@address': '172.16.31.10:26010',
 '@status': 'UP',
 'hostname': '172.16.31.10:26010',
 'name': '(SMB) '
         'USA '
         'Instagib+Hook '
         'CTF/DM '
         '[DALLAS]',
 'gametype': None,
 'map': 'concrete_space_xon',
 'numplayers': '9',
{'fraction_non_alphanumeric': 0.14447505356596266, 'fraction_numerical': 0.028160391796755432, 'mean_word_length': 2.7010192525481314, 'pattern_counts': {'":': 7, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '434163', 'n_tokens_mistral': 1185, 'n_tokens_neox': 1085, 'n_words': 311}