spb/datacenterindex
Public
HTML 53.9%
TypeScript 44.5%
JavaScript 0.6%
SQL 0.5%
1/**2 * /ai-infrastructure — AI / HPC index. Counts use ai_evidence confirmed | likely (or the legacy is_ai flag);3 * "associated" facilities are reported separately and never counted as AI infrastructure.4 */5import type { AiIndex } from "@dci/core";6import { pg, facilityJoins, facilitySummaryCols, facilityView, knownMwAgg, pipelineMwAgg, countedAgg, hasMwAgg, mwExpr, projectJoins, projectSummaryCols, projectLive, CONSTRUCTION_SET, type Sql } from "../lib/sql.js";7import { int, num, reqStr, type Row } from "../lib/rows.js";8import { asStatus, facilitySummary, projectSummary, round2, share } from "../lib/dto.js";9import { eventsWhere } from "./events.js";1011export const AI_EVIDENCE_NOTE = "AI evidence levels: confirmed = a source explicitly describes the site as AI / HPC / GPU / accelerated-computing infrastructure; likely = AI-ready, high-density, liquid- or direct-to-chip cooling or GPU signals in the source; associated = only an AI tenant, customer or company mention (reported separately, NOT counted as AI infrastructure); unknown = no signal. A single keyword never confirms a site. Counts and MW cover confirmed + likely only; MW figures are published site-scoped figures (containment-aware), never extrapolated.";1213const AI_F = (sql: Sql) => sql`(f.ai_evidence in ('confirmed', 'likely') or f.is_ai or f.facility_type = 'ai')`;14const AI_P = (sql: Sql) => sql`(p.ai_evidence in ('confirmed', 'likely') or p.is_ai)`;1516export async function aiIndex(): Promise<AiIndex> {17 const sql = pg();18 const known = knownMwAgg(sql), pipe = pipelineMwAgg(sql), counted = countedAgg(sql), hasMw = hasMwAgg(sql);19 const [fs, ps, topOps, topMetros, topCountries, stages, recentProjects, facilities, recentAnnouncements] = await Promise.all([20 sql<Row[]>`select count(*) filter (where ${counted} and ${AI_F(sql)})::int as facilities,21 count(*) filter (where ${counted} and f.ai_evidence = 'confirmed')::int as confirmed,22 count(*) filter (where ${counted} and f.ai_evidence = 'likely')::int as likely,23 count(*) filter (where ${counted} and f.ai_evidence = 'associated')::int as associated,24 sum(${pipe}) filter (where ${AI_F(sql)} and f.status = any(${CONSTRUCTION_SET}))::float as construction_mw,25 sum(${known}) filter (where ${AI_F(sql)} and f.status in ('operational', 'partially_operational', 'expansion'))::float as known_mw,26 count(*) filter (where ${counted} and ${AI_F(sql)} and ${hasMw})::int as with_mw,27 count(distinct f.country_iso2) filter (where ${AI_F(sql)})::int as f_countries,28 count(distinct f.operator_id) filter (where ${AI_F(sql)})::int as f_operators29 from ${facilityView(sql)} f`,30 sql<Row[]>`select count(*)::int as projects, sum(p.planned_mw)::float as planned_mw, count(distinct p.country_iso2)::int as countries, count(distinct p.operator_id)::int as operators from projects p where ${projectLive(sql)} and ${AI_P(sql)}`,31 sql<Row[]>`select * from (select o.id, o.slug, o.name,32 (select count(*) from ${facilityView(sql)} f where f.operator_id = o.id and ${counted} and ${AI_F(sql)})::int as facilities,33 (select count(*) from projects p where p.operator_id = o.id and ${projectLive(sql)} and ${AI_P(sql)})::int as projects,34 (select sum(p.planned_mw) from projects p where p.operator_id = o.id and ${projectLive(sql)} and ${AI_P(sql)})::float as planned_mw35 from operators o where exists (select 1 from facilities f where f.operator_id = o.id and f.merged_into is null and ${AI_F(sql)}) or exists (select 1 from projects p where p.operator_id = o.id and ${projectLive(sql)} and ${AI_P(sql)})) t order by t.facilities + t.projects desc, t.planned_mw desc nulls last, t.name limit 10`,36 sql<Row[]>`select * from (select m.id, m.slug, m.name, m.country_iso2,37 (select count(*) from ${facilityView(sql)} f where f.metro_id = m.id and ${counted} and ${AI_F(sql)})::int as facilities,38 (select count(*) from projects p where p.metro_id = m.id and ${projectLive(sql)} and ${AI_P(sql)})::int as projects,39 (select sum(p.planned_mw) from projects p where p.metro_id = m.id and ${projectLive(sql)} and ${AI_P(sql)})::float as planned_mw40 from metros m where exists (select 1 from facilities f where f.metro_id = m.id and f.merged_into is null and ${AI_F(sql)}) or exists (select 1 from projects p where p.metro_id = m.id and ${projectLive(sql)} and ${AI_P(sql)})) t order by t.facilities + t.projects desc, t.planned_mw desc nulls last, t.name limit 10`,41 sql<Row[]>`select * from (select c.iso2, c.slug, c.name,42 (select count(*) from ${facilityView(sql)} f where f.country_iso2 = c.iso2 and ${counted} and ${AI_F(sql)})::int as facilities,43 (select count(*) from projects p where p.country_iso2 = c.iso2 and ${projectLive(sql)} and ${AI_P(sql)})::int as projects,44 (select sum(p.planned_mw) from projects p where p.country_iso2 = c.iso2 and ${projectLive(sql)} and ${AI_P(sql)})::float as planned_mw45 from countries c where exists (select 1 from facilities f where f.country_iso2 = c.iso2 and f.merged_into is null and ${AI_F(sql)}) or exists (select 1 from projects p where p.country_iso2 = c.iso2 and ${projectLive(sql)} and ${AI_P(sql)})) t order by t.facilities + t.projects desc, t.planned_mw desc nulls last, t.name limit 10`,46 sql<Row[]>`select p.status, count(*)::int as n, sum(p.planned_mw)::float as mw from projects p where ${projectLive(sql)} and ${AI_P(sql)} group by 1 order by n desc`,47 sql<Row[]>`select ${projectSummaryCols(sql)} from projects p ${projectJoins(sql)} where ${projectLive(sql)} and ${AI_P(sql)} order by p.last_update desc limit 10`,48 sql<Row[]>`select ${facilitySummaryCols(sql)} from facilities f ${facilityJoins(sql)} where f.merged_into is null and ${AI_F(sql)} order by ${mwExpr(sql)} desc nulls last, f.completeness desc limit 30`,49 eventsWhere(sql`e.is_ai = true`, 15),50 ]);51 const f = fs[0] ?? {};52 const p = ps[0] ?? {};53 const facilitiesN = int(f.facilities);54 return {55 stats: {56 facilities: facilitiesN,57 confirmed: int(f.confirmed),58 likely: int(f.likely),59 associated: int(f.associated),60 projects: int(p.projects),61 plannedMw: round2(num(p.planned_mw)),62 constructionMw: round2(num(f.construction_mw)),63 countries: Math.max(int(f.f_countries), int(p.countries)),64 operators: Math.max(int(f.f_operators), int(p.operators)),65 mwCoverage: share(int(f.with_mw), facilitiesN),66 },67 topOperators: topOps.map((r) => ({ id: reqStr(r.id), slug: reqStr(r.slug), name: reqStr(r.name), facilities: int(r.facilities), projects: int(r.projects), plannedMw: round2(num(r.planned_mw)) })),68 topMetros: topMetros.map((r) => ({ id: reqStr(r.id), slug: reqStr(r.slug), name: reqStr(r.name), countryIso2: reqStr(r.country_iso2), facilities: int(r.facilities), projects: int(r.projects), plannedMw: round2(num(r.planned_mw)) })),69 topCountries: topCountries.map((r) => ({ iso2: reqStr(r.iso2), slug: reqStr(r.slug), name: reqStr(r.name), facilities: int(r.facilities), projects: int(r.projects), plannedMw: round2(num(r.planned_mw)) })),70 pipelineByStage: stages.map((r) => ({ status: asStatus(r.status), count: int(r.n), mw: round2(num(r.mw)) })),71 recentAnnouncements,72 recentProjects: recentProjects.map(projectSummary),73 facilities: facilities.map(facilitySummary),74 evidenceNote: AI_EVIDENCE_NOTE,75 };76}77