You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.3KB

  1. library(tidyverse)
  2. library(shiny)
  3. library(DT)
  4. library(RSQLite)
  5. library(stringr)
  6. library(plotly)
  7. library(forcats)
  8. library(markdown)
  9. uniq <- function(df, ..., first = F)
  10. {
  11. uniq_vector <- function(x, fst)
  12. {
  13. x %>%
  14. c %>%
  15. rle %>%
  16. .$lengths ->
  17. l
  18. if (fst)
  19. {
  20. l %>%
  21. cumsum %>%
  22. `-`(l) + 1
  23. } else
  24. {
  25. l %>% cumsum
  26. }
  27. }
  28. eval(substitute(alist(...))) %>%
  29. map_chr(as.character) %>%
  30. intersect(names(df)) %>%
  31. map(~uniq_vector(df[[.x]], first)) %>%
  32. reduce(union) %>%
  33. sort -> columns
  34. df[columns,]
  35. }
  36. Sys.setlocale("LC_TIME", "fr_FR.UTF-8")
  37. dbConnect(SQLite(), "ecn.db") -> db
  38. # Index villes et spés ----
  39. db %>%
  40. tbl("trajectoires") %>%
  41. select(Discipline, Subdivision) %>%
  42. distinct %>%
  43. collect -> villespe
  44. villespe %>%
  45. select(Subdivision) %>%
  46. distinct %>%
  47. filter(Subdivision != "") %>%
  48. arrange(Subdivision) %>%
  49. pull(Subdivision) -> villes
  50. villespe %>%
  51. select(Discipline) %>%
  52. distinct %>%
  53. filter(!Discipline %>% str_detect("(car aucun vœu)|(malgré.*)|(pas de.*)")) %>%
  54. arrange(Discipline) %>%
  55. pull(Discipline) -> spes
  56. # Max rank ----
  57. db %>%
  58. tbl("trajectoires") %>%
  59. select(Etudiant) %>%
  60. distinct %>%
  61. collect %>%
  62. pull(Etudiant) %>%
  63. max ->
  64. max_rank
  65. db %>% dbDisconnect