Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 14,984 Bytes
a8fb296 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 | // API client for the data-center "Jobs promised" panel (issue #246, DC-1.1).
// Backs GET /api/data-centers/job-claims, which returns verbatim jobs claims
// made in public meetings, split by phase. No fabricated rows — an empty
// `items` array means no claims were found for the scope.
//
import type { components } from '../lib/api.types'
import api from '../lib/api'
import { withSpan } from '../instrumentation'
// Generated from the FastAPI schema (`npm run gen:api`), so the page and the API
// can't drift apart.
type Schemas = components['schemas']
// --- who spoke for and against, and the recorded votes (#930) ------------------------------------------------------
// Written by hand to match `DataCenterPositionsResponse` in api/routes/data_centers.py; `npm run gen:api` adds the same
// shapes to api.types.ts.
export interface PositionTotals {
/** Meetings the counts come from. */
meetings: number | null
/** Analysed meetings in scope where a data center came up. */
meetings_reviewed: number | null
speakers_for: number | null
speakers_against: number | null
speakers_question: number | null
speakers_neutral: number | null
decisions_with_tally: number | null
/** Null (never 0) when no decision recorded a tally. */
votes_for: number | null
votes_against: number | null
}
export interface PositionQuote {
public_comment_id: string
/** The speaker's own words, verbatim from the transcript. */
quote: string
speaker_role?: string | null
/** "Audra T." (#1036): first name + last initial, or the first name only; null when no name was heard. */
speaker_display_name?: string | null
jurisdiction_name?: string | null
state_code?: string | null
meeting_date?: string | null
video_url?: string | null
start_seconds?: number | null
jump_url?: string | null
/** The item the comment is on (a contested decision or an uncontested item); null for general public comment. */
decision_headline?: string | null
/** Why the comment counts (#932): its decision or uncontested item names a data center, its own words do, or another speaker on the same item does. */
match_basis?: 'data_center_decision' | 'data_center_item' | 'own_words' | 'same_item' | null
}
/** One state's speaker sums for the home box map (#1087); national, never narrowed by the scope. Generated type. */
export type PositionStateCount = Schemas['PositionStateCount']
export interface DataCenterPositionsResponse {
scope: Schemas['JobClaimScope']
/** False when the table is not in the database yet: every total is null, not zero. */
available: boolean
totals: PositionTotals
quotes: { for: PositionQuote[]; against: PositionQuote[]; question: PositionQuote[] }
/** Speakers per state across the country (#1087); empty when the table isn't loaded. Optional for older servers. */
by_state?: PositionStateCount[]
/** National totals of Jev's meeting readings for the home hero (#1122); null when the lean table isn't loaded. */
lean_totals?: Schemas['LeanTotals'] | null
/** The same AI-reading totals narrowed to the scope (#1134); equal to lean_totals nationally. */
scope_lean_totals?: Schemas['LeanTotals'] | null
}
/** Public speakers for and against a data center item, questions asked and recorded votes, for the scope (#930). */
export async function fetchDataCenterPositions(params: {
state?: string
city?: string
limit?: number
/** Up to this many quotes per state and side instead of `limit` per side (the home map, named speakers first). */
perState?: number
}): Promise<DataCenterPositionsResponse> {
const q: Record<string, string> = {}
if (params.limit) q.limit = String(params.limit)
if (params.perState) q.per_state = String(params.perState)
if (params.state) q.state = params.state
if (params.city) q.city = params.city
const scopeLevel = params.city ? 'city' : params.state ? 'state' : 'national'
return withSpan(
'data-centers.positions.load',
async (span) => {
const res = await api.get<DataCenterPositionsResponse>('/data-centers/positions', { params: q })
span.setAttribute('data_centers.positions.available', res.data?.available === true)
return res.data
},
{ 'data_centers.scope_level': scopeLevel },
)
}
/** One decision a local meeting took on a data center item, debated or taken up without debate (#933). */
export interface DataCenterDecision {
data_center_decision_id: string
/** True: debated. False: taken up without debate (consent agenda). */
contested: boolean
headline?: string | null
outcome?: string | null
/** Recorded yes / no votes; null unless a debated decision's tally records both sides. */
votes_for?: number | null
votes_against?: number | null
/** How an item taken up without debate, as said ("voice vote", "5-0"); never parsed into numbers. */
vote_text?: string | null
meeting_date?: string | null
jurisdiction_name?: string | null
state_code?: string | null
video_url?: string | null
/** Site path of the decision's page; debated decisions only. */
decision_url?: string | null
}
export interface DataCenterDecisionsResponse {
scope: Schemas['JobClaimScope']
/** False when the table is not in the database yet: every count is null, not zero. */
available: boolean
counts: { contested?: number | null; uncontested?: number | null; meetings?: number | null }
items: DataCenterDecision[]
}
/** A data center hearing whose official government page states the date together with the data center item (#955). */
export interface DataCenterHearing {
data_center_hearing_id: string
jurisdiction_id?: string | null
jurisdiction_name?: string | null
state_code?: string | null
state?: string | null
body_name?: string | null
topic?: string | null
meeting_date: string
/** The official page that states the hearing. */
source_url: string
source_name?: string | null
/** Verbatim excerpt of the official page; matched words in <mark>. */
evidence?: string | null
/** The page calls the date tentative, expected, not final or to be determined. */
tentative?: boolean
checked_at?: string | null
is_upcoming: boolean
}
export interface DataCenterHearingsResponse {
scope: Schemas['JobClaimScope']
/** False when the table is not loaded: counts are null, not zero. */
available: boolean
counts: { upcoming?: number | null; past?: number | null }
items: DataCenterHearing[]
}
/** Verified upcoming data center hearings for the scope, soonest first (#955). */
export async function fetchDataCenterHearings(params: {
state?: string
city?: string
when?: 'upcoming' | 'past' | 'all'
}): Promise<DataCenterHearingsResponse> {
const q: Record<string, string> = { when: params.when ?? 'upcoming' }
if (params.state) q.state = params.state
if (params.city) q.city = params.city
const scopeLevel = params.city ? 'city' : params.state ? 'state' : 'national'
return withSpan(
'data-centers.hearings.load',
async (span) => {
const res = await api.get<DataCenterHearingsResponse>('/data-centers/hearings', { params: q })
span.setAttribute('data_centers.hearings.count', res.data?.items?.length ?? 0)
return res.data
},
{ 'data_centers.scope_level': scopeLevel },
)
}
/** Decisions on data center items for the scope, newest first, with whole-scope counts (#933). */
export async function fetchDataCenterDecisions(params: {
state?: string
city?: string
limit?: number
}): Promise<DataCenterDecisionsResponse> {
const q: Record<string, string> = {}
if (params.limit) q.limit = String(params.limit)
if (params.state) q.state = params.state
if (params.city) q.city = params.city
const scopeLevel = params.city ? 'city' : params.state ? 'state' : 'national'
return withSpan(
'data-centers.decisions.load',
async (span) => {
const res = await api.get<DataCenterDecisionsResponse>('/data-centers/decisions', { params: q })
span.setAttribute('data_centers.decisions.count', res.data?.items?.length ?? 0)
return res.data
},
{ 'data_centers.scope_level': scopeLevel },
)
}
export type JobClaim = Schemas['JobClaim']
export type JobClaimPhase = JobClaim['phase']
export type JobClaimsScope = Schemas['JobClaimScope']
export type JobClaimsResponse = Schemas['JobClaimsResponse']
export type DataCenterSite = Schemas['DataCenterSite']
export type DataCenterSiteStatus = NonNullable<DataCenterSite['status']>
export type DataCenterSitesResponse = Schemas['DataCenterSitesResponse']
export type DataCenterAgendaItem = Schemas['DataCenterAgendaItem']
export type DataCenterAgendaItemsResponse = Schemas['DataCenterAgendaItemsResponse']
export type DataCenterMeetingMention = Schemas['DataCenterMeetingMention']
export type DataCenterMeetingMentionsResponse = Schemas['DataCenterMeetingMentionsResponse']
export type AreaConcern = Schemas['AreaConcern']
export type AreaConcernsResponse = Schemas['AreaConcernsResponse']
export type CommunityEvent = Schemas['CommunityEvent']
export type CommunityEventsResponse = Schemas['CommunityEventsResponse']
export type DataCenterProject = Schemas['DataCenterProject']
export type DataCenterProjectsResponse = Schemas['DataCenterProjectsResponse']
export async function fetchJobClaims(params: {
state?: string
city?: string
limit?: number
}): Promise<JobClaimsResponse> {
const q: Record<string, string> = {}
if (params.limit) q.limit = String(params.limit)
if (params.state) q.state = params.state
if (params.city) q.city = params.city
const scopeLevel = params.city ? 'city' : params.state ? 'state' : 'national'
// Low-cardinality attributes only (scope level, not the place name).
return withSpan(
'data-centers.job-claims.load',
async (span) => {
const res = await api.get<JobClaimsResponse>('/data-centers/job-claims', { params: q })
span.setAttribute('data_centers.job_claims.count', res.data?.items?.length ?? 0)
return res.data
},
{ 'data_centers.scope_level': scopeLevel },
)
}
/** Data center sites (DC-4.1, #249): Epoch AI, CC BY 4.0. Narrows by state only. */
export async function fetchDataCenterSites(params: { state?: string; limit?: number }): Promise<DataCenterSitesResponse> {
const q: Record<string, string> = {}
if (params.state) q.state = params.state
if (params.limit) q.limit = String(params.limit)
return withSpan(
'data-centers.sites.load',
async (span) => {
const res = await api.get<DataCenterSitesResponse>('/data-centers/sites', { params: q })
span.setAttribute('data_centers.sites.count', res.data?.items?.length ?? 0)
return res.data
},
{ 'data_centers.scope_level': params.state ? 'state' : 'national' },
)
}
/** Agendas that mention a data center (DC-4.2, #250), upcoming meetings first. */
export async function fetchDataCenterAgendaItems(params: {
state?: string
city?: string
limit?: number
}): Promise<DataCenterAgendaItemsResponse> {
const q: Record<string, string> = {}
if (params.limit) q.limit = String(params.limit)
if (params.state) q.state = params.state
if (params.city) q.city = params.city
const scopeLevel = params.city ? 'city' : params.state ? 'state' : 'national'
return withSpan(
'data-centers.agenda-items.load',
async (span) => {
const res = await api.get<DataCenterAgendaItemsResponse>('/data-centers/agenda-items', { params: q })
span.setAttribute('data_centers.agenda_items.count', res.data?.items?.length ?? 0)
return res.data
},
{ 'data_centers.scope_level': scopeLevel },
)
}
/** What residents object to in their meetings (DC-4.3, #251), for the area and nationally. */
export async function fetchAreaConcerns(params: { state?: string; city?: string }): Promise<AreaConcernsResponse> {
const q: Record<string, string> = {}
if (params.state) q.state = params.state
if (params.city) q.city = params.city
const res = await api.get<AreaConcernsResponse>('/data-centers/concerns', { params: q })
return res.data
}
/** Meeting passages where a data center was discussed (#445), quoted from the transcript. */
export async function fetchDataCenterMeetingMentions(params: {
state?: string
city?: string
limit?: number
/** For the story map cards (#1230): up to this many passages per state, real meetings only, meetings where the
* public mostly opposed first, newest first (instead of the newest `limit`). Counts are unchanged. */
quotesPerState?: number
}): Promise<DataCenterMeetingMentionsResponse> {
const q: Record<string, string> = {}
if (params.limit) q.limit = String(params.limit)
if (params.quotesPerState) q.quotes_per_state = String(params.quotesPerState)
if (params.state) q.state = params.state
if (params.city) q.city = params.city
const scopeLevel = params.city ? 'city' : params.state ? 'state' : 'national'
return withSpan(
'data-centers.meeting-mentions.load',
async (span) => {
const res = await api.get<DataCenterMeetingMentionsResponse>('/data-centers/meeting-mentions', { params: q })
span.setAttribute('data_centers.meeting_mentions.count', res.data?.items?.length ?? 0)
return res.data
},
{ 'data_centers.scope_level': scopeLevel },
)
}
/** Company-hosted data center meetings found in news and press releases (#532). */
export async function fetchCommunityEvents(params: {
state?: string
city?: string
projectId?: string
limit?: number
}): Promise<CommunityEventsResponse> {
const q: Record<string, string> = {}
if (params.limit) q.limit = String(params.limit)
if (params.state) q.state = params.state
if (params.city) q.city = params.city
if (params.projectId) q.project_id = params.projectId
const scopeLevel = params.city ? 'city' : params.state ? 'state' : 'national'
return withSpan(
'data-centers.community-events.load',
async (span) => {
const res = await api.get<CommunityEventsResponse>('/data-centers/community-events', { params: q })
span.setAttribute('data_centers.community_events.count', res.data?.items?.length ?? 0)
return res.data
},
{ 'data_centers.scope_level': scopeLevel },
)
}
/** Data center projects with companies, sourced figures and a timeline (#531/#532). */
export async function fetchDataCenterProjects(params: {
state?: string
city?: string
source?: 'curated' | 'epoch'
}): Promise<DataCenterProjectsResponse> {
const q: Record<string, string> = {}
if (params.state) q.state = params.state
if (params.city) q.city = params.city
if (params.source) q.source = params.source
const scopeLevel = params.city ? 'city' : params.state ? 'state' : 'national'
return withSpan(
'data-centers.projects.load',
async (span) => {
const res = await api.get<DataCenterProjectsResponse>('/data-centers/projects', { params: q })
span.setAttribute('data_centers.projects.count', res.data?.items?.length ?? 0)
return res.data
},
{ 'data_centers.scope_level': scopeLevel },
)
}
|