diff --git a/.gitignore b/.gitignore index 6704566..e521df4 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,12 @@ dist # TernJS port file .tern-port + + +# Python cache +.Python +__pycache__/ + +# python environment +venv/ +env/ \ No newline at end of file diff --git a/images/frameworks.png b/images/frameworks.png new file mode 100644 index 0000000..8229ce9 Binary files /dev/null and b/images/frameworks.png differ diff --git a/images/languages.png b/images/languages.png new file mode 100644 index 0000000..1b13dbe Binary files /dev/null and b/images/languages.png differ diff --git a/scripts/config.py b/scripts/config.py new file mode 100644 index 0000000..325a844 --- /dev/null +++ b/scripts/config.py @@ -0,0 +1,56 @@ +import os + + +data_path = os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))), "src", "res", "survey.yaml") +plot_dir = os.path.join(os.path.abspath(os.path.dirname(os.path.dirname(__file__))), "images") + +COLORS = { + "Python": "darkgoldenrod", + "Java": "orange", + "JavaScript": "purple", + "C#": "khaki", + "C/C++": "mediumblue", + "PHP": "indianred", + "R": "darkorange", + "TypeScript": "darkgreen", + "Objective-C": "firebrick", + "Swift": "darkred", + "Matlab": "antiquewhite", + "Kotlin": "tomato", + "Go": "lightslategray", + "Rust": "springgreen", + "Ruby": "grey", + "VBA": "olivedrab", + "Ada": "blueviolet", + "Scala": "brown", + "Dart": "maroon", + "Abap": "blue", + "Visual Basic": "papayawhip", + "Lua": "darkblue", + "Groovy": "limegreen", + "Perl": "lightseagreen", + "Julia": "darkmagenta", + "Haskell": "turquoise", + "Cobol": "lavender", + "React.js": "darkolivegreen", + "jQuery": "violet", + "Express": "bisque", + "Angular": "navajowhite", + "Vue.js": "greenyellow", + "ASP.NET Core": "lightgreen", + "Flask": "goldenrod", + "ASP.NET": "darkslateblue", + "Django": "lightcoral", + "Spring": "sandybrown", + "Angular.js": "darkgray", + "Laravel": "mistyrose", + "Ruby on Rails": "tan", + "Gatsby": "rosybrown", + "FastAPI": "saddlebrown", + "Symfony": "lavenderblush", + "Svelte": "cadetblue", + "Drupal": "saddlebrown", + "Odoo": "orange", + "BackboneJS": "mediumseagreen", + "OWL (Odoo Web Library)": "lightgray" +} diff --git a/scripts/main.py b/scripts/main.py new file mode 100644 index 0000000..ede1112 --- /dev/null +++ b/scripts/main.py @@ -0,0 +1,13 @@ +import os +from utils import load_yaml, plot_fav_languages, plot_fav_frameworks +from config import data_path, plot_dir + + +def main(): + data = load_yaml(path=data_path)["items"] + plot_fav_languages(data, path=os.path.join(plot_dir, "languages.png")) + plot_fav_frameworks(data, path=os.path.join(plot_dir, "frameworks.png")) + + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/scripts/requirements.txt b/scripts/requirements.txt new file mode 100644 index 0000000..d82a706 --- /dev/null +++ b/scripts/requirements.txt @@ -0,0 +1,2 @@ +pyyaml +matplotlib \ No newline at end of file diff --git a/scripts/utils.py b/scripts/utils.py new file mode 100644 index 0000000..50334e6 --- /dev/null +++ b/scripts/utils.py @@ -0,0 +1,46 @@ +import yaml +import matplotlib.pyplot as plt +import matplotlib.colors as pltc +from config import COLORS + +from random import sample + +all_colors = [k for k,v in pltc.cnames.items()] + + +def load_yaml(path): + with open(path, 'r') as stream: + return yaml.load(stream, Loader=yaml.FullLoader) + + +def plot_fav_languages(datas: list, path: str): + languages = [] + for data in datas: + languages.extend(data["fav_languages"]) + + plot_data = {language: languages.count(language) for language in languages} + colors = [COLORS.get(lang, "red") for lang in plot_data.keys()] + fig = plt.figure() + plt.bar(list(plot_data.keys()), list(plot_data.values()), color=colors) + plt.xticks(rotation=90) + plt.xlabel("Languages") + plt.ylabel("Number of people using this language") + plt.title("Favourite languages") + # plt.legend(list(plot_data.values()) , labels=list(plot_data.keys())) + plt.savefig(path) + return plot_data + + +def plot_fav_frameworks(datas: list, path: str): + frameworks = [] + for data in datas: + frameworks.extend(data["fav_frameworks"]) + + plot_data = {framework: frameworks.count(framework) for framework in frameworks} + values = list(plot_data.values()) + X = [x/sum(values) for x in values] + colors = [COLORS.get(framework, "red") for framework in plot_data.keys()] + fig = plt.figure() + plt.pie(X, labels=tuple(plot_data.keys()), colors=colors, autopct='%1.0f%%', startangle=90) + plt.savefig(path) + return plot_data