-
Notifications
You must be signed in to change notification settings - Fork 4
/
.Rhistory
512 lines (512 loc) · 14.8 KB
/
.Rhistory
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
test_that("get_ly_legislator_bills handles errors properly", {
# Test non-existent term/name combination
expect_error(
get_ly_legislator_bills(
term = 999,
name = "不存在的立委"
)
)
# Test invalid page number
expect_error(
get_ly_legislator_bills(
term = 9,
name = "王金平",
page = -1
)
)
# Test invalid limit
expect_error(
get_ly_legislator_bills(
term = 9,
name = "王金平",
limit = 0
)
)
})
# Test error handling
test_that("get_ly_legislator_bills handles errors properly", {
# Test non-existent term/name combination
expect_error(
get_ly_legislator_bills(
term = 999,
name = "不存在的立委"
)
)
# Test invalid page number
expect_error(
get_ly_legislator_bills(
term = 9,
name = "王金平",
page = -1
)
)
})
get_tly_stat()
library(legisTaiwan)
ly_info <- get_tly_stat()
library(legisTaiwan)
ly_info <- get_tly_stat()
ly_info
ly_info$meet$terms
print(ly_info$meet$terms, type = "html")
ly_info$bill$total
ly_info$bill
ly_info$bill$terms
ly_info$legislator$terms
ly_info$gazette$yearly_stats
ly_info$gazette$agenda_total
ly_info$meet$terms
ly_info$ivod$terms
ly_info$bill$terms
ly_info$meet$total
get_tly_stat()
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
committees <- get_ly_committees_type(
type = "常設委員會"
)
committee <- get_ly_committees_type(
code = 15
)
committee
committee <- get_ly_committees_type(
)
roxygen2::roxygenise()
esult <- get_ly_committee_meets(committee_id = 22)
roxygen2::roxygenise()
esult <- get_ly_committee_meets(committee_id = 22)
page2_videos <- get_ly_ivod(
term = 9,
session_period = 1,
page = 2,
limit = 20
)
roxygen2::roxygenise()
esult <- get_ly_committee_meets(committee_id = 22)
# 取得第九屆第一會期的影片
videos <- get_ly_ivod(
term = 9,
session_period = 1,
limit = 5
)
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
file.edit("~/.Rprofile")
roxygen2::roxygenise()
stats <- get_tly_stat()
# 案例一:基本統計資訊分析
library(dplyr)
library(ggplot2)
# 取得立法院統計資料
stats <- get_tly_stat()
# 1. 分析各屆期法案統計
analyze_bills <- function(stats) {
# 計算各屆期法案數量和比例
bill_stats <- stats$bill$terms %>%
mutate(
percentage = round(count / sum(count) * 100, 2),
cumulative = cumsum(count)
)
# 繪製法案數量趨勢圖
ggplot(bill_stats, aes(x = term, y = count)) +
geom_line(color = "blue") +
geom_point(color = "red") +
labs(
title = "各屆期法案數量趨勢",
x = "屆期",
y = "法案數量"
) +
theme_minimal()
# 輸出統計摘要
cat("\n=== 法案統計摘要 ===\n")
cat(sprintf("總法案數:%d\n", stats$bill$total))
cat(sprintf("最後更新時間:%s\n", format(stats$bill$max_update_time)))
cat("\n前五屆法案數量:\n")
print(head(bill_stats, 5))
}
# 2. 分析會議資訊
analyze_meetings <- function(stats) {
# 整理會議資料
meeting_stats <- stats$meet$terms %>%
mutate(
議事錄比例 = round(議事錄_count / count * 100, 2),
最後會議日期 = format(max_meeting_date, "%Y-%m-%d")
)
# 繪製會議記錄完整性分析圖
ggplot(meeting_stats, aes(x = term)) +
geom_bar(aes(y = count), stat = "identity", fill = "blue", alpha = 0.5) +
geom_bar(aes(y = 議事錄_count), stat = "identity", fill = "red", alpha = 0.5) +
labs(
title = "各屆期會議記錄完整性分析",
x = "屆期",
y = "數量"
) +
theme_minimal()
# 輸出統計摘要
cat("\n=== 會議統計摘要 ===\n")
cat(sprintf("總會議數:%d\n", stats$meet$total))
cat("\n各屆期會議記錄統計:\n")
print(head(meeting_stats, 5))
}
# 3. 分析影片資料
analyze_ivod <- function(stats) {
# 整理影片資料
ivod_stats <- stats$ivod$terms %>%
mutate(
開始日期 = format(start_date, "%Y-%m-%d"),
結束日期 = format(end_date, "%Y-%m-%d"),
期間天數 = as.numeric(difftime(end_date, start_date, units = "days")),
平均每日影片數 = round(count / 期間天數, 2)
)
# 繪製影片數量分布圖
ggplot(ivod_stats, aes(x = term, y = count)) +
geom_bar(stat = "identity", fill = "darkgreen") +
labs(
title = "各屆期影片記錄數量",
x = "屆期",
y = "影片數量"
) +
theme_minimal()
# 輸出統計摘要
cat("\n=== 影片統計摘要 ===\n")
cat(sprintf("總影片數:%d\n", stats$ivod$total))
cat(sprintf("資料期間:%s 至 %s\n",
format(stats$ivod$date_range$start, "%Y-%m-%d"),
format(stats$ivod$date_range$end, "%Y-%m-%d")))
cat("\n各屆期影片統計:\n")
print(head(ivod_stats, 5))
}
# 4. 整合分析報告
generate_report <- function(stats) {
cat("\n==========================================")
cat("\n 立法院資料統計分析報告")
cat("\n==========================================\n")
# 1. 法案統計
cat("\nI. 法案統計")
cat("\n------------------------------------------")
cat(sprintf("\n總法案數:%d", stats$bill$total))
cat(sprintf("\n最新法案更新:%s", format(stats$bill$max_update_time, "%Y-%m-%d")))
# 2. 委員統計
cat("\n\nII. 委員統計")
cat("\n------------------------------------------")
cat(sprintf("\n歷史委員總數:%d", stats$legislator$total))
cat("\n各屆期委員人數:")
print(head(stats$legislator$terms, 5))
# 3. 公報統計
cat("\nIII. 公報統計")
cat("\n------------------------------------------")
cat(sprintf("\n公報總數:%d", stats$gazette$total))
cat(sprintf("\n議程總數:%d", stats$gazette$agenda_total))
cat(sprintf("\n最後會議日期:%s", format(stats$gazette$last_meeting, "%Y-%m-%d")))
# 4. 影片統計
cat("\n\nIV. 影片統計")
cat("\n------------------------------------------")
cat(sprintf("\n影片總數:%d", stats$ivod$total))
cat(sprintf("\n影片記錄期間:%s 至 %s",
format(stats$ivod$date_range$start, "%Y-%m-%d"),
format(stats$ivod$date_range$end, "%Y-%m-%d")))
cat("\n\n==========================================\n")
}
# 使用範例:
# 1. 執行基本分析
stats <- get_tly_stat()
analyze_bills(stats)
analyze_meetings(stats)
analyze_ivod(stats)
# 2. 產生完整報告
generate_report(stats)
# 3. 特定分析:計算每屆期的法案通過率趨勢
calculate_bill_trends <- function(stats) {
bill_trends <- stats$bill$terms %>%
left_join(stats$meet$terms, by = "term") %>%
mutate(
bills_per_meeting = round(count.x / count.y, 2),
bills_per_day = round(count.x / as.numeric(difftime(max_meeting_date,
lag(max_meeting_date), units = "days")), 2)
) %>%
select(term, count.x, count.y, bills_per_meeting, bills_per_day) %>%
rename(
bills = count.x,
meetings = count.y
)
print(bill_trends)
return(bill_trends)
}
# 4. 繪製互動式視覺化(需要安裝 plotly 套件)
library(plotly)
create_interactive_plot <- function(stats) {
bill_data <- stats$bill$terms
p <- plot_ly(bill_data, x = ~term, y = ~count, type = "scatter", mode = "lines+markers",
text = ~paste("屆期:", term, "<br>法案數:", count),
hoverinfo = "text") %>%
layout(title = "各屆期法案數量趨勢",
xaxis = list(title = "屆期"),
yaxis = list(title = "法案數量"))
return(p)
}
install.packages(c("dplyr", "ggplot2", "plotly", "lubridate"))
stats <- get_tly_stat()
analyze_bills(stats)
analyze_meetings(stats)
analyze_ivod(stats)
analyze_ivod(stats)
analyze_meetings(stats)
calculate_bill_trends <- function(stats) {
bill_trends <- stats$bill$terms %>%
left_join(stats$meet$terms, by = "term") %>%
mutate(
bills_per_meeting = round(count.x / count.y, 2),
bills_per_day = round(count.x / as.numeric(difftime(max_meeting_date,
lag(max_meeting_date), units = "days")), 2)
) %>%
select(term, count.x, count.y, bills_per_meeting, bills_per_day) %>%
rename(
bills = count.x,
meetings = count.y
)
print(bill_trends)
return(bill_trends)
}
calculate_bill_trends()
calculate_bill_trends(stats)
create_interactive_plot(stats )
calculate_bill_trends(stats)
stats
# 2. Meeting information analysis
analyze_meetings <- function(stats) {
# Process meeting data
meeting_stats <- stats$meet$terms %>%
mutate(
minutes_ratio = round(議事錄_count / count * 100, 2),
last_meeting_date = format(max_meeting_date, "%Y-%m-%d")
)
# Create meeting records completeness analysis plot
ggplot(meeting_stats, aes(x = term)) +
geom_bar(aes(y = count), stat = "identity", fill = "blue", alpha = 0.5) +
geom_bar(aes(y = 議事錄_count), stat = "identity", fill = "red", alpha = 0.5) +
labs(
title = "Meeting Records Completeness by Term",
x = "Term",
y = "Count"
) +
theme_minimal()
# Output statistical summary
cat("\n=== Meeting Statistics Summary ===\n")
cat(sprintf("Total Meetings: %d\n", stats$meet$total))
cat("\nMeeting Records Statistics by Term:\n")
print(head(meeting_stats, 5))
}
# 3. Video data analysis
analyze_ivod <- function(stats) {
# Process video data
ivod_stats <- stats$ivod$terms %>%
mutate(
start_date_fmt = format(start_date, "%Y-%m-%d"),
end_date_fmt = format(end_date, "%Y-%m-%d"),
period_days = as.numeric(difftime(end_date, start_date, units = "days")),
avg_daily_videos = round(count / period_days, 2)
)
# Create video count distribution plot
ggplot(ivod_stats, aes(x = term, y = count)) +
geom_bar(stat = "identity", fill = "darkgreen") +
labs(
title = "Video Records Count by Term",
x = "Term",
y = "Number of Videos"
) +
theme_minimal()
# Output statistical summary
cat("\n=== Video Statistics Summary ===\n")
cat(sprintf("Total Videos: %d\n", stats$ivod$total))
cat(sprintf("Data Period: %s to %s\n",
format(stats$ivod$date_range$start, "%Y-%m-%d"),
format(stats$ivod$date_range$end, "%Y-%m-%d")))
cat("\nVideo Statistics by Term:\n")
print(head(ivod_stats, 5))
}
# 4. Integrated analysis report
generate_report <- function(stats) {
cat("\n==========================================")
cat("\n Legislative Yuan Data Analysis Report")
cat("\n==========================================\n")
# 1. Bill statistics
cat("\nI. Bill Statistics")
cat("\n------------------------------------------")
cat(sprintf("\nTotal Bills: %d", stats$bill$total))
cat(sprintf("\nLast Bill Update: %s", format(stats$bill$max_update_time, "%Y-%m-%d")))
# 2. Legislator statistics
cat("\n\nII. Legislator Statistics")
cat("\n------------------------------------------")
cat(sprintf("\nHistorical Total Legislators: %d", stats$legislator$total))
cat("\nLegislators by Term:")
print(head(stats$legislator$terms, 5))
# 3. Gazette statistics
cat("\nIII. Gazette Statistics")
cat("\n------------------------------------------")
cat(sprintf("\nTotal Gazettes: %d", stats$gazette$total))
cat(sprintf("\nTotal Agendas: %d", stats$gazette$agenda_total))
cat(sprintf("\nLast Meeting Date: %s", format(stats$gazette$last_meeting, "%Y-%m-%d")))
# 4. Video statistics
cat("\n\nIV. Video Statistics")
cat("\n------------------------------------------")
cat(sprintf("\nTotal Videos: %d", stats$ivod$total))
cat(sprintf("\nVideo Recording Period: %s to %s",
format(stats$ivod$date_range$start, "%Y-%m-%d"),
format(stats$ivod$date_range$end, "%Y-%m-%d")))
cat("\n\n==========================================\n")
}
# 2. Meeting information analysis
analyze_meetings <- function(stats) {
# Process meeting data
meeting_stats <- stats$meet$terms %>%
mutate(
minutes_ratio = round(議事錄_count / count * 100, 2),
last_meeting_date = format(max_meeting_date, "%Y-%m-%d")
)
# Create meeting records completeness analysis plot
ggplot(meeting_stats, aes(x = term)) +
geom_bar(aes(y = count), stat = "identity", fill = "blue", alpha = 0.5) +
geom_bar(aes(y = 議事錄_count), stat = "identity", fill = "red", alpha = 0.5) +
labs(
title = "Meeting Records Completeness by Term",
x = "Term",
y = "Count"
) +
theme_minimal()
# Output statistical summary
cat("\n=== Meeting Statistics Summary ===\n")
cat(sprintf("Total Meetings: %d\n", stats$meet$total))
cat("\nMeeting Records Statistics by Term:\n")
print(head(meeting_stats, 5))
}
analyze_meetings(stats)
# Process meeting data
meeting_stats <- stats$meet$terms %>%
mutate(
minutes_ratio = round(議事錄_count / count * 100, 2),
last_meeting_date = format(max_meeting_date, "%Y-%m-%d")
)
meeting_stats
ggplot(meeting_stats, aes(x = term)) +
geom_bar(aes(y = count), stat = "identity", fill = "blue", alpha = 0.5) +
geom_bar(aes(y = 議事錄_count), stat = "identity", fill = "red", alpha = 0.5) +
labs(
title = "Meeting Records Completeness by Term",
x = "Term",
y = "Count"
) +
theme_minimal()
ggplot(meeting_stats, aes(x = term)) +
geom_bar(aes(y = count), stat = "identity", fill = "blue", alpha = 0.5)
# Create meeting records completeness analysis plot
ggplot(meeting_stats, aes(x = term)) +
geom_bar(aes(y = count), stat = "identity", fill = "blue", alpha = 0.5) +
geom_bar(aes(y = 議事錄_count), stat = "identity", fill = "red", alpha = 0.5) +
labs(
title = "Meeting Records Completeness by Term",
x = "Term",
y = "Count"
) +
theme_minimal()
# Create meeting records completeness analysis plot
ggplot(meeting_stats, aes(x = term)) +
geom_bar(aes(y = count), stat = "identity", fill = "blue", alpha = 0.5) +
geom_bar(aes(y = `議事錄_count`), stat = "identity", fill = "red", alpha = 0.5) +
labs(
title = "Meeting Records Completeness by Term",
x = "Term",
y = "Count"
) +
theme_minimal()
# Create meeting records completeness analysis plot
x <- ggplot(meeting_stats, aes(x = term)) +
geom_bar(aes(y = count), stat = "identity", fill = "blue", alpha = 0.5) +
geom_bar(aes(y = `議事錄_count`), stat = "identity", fill = "red", alpha = 0.5) +
labs(
title = "Meeting Records Completeness by Term",
x = "Term",
y = "Count"
) +
theme_minimal()
x
# Create meeting records completeness analysis plot
ggplot(meeting_stats, aes(x = term)) +
geom_bar(aes(y = count), stat = "identity", fill = "blue", alpha = 0.5) +
geom_bar(aes(y = `議事錄_count`), stat = "identity", fill = "red", alpha = 0.5) +
labs(
title = "Meeting Records Completeness by Term",
x = "Term",
y = "Count"
) +
theme_minimal()
stats <- get_tly_stat()
stats
stats$bill$terms
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
stats <- get_tly_stat()
analyze_bills(stats)
analyze_bills
analyze_bills(stats)
analyze_meetings(stats)
analyze_ivod(stats)
create_interactive_plot(stats)
library(pkgdown)
build_site()
build_site()
build_site()
build_site()
build_site()
deploy_to_branch()
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
library(legisTaiwan)
devtools::check(args = c('--no-codoc', '--no-manual', '--no-check-ASCII'))
library(stringi)
# 读取文件内容
file_content <- readLines("R/bill.R", encoding = "UTF-8")
file_content
writeLines(file_content, "R/bill.R", useBytes = TRUE)
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
build_site()
roxygen2::roxygenise()
build_site()
deploy_to_branch()
library(pkgdown)
build_site()
build_site()
build_site()
roxygen2::roxygenize()
roxygen2::roxygenize()
build_site()
roxygen2::roxygenise()
pkgload::dev_help('.onAttach')
pkgload::dev_help('calculate_bill_trends')
pkgload::dev_help('calculate_bill_trends')
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
roxygen2::roxygenise()
build_site()
build_site()
build_site()
deploy_to_branch()