File size: 2,229 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
// Every major meeting topic, last full year against this year (#1343, #1361): GET /api/topics/yoy?state=&city=&source=.
// Backs /browse-topics/all.
import api from '../lib/api'

export interface YoyScope {
  level: 'national' | 'state' | 'city'
  state_code: string | null
  state: string | null
  city: string | null
}

export interface YoyTopic {
  topic_id: number
  /** civicsearch_topic.query_id; live stories are /stories/<slug>. */
  slug: string
  name: string
  /** 'curated' or 'civicsearch'. */
  source: 'curated' | 'civicsearch' | string
  /** True when this topic already has a live story at /stories/<slug>. */
  has_story: boolean
  year_a: string
  year_b: string
  meetings_a: number
  meetings_b: number
  recorded_a: number
  recorded_b: number
  /** meetings / recorded (0–1); null when the scope recorded no meetings that year. */
  share_a: number | null
  share_b: number | null
  /** False when either year has too few topic meetings (< min_meetings) or recorded meetings (< min_recorded_meetings). */
  comparable: boolean
  /** #1407: public speakers in scope whose heat (1-5) a classifier rated on this topic; absent on older servers. */
  heat_rated?: number
  /** Their mean heat; null under min_heat_rated (or none rated). */
  heat_mean?: number | null
}

export interface YoyResponse {
  scope: YoyScope
  year_a: string
  year_b: string
  /** ISO date of the latest topic meeting in year_b in the scope (the partial year's label). */
  year_b_through: string | null
  year_b_partial: boolean
  recorded_a: number
  recorded_b: number
  /** A year with thin recording coverage in the scope, if any. */
  thin_year: string | null
  min_meetings: number
  min_recorded_meetings: number
  /** #1407: rated speakers a topic needs before its heat is shown. */
  min_heat_rated?: number
  topics: YoyTopic[]
}

export async function fetchTopicsYoy(
  state?: string,
  city?: string | null,
  source?: 'curated' | 'civicsearch',
): Promise<YoyResponse> {
  const params: Record<string, string> = {}
  if (state) params.state = state
  if (state && city) params.city = city
  if (source) params.source = source
  const res = await api.get<YoyResponse>('/topics/yoy', { params })
  return res.data
}