Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package cl.uchile.tarea3;
  7.  
  8. import com.datastax.driver.core.Cluster;
  9. import com.datastax.driver.core.LocalDate;
  10. import com.datastax.driver.core.ResultSet;
  11. import com.datastax.driver.core.Row;
  12. import com.datastax.driver.core.Session;
  13. import java.util.Date;
  14. import java.util.UUID;
  15. import java.util.*;
  16. import java.lang.*;
  17. import java.io.*;
  18. class Pair<A,B> {
  19. public A first;
  20. public B second;
  21. public Pair(A first, B second) {
  22. this.first = first;
  23. this.second = second;
  24. }
  25. }
  26. /**
  27. *
  28. * @author FelipeEsteban
  29. */
  30. public class Cassandra {
  31.  
  32. /**
  33. * @param args the command line arguments
  34. */
  35. public static void main(String[] args) {
  36.  
  37. Cluster cluster;
  38. Session session;
  39.  
  40. cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
  41. session = cluster.connect("mari");
  42.  
  43. // double probabilidad;
  44. // LocalDate date;
  45. // ResultSet results1 = session.execute("SELECT * FROM probabilidad");
  46. // for (Row row : results1) {
  47. // probabilidad = (double)row.getLong("entrega_rut") / (double)row.getLong("total_rut");
  48. // date = row.getDate("date");
  49. // System.out.println("Date: " + date + "Probabilidad: " + probabilidad);
  50. // }
  51.  
  52.  
  53. //Top 10 productos ordenados!!
  54.  
  55. ResultSet results2 = session.execute("SELECT * FROM Top10");
  56. ArrayList<Pair<Integer,String>> top = new ArrayList<>();
  57. for(Row row: results2){
  58. //transformo count en int para que no colapse
  59. int sumador = (int) row.getLong("count");
  60. top.add(new Pair<Integer, String>(sumador, row.getString("name")));
  61. //top.add(new Pair<Integer,String>(33, "MiProducto"));
  62.  
  63.  
  64.  
  65. Collections.sort(top, new Comparator<Pair<Integer,String>>() {
  66. public int compare(Pair<Integer,String> p1, Pair<Integer,String> p2) {
  67. return p2.first - p1.first;
  68. }
  69. });
  70.  
  71. int count = 0;
  72. //int max = 10;
  73. for (Pair<Integer,String> producto : top) {
  74. //System.out.println("Producto," + producto.second +",Cantidad," + producto.first);
  75. count = count +1;
  76. if (count == 10) {
  77. break;
  78. }
  79. }
  80. }
  81.  
  82.  
  83.  
  84.  
  85. cluster.close();
  86. }
  87. static final long NUM_100NS_INTERVALS_SINCE_UUID_EPOCH = 0x01b21dd213814000L;
  88.  
  89. public static long getTimeFromUUID(UUID uuid) {
  90. return (uuid.timestamp() - NUM_100NS_INTERVALS_SINCE_UUID_EPOCH) / 10000;
  91. }
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement