Skip to content
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

writte some scripts to create plots from the survey data #41

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,12 @@ dist

# TernJS port file
.tern-port


# Python cache
.Python
__pycache__/

# python environment
venv/
env/
Binary file added images/frameworks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/languages.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions scripts/config.py
Original file line number Diff line number Diff line change
@@ -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"
}
13 changes: 13 additions & 0 deletions scripts/main.py
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 2 additions & 0 deletions scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pyyaml
matplotlib
46 changes: 46 additions & 0 deletions scripts/utils.py
Original file line number Diff line number Diff line change
@@ -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