Skip to content

Commit

Permalink
refactor: move into src
Browse files Browse the repository at this point in the history
  • Loading branch information
cathaypacific8747 committed Feb 9, 2024
1 parent 95c27ce commit 7624402
Show file tree
Hide file tree
Showing 94 changed files with 113 additions and 132 deletions.
8 changes: 4 additions & 4 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
research/** linguist-vendored
am4/utils/stubs/** linguist-vendored
am4/utils/tests/** linguist-vendored
am4/utils/cpp/include/ext/** linguist-vendored
am4/db/pb_migrations/** linguist-vendored
src/am4/utils/stubs/** linguist-vendored
src/am4/utils/tests/** linguist-vendored
src/am4/utils/cpp/include/ext/** linguist-vendored
src/am4/db/pb_migrations/** linguist-vendored
src-v2-v3/** linguist-vendored
src-old/** linguist-vendored
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ research/nn/routes.csv
research/nn/nn_selfself.py
research/analytics/*.json
research/analytics/*.parquet
config.json
config.production.json
am4/utils/build*
*config.json
*config.production.json

# Python.gitignore, C++.gitignore, CMake.gitignore
# Prerequisites
Expand Down
6 changes: 1 addition & 5 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"${workspaceFolder}/**",
"${vcpkgRoot}/x64-windows/include",
"${vcpkgRoot}/x86-windows/include",
"${workspaceFolder}/am4/utils/build/_deps/duckdb_folder-src"
],
"defines": [
"_DEBUG",
Expand All @@ -21,10 +20,7 @@
},
{
"name": "Linux",
"includePath": [
// "${workspaceFolder}/**",
// "${workspaceFolder}/am4/utils/build/_deps/duckdb_folder-src"
],
"includePath": [],
"defines": [],
"compilerPath": "/usr/bin/clang++",
"cppStandard": "c++17",
Expand Down
6 changes: 3 additions & 3 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"files.associations": {
"*.spec": "python"
},
"cmake.sourceDirectory": "${workspaceFolder}/am4/utils",
"cmake.buildDirectory": "${workspaceFolder}/am4/utils/build-vscode",
"cmake.sourceDirectory": "${workspaceFolder}/src/am4/utils",
"cmake.buildDirectory": "${workspaceFolder}/src/am4/utils/build-vscode",
"cmake.configureArgs": [
"-DCOPY_DATA=1",
"-DCMAKE_VERBOSE_MAKEFILE=1",
],
"C_Cpp.autoAddFileAssociations": false,
"cmake.configureOnOpen": true
"cmake.configureOnOpen": true,
}
8 changes: 1 addition & 7 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"label": "py: generate stubs",
"type": "shell",
"options": {
"cwd": "${workspaceFolder}/am4/utils"
"cwd": "${workspaceFolder}/src/am4/utils"
},
"command": "${command:python.interpreterPath} generate-stubs.py",
"problemMatcher": []
Expand All @@ -40,11 +40,5 @@
"type": "shell",
"command": "${command:python.interpreterPath} -m pytest"
},
// {
// "label": "upload: source",
// "type": "shell",
// "command": "rsync -avz --mkpath src config.production.json main.py pyproject.toml am4tools:/home/thiago/am4bot-api/",
// "problemMatcher": []
// }
]
}
54 changes: 25 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# ![logo](am4/bot/assets/img/logo-small.png) am4bot
# ![logo](src/am4bot/assets/img/logo-small.png) am4bot

[![](https://dcbadge.vercel.app/api/server/4tVQHtf?style=flat)](https://discord.gg/4tVQHtf) [![CI](https://github.com/cathaypacific8747/am4bot/actions/workflows/ci.yml/badge.svg)](https://github.com/cathaypacific8747/am4bot/actions/workflows/ci.yml)

A discord bot for the game [Airline Manager 4](airlinemanager.com), used on our [server](https://discord.gg/4tVQHtf).

Our bot is currently running legacy code under [`src-old`](./src-old/) and is being rewritten completely:
- [x] core calculations rewritten in C++ for bettter performance ([`am4/utils`](./am4/utils))
- [ ] api written in Python ([`am4/api (under construction)`](./am4/api/))
- [ ] discord bot written in Python ([`am4/bot (under construction)`](./am4/bot/))
- [ ] [`am4help.com`](https://am4help.com/) utilising this codebase ([`am4/web (under construction)`](./am4/web/)to be developed)
- [x] core calculations rewritten in C++ for bettter performance ([`src/am4/utils`](./src/am4/utils))
- [ ] api written in Python ([`src/am4/api (under construction)`](./src/am4/api/))
- [ ] discord bot written in Python ([`src/am4/bot (under construction)`](./src/am4/bot/))
- [ ] [`am4help.com`](https://am4help.com/) utilising this codebase ([`src/am4web (under construction)`](./src/am4/web/)to be developed)

![overview](am4/bot/assets/img/overview.drawio.svg)
![overview](src/am4bot/assets/img/overview.drawio.svg)


## Installation
Expand All @@ -19,11 +19,7 @@ Clone the repo and in the root directory:
python3 -m virtualenv .venv
source .venv/bin/activate
pip install .
am4 --help
```

```sh
python3 -m am4.__main__ --help
python3 -m src.am4 --help
```

## Features
Expand All @@ -44,7 +40,7 @@ Old bot:
- realtime alliance-member comparisons: SV/contribution distribution
- member tracking: cheat detection tools, departure pattern identification

## am4/utils Development
## src/am4/utils Development
Recommended: C++17 compliant compiler, python3.9+

### C++ debug executable
Expand All @@ -54,7 +50,7 @@ sudo apt-get install build-essential bison flex
vcpkg install arrow
# optionally install vtune for profiling

cd am4/utils
cd src/am4/utils
mkdir build
cd build
cmake .. && cmake --build . --target _core_executable && ./_core_executable
Expand All @@ -70,13 +66,13 @@ python3 -m pip install --verbose "src/am4/utils/.[dev]" --config-settings=cmake.
pytest
cd src/am4/utils
python3 generate-stubs.py
pip3 uninstall am4/utils -y
pip3 uninstall src/am4/utils -y
```
### Build wheel
```sh
mkdir wheelhouse
python3 -m pip wheel . --wheel-dir=wheelhouse no-deps -v
pip install wheelhouse/am4/utils-*.whl --force-reinstall
pip install wheelhouse/src/am4/utils-*.whl --force-reinstall
```

## AM4 Bot development
Expand All @@ -91,46 +87,46 @@ PRODUCTION=1 python3 main.py
### Public
- `$route|stop <airport> <airport> <aircraft> [flights_per_day] [reputation]`: finds the best route between two airports

![route](am4/bot/assets/img/route.png)
![route](src/am4bot/assets/img/route.png)
- `$routes <airport> <aircraft> <max_distance> <flights_per_day> [reputation]`: finds the best destinations from a certain airport, sorted by decreasing estimated income

![routes](am4/bot/assets/img/routes.png)
![routes](src/am4bot/assets/img/routes.png)
- `$user [player]`: shows player (and associated alliance if found) statistics

![user](am4/bot/assets/img/user.png)
![user](src/am4bot/assets/img/user.png)
- `$fleet [player]`: shows player fleet and estimated income

![fleet](am4/bot/assets/img/fleet.png)
![fleet](src/am4bot/assets/img/fleet.png)
- `$info <aircraft>`: shows basic aircraft information and rough profit estimations

![info](am4/bot/assets/img/info.png)
![info](src/am4bot/assets/img/info.png)
- `$compare <aircraft>`: compares two aircrafts

![compare](am4/bot/assets/img/compare.png)
![compare](src/am4bot/assets/img/compare.png)
- `$search <aircraft>`: finds the associated aircraft shortname for aircraft commands

![search](am4/bot/assets/img/search.png)
![search](src/am4bot/assets/img/search.png)
- `$airport <airport>`: shows airport information

![airport](am4/bot/assets/img/airport.png)
![airport](src/am4bot/assets/img/airport.png)
- `$price f[fuel_price] c[co2_price]`: notifies everyone for the fuel price

![price](am4/bot/assets/img/price.png)
![price](src/am4bot/assets/img/price.png)

### Internal Alliance Tools
- `$memberCompare <player> <player>`: compares descending structure of contribution/day and SV

![member-compare](am4/bot/assets/img/member-compare.png)
![member-compare](src/am4bot/assets/img/member-compare.png)
- `$alliance <alliance>`: shows AV progression and d(AV)/dt.

![alliance](am4/bot/assets/img/alliance.png)
![alliance](src/am4bot/assets/img/alliance.png)
- `$allianceCompare <alliance> <alliance>`: compares AV progression and gap difference over time, shows 48h/12h-average contribution/day graphs

![alliance-compare](am4/bot/assets/img/alliance-compare.png)
![alliance-compare](src/am4bot/assets/img/alliance-compare.png)
- `$member <player> [player[]]` shows contribution/day, total contribution and SV history for 1+ members

![member](am4/bot/assets/img/member.png)
![member](src/am4bot/assets/img/member.png)
- `$actions <player> [maxResults]`: shows log of estimated departures, contributions and income

![member-compare](am4/bot/assets/img/member-compare.png)
![member-compare](src/am4bot/assets/img/member-compare.png)
- `$watchlist [add|+, remove|rm|-] [alliance]`: shows, adds or remove alliance(s) to the watchlist
1 change: 0 additions & 1 deletion am4/utils/stubs/__init__.py

This file was deleted.

7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ requires = ["scikit_build_core[pyproject]", "pybind11"]
build-backend = "scikit_build_core.build"

[tool.scikit-build]
build-dir = "am4/utils/build"
build-dir = "src/am4/utils/build"
cmake.args = ["-DEXCLUDE_EXECUTABLES=1"]
cmake.build-type = "Release"
cmake.source-dir = "am4/utils"
cmake.source-dir = "src/am4/utils"
cmake.verbose = true
logging.level = "DEBUG"
wheel.install-dir = "am4"
Expand All @@ -33,6 +33,7 @@ dependencies = [
"pydantic>=2.6.1",
"loguru>=0.7.2",
"typer>=0.9.0",
"orjson>=3.9.13",
]

[project.optional-dependencies]
Expand Down Expand Up @@ -61,7 +62,7 @@ debug = [
[tool.pytest.ini_options]
minversion = "6.0"
addopts = ["-ra", "--showlocals"]
testpaths = ["am4/utils/tests"]
testpaths = ["src/am4/utils/tests"]


[tool.ruff]
Expand Down
File renamed without changes.
7 changes: 3 additions & 4 deletions am4/api/fapi.py → src/am4/api/fapi.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from contextlib import asynccontextmanager
from typing import Annotated

from fastapi import Depends, FastAPI
from fastapi.responses import ORJSONResponse
from uvicorn import Config, Server

from am4.utils.aircraft import Aircraft
from am4.utils.airport import Airport
from am4.utils.db import init as utils_init
from am4.utils.route import AircraftRoute, Route, find_routes
from fastapi import Depends, FastAPI
from fastapi.responses import ORJSONResponse
from uvicorn import Config, Server

from ..config import cfg
from ..db.client import pb
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Loading

0 comments on commit 7624402

Please sign in to comment.