Advertisement
Guest User

Untitled

a guest
Jan 15th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. library(RPostgreSQL)
  2. # library(DT)
  3. # library(plotly)
  4. # library(rjson)
  5. # library(pool)
  6. # library(DBI)
  7.  
  8.  
  9.  
  10. library(config)
  11. library(dplyr)
  12.  
  13.  
  14.  
  15. profile = 'polon_dev'
  16. conf = config::get("dataconnection", config = Sys.getenv("R_CONFIG_ACTIVE", profile))
  17.  
  18. psql <- dbDriver("PostgreSQL")
  19. pcon <- dbConnect(psql, dbname = conf$dbname, host = conf$host, port = conf$port, user = conf$user, password = conf$password, DBMSencoding="utf-8")
  20.  
  21. dbListTables(pcon)
  22.  
  23.  
  24. # Construct the fetching query
  25. query <- sprintf("SELECT * FROM polon_dev.studies")
  26. dbGetQuery(pcon, query)
  27. # Submit the fetch query and disconnect
  28. dbDisconnect(pcon)
  29.  
  30. pcon <- src_postgres(dbname = conf$dbname, host = conf$host, port = conf$port, user = conf$user, password = conf$password)
  31. pcon <- src_postgres(dbname = 'jsa', host = '10.20.25.23', port = 5432, user = 'postgres', password = 'postgres')
  32.  
  33. query_get_integration_thesis <-
  34. "
  35. SELECT i.name, count(1)
  36. FROM %s.thesis_meta AS m
  37. INNER JOIN %s.institution AS i
  38. ON m.institution_owner_uuid = i.uuid
  39. where owner_id IS NULL and owner_uid IS NULL AND creation_date >= %s
  40. GROUP BY i.name
  41. ORDER BY count DESC
  42. "
  43.  
  44. query_get_ui_thesis <-
  45. "
  46. SELECT i.name, count(1)
  47. FROM %s.thesis_meta AS m
  48. INNER JOIN %s.institution AS i
  49. ON m.institution_owner_uuid = i.uuid
  50. WHERE owner_id IS NOT NULL AND creation_date >= %s
  51. GROUP BY i.name
  52. ORDER BY count DESC;
  53. "
  54.  
  55.  
  56. filled_query_get_integration_thesis <- sprintf(query_get_integration_thesis, profile, profile, "'2019-01-01'")
  57. data_integration_thesis <- tbl(pcon, sql(filled_query_get_integration_thesis), encoding = 'UTF-8')
  58. data_integration_thesis
  59.  
  60. filled_query_get_ui_thesis <- sprintf(query_get_ui_thesis, profile, profile, "'2019-01-01'")
  61. data_ui_thesis <- dbGetQuery(pcon, filled_query_get_ui_thesis)
  62. data_ui_thesis
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement