daily pastebin goal
5%
SHARE
TWEET

Untitled

a guest Jun 30th, 2018 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.sql.*;
  2.  
  3.  
  4. // SQL VARS
  5. private Connection con;
  6. private static final String DBNAME = "aoldata.querydata";
  7. private static final String URL = "jdbc:oracle:thin:@dbl43.beuth-hochschule.de:1521:oracle";
  8. private static final String USER = "s860629";
  9. private static final String PASSWORD = "beuthvogel";
  10.  
  11. //Padding VARS
  12. int padd = 60,padd_left = 120,padd_top = 120;
  13. int barGap = 4;
  14.  
  15. //color VARS
  16. int colors[][] = {{51,102,204},{220,57,18}};
  17.  
  18. void setup(){
  19.   size(1080, 640);
  20.   background(255);
  21.   drawLeg();
  22.   connect();
  23.   drawBaseLine();
  24.  
  25.  
  26.   //disconnect();
  27.   save("u1.jpg");
  28. }
  29.  
  30. void drawLeg(){
  31.   stroke(128);
  32.   strokeWeight(1);
  33.   line((width-padd_left-padd)/2+padd_left,padd_top-padd/2,(width-padd_left-padd)/2+padd_left, height-padd/2);
  34.   line(width-padd,padd_top-padd/2,width-padd, height-padd/2);
  35.  
  36.   //title
  37.   fill(0);
  38.   textSize(22);
  39.   textAlign(CENTER);
  40.   text("Titel dieses Diagramms",width/2,padd_top/2);
  41. }
  42.  
  43. void drawBaseLine(){
  44.   stroke(0);
  45.   strokeWeight(2);
  46.   line(padd_left,padd_top-padd/2,padd_left, height-padd/2);
  47. }
  48.  
  49. void drawBars(int[] bars,String[] headers){
  50.  
  51.   float h = (height - (padd+padd_left)) / bars.length;
  52.  
  53.   int maxNum = 0;
  54.  
  55.   //get highest number
  56.   for(int i = 0; i < bars.length; i++){
  57.     if(bars[i]>maxNum) maxNum = bars[i];
  58.   }
  59.  
  60.   //Draw Bars
  61.   noStroke();
  62.   for(int i = 0; i < bars.length; i++){
  63.     if(i%2==0)  fill(colors[0][0],colors[0][1],colors[0][2]);
  64.     else        fill(colors[1][0],colors[1][1],colors[1][2]);
  65.    
  66.     float num = map(bars[i], 0, maxNum, 0, height-(padd*2));
  67.    
  68.     rect(padd_left,padd_top+(h*i)+barGap/2,num,h-barGap/2,0,5,5,0);
  69.    
  70.     textSize(16);
  71.     fill(0);
  72.     textAlign(LEFT);
  73.     text(""+bars[i],padd_left+num+5,(h*i)+padd_top+h/2);
  74.     textAlign(CENTER);
  75.     text(headers[i],padd_left/2,(h*i)+padd_top+h/2);
  76.    
  77.     System.out.println(bars[i]);  
  78.   }
  79. }
  80.  
  81.  
  82.  
  83.  
  84. public void connect() {
  85.   try {
  86.     Class.forName("oracle.jdbc.driver.OracleDriver");
  87.  
  88.     //öffnet Verbindung zur Datenbank
  89.     con=DriverManager.getConnection(URL, USER, PASSWORD);
  90.  
  91.     Statement stmt=con.createStatement();
  92.    
  93.     String anfrage = "Select"+
  94.     "sum(case when QUERY like '%cooking recipe%' or CLICKURL like '%recipe%' and MOD(TO_CHAR(QUERYTIME, 'J'), 7) + 1 IN (1) THEN 1 ELSE 0 END ) as Montag,"+
  95.     "sum(case when QUERY like '%cooking recipe%' or CLICKURL like '%recipe%' and MOD(TO_CHAR(QUERYTIME, 'J'), 7) + 1 IN (2) THEN 1 ELSE 0 END ) as Dienstag,"+
  96.     "sum(case when QUERY like '%cooking recipe%' or CLICKURL like '%recipe%' and MOD(TO_CHAR(QUERYTIME, 'J'), 7) + 1 IN (3) THEN 1 ELSE 0 END ) as Mittwoch,"+
  97.     "sum(case when QUERY like '%cooking recipe%' or CLICKURL like '%recipe%' and MOD(TO_CHAR(QUERYTIME, 'J'), 7) + 1 IN (4) THEN 1 ELSE 0 END ) as Donnerstag,"+
  98.     "sum(case when QUERY like '%cooking recipe%' or CLICKURL like '%recipe%' and MOD(TO_CHAR(QUERYTIME, 'J'), 7) + 1 IN (5) THEN 1 ELSE 0 END ) as Freitag,"+
  99.     "sum(case when QUERY like '%cooking recipe%' or CLICKURL like '%recipe%' and MOD(TO_CHAR(QUERYTIME, 'J'), 7) + 1 IN (6) THEN 1 ELSE 0 END ) as Samstag,"+
  100.     "sum(case when QUERY like '%cooking recipe%' or CLICKURL like '%recipe%' and MOD(TO_CHAR(QUERYTIME, 'J'), 7) + 1 IN (7) THEN 1 ELSE 0 END ) as Sonntag"+
  101.     "from aoldata.querydata"+DBNAME;
  102.  
  103.     //Stellt Suchanfrage
  104.     ResultSet rs=stmt.executeQuery(anfrage);
  105.    
  106.    
  107.     ResultSetMetaData rsmd = rs.getMetaData();
  108.    
  109.  
  110.     int[] arr = {rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getInt(4), rs.getInt(5), rs.getInt(6), rs.getInt(7)};
  111.     String[] header = {rsmd.getColumnName(1), rsmd.getColumnName(2), rsmd.getColumnName(3), rsmd.getColumnName(4), rsmd.getColumnName(5), rsmd.getColumnName(6), rsmd.getColumnName(7)};
  112.    
  113.     //int[] arr = {2342, 8923, 2342, 5342, 1337, 1323, 3131};
  114.     //String[] header = {"Montag","Dienstag","Mittwoch","Donnerstag","Freitag","Samstag","Sonntag"};
  115.  
  116.     drawBars(arr,header);
  117.   }
  118.   catch(Exception e) {
  119.     System.out.println(e);
  120.   }
  121. }
  122.  
  123. //Schließt verbindung zur Datenbank
  124. public void disconnect() {
  125.   try {
  126.     con.close();
  127.   }
  128.   catch(Exception e) {
  129.     System.out.println(e);
  130.   }
  131. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top