Skip to content

Commit

Permalink
Redid CSV generation to include moves for that pokemon
Browse files Browse the repository at this point in the history
  • Loading branch information
asif4318 committed Apr 24, 2023
1 parent 51578e7 commit 64f67db
Show file tree
Hide file tree
Showing 1,829 changed files with 634,634 additions and 100,006 deletions.
16 changes: 16 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"python.defaultInterpreterPath": "",
"cSpell.words": [
"learnset",
"learnsets"
],
"python.testing.unittestArgs": [
"-v",
"-s",
"./backend/tests",
"-p",
"*_test.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
Empty file added backend/.env
Empty file.
160 changes: 160 additions & 0 deletions backend/Python.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# 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/
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/
cover/

# 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
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .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

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__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/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
5 changes: 5 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Navigate to backend folder (cd backend)

### Run '. venv/bin/activate' before working

### Make sure flask library is installed with 'pip install Flask'
Binary file added backend/__pycache__/main.cpython-311.pyc
Binary file not shown.
23 changes: 23 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from flask import Flask
from modules import hashmap

app = Flask(__name__)

# Create a hashmap of pokemon;
# Get names from CSV file, get proper moves from learnsets.json


def getSpecies(name: str) -> str:
upperLetter = ''
for letter in name:
if (letter.isupper()):
upperLetter = letter
break
if (upperLetter == ''):
raise ValueError
return name.split(upperLetter)[0]


@app.route("/")
def test():
return '<p>Hi</p>'
3 changes: 3 additions & 0 deletions backend/modules/graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Graph:
def __init__():
print('Graph')
48 changes: 48 additions & 0 deletions backend/modules/hashmap.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

class HashMap:
def __init__(self, capacity=8):
self.capacity = capacity
self.size = 0
self.table = [None] * self.capacity

def __len__(self):
return self.size

def __contains__(self, key):
index = self._get_index(key)
if self.table[index] is not None:
return True
return False

def __getitem__(self, key):
index = self._get_index(key)
if self.table[index] is None:
raise KeyError(key)
return self.table[index][1]

def __setitem__(self, key, value):
if self.size >= self.capacity * 0.8:
self._resize()
index = self._get_index(key)
self.table[index] = (key, value)
self.size += 1

def _resize(self):
old_table = self.table
self.capacity *= 2
self.size = 0
self.table = [None] * self.capacity
for pair in old_table:
if pair is not None:
self[pair[0]] = pair[1]

def _hash(self, key):
return hash(key) % self.capacity

def _get_index(self, key):
index = self._hash(key)
i = 1
while self.table[index] is not None and self.table[index][0] != key:
index = (index + i * i) % self.capacity
i += 1
return index
17 changes: 17 additions & 0 deletions backend/modules/helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Helper:
def __init__(self, names_csv_path, learnsets_path):
self.moves: list[str] = []
self.names_csv_path = names_csv_path
self.learnsets_path = learnsets_path

def getSpecies(name: str) -> str:
upperLetter = ''
for letter in name:
if (letter.isupper()):
upperLetter = letter
break
if (upperLetter == ''):
raise ValueError
return name.split(upperLetter)[0]

def getMoves(pokemon_name: str) -> list[str]:
27 changes: 27 additions & 0 deletions backend/modules/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from hashmap import HashMap
import json

# Read data from JSON file
with open('learnsets.json') as f:
data = json.load(f)


# maps pokemon to moves they learn
pokemonList = HashMap()
for pokemon, learnset in data.items():
if 'learnset' not in learnset:
continue
pokemonList[f'{pokemon}'] = learnset

# maps moves to pokemon that can learn it
moveList = HashMap()
for pokemon, learnset, in data.items():
if 'learnset' not in learnset:
continue
for move, levels in learnset['learnset'].items():
if move in moveList:
moveList[move] += f', {pokemon}'
else:
moveList[move] = pokemon

print(moveList['cut'])
1 change: 1 addition & 0 deletions backend/static/learnsets.json

Large diffs are not rendered by default.

File renamed without changes.
Binary file not shown.
18 changes: 18 additions & 0 deletions backend/tests/example_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import unittest


def getSpecies(name: str) -> str:
upperLetter = ''
for letter in name:
if (letter.isupper()):
upperLetter = letter
break
if (upperLetter == ''):
raise ValueError
return name.split(upperLetter)[0]


class TestGetSpecies(unittest.TestCase):
def test_case(self):
self.assertEqual('pikachu', getSpecies('pikachuHey'))
self.assertRaises(ValueError, getSpecies, 'trash')
Loading

0 comments on commit 64f67db

Please sign in to comment.