Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
File size: 15,845 Bytes
d15f07c | 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 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 | // API client for the policy-topic taxonomy (browse of topics + their keyword
// clusters). Backs the Browse Topics page.
import api from '../lib/api'
export interface TopicSummary {
topic_id: number
name: string
query_id: string | null
keywords: string[]
/** Transcript snippets tagged with this topic — the API sorts by this desc.
* 0 for curated topics (CivicSearch never tagged them). */
transcript_occurrences: number
/** 'civicsearch' (CivicSearch taxonomy) or 'curated' (hand-authored, e.g.
* "Data centers"). Older API builds omit it. */
source?: 'civicsearch' | 'curated' | string
/** Meetings whose transcript matched the topic, in the requested scope
* (national, state, or city when both `state` and `city` are passed).
* null/undefined = no count available. */
meeting_count?: number | null
}
/** Fetch the topic catalog. Pass a 2-letter `state` (and optional `city`) to
* restrict to topics discussed there and get matching meeting_count grain. */
export async function fetchTopics(state?: string, city?: string): Promise<TopicSummary[]> {
const params: Record<string, string> = {}
if (state) params.state = state
if (state && city) params.city = city
const res = await api.get<TopicSummary[]>('/topics', {
params: Object.keys(params).length ? params : undefined,
})
return res.data
}
/** A meeting whose transcript matched a curated topic's keywords. */
export interface TopicMeeting {
video_id: string
title: string | null
/** ISO yyyy-mm-dd or null. */
date: string | null
state_code: string | null
state: string | null
city: string | null
jurisdiction_name: string | null
video_url: string | null
/** Verbatim transcript passage with the matched words in <mark>…</mark>.
* Render with highlightSnippet (React-escaped), never as raw HTML. */
excerpt: string | null
n_keyword_hits: number
/** Who said the passage, from their self-introduction in the recording (#1231): an official's name, a resident's
* "First L.", or null (unknown, or withheld for a student, a minor or a school board resident). /states only. */
speaker_display_name?: string | null
/** The official's title, or "Resident" when they said they live here; null otherwise. */
speaker_role?: string | null
/** On `/states` `newest` (#1230) and `/meetings` (#1293): how the public leaned at this meeting in the AI reading
* (topic_meeting_lean, same thresholds as the map): 'against' | 'for' | 'split' | 'silent', or null when not read. */
public_stance?: 'against' | 'for' | 'split' | 'silent' | null
/** `/meetings` (#1293): the meeting's five-position public reading (water fluoridation), only when on the same side. */
public_position?: string | null
/** `/meetings`: what the council or board did on the topic, in the same AI reading. */
vote?: 'advanced' | 'blocked' | 'tabled_or_deferred' | null
/** `/meetings`: the card's position chip key and where it comes from; both null = no chip. 'meeting' is the meeting's
* overall public position, never the quoted speaker's. */
position?: string | null
position_source?: 'speaker' | 'meeting' | 'vote' | null
/** `/meetings`: named public commenters whose words matched the topic ("First L."), up to 3, and how many in all. */
commenters?: string[]
commenter_count?: number
/** `/meetings`: no person, no public position and no vote on record. */
in_passing?: boolean
/** `/meetings`: the meeting's page in the app, or null. */
meeting_url?: string | null
}
/** `/meetings` (#1293): the scope's meetings by what the record says about people and positions. Never speakers. */
export interface TopicSaidCounts {
against: number
for: number
split: number
silent: number
unread: number
vote_advanced: number
vote_blocked: number
vote_tabled: number
with_person: number
public_position_meetings: number
in_passing: number
}
export interface TopicMeetingList {
topic_id: number
total: number
items: TopicMeeting[]
/** First page only; null on later pages or on a serving copy without the tables. */
position_counts?: TopicSaidCounts | null
}
export async function fetchTopicMeetings(
topicId: number,
params: { state?: string; city?: string; limit?: number; offset?: number; sort?: 'newest' | 'people' } = {},
): Promise<TopicMeetingList> {
const res = await api.get<TopicMeetingList>(`/topics/${topicId}/meetings`, { params })
return res.data
}
/** A decision whose record matched the topic (#1293), with its meeting and why it is on the topic or only in passing. */
export interface TopicDecision extends DecisionPeople {
event_decision_id: string
title: string
/** Matched passage, terms in <mark> (render with highlightSnippet). */
excerpt?: string | null
outcome?: string | null
jurisdiction_name?: string | null
state_code?: string | null
state?: string | null
meeting_name?: string | null
meeting_date?: string | null
decision_url: string
meeting_url?: string | null
video_url?: string | null
video_id?: string | null
relevance: 'on_topic' | 'in_passing'
relevance_basis: string
}
/** One person on a decision's side (#1320): an official by full name and reliable role, anyone else "First L.". */
export interface DecisionPerson {
name: string
role?: string | null
kind: 'official' | 'resident'
}
/** Who was on each side of a decision, and its recorded vote (#1320). All optional: older servers omit them. */
export interface DecisionPeople {
supported_by?: DecisionPerson[]
opposed_by?: DecisionPerson[]
spoke_on_it?: DecisionPerson[]
supported_view?: string | null
/** false: no counter view on record; null: the record has no competing views. */
opposition_recorded?: boolean | null
vote_yes?: number | null
vote_no?: number | null
}
export interface TopicDecisionList {
topic_id: number
topic_slug?: string | null
total: number
on_topic_total: number
in_passing_total: number
on_topic: TopicDecision[]
in_passing: TopicDecision[]
}
/** `GET /api/topics/{id}/decisions`: decisions on the topic and ones that only mention it (#1293). */
export async function fetchTopicDecisions(
topicId: number,
params: { state?: string; city?: string; limit?: number } = {},
): Promise<TopicDecisionList> {
const res = await api.get<TopicDecisionList>(`/topics/${topicId}/decisions`, { params })
return res.data
}
export interface TopicStateCount {
state_code: string
state: string | null
meetings: number
}
export interface TopicStates {
topic_id: number
total_meetings: number
states: TopicStateCount[]
/** The newest matched meeting per state, with its verbatim passage. */
newest: TopicMeeting[]
}
/** Meetings per state for a curated topic, and each state's newest passage(s) (#1013, #1357). */
export async function fetchTopicStates(
topicId: number,
params: { state?: string; quotes_per_state?: number } = {},
): Promise<TopicStates> {
const res = await api.get<TopicStates>(`/topics/${topicId}/states`, { params })
return res.data
}
/** One state's meetings and the AI reading of them (#1127): distinct meetings, never counted speakers. */
export interface TopicStanceStateCount {
state_code: string
state: string | null
meetings: number
lean_meetings: number
public_against_meetings: number
public_for_meetings: number
/** Read as split (#1200): the public spoke but was divided, or the reading was unsure (mixed, or a lean under P 0.7). */
no_side_meetings: number
/** Read, but the public didn't speak on the topic (#1200): missing, never split. Absent on older servers. */
silent_meetings?: number
/** The public mostly opposed while officials mostly supported it. */
disagreement_meetings: number
}
export interface TopicStanceMap {
topic_id: number
/** False until the AI reading (`topic_meeting_lean`, #1126) has this topic: the map shows meetings only. */
available: boolean
by_state: TopicStanceStateCount[]
}
/** Meetings per state with the AI reading behind a topic story's four-colour box map (#1127). */
export async function fetchTopicStanceMap(topicId: number, params: { state?: string } = {}): Promise<TopicStanceMap> {
const res = await api.get<TopicStanceMap>(`/topics/${topicId}/state-map`, { params })
return res.data
}
/**
* One government's meetings on a topic in a state (#1349), in the data-center map's `by_place` shape, so StoryCountyMap
* reads it as it is. `speakers_*` are MEETINGS as the AI read them (public mostly opposed / supported / split), never
* counted speakers; 0 where the government has no reading.
*/
export interface TopicPlaceCount {
jurisdiction_id: string
jurisdiction_name: string | null
jurisdiction_type: string | null
geoid: string | null
latitude: number | null
longitude: number | null
meetings: number
lean_meetings: number
speakers_against: number
speakers_for: number
speakers_neutral: number
speakers_question: number
silent_meetings: number
public_against_meetings: number
disagreement_meetings: number
}
export interface TopicPlaces {
topic_id: number
state_code: string
/** Distinct meetings on the topic in the state (the same count as /states for it). */
total_meetings: number
/** Meetings whose government can't be drawn: total minus the sum of `by_place`. Footnoted, never spread. */
unplaced_meetings: number
/** False until `topic_place_meeting` is published: the page keeps the state outline. */
available: boolean
by_place: TopicPlaceCount[]
}
/** `GET /api/topics/{id}/places?state=` (#1349): a topic's meetings per government for the state's county map. */
export async function fetchTopicPlaces(topicId: number, state: string): Promise<TopicPlaces> {
const res = await api.get<TopicPlaces>(`/topics/${topicId}/places`, { params: { state } })
return res.data
}
/** A company's newest mention: verbatim evidence with the matched words in <mark> (render with highlightSnippet). */
export interface TopicCompanyMention {
mention_kind: string
title?: string | null
/** ISO yyyy-mm-dd or null. */
date?: string | null
jurisdiction_name?: string | null
state_code?: string | null
url?: string | null
evidence?: string | null
}
/** One company a topic names (#1052), with its real meeting and decision counts in scope. */
export interface TopicCompany {
company_key: string
company_name: string
aliases: string[]
website_url?: string | null
/** The organization page id, when the company is in MDM. */
master_org_id?: string | null
meetings: number
decisions: number
newest?: TopicCompanyMention | null
}
export interface TopicCompanies {
topic_query_id: string
scope: { level: string; state_code?: string | null; city?: string | null }
companies: TopicCompany[]
}
/** `GET /api/topics/{queryId}/companies?state=&city=`: each company's meetings and decisions in scope, busiest first. */
export async function fetchTopicCompanies(queryId: string, state?: string, city?: string | null): Promise<TopicCompanies> {
const params: Record<string, string> = {}
if (state) params.state = state
if (state && city) params.city = city
const res = await api.get<TopicCompanies>(`/topics/${encodeURIComponent(queryId)}/companies`, {
params: Object.keys(params).length ? params : undefined,
})
return res.data
}
/** One state's meetings for a topic, with its population when on record (#1125). */
export interface CaptionStateCount {
state_code: string
state: string | null
meetings: number
population: number | null
}
/** The real counts behind a topic caption for one scope (#1125). Null means not on record, never zero. */
export interface TopicCaptionFacts {
topic: string
topic_id: number
scope: { level: string; state_code: string | null; state: string | null; city: string | null }
meetings: number | null
/** Meetings per state for the whole country, largest first (never narrowed by the scope). */
states: CaptionStateCount[]
top_state: string | null
ratio_to_next: number | null
/** City scope: the place name the city matched, and meetings per place in the state. */
place: string | null
places: { name: string; meetings: number }[] | null
/** Counted speakers (data centers only); `states` is how many states in scope have any (#1134). */
speakers: { for: number; against: number; question: number; neutral: number; states?: number; meetings_reviewed?: number } | null
/**
* Recorded votes in scope (data centers only, #1289): decisions with a tally and their summed votes. Null when no meeting
* in scope was reviewed; absent on older servers.
*/
votes?: {
decisions: number
for: number
against: number
/** #1290: decisions whose vote went for / against the data center (dbt vote_side); null when not available. */
decisions_for?: number | null
decisions_against?: number | null
} | null
/** #1330: officials' position in the meeting reading (P >= 0.7 for a side), and meetings with any position. */
official_against_meetings?: number | null
official_for_meetings?: number | null
official_divided_meetings?: number | null
/** Meetings with any recorded position, public (against, for or split) or official. */
position_meetings?: number | null
/** Meetings where both the public and officials took a position. */
both_position_meetings?: number | null
/** #1290: public comments from our own captions in scope (data centers only); their side isn't classified yet. */
caption_comments?: { comments: number; governments: number } | null
/**
* #1391: public speakers in scope whose own words on the topic a classifier read with confidence (low-confidence readings
* are never served). A separate, labelled source ("speakers' own words, classifier"), never added to `speakers`.
*/
classifier_speakers?: {
source: string
for: number
against: number
concerns_only: number
no_position: number
meetings: number
} | null
/** AI readings (Jev) of meeting transcripts: never counted speakers. */
lean_meetings: number | null
public_against_meetings: number | null
/** States with at least one public-against meeting in scope (#1134); absent on older servers. */
public_against_states?: number | null
public_for_meetings: number | null
/** #1200: meetings where the public spoke but was split or the reading unsure; absent on older servers. */
public_split_meetings?: number | null
/** #1200: meetings read where the public didn't speak on the topic; absent on older servers. */
public_silent_meetings?: number | null
disagreement_meetings: number | null
disagreement_states: number | null
/**
* The broader scopes' AI readings (#1182): for a city `[state, national]`, for a state `[national]`, nationally null.
* An entry is left out when no reading is loaded for it. Absent on older servers.
*/
wider?: CaptionWiderLean[] | null
}
/** One broader scope's AI reading (Jev) for the caption's fallback (#1182). */
export interface CaptionWiderLean {
level: 'state' | 'national'
state_code: string | null
state: string | null
lean_meetings: number
public_against_meetings: number
public_against_states: number
/** #1200: absent on older servers. */
public_for_meetings?: number
public_split_meetings?: number
public_silent_meetings?: number
disagreement_meetings: number
}
/** `GET /api/topics/{topic}/caption-facts?state=&city=` (#1125). */
export async function fetchTopicCaptionFacts(topic: string, state?: string, city?: string | null): Promise<TopicCaptionFacts> {
const params: Record<string, string> = {}
if (state) params.state = state
if (state && city) params.city = city
const res = await api.get<TopicCaptionFacts>(`/topics/${encodeURIComponent(topic)}/caption-facts`, { params })
return res.data
}
|