Skip to content
This repository has been archived by the owner on Jan 9, 2021. It is now read-only.

Commit

Permalink
Add ps2_analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
spascou committed May 4, 2020
0 parents commit b93caa2
Show file tree
Hide file tree
Showing 40 changed files with 54,088 additions and 0 deletions.
134 changes: 134 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Datafiles
examples/datafiles/*
# Plots
examples/plots/*
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Sylvain Pascou

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# ps2-analysis [WIP]

*ps2-analysis* is a library written in Python >= 3.8 that uses the [ps2-census](https://github.com/spascou/ps2-census)
Daybreak Planetside 2 Census API client to get data and then analyses it.

* [ps2-analysis](#ps2-analysis)
* [Setup](#setup)

## Setup

- Clone this repository
- Setup a Python >= 3.8 virtual environment
- Install [poetry](https://github.com/python-poetry/poetry)
- Install dependencies with `poetry install`
- Run tests with `pytest`
- Update dependencies with `poetry update`

- Add your Census API service ID to the `CENSUS_SERVICE_ID` environment variable
- Create two folders inside the `examples` of the cloned repository: `datafiles` and `plots`

- Run python scripts in examples

It will update the `examples/datafiles/weapons.ndjson` file from the Census API, then parse the data
and generate whatever output the example script calls for.

Plots are interactive and generated with [altair](https://github.com/altair-viz/altair), so they need to be opened in
a browser.

If `examples/datafiles/weapons.ndjson` already exists, next execution will simply read it instead of
updating from the API. Delete it to force the update, if so wished.
26 changes: 26 additions & 0 deletions examples/discover.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import json
import os
from typing import List, Optional

from ps2_analysis.data_file import DataFile, load_data_file, update_data_file
from ps2_analysis.utils import discover

SERVICE_ID: Optional[str] = os.environ.get("CENSUS_SERVICE_ID")
DATAFILES_DIRECTORY: str = "datafiles"

if not SERVICE_ID:
raise ValueError("CENSUS_SERVICE_ID envvar not found")

update_data_file(
data_file=DataFile.WEAPONS, directory=DATAFILES_DIRECTORY, service_id=SERVICE_ID
)

data: List[dict] = load_data_file(
data_file=DataFile.WEAPONS, directory=DATAFILES_DIRECTORY
)

print(
json.dumps(
{k: list(v) for k, v in discover(data).items()}, sort_keys=True, indent=2
)
)
34 changes: 34 additions & 0 deletions examples/fire_simulation_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os
from typing import Dict, List, Optional

from ps2_analysis.data_file import DataFile, update_data_file
from ps2_analysis.visualizations.fire_simulation import (
generate_infantry_weapon_fire_simulation_plot,
)
from ps2_analysis.weapons.classes.infantry_weapon import InfantryWeapon
from ps2_analysis.weapons.infantry_weapons import generate_infantry_weapons

SERVICE_ID: Optional[str] = os.environ.get("CENSUS_SERVICE_ID")
DATAFILES_DIRECTORY: str = "datafiles"
PLOTS_DIRECTORY: str = "plots"

if not SERVICE_ID:
raise ValueError("CENSUS_SERVICE_ID envvar not found")

update_data_file(
data_file=DataFile.WEAPONS, directory=DATAFILES_DIRECTORY, service_id=SERVICE_ID
)

infantry_weapons: List[InfantryWeapon] = generate_infantry_weapons(
data_files_directory=DATAFILES_DIRECTORY
)

ifw_id_idx: Dict[int, InfantryWeapon] = {w.item_id: w for w in infantry_weapons}

trac_5 = ifw_id_idx[43]
uppercut = ifw_id_idx[39001]
ksr = ifw_id_idx[25002]

generate_infantry_weapon_fire_simulation_plot(
weapon=trac_5, shots=10, runs=100, directory=PLOTS_DIRECTORY
)
22 changes: 22 additions & 0 deletions examples/generate_infantry_weapons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import os
from typing import Dict, List, Optional

from ps2_analysis.data_file import DataFile, update_data_file
from ps2_analysis.weapons.classes.infantry_weapon import InfantryWeapon
from ps2_analysis.weapons.infantry_weapons import generate_infantry_weapons

SERVICE_ID: Optional[str] = os.environ.get("CENSUS_SERVICE_ID")
DATAFILES_DIRECTORY: str = "datafiles"

if not SERVICE_ID:
raise ValueError("CENSUS_SERVICE_ID envvar not found")

update_data_file(
data_file=DataFile.WEAPONS, directory=DATAFILES_DIRECTORY, service_id=SERVICE_ID
)

infantry_weapons: List[InfantryWeapon] = generate_infantry_weapons(
data_files_directory=DATAFILES_DIRECTORY
)

item_id_idx: Dict[int, InfantryWeapon] = {w.item_id: w for w in infantry_weapons}
Loading

0 comments on commit b93caa2

Please sign in to comment.