-
Notifications
You must be signed in to change notification settings - Fork 0
集計対象アイテムのフィルターおよびソートを追加 #15
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
Merged
Merged
Changes from all commits
Commits
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
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,86 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import argparse | ||
| import json | ||
| import logging | ||
| import sys | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def make_item_dict(item: dict) -> dict: | ||
| return { | ||
| "id": item["id"], | ||
| "rarity": item.get("rarity", 0), | ||
| "shortname": item["shortname"], | ||
| "dropPriority": item["dropPriority"], | ||
| } | ||
|
|
||
|
|
||
| def main(args: argparse.Namespace): | ||
| items = json.load(args.input) | ||
| filtered_items = [] | ||
|
|
||
| # 特攻礼装 9005 | ||
| # ボーナス礼装 9005 | ||
| # 泥礼装 9005 | ||
| # 礼装 9005 | ||
| # ★4EXP礼装 9004 | ||
| # ★3EXP礼装 9003 | ||
| ce_cache: dict[str, dict] = {} | ||
|
|
||
| for item in items: | ||
| if "shortname" not in item: | ||
| continue | ||
| item_id = item["id"] | ||
| if item_id < 10_000_000: | ||
| # 礼装のデータは1つだけあればよいので、同一の shortname であれば id が大きい方を優先する | ||
| if item["shortname"] in ["特攻礼装", "ボーナス礼装", "泥礼装", "礼装", "★4EXP礼装", "★3EXP礼装"]: | ||
| if item["shortname"] in ce_cache: | ||
| cached_item = ce_cache[item["shortname"]] | ||
| if item["id"] > cached_item["id"]: | ||
| ce_cache[item["shortname"]] = item | ||
| else: | ||
| pass | ||
max747 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| else: | ||
| ce_cache[item["shortname"]] = item | ||
|
|
||
| # filtered_items への追加は最後にまとめて行うので、ここではスキップ | ||
| continue | ||
|
|
||
| # 種火はレアリティ 4, 5 のみを対象とする | ||
| if item["type"] == "Exp. UP" and item["rarity"] < 4: | ||
| continue | ||
|
|
||
| # 上記規則に当てはまらない礼装は無視 | ||
| if item["type"] == "Craft Essence": | ||
| logger.warning(f"Unknown Craft Essence: {item['name']} (id: {item['id']})") | ||
| continue | ||
|
|
||
| filtered_items.append(make_item_dict(item)) | ||
|
|
||
| # 礼装のデータを filtered_items に追加 | ||
| for item in ce_cache.values(): | ||
| filtered_items.append(make_item_dict(item)) | ||
|
|
||
| sorted_items = sorted(filtered_items, key=lambda x: x["dropPriority"], reverse=True) | ||
|
|
||
| if args.output_format == "tsv": | ||
| print("id\trarity\tshortname\tdropPriority", file=args.output) | ||
| for item in sorted_items: | ||
| print(f"{item['id']}\t{item['rarity']}\t{item['shortname']}\t{item['dropPriority']}", file=args.output) | ||
| else: | ||
| print(json.dumps(sorted_items, indent=2, ensure_ascii=False), file=args.output) | ||
|
|
||
|
|
||
| def parse_args() -> argparse.Namespace: | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("--input", "-i", type=argparse.FileType("r"), default=sys.stdin) | ||
| parser.add_argument("--output", "-o", type=argparse.FileType("w"), default=sys.stdout) | ||
| parser.add_argument("--output-format", "-f", choices=["json", "tsv"], default="json") | ||
| return parser.parse_args() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| args = parse_args() | ||
| main(args) | ||
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logger is created but never configured with basicConfig or a handler. When warnings are logged at line 57, they won't be displayed to the user unless the logging level is configured. Consider adding logging.basicConfig() in the main function or in the if name == "main" block to ensure warning messages are visible.