Skip to content
Merged
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
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
Jinja2==3.1.6
requests==2.32.4
requests==2.32.4
PyYAML==6.0.3
23 changes: 23 additions & 0 deletions settings.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
general:
top_k: 4
plane:
height: 140
width: 250
coloring:
type: "oklch"
chroma: 0.099
lightness: 0.636
excluded_languages:
- Jupyter Notebook

legend:
margin_x: 140
margin_y: 30
space_between_captions: 22
font_color: "#c1c1c1"

diagram:
outer_radius: 55
thickness: 12
margin_x: 20
margin_y: 15
88 changes: 36 additions & 52 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,88 +3,72 @@
from renderer.renderer import RenderBuilder
from oklchUtils.OKLCHUtils import OKLCHUtils
from calc import Calc

from settings import Settings
from fetcher.fetcher import FetchLangStats

# Fetch info
USERNAME = os.environ['USERNAME']
TOKEN = os.environ['GITHUB_TOKEN']

# Plane settings
HEIGHT: int = 140
WIDTH: int = 250

# Captions settings
LEGEND_MARGIN_X: int = 140
LEGEND_MARGIN_Y: int = 30
SPACE_BETWEEN_CAPTIONS: int = 22
FONT_COLOR: str = "#c1c1c1"

# Color settings
OKLCH_CHROMA: float = 0.099
OKLCH_LIGHTNESS: float = 0.636
OTHER_COLOR_CHROMA: float = 0.000

# Round sizes settings
OUTER_RADIUS: int = 55
THICKNESS: int = 12

# Margins settings
MARGIN_X: int = 20
MARGIN_Y: int = 15

# Arrays settings
TOP_K: int = 4

# Output filepath
OUTPUT_FILE: str = "./out.svg"
SETTINGS_FILE: str = "./settings.yaml"

SETTINGS = Settings.from_yaml(SETTINGS_FILE)

def get_langs_data(token: str):
def get_langs_data(
token: str,
username: str,
exclude_langs: list[str] = SETTINGS.GENERAL_SETTINGS.EXCLUDED_LANGUAGES
) -> dict[str, float]:
info = {}

total_size = 0

for elem in FetchLangStats(token).fetch_user(USERNAME):
for elem in FetchLangStats(token).fetch_user(username):
if elem.name in exclude_langs: continue

total_size += elem.size
if elem.name not in info: info[elem.name] = elem.size
else: info[elem.name] += elem.size

return info.keys(), map(lambda x: x/total_size, info.values())
return {k: info[k]/total_size for k in info}

def truncate(langs_arr: list[tuple[float, str]], k: int):
if len(langs_arr) <= k: return langs_arr
return langs_arr[:k-1] + [(sum(map(lambda x: x[0], langs_arr[k-1:])), "Other")]

def main():
NAMES_ARR, PERCENT_ARR = get_langs_data(TOKEN)
languages_stats = get_langs_data(TOKEN, USERNAME)

sorted_percents = sorted([(percent, name) for percent,name in zip(PERCENT_ARR, NAMES_ARR)], key=lambda x: x[0], reverse=True)
sorted_percents = sorted(
[(percent, name) for percent,name in zip(languages_stats.values(), languages_stats.keys())],
key=lambda x: x[0],
reverse=True
)

sorted_percents = truncate(sorted_percents, TOP_K)
sorted_percents = truncate(sorted_percents, SETTINGS.GENERAL_SETTINGS.TOP_K)

_ = Calc(
outer_radius=OUTER_RADIUS,
thickness=THICKNESS,
outer_radius=SETTINGS.DIAGRAM_SETTINGS.OUTER_RADIUS,
thickness=SETTINGS.DIAGRAM_SETTINGS.THICKNESS,
percent_array=[elem[0] for elem in sorted_percents],
sections_colors_array=OKLCHUtils.create_colors_array(
length=len(sorted_percents),
chroma=OKLCH_CHROMA,
lightness=OKLCH_LIGHTNESS
chroma=SETTINGS.GENERAL_SETTINGS.COLORING.CHROMA,
lightness=SETTINGS.GENERAL_SETTINGS.COLORING.LIGHTNESS
),
renderer=RenderBuilder(
height=HEIGHT,
width=WIDTH,
outer_radius=OUTER_RADIUS,
thickness=THICKNESS,
margin_x=MARGIN_X,
margin_y=MARGIN_Y,
legend_margin_x=LEGEND_MARGIN_X,
legend_margin_y=LEGEND_MARGIN_Y,
space_between_captions=SPACE_BETWEEN_CAPTIONS,
font_color=FONT_COLOR
height=SETTINGS.GENERAL_SETTINGS.PLANE.HEIGHT,
width=SETTINGS.GENERAL_SETTINGS.PLANE.WIDTH,
outer_radius=SETTINGS.DIAGRAM_SETTINGS.OUTER_RADIUS,
thickness=SETTINGS.DIAGRAM_SETTINGS.THICKNESS,
margin_x=SETTINGS.DIAGRAM_SETTINGS.MARGIN_X,
margin_y=SETTINGS.DIAGRAM_SETTINGS.MARGIN_Y,
legend_margin_x=SETTINGS.LEGEND_SETTINGS.MARGIN_X,
legend_margin_y=SETTINGS.LEGEND_SETTINGS.MARGIN_Y,
space_between_captions=SETTINGS.LEGEND_SETTINGS.SPACE_BETWEEN_CAPTIONS,
font_color=SETTINGS.LEGEND_SETTINGS.FONT_COLOR
),
margin_x=MARGIN_X,
margin_y=MARGIN_Y,
margin_x=SETTINGS.DIAGRAM_SETTINGS.MARGIN_X,
margin_y=SETTINGS.DIAGRAM_SETTINGS.MARGIN_Y,
names_array=[elem[1] for elem in sorted_percents]
)

Expand Down
8 changes: 8 additions & 0 deletions src/settings/DiagramSettings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from dataclasses import dataclass

@dataclass
class DiagramSettings():
OUTER_RADIUS: int
THICKNESS: int
MARGIN_X: int
MARGIN_Y: int
14 changes: 14 additions & 0 deletions src/settings/GeneralSettings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from dataclasses import dataclass
from .coloring.OKLCHColoring import OKLCHColoring

@dataclass
class GeneralSettings:
TOP_K: int
PLANE: "PlaneSubsettings"
COLORING: OKLCHColoring
EXCLUDED_LANGUAGES: list[str]

@dataclass
class PlaneSubsettings:
HEIGHT: int
WIDTH: int
9 changes: 9 additions & 0 deletions src/settings/LegendSettings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from dataclasses import dataclass

@dataclass
class LegendSettings:
MARGIN_X: int
MARGIN_Y: int
SPACE_BETWEEN_CAPTIONS: int
FONT_COLOR: str

48 changes: 48 additions & 0 deletions src/settings/Settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import yaml
from typing import Self

from .GeneralSettings import GeneralSettings, PlaneSubsettings
from .LegendSettings import LegendSettings
from .DiagramSettings import DiagramSettings
from .coloring.OKLCHColoring import OKLCHColoring

class Settings:
GENERAL_SETTINGS: GeneralSettings
LEGEND_SETTINGS: LegendSettings
DIAGRAM_SETTINGS: DiagramSettings

@classmethod
def from_yaml(cls, path: str) -> Self:
with open(path, 'r') as stream:
data = yaml.safe_load(stream)

inst = cls()

inst.GENERAL_SETTINGS = GeneralSettings(
data["general"]["top_k"],
PlaneSubsettings(
data["general"]["plane"]["height"],
data["general"]["plane"]["width"]
),
OKLCHColoring(
data["general"]["coloring"]["chroma"],
data["general"]["coloring"]["lightness"]
),
data["general"]["excluded_languages"]
)

inst.LEGEND_SETTINGS = LegendSettings(
data["legend"]["margin_x"],
data["legend"]["margin_y"],
data["legend"]["space_between_captions"],
data["legend"]["font_color"]
)

inst.DIAGRAM_SETTINGS = DiagramSettings(
data["diagram"]["outer_radius"],
data["diagram"]["thickness"],
data["diagram"]["margin_x"],
data["diagram"]["margin_y"]
)

return inst
1 change: 1 addition & 0 deletions src/settings/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .Settings import Settings
7 changes: 7 additions & 0 deletions src/settings/coloring/OKLCHColoring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from dataclasses import dataclass

@dataclass
class OKLCHColoring():
CHROMA: float
LIGHTNESS: float
TYPE = "oklvh"