MCPcopy Index your code
hub / github.com/fatihak/InkyPi / parse_contributions

Function parse_contributions

src/plugins/github/github_contributions.py:70–99  ·  view source on GitHub ↗
(data, colors)

Source from the content-addressed store, hash-verified

68 return resp.json()
69
70def parse_contributions(data, colors):
71 weeks = data["data"]["user"]["contributionsCollection"]["contributionCalendar"]["weeks"]
72
73 grid = [list(week["contributionDays"]) for week in weeks]
74 max_contrib = max(day["contributionCount"] for week in grid for day in week)
75
76 def get_color(count):
77 if max_contrib == 0 or count == 0:
78 return colors[0]
79 level = int((count / max_contrib) * (len(colors) - 1))
80 return colors[max(1, level)]
81
82 for week in grid:
83 for day in week:
84 day["color"] = get_color(day["contributionCount"])
85
86 month_positions = []
87 seen_months = set()
88 for i, week in enumerate(weeks):
89 first_day = week["contributionDays"][0]["date"]
90 dt = datetime.strptime(first_day, "%Y-%m-%d")
91 month_year = f"{dt.strftime('%b')}-{dt.year}"
92 if month_year not in seen_months:
93 month_positions.append({"name": dt.strftime("%b"), "index": i})
94 seen_months.add(month_year)
95
96 if month_positions:
97 month_positions.pop(0)
98
99 return grid, month_positions
100
101def calculate_metrics(data):
102 weeks = data["data"]["user"]["contributionsCollection"]["contributionCalendar"]["weeks"]

Callers 1

Calls 1

get_colorFunction · 0.85

Tested by

no test coverage detected