Created
November 27, 2018 08:51
-
-
Save mylamour/707f145c3eaa0c049efb7f8dc838916e to your computer and use it in GitHub Desktop.
This file contains 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
import os | |
import fire | |
from colorama import Fore | |
from collections import Counter | |
# SUPPORT_SUFFIX = ['lua','c','cpp','py','java','scala','php','js'] | |
# 如果给个最低均值就好了,或者比率 | |
PROJECTLAN = { | |
'h':0, | |
'c':0, | |
'py':0, | |
'cmakelists':0, | |
'makefile':0, | |
'composer.json':0, | |
'php':0, | |
'yarn':0, | |
'gruntfile':0, | |
'.eslintignore':0, | |
'webpack':0, | |
'js':0, | |
'.npmignore':0, | |
'package.json':0, | |
'.eslintrc.json':0, | |
'index.js':0, | |
"java":0, | |
'gradlew':0, | |
'gradle':0 | |
} | |
def guess(dirname): | |
pfs = [] | |
for root,d,files in os.walk(dirname): | |
for f in files: | |
suffix = f.lower().split(".")[-1] | |
if suffix in PROJECTLAN.keys() or f in PROJECTLAN.keys(): | |
pfs.append(suffix) | |
Count = Counter(pfs) | |
staticCount = sorted(Count.items(), key=lambda item: item[1],reverse=True) | |
if len(staticCount) >= 2: | |
diff = staticCount[0][1] - staticCount[1][1] | |
ratio = staticCount[0][1]/(staticCount[0][1] + staticCount[1][1]) | |
if diff > 10 or ratio > 0.5: | |
guess = staticCount[0][0] | |
if guess == dirname.split('/')[0]: | |
# print("猜对了: ", guess, staticCount, diff, ratio) | |
return guess | |
else: | |
# print("猜错了吧?", guess,staticCount,diff,ratio) | |
return None | |
elif staticCount: | |
# if staticCount[0][0] == dirname.split('/')[1]: | |
# print("猜对了: ", staticCount) | |
return staticCount[0][0] | |
else: | |
return None | |
if __name__ == '__main__': | |
fire.Fire() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment