Status analyzer

This commit is contained in:
Oleg Morozenkov
2016-02-22 13:16:36 +03:00
parent 6b0b3c9300
commit 7c39389384

View File

@@ -1,9 +1,17 @@
import json import json
import sys import sys
from collections import OrderedDict
from nltk.stem.snowball import RussianStemmer from nltk.stem.snowball import RussianStemmer
from nltk.tokenize import RegexpTokenizer from nltk.tokenize import RegexpTokenizer
def dictWithoutOneKey(d, key):
new_d = d.copy()
new_d.pop(key)
return new_d
# load pazans # load pazans
pazansGroups = None pazansGroups = None
@@ -37,8 +45,9 @@ with open(usersFileName, "r") as file:
statusStats[filteredStatusText] = statusStatsItem statusStats[filteredStatusText] = statusStatsItem
# print result # print result
with open(sys.argv[3], "w", encoding="utf-8") as file: destFileName = sys.argv[3]
for item in sorted(statusStats.items(), key=lambda item: item[1]["count-boys"] + item[1]["count-girls"], reverse=True): with open(destFileName, "w", encoding="utf8") as file:
file.write(item[1]["full"] + "\n") sortKeyGetter = lambda item: item[1]["count-boys"] + item[1]["count-girls"]
file.write("\tboys: " + str(item[1]["count-boys"]) + "\n") sortedStatues = [item[1] for item in sorted(statusStats.items(), key=sortKeyGetter, reverse=True)]
file.write("\tgirls: " + str(item[1]["count-girls"]) + "\n") data = OrderedDict([(item["full"], dictWithoutOneKey(item, "full")) for item in sortedStatues])
file.write(json.dumps(data, ensure_ascii=False, indent=4))