-
-
Notifications
You must be signed in to change notification settings - Fork 10
feat: add CPM data generation and related functionality #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
captbunzo
wants to merge
2
commits into
WatWowMap:main
Choose a base branch
from
captbunzo:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| # devWrapper.ts - Script Outline | ||
|
|
||
| ## Purpose | ||
|
|
||
| Development script that fetches the latest Pokémon GO game master data and generates a structured masterfile with various Pokémon GO data entities (Pokémon, moves, items, invasions, etc.) | ||
|
|
||
| --- | ||
|
|
||
| ## Main Flow | ||
|
|
||
| ### 1. Data Fetching | ||
|
|
||
| - Fetches latest game master JSON from PokeMiners GitHub repository | ||
| - Saves raw data to `./latest.json` for reference | ||
|
|
||
| ### 2. Command-Line Argument Processing | ||
|
|
||
| - `--pokeapi-staging`: Uses PokeAPI staging environment | ||
| - `--pokeapi`: Uses PokeAPI production (or static cached data if neither flag) | ||
| - `--raw`: Generates raw data format | ||
| - `--test`: Enables test mode for file output | ||
| - `--invasions`: Generates Team Rocket invasion data | ||
|
|
||
| ### 3. Data Generation | ||
|
|
||
| - Calls the `generate()` function from `src/index.ts` | ||
| - Passes configuration options based on command-line flags | ||
| - Either uses PokeAPI (live or staging) or static cached files: | ||
| - `static/baseStats.json` - Base stats data | ||
| - `static/tempEvos.json` - Temporary evolution data | ||
| - `static/types.json` - Type effectiveness data | ||
| - Times the generation process | ||
|
|
||
| ### 4. Test Mode File Output | ||
|
|
||
| When `--test` flag is present: | ||
|
|
||
| #### a. Invasion Data | ||
|
|
||
| - If `--invasions` flag: Writes `invasions.json` with Team Rocket invasion data | ||
|
|
||
| #### b. PokeAPI Cache Update | ||
|
|
||
| - If using PokeAPI: Updates static cache files with fresh data: | ||
| - `static/baseStats.json` | ||
| - `static/tempEvos.json` | ||
| - `static/types.json` | ||
| - Removes PokeAPI data from final output | ||
|
|
||
| #### c. Masterfile Output | ||
|
|
||
| - Writes complete generated data to `./masterfile.json` | ||
|
|
||
| ### 5. Completion | ||
|
|
||
| - Logs generation time | ||
| - Handles errors | ||
| - Confirms successful generation | ||
|
|
||
| --- | ||
|
|
||
| ## Key Features | ||
|
|
||
| - **Flexible data sources**: Can use live PokeAPI or cached static data | ||
| - **Modular output**: Different flags control what data is generated | ||
| - **Development-friendly**: Timing, error handling, and formatted JSON output | ||
| - **Cache management**: Updates static files when using live PokeAPI | ||
| - **Test mode**: Prevents accidental production runs without explicit flag | ||
|
|
||
| ## Usage Examples | ||
|
|
||
| ```bash | ||
| # Generate with default settings (using static cache) | ||
| yarn generate | ||
|
|
||
| # Generate using live PokeAPI data | ||
| yarn pokeapi | ||
|
|
||
| # Generate raw format data | ||
| yarn raw | ||
|
|
||
| # Generate invasion data | ||
| yarn invasions | ||
| ``` | ||
|
|
||
| ## Command-Line Flags | ||
|
|
||
| | Flag | Description | | ||
| | ------------------- | ------------------------------------------- | | ||
| | `--test` | Enable test mode (required for file output) | | ||
| | `--pokeapi` | Use PokeAPI production environment | | ||
| | `--pokeapi-staging` | Use PokeAPI staging environment | | ||
| | `--raw` | Generate raw data format | | ||
| | `--invasions` | Generate Team Rocket invasion data | | ||
|
|
||
| ## Output Files | ||
|
|
||
| | File | Condition | Description | | ||
| | ----------------------- | ------------------------------ | ------------------------------------ | | ||
| | `latest.json` | Always | Raw game master data from PokeMiners | | ||
| | `masterfile.json` | `--test` flag | Complete generated masterfile | | ||
| | `invasions.json` | `--test` + `--invasions` flags | Team Rocket invasion data | | ||
| | `static/baseStats.json` | `--test` + `--pokeapi*` flags | Pokemon base stats cache | | ||
| | `static/tempEvos.json` | `--test` + `--pokeapi*` flags | Temporary evolutions cache | | ||
| | `static/types.json` | `--test` + `--pokeapi*` flags | Type effectiveness cache | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import type { AllCpm } from '../typings/dataTypes' | ||
| import type { NiaMfObj } from '../typings/general' | ||
| import Masterfile from './Masterfile' | ||
|
|
||
| export default class Cpm extends Masterfile { | ||
| parsedCpm: AllCpm | ||
|
|
||
| constructor() { | ||
| super() | ||
| this.parsedCpm = {} | ||
| } | ||
|
|
||
| addCpm(object: NiaMfObj) { | ||
| const playerLevel = object.data.playerLevel | ||
| if (playerLevel?.cpMultiplier) { | ||
| const tempCpm: { level: number; multiplier: number }[] = [] | ||
|
|
||
| // First, generate all whole level values | ||
| for (let i = 0; i < playerLevel.cpMultiplier.length; i++) { | ||
| const wholeLevel = i + 1 | ||
|
|
||
| tempCpm.push({ | ||
| level: wholeLevel, | ||
| multiplier: playerLevel.cpMultiplier[i], | ||
| }) | ||
|
|
||
| const halfLevel = i + 1.5 | ||
| const cpmCurrent = playerLevel.cpMultiplier[i] | ||
| const cpmNext = playerLevel.cpMultiplier[i + 1] | ||
|
|
||
| if (cpmNext) { | ||
| // Calculate half-level CPM using: sqrt((CPM(n)^2 + CPM(n+1)^2) / 2) | ||
| const cpmHalf = Math.sqrt((cpmCurrent ** 2 + cpmNext ** 2) / 2) | ||
|
|
||
| tempCpm.push({ | ||
| level: halfLevel, | ||
| multiplier: cpmHalf, | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // Add to parsedCpm with consistent key format (n.0 or n.5) | ||
| for (const entry of tempCpm) { | ||
| this.parsedCpm[entry.level.toFixed(1)] = entry | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| const { generate } = require('../dist/index') | ||
|
|
||
| jest.setTimeout(30_000) | ||
|
|
||
| describe('CPM Generation', () => { | ||
| let cpmData | ||
|
|
||
| beforeAll(async () => { | ||
| const data = await generate({ raw: true }) | ||
| cpmData = data.cpm | ||
| }); | ||
|
|
||
| test('generates CPM data', () => { | ||
| expect(cpmData).toBeDefined() | ||
| expect(Object.keys(cpmData).length).toBeGreaterThan(0) | ||
| }) | ||
|
|
||
| test('has correct whole level values', () => { | ||
| // Level 1 | ||
| expect(cpmData["1.0"]).toBeDefined() | ||
| expect(cpmData["1.0"].level).toBe(1) | ||
| expect(cpmData["1.0"].multiplier).toBe(0.094) | ||
|
|
||
| // Level 40 | ||
| expect(cpmData["40.0"]).toBeDefined() | ||
| expect(cpmData["40.0"].level).toBe(40) | ||
| expect(cpmData["40.0"].multiplier).toBe(0.7903) | ||
|
|
||
| // Level 55 | ||
| expect(cpmData["55.0"]).toBeDefined() | ||
| expect(cpmData["55.0"].level).toBe(55) | ||
| expect(cpmData["55.0"].multiplier).toBe(0.8653) | ||
| }); | ||
|
|
||
| test('calculates half level values correctly', () => { | ||
| // Level 1.5 | ||
| expect(cpmData["1.5"]).toBeDefined() | ||
| expect(cpmData["1.5"].level).toBe(1.5) | ||
| expect(cpmData["1.5"].multiplier).toBeCloseTo(0.1351374, 6) | ||
|
|
||
| // Level 40.5 | ||
| expect(cpmData["40.5"]).toBeDefined() | ||
| expect(cpmData["40.5"].level).toBe(40.5) | ||
| }); | ||
captbunzo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| test('keys are in correct format (n.0 or n.5)', () => { | ||
| const keys = Object.keys(cpmData) | ||
| keys.forEach((key) => { | ||
| expect(key).toMatch(/^\d+\.(0|5)$/) | ||
| }) | ||
| }) | ||
|
|
||
| test('levels are in sequential order', () => { | ||
| const keys = Object.keys(cpmData) | ||
| const levels = keys.map((k) => parseFloat(k)) | ||
|
|
||
| for (let i = 1; i < levels.length; i++) { | ||
| expect(levels[i]).toBeGreaterThan(levels[i - 1]) | ||
| } | ||
| }) | ||
|
|
||
| test('has expected total number of entries', () => { | ||
| // 80 whole levels + 79 half levels = 159 total | ||
| expect(Object.keys(cpmData).length).toBe(159) | ||
| }) | ||
| }) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.