Advertisement
Guest User

Untitled

a guest
Apr 8th, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. con <- dbConnect(MySQL(), user="trollbox", password="trollbox", dbname="trollbox-v1", host="localhost")
  2. #on.exit(dbDisconnect(con))
  3. rs <- dbSendQuery(con, "select DATE_FORMAT(
  4. MIN(created),
  5. '%H:%i:00'
  6. ) AS timestamp, sum(message.up) AS up, sum(message.down) AS down from message
  7. join message_has_currency on message.id = message_has_currency.message_id join currency on message_has_currency.currency_id = currency.id
  8. where currency.id = 1 and message.created > '2016-04-07 12:00:00'
  9. GROUP BY ROUND(UNIX_TIMESTAMP(created) / 900)")
  10. data <- fetch(rs)
  11.  
  12. rs2 <- dbSendQuery(con, "select DATE_FORMAT(
  13. MIN(created),
  14. '%H:%i:00'
  15. ) AS timestamp, sum(currency.id=1) as ethereum, sum(currency.id=2) as bitcoin from message join message_has_currency on message.id = message_has_currency.message_id join currency on message_has_currency.currency_id = currency.id
  16. where message.created > '2016-04-07 12:00:00' GROUP BY ROUND(UNIX_TIMESTAMP(created) / 900)")
  17. data2 <- fetch(rs2)
  18.  
  19. huh <- dbHasCompleted(rs)
  20. huh2 <- dbHasCompleted(rs2)
  21.  
  22.  
  23. # currency plot
  24. ggplot(data2, aes(timestamp, y = count, color = currency)) + geom_line(aes(y = ethereum, col = "ethereum", group = 1)) + geom_line(aes(y = bitcoin, col = "bitcoin", group = 1))
  25.  
  26.  
  27. # trend plot
  28. ggplot(data, aes(timestamp, y = count, color = trend_category)) + geom_line(aes(y = up, col = "UP", group = 1)) + geom_line(aes(y = down, col = "DOWN", group = 1))
  29.  
  30. #dbClearResult(rs)
  31. #dbDisconnect(con)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement