-
Notifications
You must be signed in to change notification settings - Fork 3k
/
language_stats.py
53 lines (42 loc) · 1.84 KB
/
language_stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Script para calcular el % de uso de cada lenguaje
import os
import operator
def scan_dir(dir_path, challenges={}, languages={}, total=0, challenge_name=None, path_name=None) -> tuple:
for path in os.scandir(dir_path):
if path.is_dir():
if "Reto #" in path.name and path.name not in challenges:
challenges[path.name] = 0
challenge_name = path.name
elif "Reto #" not in path.name and path.name not in languages:
languages[path.name] = 0
_, _, total = scan_dir(
path.path, challenges,
languages, total, challenge_name, path.name)
else:
if path_name in languages:
total += 1
if challenge_name is not None:
challenges[challenge_name] += 1
languages[path_name] += 1
return (challenges, languages, total)
# Directorio de retos a analizar
dir_path = os.path.dirname(__file__)
# Directorio de un reto específico
# dir_path += "/Reto #0 - EL FAMOSO FIZZ BUZZ [Fácil]"
# Función recursiva para recorrer el directorio y almacenar el número de archivos por reto y lenguaje
challenges, languajes, total = scan_dir(dir_path)
# Ordenación por uso
challenges = dict(
sorted(challenges.items(), key=operator.itemgetter(1), reverse=True))
languajes = dict(
sorted(languajes.items(), key=operator.itemgetter(1), reverse=True))
# Estadísticas
print(
f"\nESTADÍSTICAS RETOS DE PROGRAMACIÓN:\n> {len(languajes.keys())} LENGUAJES ({total} CORRECCIONES)\n")
for challenge in challenges:
print(
f"> {challenge.upper()} ({challenges[challenge]}): {round(challenges[challenge] / total * 100, 2)}%")
print()
for languaje in languajes:
print(
f"> {languaje.upper()} ({languajes[languaje]}): {round(languajes[languaje] / total * 100, 2)}%")