Skip to content

Commit

Permalink
Merge pull request #46 from Ledenel/tenhou-uni-paifu-full
Browse files Browse the repository at this point in the history
Tenhou uni paifu full support
  • Loading branch information
Ledenel authored Feb 2, 2020
2 parents b8cf0cf + d4c2eb6 commit 9775241
Show file tree
Hide file tree
Showing 26 changed files with 849 additions and 340 deletions.
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ loguru = "*"
pandas = "*"

[requires]
python_version = "3.8"
python_version = "3.7"
120 changes: 63 additions & 57 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,40 @@ with open(filename, "w", encoding='utf-8') as f:

This converter extract paifus as a universal format, to csv files for easy analysis.

**After installation**, you can run the tools with

`paifu-extract`

Now support tenhou.net only.

**IT IS JUST A DEMO TO SHOW THE CONCEPTS, TRANSLATED COMMANDS AND STATES ARE NEITHER COMPLETE NOR CORRECT YET!**

Type your tenhou.net log url (like`http://tenhou.net/0/?log=2019012600gm-0089-0000-100908f0&tw=0`).
## Testing

For APIs, see [code here](https://github.com/Ledenel/auto-white-reimu/blob/master/mahjong/universe_paifu_convert.py).

Extra APIs are provided to analyse the csv with usage examples below:
```python
import pandas as pd
from mahjong.record.universe.command import GameCommand
df = pd.read_csv("command_list.csv")
# clean up df, make states as python value
df = df.apply(GameCommand.pandas_columns_clean, axis="columns")
# extract all state changes
column_props = ["sub_scope_id", "property"]
df_state = df[column_props + ["state"]]
# pivot combined column to multi-level state.
df_state = df_state.set_index(column_props, append=True)
df_state = df_state.unstack(level=column_props)
# fill in all state to get exact state after each command executed.
df_state = df_state.ffill()
```

### Extending universal paifu format

See pull request [here](https://github.com/Ledenel/auto-white-reimu/pull/45) for more details.

# Testing

you could run test by executing `pip install .[test]` at root dir, this would install all dependence for you.

Expand Down
9 changes: 9 additions & 0 deletions mahjong/record/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .util_functions\
import parse_dataframe_from_tenhou_record,\
light_dataframe_from_file
from .reader \
import from_url as tenhou_from_url, \
from_file as tenhou_from_file, \
log_id_from_url as tenhou_log_id_from_url, \
log_id_to_url as tenhou_log_id_to_url, \
download_url as tenhou_download_url
7 changes: 6 additions & 1 deletion mahjong/record/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ def __init__(self, index, name_encoded, level, rate, sex):
self.index = index

def __str__(self):
level = self.level_str()
return "%s %s R%.2f" % (
self.name,
RANKS[self.level],
level,
self.rate
)

def level_str(self):
level_str = RANKS[self.level]
return level_str

def clear(self):
pass

Expand Down
2 changes: 1 addition & 1 deletion mahjong/record/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def xml_message_config_scan(namespace: Namespace, message):


def list_of_xml_configs(xml_element_list):
return reduce(xml_message_config_scan, xml_element_list, Namespace())
return reduce(xml_message_config_scan, reversed(xml_element_list), Namespace())


class TenhouRecord:
Expand Down
Loading

0 comments on commit 9775241

Please sign in to comment.