mirror of
https://github.com/pugarte7/spanish-top-tech-companies.git
synced 2026-10-26 06:58:11 +01:00
904 lines
43 KiB
Python
904 lines
43 KiB
Python
#!/usr/bin/env python3
|
||
"""Generate the static salary site from companies.csv.
|
||
|
||
python3 scripts/site.py # writes _site/
|
||
python3 -m http.server -d _site # then open http://localhost:8000/es/
|
||
|
||
The site publishes aggregates only: every number on it comes from at least
|
||
lib.MIN_GROUP people, quartiles from lib.QUARTILE_MIN, and every euro figure
|
||
is rounded to lib.ROUND_EUR. The CSV stays row-level; a city x role x years
|
||
cell of a few people would name them.
|
||
|
||
Pages come in English and Spanish under /en/ and /es/. The page's look lives
|
||
in web/ (app.js, style.css); this script renders the HTML shell, the map of
|
||
Spain and /api/v1/data.json, which serves both the page and agents. Agents
|
||
that only read URLs get /llms.txt and /llms-full.txt (markdown, from the same
|
||
aggregates through query.py); agents that speak MCP get scripts/mcp_server.py.
|
||
Set SITE_URL to the public origin so those pages carry absolute links.
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import collections
|
||
import hashlib
|
||
import html
|
||
import itertools
|
||
import json
|
||
import math
|
||
import os
|
||
import shutil
|
||
import statistics
|
||
import sys
|
||
import urllib.request
|
||
|
||
import lib
|
||
import query
|
||
import taxonomy
|
||
|
||
OUT = lib.ROOT / "_site"
|
||
WEB = lib.ROOT / "web"
|
||
REPO = "https://github.com/pugarte7/spanish-top-tech-companies"
|
||
# The branch the site, the MCP server and the skill live on: main holds the README alone.
|
||
BRANCH = "website"
|
||
SITE = os.environ.get("SITE_URL", "").rstrip("/")
|
||
|
||
# Region outlines, fetched once into .cache/ (gitignored is fine: it is
|
||
# rebuilt from the pinned URL).
|
||
TOPO_URL = "https://unpkg.com/es-atlas@0.6.0/es/autonomous_regions.json"
|
||
TOPO = lib.ROOT / ".cache" / "es_autonomous_regions.json"
|
||
# Keyed by the atlas's own names, bilingual ones included: "Cataluña" alone
|
||
# matched nothing, and the map shipped without Cataluña and País Vasco.
|
||
ES_ATLAS = {
|
||
"Andalucía": "AN", "Aragón": "AR", "Principado de Asturias": "AS",
|
||
"Cantabria": "CB", "Castilla y León": "CL", "Castilla-La Mancha": "CM",
|
||
"Cataluña/Catalunya": "CT", "Comunidad de Madrid": "MD", "Comunitat Valenciana": "VC",
|
||
"Comunidad Valenciana": "VC", "Extremadura": "EX", "Galicia": "GA",
|
||
"Illes Balears": "IB", "Islas Baleares": "IB", "Canarias": "CN",
|
||
"La Rioja": "RI", "Región de Murcia": "MU", "Comunidad Foral de Navarra": "NC",
|
||
"País Vasco/Euskadi": "PV", "Ciudad Autónoma de Ceuta": "CE",
|
||
"Ciudad Autónoma de Melilla": "ML",
|
||
}
|
||
# The Canaries sit far southwest; slide them into the usual inset corner.
|
||
CANARY_SHIFT = (5.5, 7.6)
|
||
MAP_W, MAP_H = 600, 470
|
||
|
||
REGIONS_ES = {
|
||
"AN": "Andalucía", "AR": "Aragón", "AS": "Asturias", "CB": "Cantabria",
|
||
"CE": "Ceuta", "CL": "Castilla y León", "CM": "Castilla-La Mancha",
|
||
"CN": "Canarias", "CT": "Cataluña", "EX": "Extremadura", "GA": "Galicia",
|
||
"IB": "Baleares", "MD": "Madrid", "ML": "Melilla", "MU": "Murcia",
|
||
"NC": "Navarra", "PV": "País Vasco", "RI": "La Rioja", "VC": "C. Valenciana",
|
||
}
|
||
|
||
# A city has no region column on pre-2026-10 rows; this maps the observed
|
||
# spellings so the map works before the feed backfills `region`.
|
||
CITY_REGION = {
|
||
"barcelona": "CT", "badalona": "CT", "reus": "CT", "girona": "CT",
|
||
"lleida": "CT", "tarragona": "CT", "sabadell": "CT",
|
||
"madrid": "MD", "alcobendas": "MD", "pozuelo de alarcon": "MD",
|
||
"malaga": "AN", "sevilla": "AN", "granada": "AN", "cordoba": "AN",
|
||
"marbella": "AN", "cadiz": "AN", "almeria": "AN", "jaen": "AN",
|
||
"valencia": "VC", "alicante": "VC", "castellon": "VC", "elche": "VC",
|
||
"bilbao": "PV", "san sebastian": "PV", "vitoria": "PV", "donostia": "PV",
|
||
"getxo": "PV", "barakaldo": "PV",
|
||
"zaragoza": "AR", "a coruna": "GA", "vigo": "GA", "santiago": "GA",
|
||
"santiago de compostela": "GA", "oviedo": "AS", "gijon": "AS",
|
||
"pontevedra": "GA", "ourense": "GA", "lugo": "GA", "ferrol": "GA",
|
||
"santander": "CB", "valladolid": "CL", "salamanca": "CL", "leon": "CL",
|
||
"burgos": "CL", "palma": "IB", "palma de mallorca": "IB",
|
||
"las palmas": "CN", "las palmas de gran canaria": "CN",
|
||
"santa cruz de tenerife": "CN", "tenerife": "CN",
|
||
"torrevieja": "VC", "benidorm": "VC",
|
||
"murcia": "MU", "cartagena": "MU", "pamplona": "NC", "logrono": "RI",
|
||
"toledo": "CM", "albacete": "CM", "badajoz": "EX", "ceuta": "CE",
|
||
"melilla": "ML",
|
||
}
|
||
|
||
# The site covers companies whose median base, over every salary on file at
|
||
# any role and seniority, reaches this. The CSV keeps the rest.
|
||
COMPANY_FLOOR_EUR = 45_000
|
||
# A yearly base under this is no full-time salary in Spain, whose minimum wage
|
||
# has been above it since 2023: it is a monthly figure, a stipend or part-time,
|
||
# and one of them in a group of five moves the median.
|
||
MIN_BASE_EUR = 15_000
|
||
|
||
YEAR_BUCKETS = [(0, 2), (2, 5), (5, 8), (8, 12), (12, 20), (20, None)]
|
||
# Histogram bins of 10k; the ends are open so a lone outlier joins a crowd.
|
||
HIST_LOW, HIST_HIGH, HIST_STEP = 20_000, 150_000, 10_000
|
||
|
||
# GitHub's outline star (octicon star-16), the one on its Star button.
|
||
STAR_ICON = ('<svg viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M8 .25a.75.75 0 0 1 '
|
||
'.673.418l1.882 3.815 4.21.612a.75.75 0 0 1 .416 1.279l-3.046 2.97.719 4.192a.751.751 0 0 1-1.088.791'
|
||
'L8 12.347l-3.766 1.98a.75.75 0 0 1-1.088-.79l.72-4.194L.818 6.374a.75.75 0 0 1 .416-1.28l4.21-.611'
|
||
'L7.327.668A.75.75 0 0 1 8 .25Zm0 2.445L6.615 5.5a.75.75 0 0 1-.564.41l-3.097.45 2.24 2.184a.75.75 0 '
|
||
'0 1 .216.664l-.528 3.084 2.769-1.456a.75.75 0 0 1 .698 0l2.77 1.456-.53-3.084a.75.75 0 0 1 .216-.664'
|
||
'l2.24-2.183-3.096-.45a.75.75 0 0 1-.564-.41L8 2.694Z"/></svg>')
|
||
GITHUB_ICON = ('<svg viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M8 0C3.58 0 0 3.58 0 8'
|
||
'c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94'
|
||
'-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66'
|
||
'.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12'
|
||
' 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16'
|
||
' 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01'
|
||
' 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0 0 16 8c0-4.42-3.58-8-8-8z"/></svg>')
|
||
# Both glyphs ship; the stylesheet shows the moon in light mode and the sun in dark.
|
||
THEME_ICON = ('<svg class="moon" viewBox="0 0 24 24" aria-hidden="true"><path fill="currentColor" '
|
||
'd="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z"/></svg>'
|
||
'<svg class="sun" viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" '
|
||
'stroke-width="2" stroke-linecap="round"><circle cx="12" cy="12" r="4.5"/><path d="M12 1.5v2'
|
||
'M12 20.5v2M1.5 12h2M20.5 12h2M4.6 4.6l1.4 1.4M18 18l1.4 1.4M4.6 19.4 6 18M18 6l1.4-1.4"/></svg>')
|
||
|
||
STRINGS = {
|
||
"en": {
|
||
"title": "Spanish Top Tech Companies", "theme": "Light or dark mode",
|
||
"source": "Data: Levels.fyi",
|
||
"rule": "Only companies in Spain whose median base salary, counting all their salaries, "
|
||
"is {floor} or more. The rest are not shown.",
|
||
"how_title": "How it is calculated",
|
||
"how_source_t": "Source.",
|
||
"how_source": "Individual salaries from Levels.fyi, each kept only if its own location is in Spain. "
|
||
"A base under {minbase} a year, below the full-time minimum wage, is left out.",
|
||
"how_when_t": "When.",
|
||
"how_when": "Reported from {from} to {to}, half of them since {since}. Older salaries stay in, "
|
||
"so figures can trail what companies offer today.",
|
||
"how_floor_t": "Which companies.",
|
||
"how_floor": "For each company, the median base salary over all its salaries, any role and "
|
||
"experience. It is shown if that reaches {floor}; the rest are left out.",
|
||
"how_groups_t": "Groups of {min} or more.",
|
||
"how_groups": "By role, region and years of experience. No figure comes from fewer than "
|
||
"{min} salaries, the middle half needs {qmin}, and every amount is rounded "
|
||
"to the nearest {round}, so nobody's pay can be read off a figure.",
|
||
"how_figures_t": "What you see.",
|
||
"how_figures": "Median base, the middle half (p25–p75), median total pay (base + bonus + stock) "
|
||
"and the share with a base of {bar} or more. They describe these companies, "
|
||
"not all of Spain.",
|
||
"all_roles": "All roles", "all_years": "Any",
|
||
"years_label": "Experience", "years_unit": "yrs",
|
||
"hero_label": "Median base salary",
|
||
"kpi_total": "Median total comp", "kpi_people": "Salaries",
|
||
"kpi_share": "60k+ base", "kpi_companies": "Companies",
|
||
"map_title": "By region",
|
||
"map_pay": "Median base", "map_count": "Salaries",
|
||
"map_pay_sub": "Median gross yearly base salary of everyone reported in each region.",
|
||
"map_count_sub": "How many salaries were reported in each region.",
|
||
"map_empty": "Fewer than {min} salaries",
|
||
"matrix_title": "Pay by role and experience",
|
||
"matrix_sub": "Median gross yearly base salary for the roles with most data. "
|
||
"Click a cell to see which companies pay most there.",
|
||
"sum_range": "Middle half earns",
|
||
"companies_title": "Companies",
|
||
"search": "Search",
|
||
"col_company": "Company", "col_median": "Median base salary",
|
||
"col_n": "Salaries reported",
|
||
"col_share": "Earning 60k+",
|
||
"tip_median": "Gross yearly base salary: half earn more, half earn less",
|
||
"tip_share": "Share of salaries with a base of 60,000 € or more",
|
||
"tip_n": "How many salaries this company has under the filters chosen",
|
||
"split_base": "Base", "split_bonus": "Bonus", "split_stock": "Stock",
|
||
"split_total": "Median total pay", "split_tip": "How much of these salaries' pay is base, bonus and stock",
|
||
"show_all": "Show all {n}", "show_less": "Show less",
|
||
"none": "No group of {min} or more salaries.",
|
||
"people": "salaries", "median": "Median", "range": "p25–p75",
|
||
"updated": "Updated {date}",
|
||
"data": "JSON", "repo": "GitHub", "web": "Website",
|
||
"star_title": "Finding this useful?",
|
||
"star_text": "Give the repo a star on GitHub. It helps more people find it.",
|
||
"star_button": "Star on GitHub", "star_close": "Close",
|
||
"under": "Under", "over": "Over",
|
||
"role_label": "Role", "mode_label": "Work",
|
||
"mode_remote": "Remote", "mode_hybrid": "Hybrid", "mode_office": "Office",
|
||
"any": "Any", "loading": "Loading…", "from": "From", "to": "To",
|
||
},
|
||
"es": {
|
||
"title": "Spanish Top Tech Companies", "theme": "Modo claro u oscuro",
|
||
"source": "Datos: Levels.fyi",
|
||
"rule": "Solo empresas en España con un sueldo base mediano de {floor} o más, contando "
|
||
"todos sus salarios. Las demás no aparecen.",
|
||
"how_title": "Cómo se calcula",
|
||
"how_source_t": "Fuente.",
|
||
"how_source": "Salarios individuales de Levels.fyi. Cada uno se acepta solo si su propia "
|
||
"ubicación está en España. Un sueldo base de menos de {minbase} al año, por "
|
||
"debajo del salario mínimo a jornada completa, se descarta.",
|
||
"how_when_t": "Cuándo.",
|
||
"how_when": "Publicados entre {from} y {to}, la mitad desde {since}. Los antiguos se "
|
||
"mantienen, así que las cifras pueden ir por detrás de lo que se ofrece hoy.",
|
||
"how_floor_t": "Qué empresas entran.",
|
||
"how_floor": "Por empresa, la mediana del sueldo base de todos sus salarios, de cualquier rol "
|
||
"y experiencia. Entra si llega a {floor}; las demás se quedan fuera.",
|
||
"how_groups_t": "Grupos de {min} o más.",
|
||
"how_groups": "Por rol, comunidad y años de experiencia. Ninguna cifra sale de menos de "
|
||
"{min} salarios, la mitad central necesita {qmin} y todos los importes se "
|
||
"redondean a {round}, para que no se pueda deducir el sueldo de nadie.",
|
||
"how_figures_t": "Qué se muestra.",
|
||
"how_figures": "Sueldo base mediano, la mitad central (p25–p75), el total mediano (base + bonus "
|
||
"+ acciones) y el porcentaje con una base de {bar} o más. Son cifras de estas "
|
||
"empresas, no de toda España.",
|
||
"all_roles": "Todos los roles", "all_years": "Todas",
|
||
"years_label": "Experiencia", "years_unit": "años",
|
||
"hero_label": "Salario base mediano",
|
||
"kpi_total": "Total mediano", "kpi_people": "Salarios",
|
||
"kpi_share": "60k+ de base", "kpi_companies": "Empresas",
|
||
"map_title": "Por comunidad",
|
||
"map_pay": "Base mediana", "map_count": "Salarios",
|
||
"map_pay_sub": "Salario base bruto anual mediano de todos los salarios de cada comunidad.",
|
||
"map_count_sub": "Cuántos salarios se han recogido en cada comunidad.",
|
||
"map_empty": "Menos de {min} salarios",
|
||
"matrix_title": "Sueldo según rol y experiencia",
|
||
"matrix_sub": "Sueldo base bruto anual mediano de los roles con más datos. "
|
||
"Pulsa una celda para ver qué empresas pagan más en ese caso.",
|
||
"sum_range": "La mitad cobra entre",
|
||
"companies_title": "Empresas",
|
||
"search": "Buscar",
|
||
"col_company": "Empresa", "col_median": "Sueldo base mediano",
|
||
"col_n": "Nº de salarios",
|
||
"col_share": "Cobran 60k o más",
|
||
"tip_median": "Salario base bruto anual: la mitad cobra más y la mitad menos",
|
||
"tip_share": "Porcentaje de salarios con una base de 60.000 € o más",
|
||
"tip_n": "Cuántos salarios de esta empresa hay con los filtros elegidos",
|
||
"split_base": "Base", "split_bonus": "Bonus", "split_stock": "Acciones",
|
||
"split_total": "Sueldo total mediano", "split_tip": "Qué parte del pago de estos salarios es base, bonus y acciones",
|
||
"show_all": "Ver los {n}", "show_less": "Ver menos",
|
||
"none": "Ningún grupo de {min} o más salarios.",
|
||
"people": "salarios", "median": "Mediana", "range": "p25–p75",
|
||
"updated": "Actualizado {date}",
|
||
"data": "JSON", "repo": "GitHub", "web": "Web",
|
||
"star_title": "¿Te está sirviendo?",
|
||
"star_text": "Dale una estrella al repo en GitHub. Ayuda a que lo encuentre más gente.",
|
||
"star_button": "Dar una estrella en GitHub", "star_close": "Cerrar",
|
||
"under": "Menos de", "over": "Más de",
|
||
"role_label": "Rol", "mode_label": "Modalidad",
|
||
"mode_remote": "Remoto", "mode_hybrid": "Híbrido", "mode_office": "Presencial",
|
||
"any": "Cualquiera", "loading": "Cargando…", "from": "Desde", "to": "Hasta",
|
||
},
|
||
}
|
||
|
||
|
||
def asset_version(name: str) -> str:
|
||
"""A short hash of a file in web/, put in its URL so a browser fetches it
|
||
again whenever it changes instead of running a cached copy."""
|
||
return hashlib.sha256((WEB / name).read_bytes()).hexdigest()[:10]
|
||
|
||
|
||
def year_bucket(years: int | None) -> str | None:
|
||
if years is None:
|
||
return None
|
||
for low, high in YEAR_BUCKETS:
|
||
if years >= low and (high is None or years < high):
|
||
return f"{low}-{high - 1}" if high else f"{low}+"
|
||
return None
|
||
|
||
|
||
def bucket_labels() -> list[str]:
|
||
return [f"{low}-{high - 1}" if high else f"{low}+" for low, high in YEAR_BUCKETS]
|
||
|
||
|
||
def role_info(slug: str) -> dict:
|
||
name, category = taxonomy.ROLES.get(slug, (slug.replace("-", " ").title(), "Other"))
|
||
return {"slug": slug, "name": name, "category": category}
|
||
|
||
|
||
def region_of(entry: dict) -> str | None:
|
||
if entry.get("region"):
|
||
return lib.region_code(entry["region"]) or entry["region"]
|
||
return CITY_REGION.get(lib._norm_words(entry.get("city")))
|
||
|
||
|
||
def histogram(bases: list[int]) -> list[int | None]:
|
||
"""Counts per band; a band of fewer than MIN_GROUP people is withheld as None."""
|
||
bands = (HIST_HIGH - HIST_LOW) // HIST_STEP + 2
|
||
counts = [0] * bands
|
||
for b in bases:
|
||
i = 0 if b < HIST_LOW else min(bands - 1, 1 + (b - HIST_LOW) // HIST_STEP)
|
||
counts[i] += 1
|
||
return [c if c == 0 or c >= lib.MIN_GROUP else None for c in counts]
|
||
|
||
|
||
def rounded(eur: float) -> int:
|
||
"""To the nearest lib.ROUND_EUR, halves up, so no figure is someone's exact pay."""
|
||
return int(math.floor(eur / lib.ROUND_EUR + 0.5)) * lib.ROUND_EUR
|
||
|
||
|
||
def aggregate(entries: list[dict], hist: bool = False) -> dict | None:
|
||
"""Median, quartiles and share at the bar, or None under MIN_GROUP.
|
||
|
||
Quartiles are None under QUARTILE_MIN: in a small group they pin down the
|
||
salaries around them."""
|
||
bases = sorted(e["base"] for e in entries if e.get("base"))
|
||
if len(bases) < lib.MIN_GROUP:
|
||
return None
|
||
totals = [e["total"] for e in entries if e.get("total")]
|
||
quartiles = (statistics.quantiles(bases, n=4, method="inclusive")
|
||
if len(bases) >= lib.QUARTILE_MIN else None)
|
||
at_bar = sum(1 for b in bases if b >= lib.THRESHOLD_EUR)
|
||
out = {
|
||
"n": len(bases),
|
||
"median": rounded(statistics.median(bases)),
|
||
"p25": rounded(quartiles[0]) if quartiles else None,
|
||
"p75": rounded(quartiles[2]) if quartiles else None,
|
||
"total": rounded(statistics.median(totals)) if len(totals) >= lib.MIN_GROUP else None,
|
||
"share": round(at_bar / len(bases), 3),
|
||
}
|
||
if hist:
|
||
out["hist"] = histogram(bases)
|
||
return out
|
||
|
||
|
||
def pay_mix(entries: list[dict]) -> list[int]:
|
||
"""Percent of the group's pay that is base, bonus and stock, summing to 100.
|
||
|
||
A share of the summed pay, not a median per part: the medians of base,
|
||
bonus and stock come from different people and never add up to the
|
||
median total. Totals that carry pay outside the three are left out."""
|
||
sums = [sum(e.get(k) or 0 for e in entries) for k in ("base", "bonus", "stock")]
|
||
exact = [100 * x / sum(sums) for x in sums]
|
||
out = [int(x) for x in exact]
|
||
# Largest remainders, so the three always sum to 100.
|
||
for k in sorted(range(3), key=lambda k: out[k] - exact[k])[:100 - sum(out)]:
|
||
out[k] += 1
|
||
return out
|
||
|
||
|
||
def counted(entry: dict) -> bool:
|
||
return bool(entry.get("base")) and entry["base"] >= MIN_BASE_EUR
|
||
|
||
|
||
def pays_enough(company: dict) -> bool:
|
||
bases = [e["base"] for e in company["entries"] if counted(e)]
|
||
return bool(bases) and statistics.median(bases) >= COMPANY_FLOOR_EUR
|
||
|
||
|
||
def build_data(companies: list[dict]) -> dict:
|
||
"""Every publishable aggregate, keyed "role|region|years" ("" = all)."""
|
||
return _build(companies)[0]
|
||
|
||
|
||
def build_site(companies: list[dict]) -> tuple[dict, dict[str, dict]]:
|
||
"""data.json, and the companies table's own files, one per role."""
|
||
data, rows, index = _build(companies)
|
||
return data, company_filters(rows, index)
|
||
|
||
|
||
def _build(companies: list[dict]) -> tuple[dict, list, dict, dict]:
|
||
rows = []
|
||
for i, company in enumerate(companies):
|
||
if not pays_enough(company):
|
||
continue
|
||
for e in company["entries"]:
|
||
if counted(e):
|
||
rows.append((i, e.get("role") or "", region_of(e) or "",
|
||
year_bucket(lib.years(e.get("years_experience"))) or "", e))
|
||
|
||
cells: dict[str, list[dict]] = collections.defaultdict(list)
|
||
by_company: dict[str, dict[int, list[dict]]] = collections.defaultdict(
|
||
lambda: collections.defaultdict(list))
|
||
for i, role, region, bucket, e in rows:
|
||
for r in {"", role}:
|
||
for g in {"", region}:
|
||
for y in {"", bucket}:
|
||
key = f"{r}|{g}|{y}"
|
||
cells[key].append(e)
|
||
by_company[key][i].append(e)
|
||
|
||
stats = {k: a for k, v in cells.items() if (a := aggregate(v, hist=True))}
|
||
company_stats = {}
|
||
for key in stats:
|
||
found = []
|
||
for i, entries in by_company[key].items():
|
||
if a := aggregate(entries):
|
||
found.append({"c": i, **a})
|
||
found.sort(key=lambda a: (-a["median"], -a["share"]))
|
||
company_stats[key] = found
|
||
|
||
role_counts = collections.Counter(r for _, r, _, _, _ in rows if r)
|
||
used = sorted({i for v in company_stats.values() for a in v for i in [a["c"]]})
|
||
index = {old: new for new, old in enumerate(used)}
|
||
for found in company_stats.values():
|
||
for a in found:
|
||
a["c"] = index[a["c"]]
|
||
|
||
# When the salaries are from, not when this ran: a rebuild with the same
|
||
# rows used to move the page's "Updated" date forward.
|
||
fetched = [str(e["date"])[:10] for *_, e in rows if e.get("date")]
|
||
months = sorted(e["reported"] for *_, e in rows if e.get("reported"))
|
||
data = {
|
||
"generated": lib.today_utc().isoformat(),
|
||
"data_as_of": max(fetched) if fetched else lib.today_utc().isoformat(),
|
||
"reported": {"from": months[0], "to": months[-1], "median": months[len(months) // 2]}
|
||
if months else None,
|
||
"min_base": MIN_BASE_EUR,
|
||
"min_group": lib.MIN_GROUP,
|
||
"quartile_min": lib.QUARTILE_MIN,
|
||
"round_eur": lib.ROUND_EUR,
|
||
"threshold": lib.THRESHOLD_EUR,
|
||
"company_floor": COMPANY_FLOOR_EUR,
|
||
"hist": {"low": HIST_LOW, "high": HIST_HIGH, "step": HIST_STEP},
|
||
"roles": [role_info(r) for r, _ in role_counts.most_common() if f"{r}||" in stats],
|
||
"years": [b for b in bucket_labels() if f"||{b}" in stats],
|
||
"regions": {code: {"en": name, "es": REGIONS_ES[code]}
|
||
for code, name in lib.REGIONS.items()},
|
||
"companies": [company_info(companies[i]) for i in used],
|
||
"cells": stats,
|
||
"company_cells": company_stats,
|
||
}
|
||
return data, rows, index
|
||
|
||
|
||
def _subsets(values: list[str]) -> list[tuple[str, ...]]:
|
||
"""Every non-empty choice of values, in their own order; all of them is ""."""
|
||
return [c for n in range(1, len(values)) for c in itertools.combinations(values, n)]
|
||
|
||
|
||
def _spans(values: list[str]) -> list[tuple[str, ...]]:
|
||
"""Every run of consecutive values, short of all of them."""
|
||
return [tuple(values[i:j]) for i in range(len(values))
|
||
for j in range(i + 1, len(values) + 1) if j - i < len(values)]
|
||
|
||
|
||
def company_filters(rows: list, index: dict) -> dict[str, dict]:
|
||
"""The companies table for any role or specialization, any span of
|
||
experience bands and any set of work arrangements.
|
||
|
||
One file per role ("" = every role) and per role/specialization, keyed
|
||
"arrangements|bands" (comma-joined, "" = all). Rows are arrays in
|
||
`fields` order: objects would double the size of a file the page has to
|
||
load.
|
||
|
||
The page lets a reader pick a span of years and several arrangements, and
|
||
a median of a union cannot be built from the medians of its parts, so
|
||
every combination is aggregated here. Each is still a group of MIN_GROUP
|
||
or more people, the same rule as data.json; region is left out, which
|
||
keeps the files small.
|
||
"""
|
||
bands, modes = bucket_labels(), list(lib.WORK_ARRANGEMENTS)
|
||
band_sets = [("",)] + _spans(bands)
|
||
mode_sets = [("",)] + _subsets(modes)
|
||
groups: dict[str, dict[str, dict[int, list]]] = collections.defaultdict(
|
||
lambda: collections.defaultdict(lambda: collections.defaultdict(list)))
|
||
counts = collections.Counter()
|
||
for i, role, _, bucket, e in rows:
|
||
spec = e.get("specialization") or ""
|
||
tables = {"", role, f"{role}/{spec}" if role and spec else ""}
|
||
counts.update(t for t in tables if t)
|
||
mode = e.get("work_arrangement") or ""
|
||
for ms in mode_sets:
|
||
if ms != ("",) and mode not in ms:
|
||
continue
|
||
for bs in band_sets:
|
||
if bs != ("",) and bucket not in bs:
|
||
continue
|
||
key = f"{','.join(m for m in ms if m)}|{','.join(b for b in bs if b)}"
|
||
for t in tables:
|
||
groups[t][key][i].append(e)
|
||
|
||
files = {}
|
||
fields = ["c", "n", "median", "p25", "p75", "total", "share", "mix"]
|
||
# The summary above the table: everyone under the same filters, one
|
||
# aggregate per key, with its histogram.
|
||
summary_fields = ["n", "median", "p25", "p75", "share", "hist"]
|
||
for name, cells in groups.items():
|
||
out, summary = {}, {}
|
||
for key, by_company in cells.items():
|
||
if a := aggregate([e for entries in by_company.values() for e in entries], hist=True):
|
||
summary[key] = [a[f] for f in summary_fields]
|
||
found = []
|
||
for i, entries in by_company.items():
|
||
if a := aggregate(entries):
|
||
a["mix"] = pay_mix(entries)
|
||
found.append({"c": index[i], **a})
|
||
if found:
|
||
found.sort(key=lambda a: (-a["median"], -a["share"]))
|
||
out[key] = [[a[f] for f in fields] for a in found]
|
||
if out:
|
||
files[name] = {"fields": fields, "cells": out,
|
||
"summary_fields": summary_fields, "summary": summary}
|
||
|
||
# The role menu, most salaries first, each role with its specializations.
|
||
# Only tables that exist are offered.
|
||
def entry(slug: str, name: str) -> dict:
|
||
return {"slug": slug, "name": name, "n": counts[slug]}
|
||
menu = []
|
||
for role in sorted((t for t in files if t and "/" not in t), key=lambda t: -counts[t]):
|
||
specs = taxonomy.SPECIALIZATIONS.get(role, {})
|
||
item = entry(role, role_info(role)["name"])
|
||
item["specs"] = [entry(t, specs.get(t.split("/")[1], (t.split("/")[1],))[0])
|
||
for t in sorted((t for t in files if t.startswith(role + "/")),
|
||
key=lambda t: -counts[t])]
|
||
menu.append(item)
|
||
files[""]["roles"] = menu
|
||
files[""]["bands"] = bands
|
||
return files
|
||
|
||
|
||
def company_info(company: dict) -> dict:
|
||
cities = collections.Counter(e["city"] for e in company["entries"] if e.get("city"))
|
||
# "-" means checked and there is none. The careers page first: it is where to apply.
|
||
web = next((u for u in (company.get("careers_url"), company.get("website")) if u and u != "-"), None)
|
||
url = web
|
||
if not url and company.get("levels_slug"):
|
||
url = f"https://www.levels.fyi/companies/{company['levels_slug']}/salaries"
|
||
return {"name": company["company"], "url": url, "web": web,
|
||
"levels": company.get("levels_slug"),
|
||
"linkedin": company.get("linkedin_url"),
|
||
"cities": [c for c, _ in cities.most_common(3)]}
|
||
|
||
|
||
# --- Map ---------------------------------------------------------------------
|
||
|
||
def topojson() -> dict:
|
||
if not TOPO.exists():
|
||
TOPO.parent.mkdir(exist_ok=True)
|
||
with urllib.request.urlopen(TOPO_URL, timeout=30) as r:
|
||
TOPO.write_bytes(r.read())
|
||
return json.loads(TOPO.read_text())
|
||
|
||
|
||
def decoded_regions(topo: dict) -> list[tuple[str, list]]:
|
||
"""[(code, polygons)], each polygon a list of rings of (lon, lat)."""
|
||
sx, sy = topo["transform"]["scale"]
|
||
tx, ty = topo["transform"]["translate"]
|
||
arcs = []
|
||
for arc in topo["arcs"]:
|
||
x = y = 0
|
||
points = []
|
||
for dx, dy in arc:
|
||
x, y = x + dx, y + dy
|
||
points.append((x * sx + tx, y * sy + ty))
|
||
arcs.append(points)
|
||
|
||
def stitch(indices):
|
||
ring = []
|
||
for i in indices:
|
||
arc = arcs[i] if i >= 0 else arcs[~i][::-1]
|
||
ring += arc[1:] if ring else arc
|
||
return ring
|
||
|
||
out, unmatched = [], []
|
||
for g in topo["objects"]["autonomous_regions"]["geometries"]:
|
||
code = ES_ATLAS.get(g["properties"].get("name"))
|
||
if not code:
|
||
unmatched.append(g["properties"].get("name"))
|
||
continue
|
||
polys = g["arcs"] if g["type"] == "MultiPolygon" else [g["arcs"]]
|
||
out.append((code, [[stitch(part) for part in poly] for poly in polys]))
|
||
# A region left off the map looks like a region with no data, so stop the build.
|
||
missing = sorted(set(lib.REGIONS) - {code for code, _ in out})
|
||
if missing:
|
||
raise SystemExit(f"No map outline for {', '.join(missing)}; "
|
||
f"atlas names not in ES_ATLAS: {unmatched}")
|
||
return out
|
||
|
||
|
||
def project(lon: float, lat: float, code: str) -> tuple[float, float]:
|
||
if code == "CN":
|
||
lon, lat = lon + CANARY_SHIFT[0], lat + CANARY_SHIFT[1]
|
||
return (lon + 4.0) * math.cos(math.radians(39.5)), -lat
|
||
|
||
|
||
def spain_svg() -> str:
|
||
regions = [(code, [[[project(lon, lat, code) for lon, lat in ring] for ring in poly]
|
||
for poly in polys]) for code, polys in decoded_regions(topojson())]
|
||
xy = [p for _, polys in regions for poly in polys for ring in poly for p in ring]
|
||
minx, maxx = min(p[0] for p in xy), max(p[0] for p in xy)
|
||
miny, maxy = min(p[1] for p in xy), max(p[1] for p in xy)
|
||
pad = 8
|
||
scale = min((MAP_W - 2 * pad) / (maxx - minx), (MAP_H - 2 * pad) / (maxy - miny))
|
||
ox = (minx + maxx) / 2 - MAP_W / (2 * scale)
|
||
oy = (miny + maxy) / 2 - MAP_H / (2 * scale)
|
||
|
||
def pt(p):
|
||
return (p[0] - ox) * scale, (p[1] - oy) * scale
|
||
|
||
paths = []
|
||
for code, polys in regions:
|
||
d = "".join("M" + "L".join(f"{x:.1f},{y:.1f}" for x, y in map(pt, ring)) + "Z"
|
||
for poly in polys for ring in poly)
|
||
paths.append(f'<path class="region" data-code="{code}" d="{d}"/>')
|
||
return (f'<svg id="map" viewBox="0 0 {MAP_W} {MAP_H}" role="img">'
|
||
f'{"".join(paths)}</svg>')
|
||
|
||
|
||
# --- Page --------------------------------------------------------------------
|
||
|
||
def euros(n: int, lang: str) -> str:
|
||
return f"{n:,}\u00a0€".replace(",", ".") if lang == "es" else f"€{n:,}"
|
||
|
||
|
||
MONTHS = {"en": "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(),
|
||
"es": "ene feb mar abr may jun jul ago sep oct nov dic".split()}
|
||
|
||
|
||
def month(ym: str, lang: str) -> str:
|
||
""""2024-11" as "Nov 2024" or "nov 2024"."""
|
||
year, number = ym.split("-")
|
||
return f"{MONTHS[lang][int(number) - 1]} {year}"
|
||
|
||
|
||
def strings(lang: str, data: dict) -> dict:
|
||
reported = data.get("reported") or {"from": "", "to": "", "median": ""}
|
||
fill = {"{min}": str(lib.MIN_GROUP), "{qmin}": str(lib.QUARTILE_MIN),
|
||
"{round}": euros(lib.ROUND_EUR, lang), "{floor}": euros(COMPANY_FLOOR_EUR, lang),
|
||
"{bar}": euros(lib.THRESHOLD_EUR, lang), "{minbase}": euros(MIN_BASE_EUR, lang),
|
||
**{f"{{{k}}}": month(v, lang) if v else "" for k, v in
|
||
(("from", reported["from"]), ("to", reported["to"]), ("since", reported["median"]))}}
|
||
out = {}
|
||
for k, v in STRINGS[lang].items():
|
||
for mark, value in fill.items():
|
||
v = v.replace(mark, value)
|
||
out[k] = v
|
||
return out
|
||
|
||
|
||
def page(lang: str, svg: str, data_version: str, data: dict) -> str:
|
||
s = strings(lang, data)
|
||
e = {k: html.escape(v) for k, v in s.items()}
|
||
other = "es" if lang == "en" else "en"
|
||
levels = '<a href="https://www.levels.fyi" target="_blank" rel="noopener">Levels.fyi</a>'
|
||
steps = "".join(f"\n <li><b>{e[f'how_{k}_t']}</b> {e[f'how_{k}']}</li>"
|
||
for k in ("source", "when", "floor", "groups", "figures"))
|
||
lang_links = "".join(
|
||
f'<a class="on" aria-current="page">{code.upper()}</a>' if code == lang
|
||
else f'<a href="/{code}/" hreflang="{code}">{code.upper()}</a>'
|
||
for code in ("es", "en"))
|
||
return f"""<!doctype html>
|
||
<html lang="{lang}">
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>{e['title']}</title>
|
||
<meta name="color-scheme" content="light dark">
|
||
<meta name="theme-color" content="#f5f5f7" media="(prefers-color-scheme: light)">
|
||
<meta name="theme-color" content="#000000" media="(prefers-color-scheme: dark)">
|
||
<script>try {{ const t = localStorage.getItem("theme"); if (t) document.documentElement.dataset.theme = t; }} catch (_) {{}}</script>
|
||
<link rel="alternate" hreflang="{other}" href="/{other}/">
|
||
<link rel="alternate" type="application/json" href="/api/v1/data.json" title="Salary aggregates">
|
||
<link rel="alternate" type="text/markdown" href="/llms-full.txt" title="Salary aggregates for agents">
|
||
<script type="application/ld+json">{json_ld(lang, data)}</script>
|
||
<link rel="stylesheet" href="/style.css?v={asset_version("style.css")}">
|
||
</head>
|
||
<body data-lang="{lang}">
|
||
<nav class="topbar">
|
||
<div class="topbar-in">
|
||
<a class="brand" href="/{lang}/">{e['title']}</a>
|
||
<div class="topbar-end">
|
||
<a class="icon-btn" href="{REPO}" target="_blank" rel="noopener" title="GitHub" aria-label="GitHub">{GITHUB_ICON}</a>
|
||
<div class="seg" role="group">{lang_links}</div>
|
||
<button class="icon-btn" id="theme" type="button" title="{e['theme']}" aria-label="{e['theme']}">{THEME_ICON}</button>
|
||
</div>
|
||
</div>
|
||
</nav>
|
||
|
||
<header class="hero">
|
||
<p class="eyebrow" id="eyebrow"></p>
|
||
<div class="hero-stat">
|
||
<span class="hero-value" id="k-median"></span>
|
||
<span class="hero-label">{e['hero_label']}</span>
|
||
</div>
|
||
<dl class="stats">
|
||
<div><dt>{e['kpi_total']}</dt><dd id="k-total"></dd></div>
|
||
<div><dt>{e['kpi_share']}</dt><dd id="k-share"></dd></div>
|
||
<div><dt>{e['kpi_people']}</dt><dd id="k-people"></dd></div>
|
||
<div><dt>{e['kpi_companies']}</dt><dd id="k-companies"></dd></div>
|
||
</dl>
|
||
<p class="rule">{e['rule']}</p>
|
||
<p class="source">{e['source'].replace('Levels.fyi', levels)}</p>
|
||
<details class="how">
|
||
<summary>{e['how_title']}</summary>
|
||
<ol class="steps">{steps}
|
||
</ol>
|
||
</details>
|
||
</header>
|
||
|
||
<main class="bento">
|
||
<section class="tile wide map-tile">
|
||
<div class="tile-head">
|
||
<div><h2>{e['map_title']}</h2><p class="lede" id="map-sub"></p></div>
|
||
<div class="seg" id="map-metric" role="group" aria-label="{e['map_title']}">
|
||
<button data-m="pay">{e['map_pay']}</button><button data-m="count">{e['map_count']}</button>
|
||
</div>
|
||
</div>
|
||
<div class="map-grid">
|
||
<div class="map-box">{svg}<div class="legend" id="legend"></div></div>
|
||
<ol class="ranking" id="ranking"></ol>
|
||
</div>
|
||
</section>
|
||
|
||
<section class="tile wide" id="matrix-card">
|
||
<h2>{e['matrix_title']}</h2>
|
||
<p class="lede">{e['matrix_sub']}</p>
|
||
<div class="matrix-wrap"><table class="matrix" id="matrix"></table></div>
|
||
<div class="legend" id="matrix-legend"></div>
|
||
</section>
|
||
|
||
<section class="tile wide" id="companies-card">
|
||
<h2>{e['companies_title']}</h2>
|
||
<div class="filter-row">
|
||
<div class="filters" id="filters"></div>
|
||
<input id="search" type="search" placeholder="{e['search']}" aria-label="{e['search']}" autocomplete="off">
|
||
</div>
|
||
<div class="summary" id="summary" aria-live="polite"></div>
|
||
<div class="table-wrap"><table id="companies"></table></div>
|
||
<button class="more" id="more" hidden></button>
|
||
</section>
|
||
</main>
|
||
|
||
<footer>
|
||
<p>{e['source'].replace('Levels.fyi', levels)} · <span id="updated"></span> ·
|
||
<a href="/api/v1/data.json" target="_blank" rel="noopener">{e['data']}</a> ·
|
||
<a href="{REPO}" target="_blank" rel="noopener">{e['repo']}</a></p>
|
||
</footer>
|
||
<div id="tip" role="tooltip" hidden></div>
|
||
<aside class="star-pop" id="star" role="dialog" aria-labelledby="star-title" hidden>
|
||
<button class="star-x" id="star-close" type="button" aria-label="{e['star_close']}">×</button>
|
||
<p class="star-title" id="star-title">{e['star_title']}</p>
|
||
<p class="star-text">{e['star_text']}</p>
|
||
<a class="star-btn" id="star-go" href="{REPO}" target="_blank" rel="noopener" aria-label="{e['star_button']}" title="{e['star_button']}">{STAR_ICON}</a>
|
||
</aside>
|
||
<script>window.S={json.dumps(s, ensure_ascii=False)};window.DATA_V="{data_version}";</script>
|
||
<script src="/app.js?v={asset_version("app.js")}"></script>
|
||
</body>
|
||
</html>
|
||
"""
|
||
|
||
|
||
def main(argv: list[str]) -> int:
|
||
if OUT.exists():
|
||
shutil.rmtree(OUT)
|
||
(OUT / "api" / "v1").mkdir(parents=True)
|
||
data, tables = build_site(lib.load_companies())
|
||
dump = lambda v: json.dumps(v, ensure_ascii=False, separators=(",", ":"))
|
||
files = {"data.json": dump(data)}
|
||
files.update({f"companies/{name or 'all'}.json": dump(t) for name, t in tables.items()})
|
||
# Like asset_version, for the JSON the page fetches: a browser holding
|
||
# yesterday's tables under the same URL would run new code on old fields.
|
||
data_version = hashlib.sha256("".join(files.values()).encode()).hexdigest()[:10]
|
||
svg = spain_svg()
|
||
for lang in ("en", "es"):
|
||
(OUT / lang).mkdir()
|
||
(OUT / lang / "index.html").write_text(page(lang, svg, data_version, data), encoding="utf-8")
|
||
(OUT / "index.html").write_text(
|
||
'<!doctype html><meta charset="utf-8"><script>location.replace('
|
||
'(navigator.language || "").startsWith("es") ? "/es/" : "/en/")</script>'
|
||
'<a href="/es/">ES</a> · <a href="/en/">EN</a>', encoding="utf-8")
|
||
for name in ("app.js", "style.css"):
|
||
shutil.copy(WEB / name, OUT / name)
|
||
|
||
for name, text in files.items():
|
||
path = OUT / "api" / "v1" / name
|
||
path.parent.mkdir(parents=True, exist_ok=True)
|
||
path.write_text(text, encoding="utf-8")
|
||
(OUT / "llms.txt").write_text(llms_txt(data), encoding="utf-8")
|
||
(OUT / "llms-full.txt").write_text(llms_full(data), encoding="utf-8")
|
||
print(f"Built _site/: {len(data['companies'])} companies, {len(data['cells'])} cells "
|
||
f"of {lib.MIN_GROUP}+ people.")
|
||
return 0
|
||
|
||
|
||
# --- Agents ------------------------------------------------------------------
|
||
|
||
def json_ld(lang: str, data: dict) -> str:
|
||
# Its own wording, not STRINGS: the page copy changes without the dataset changing.
|
||
description = {
|
||
"en": "Median yearly gross salaries in euros of people working in Spain, by role, "
|
||
f"region and years of experience, each from {lib.MIN_GROUP} or more people.",
|
||
"es": "Salarios brutos anuales medianos en euros de gente que trabaja en España, por "
|
||
f"rol, comunidad y años de experiencia, cada uno de {lib.MIN_GROUP} personas o más.",
|
||
}[lang]
|
||
dataset = {
|
||
"@context": "https://schema.org", "@type": "Dataset",
|
||
"name": "Spanish Top Tech Companies", "description": description, "inLanguage": lang,
|
||
"url": SITE + "/" if SITE else REPO, "isAccessibleForFree": True,
|
||
"license": "https://creativecommons.org/licenses/by-sa/4.0/",
|
||
"dateModified": data["data_as_of"],
|
||
"spatialCoverage": {"@type": "Country", "name": "Spain"},
|
||
"variableMeasured": ["median base salary (EUR)", "median total compensation (EUR)"],
|
||
"distribution": [
|
||
{"@type": "DataDownload", "encodingFormat": "application/json",
|
||
"contentUrl": SITE + "/api/v1/data.json"},
|
||
],
|
||
}
|
||
return json.dumps(dataset, ensure_ascii=False).replace("</", "<\\/")
|
||
|
||
|
||
def _k(n: int | None) -> str:
|
||
return "-" if n is None else f"{n / 1000:.1f}k"
|
||
|
||
|
||
def _table(head: list[str], rows: list[list]) -> str:
|
||
lines = ["| " + " | ".join(head) + " |", "|" + "---|" * len(head)]
|
||
lines += ["| " + " | ".join(str(c) for c in r) + " |" for r in rows]
|
||
return "\n".join(lines)
|
||
|
||
|
||
def _stat_row(label: str, r: dict) -> list:
|
||
return [label, _k(r["median_base_eur"]),
|
||
f"{_k(r['p25_base_eur'])} - {_k(r['p75_base_eur'])}",
|
||
_k(r["median_total_eur"]), f"{round(r['share_at_60k_base'] * 100)}%", r["people"]]
|
||
|
||
|
||
STAT_HEAD = ["", "Median base", "Middle half", "Median total", "60k+ base", "People"]
|
||
|
||
|
||
def llms_txt(data: dict) -> str:
|
||
return f"""# Spanish Top Tech Companies
|
||
|
||
> What tech and other professional jobs pay in Spain: medians of yearly gross
|
||
> salaries in euros, by role, region and years of experience, from Levels.fyi
|
||
> submissions. Every figure comes from {data['min_group']} or more people. Data as of {data['data_as_of']}.
|
||
|
||
Base is gross yearly salary; total adds bonus and stock. Spain only: no
|
||
salary from another country is ever mixed in. A selection with fewer than
|
||
{data['min_group']} people has no figure; widen it rather than estimate. The
|
||
middle half (p25-p75) needs {data['quartile_min']} people, and every euro
|
||
figure is rounded to the nearest {data['round_eur']:,} EUR.
|
||
{_reported(data)}{_coverage(data)}
|
||
## Data
|
||
|
||
- [All aggregates for agents (markdown)]({SITE}/llms-full.txt): national, per role, region, experience and the best-paying companies
|
||
- [All aggregates (JSON)]({SITE}/api/v1/data.json): `cells["role|region|years"]` (empty part = all) gives n, median, p25, p75 (null under {data['quartile_min']} people), total, share at 60k+; `company_cells` the same per company, `c` indexing `companies`
|
||
|
||
## Tools
|
||
|
||
- [MCP server]({SITE}/mcp): Streamable HTTP, no sign-in; or run [mcp_server.py]({REPO}/blob/{BRANCH}/scripts/mcp_server.py) locally over stdio; protocol 2026-07-28 and the handshake versions back to 2024-11-05; tools `salary_stats`, `top_companies`, `company_salaries`, `list_filters`
|
||
- [Agent skill]({REPO}/tree/{BRANCH}/skills/tech-pay-spain): SKILL.md for Hermes and other agentskills.io agents
|
||
|
||
## Optional
|
||
|
||
- [Web page, Spanish]({SITE}/es/)
|
||
- [Web page, English]({SITE}/en/)
|
||
- [Methodology]({REPO}/blob/{BRANCH}/METHODOLOGY.md#the-website-and-the-mcp-server)
|
||
"""
|
||
|
||
|
||
def _reported(data: dict) -> str:
|
||
r = data.get("reported")
|
||
if not r:
|
||
return ""
|
||
return (f"\nSalaries were reported from {r['from']} to {r['to']}, half of them since\n"
|
||
f"{r['median']}; older ones stay in, so figures can trail today's offers. A base\n"
|
||
f"under {data['min_base']:,} EUR a year is left out as no full-time salary.\n")
|
||
|
||
|
||
def _coverage(data: dict) -> str:
|
||
floor = data.get("company_floor")
|
||
if not floor:
|
||
return ""
|
||
return (f"\nOnly companies whose median base, over all their salaries at any role and\n"
|
||
f"seniority, is {_k(floor)} or more are counted, so every figure here leaves\n"
|
||
f"out the lowest-paying employers. Say so when quoting a figure for Spain.\n")
|
||
|
||
|
||
def llms_full(data: dict) -> str:
|
||
parts = [llms_txt(data).split("\n## Data")[0].rstrip()]
|
||
|
||
overall = query.stats(data)["result"]
|
||
parts.append("## Spain, every role\n\n" + _table(STAT_HEAD, [_stat_row("All", overall)]))
|
||
|
||
rows = [_stat_row(f"{r['name']} (`{r['slug']}`)", res)
|
||
for r in data["roles"] if (res := query.stats(data, role=r["slug"])["result"])]
|
||
parts.append("## By role\n\n" + _table(STAT_HEAD, rows))
|
||
|
||
rows = [_stat_row(f"{names['es']} (`{code}`)", res) for code, names in data["regions"].items()
|
||
if (res := query.stats(data, region=code)["result"])]
|
||
rows.sort(key=lambda r: -r[-1])
|
||
parts.append("## By region\n\n" + _table(STAT_HEAD, rows))
|
||
|
||
for role in ("", "software-engineer"):
|
||
rows = [_stat_row(f"{y} years", res) for y in data["years"]
|
||
if (res := query.stats(data, role=role, years=y)["result"])]
|
||
title = "software engineers" if role else "every role"
|
||
parts.append(f"## By years of experience, {title}\n\n" + _table(STAT_HEAD, rows))
|
||
|
||
head = ["Company", "Median base", "Median total", "60k+ base", "People"]
|
||
for role, title in (("", "every role"), ("software-engineer", "software engineers")):
|
||
top = query.top_companies(data, role=role, limit=50)["result"]
|
||
rows = [[f"[{c['company']}]({c['url']})" if c["url"] else c["company"],
|
||
_k(c["median_base_eur"]), _k(c["median_total_eur"]),
|
||
f"{round(c['share_at_60k_base'] * 100)}%", c["people"]] for c in top]
|
||
parts.append(f"## Best-paying companies, {title} (top {len(rows)})\n\n"
|
||
+ _table(head, rows))
|
||
|
||
parts.append("Narrower selections (a role in a region, a company by role) are in "
|
||
f"[data.json]({SITE}/api/v1/data.json) and through the MCP server.")
|
||
return "\n\n".join(parts) + "\n"
|
||
|
||
if __name__ == "__main__":
|
||
sys.exit(main(sys.argv[1:]))
|