time-summary.R 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #!/usr/bin/env Rscript
  2. library(tidyverse)
  3. complete <- read_csv2("../app/data/completo.csv", na = "NA",
  4. col_types = cols(
  5. pais = col_character(),
  6. regiao = col_character(),
  7. uf = col_character(),
  8. mesorregiao = col_character(),
  9. microrregiao = col_character(),
  10. municipio = col_character(),
  11. st_acidente_feriado = col_character(),
  12. ds_agente_causador = col_character(),
  13. ano_cat = col_integer(),
  14. ds_cnae_classe_cat = col_character(),
  15. dt_acidente = col_date(),
  16. st_dia_semana_acidente = col_character(),
  17. ds_emitente_cat = col_character(),
  18. hora_acidente = col_time(),
  19. idade_cat = col_integer(),
  20. cd_indica_obito = col_character(),
  21. ds_natureza_lesao = col_character(),
  22. ds_cbo = col_character(),
  23. ds_parte_corpo_atingida = col_character(),
  24. cd_tipo_sexo_empregado_cat = col_character(),
  25. ds_tipo_acidente = col_character(),
  26. ds_tipo_local_acidente = col_character()
  27. ))
  28. estimativa_pop <- read_csv2("../app/data/estimativas.csv", na = "NA",
  29. col_types = cols(
  30. uf = col_character(),
  31. municipio = col_character(),
  32. populacao = col_integer(),
  33. ano = col_integer()
  34. ))
  35. estimativa_pop <- rename(estimativa_pop, ano_cat = ano)
  36. #Summarization of the number of accidents occurred by year 2012-2016
  37. ac_mun_2012 <- complete %>%
  38. group_by(uf, municipio, ano_cat) %>%
  39. filter(ano_cat == 2012) %>%
  40. summarize(acidentes = n())
  41. ac_mun_2013 <- complete %>%
  42. group_by(uf, municipio, ano_cat) %>%
  43. filter(ano_cat == 2013) %>%
  44. summarize(acidentes = n())
  45. ac_mun_2014 <- complete %>%
  46. group_by(uf, municipio, ano_cat) %>%
  47. filter(ano_cat == 2014) %>%
  48. summarize(acidentes = n())
  49. ac_mun_2015 <- complete %>%
  50. group_by(uf, municipio, ano_cat) %>%
  51. filter(ano_cat == 2015) %>%
  52. summarize(acidentes = n())
  53. ac_mun_2016 <- complete %>%
  54. group_by(uf, municipio, ano_cat) %>%
  55. filter(ano_cat == 2016) %>%
  56. summarize(acidentes = n())
  57. ac_mun <- rbind(ac_mun_2012, ac_mun_2013, ac_mun_2014, ac_mun_2015, ac_mun_2016)
  58. est_mun <- estimativa_pop %>% filter(ano_cat < 2017)
  59. write_delim(ac_mun_2012, "../app/data/ac_mun_2012.csv", delim = ";")
  60. write_delim(ac_mun_2013, "../app/data/ac_mun_2013.csv", delim = ";")
  61. write_delim(ac_mun_2014, "../app/data/ac_mun_2014.csv", delim = ";")
  62. write_delim(ac_mun_2015, "../app/data/ac_mun_2015.csv", delim = ";")
  63. write_delim(ac_mun_2016, "../app/data/ac_mun_2016.csv", delim = ";")