onix.collection.log_reader module¶
Functionality for taking PS logs & structuring them into a desired format
-
exception
onix.collection.log_reader.ParsingError(log_ref, message)[source]¶ Bases:
exceptions.ExceptionRaised if there’s a problem parsing the log
Parameters: - log_ref – an identifier specifying the log whose parsing raised the exception
- message (str) – a description of the cause of the failure. The log_ref should not be included.
-
log_ref¶ an identifier specifying the log whose parsing raised the exception
-
onix.collection.log_reader.get_all_formes(species, ability, item, moves, context, hackmons=False, any_ability=False)[source]¶ Get all formes a Pokemon might appear as during a battle
Parameters: - species (str) – the species (as represented in the Showdown log)
- ability (str) – the Pokemon’s ability
- item (str) – the held item
- moves (
listofstr) – sanitized list of moves - context (contexts.Context) – The resources needed by the function. Requires pokedex, accessible_formes and sanitizer.
- hackmons (
bool, optional) – Set to True if this is for a metagame where a battle forme or mega evolution can appear outside its base forme. Default is False. - any_ability (
bool, optional) – Set to True if the Pokemon can have have “illegal” abilities. Default is False.
Returns: the formes the Pokemon might take on during a battle.
Note
The stats attribute represents base stats, not battle stats
Return type: listofFormesExamples
>>> from onix import contexts >>> from onix.collection.log_reader import get_all_formes >>> context = contexts.get_standard_context() >>> formes = get_all_formes('aggron', 'heavymetal', 'aggronite', ... ['earthquake', 'heavyslam'], context) >>> print(', '.join([forme.species for forme in formes])) aggron, aggronmega
-
onix.collection.log_reader.rating_dict_to_model(rating_dict)[source]¶ Make a
Playerfrom an entry in a Pokemon Showdown logParameters: rating_dict (dict) – the ratings dict as parsed from the log Returns: the corresponding Player Return type: Player Notes
If a relevant rating is missing from the
rating_dict, it will be represented in the resultingPlayerasNone.Examples
>>> from future.utils import iteritems >>> from onix.model import Player >>> from onix.collection.log_reader import rating_dict_to_model >>> rating_dict = {'r': 1630, 'rd': 100, 'rpr': 1635, 'rprd': 95, ... 'w': 10, 'l': 3, 't': 0, 'cool_new_rating': 63.1, ... 'username': 'Testy McTestFace', 'userid': 'test'} >>> player = rating_dict_to_model(rating_dict) >>> player.id 'test' >>> sorted(iteritems(player.rating)) [('elo', None), ('l', 3.0), ('r', 1630.0), ('rd', 100.0), ('rpr', 1635.0), ('rprd', 95.0), ('t', 0.0), ('w', 10.0)]
In theory, Pokemon Showdown sets the correct Hidden Power type from the IVs and represents Hidden Power in the moveset as the specifically-typed Hidden Power. But it’s best not to assume such things, so let’s calculate it ourselves
Parameters: - moves (
listofstr) – the moves the Pokemon knows (should already be sanitized) - ivs (PokeStats) – the Pokemon’s Indiviual Values
Returns: sanitized move list, with Hidden Power (if present) correctly typed
Return type: listofstrExamples
>>> from onix.model import PokeStats >>> from onix.collection.log_reader import normalize_hidden_power >>> normalize_hidden_power(['hiddenpower', 'roost', 'thunderbolt', ... 'voltswitch'], ... PokeStats(31, 31, 31, 31, 31, 30)) ['hiddenpowerice', 'roost', 'thunderbolt', 'voltswitch']
- moves (
-
class
onix.collection.log_reader.LogReader(context)[source]¶ Bases:
objectAn object which takes in a Pokemon Showdown log (in whatever format it exists) and returned structured data, ready for compiling or storing. The intent is for a separate LogReader to be instantiated for different contexts (_i.e._ different generations or mods)
Parameters: context (onix.contexts.Context) – The resources needed by the log reader. Must have: pokedex, items, formats, sanitizer, accessible_formes and natures -
parse_log(log_ref)[source]¶ Parses the provided log and returns structured and normalized data.
Parameters: log_ref – an identifier specifying the log to parse Returns: - BattleInfo : metadata about the match
dictofstrtoMoveset: a mapping of set IDs to movesets for the movesets appearing in the battle- Battle : a structured turn-by-turn recounting of the battle
Return type: (tuple) Raises: ParsingError– if there’s a problem parsing the log
-
-
class
onix.collection.log_reader.JsonFileLogReader(context)[source]¶ Bases:
onix.collection.log_reader.LogReaderParses Pokemon Showdown
.jsonfilesParameters: context (onix.contexts.Context) – The resources needed by the log reader. Must have: pokedex, items, formats. sanitizer, accessible_formes and natures -
date¶ datetime.datetime
If the date cannot be determined from the log or from the file’s path, the date attribute in the parsed
BattleInfowill be set to this value, which, by default is Epoch. Feel free to change it.
-