Advertisement
Guest User

zadanie1

a guest
Jul 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.12 KB | None | 0 0
  1. import java.sql.*;
  2.  
  3. /**
  4.  * Created by Jakubek on 2017-07-12.
  5.  */
  6. public class zadanie {
  7.     //todo pobieranie danych z tabeli na bieżco, optymalizacja działnia całego programu
  8.     private String stopName[] = getDataString("C:\\Users\\Jakubek\\Desktop\\NewagIP\\Wojtek\\Zadanie 1\\Baza danych\\passcount.sqlite",
  9.             "recorded_course_stops",
  10.             "stop_name");
  11.  
  12.     private int stopGlobalId[] = getDataInt("C:\\Users\\Jakubek\\Desktop\\NewagIP\\Wojtek\\Zadanie 1\\Baza danych\\passcount.sqlite",
  13.             "recorded_course_stops",
  14.             "stop_global_id");
  15.  
  16.     private int courseRowId[] = getDataInt("C:\\Users\\Jakubek\\Desktop\\NewagIP\\Wojtek\\Zadanie 1\\Baza danych\\passcount.sqlite",
  17.             "recorded_course_stops",
  18.             "course_rowid");
  19.  
  20.     private int firstEventRowId[] = getDataInt("C:\\Users\\Jakubek\\Desktop\\NewagIP\\Wojtek\\Zadanie 1\\Baza danych\\passcount.sqlite",
  21.             "recorded_course_stops",
  22.             "first_event_rowid");
  23.  
  24.     private int lastEventRowId[] = getDataInt("C:\\Users\\Jakubek\\Desktop\\NewagIP\\Wojtek\\Zadanie 1\\Baza danych\\passcount.sqlite",
  25.             "recorded_course_stops",
  26.             "last_event_rowid");
  27.  
  28.    
  29.     //tutaj jest import.
  30.     private int eventCode[] = getDataInt("C:\\Users\\Jakubek\\Desktop\\NewagIP\\Wojtek\\Zadanie 1\\Baza danych\\passcount.sqlite",
  31.             "recorded_events",
  32.             "event_code");
  33.  
  34.    
  35.    
  36.     private int eventTimeUnix[] = getDataInt("C:\\Users\\Jakubek\\Desktop\\NewagIP\\Wojtek\\Zadanie 1\\Baza danych\\passcount.sqlite",
  37.             "recorded_events",
  38.             "event_time_unix");
  39.  
  40.     private int eventSubCode[] = getDataInt("C:\\Users\\Jakubek\\Desktop\\NewagIP\\Wojtek\\Zadanie 1\\Baza danych\\passcount.sqlite",
  41.             "recorded_events",
  42.             "event_subcode");
  43.  
  44.     private int stopRowIdFromStopsTable[] = getDataInt("C:\\Users\\Jakubek\\Desktop\\NewagIP\\Wojtek\\Zadanie 1\\Baza danych\\passcount.sqlite",
  45.             "recorded_course_stops",
  46.             "stop_rowid");
  47.  
  48.     private int stopRowId[] = getDataInt("C:\\Users\\Jakubek\\Desktop\\NewagIP\\Wojtek\\Zadanie 1\\Baza danych\\passcount.sqlite",
  49.             "recorded_state",
  50.             "stop_rowid");
  51.  
  52.     private int trainNumber[] = getDataInt("C:\\Users\\Jakubek\\Desktop\\NewagIP\\Wojtek\\Zadanie 1\\Baza danych\\passcount.sqlite",
  53.             "recorded_courses",
  54.             "train_number");
  55.  
  56.     private int distanceSincePowerUp[] = getDataInt("C:\\Users\\Jakubek\\Desktop\\NewagIP\\Wojtek\\Zadanie 1\\Baza danych\\passcount.sqlite",
  57.             "recorded_state",
  58.             "distance_since_power_up_meters");
  59.  
  60.     private int distanceSinceProduced[] = getDataInt("C:\\Users\\Jakubek\\Desktop\\NewagIP\\Wojtek\\Zadanie 1\\Baza danych\\passcount.sqlite",
  61.             "recorded_state",
  62.             "vehicle_lifelong_distance_meters");
  63.  
  64.     private double gps1Longitude[] = getDataDouble("C:\\Users\\Jakubek\\Desktop\\NewagIP\\Wojtek\\Zadanie 1\\Baza danych\\passcount.sqlite",
  65.             "recorded_state",
  66.             "gps1_lon");
  67.  
  68.     private double gps1Latitude[] = getDataDouble("C:\\Users\\Jakubek\\Desktop\\NewagIP\\Wojtek\\Zadanie 1\\Baza danych\\passcount.sqlite",
  69.             "recorded_state",
  70.             "gps1_lat");
  71.  
  72.     private double gps2Longitude[] = getDataDouble("C:\\Users\\Jakubek\\Desktop\\NewagIP\\Wojtek\\Zadanie 1\\Baza danych\\passcount.sqlite",
  73.             "recorded_state",
  74.             "gps2_lon");
  75.  
  76.     private double gps2Latitude[] = getDataDouble("C:\\Users\\Jakubek\\Desktop\\NewagIP\\Wojtek\\Zadanie 1\\Baza danych\\passcount.sqlite",
  77.             "recorded_state",
  78.             "gps2_lat");
  79.  
  80.     private String[] result;
  81.  
  82.     zadanie() {    }
  83.  
  84.     private String[] getDataString(String url, String from, String select){
  85.         int i=0;
  86.         //TODO Dynamiczna alojacja pamięci
  87.         String[] result = new String[500000];
  88.         try{
  89.             Class.forName("org.sqlite.JDBC");
  90.             Connection connection = DriverManager.getConnection("jdbc:sqlite:"+url);
  91.             Statement stmt  = connection.createStatement();
  92.             ResultSet rs    = stmt.executeQuery("SELECT " + select + " FROM "+ from);
  93.             while (rs.next()){
  94.                 result[i]=rs.getString(select);
  95.                 i++;
  96.             }
  97.             System.out.println("Pobrano z tabeli: "+from+" Dane dot.: "+select);
  98.         } catch (ClassNotFoundException e) {
  99.             e.printStackTrace();
  100.         } catch (SQLException e) {
  101.             System.out.println("Wielbłąd!" + e.getMessage());
  102.             e.printStackTrace();
  103.         }
  104.         return result;
  105.     }
  106.  
  107.     private int[] getDataInt(String url, String from, String select){
  108.         int i=0;
  109.         //TODO Dynamiczna alojacja pamięci
  110.         int[] result = new int[5000000];
  111.         try{
  112.             Class.forName("org.sqlite.JDBC");
  113.             Connection connection = DriverManager.getConnection("jdbc:sqlite:"+url);
  114.             Statement stmt  = connection.createStatement();
  115.             ResultSet rs    = stmt.executeQuery("SELECT " + select + " FROM "+ from);
  116.             while (rs.next()){
  117.                 result[i]=rs.getInt(select);
  118.                 i++;
  119.             }
  120.             System.out.println("Pobrano z tabeli: "+from+" Dane dot.: "+select);
  121.         } catch (ClassNotFoundException e) {
  122.             e.printStackTrace();
  123.         } catch (SQLException e) {
  124.             System.out.println("Wielbłąd!" + e.getMessage());
  125.             e.printStackTrace();
  126.         }
  127.         return result;
  128.     }
  129.  
  130.     private double[] getDataDouble(String url, String from, String select){
  131.         int i=0;
  132.         //TODO Dynamiczna alojacja pamięci
  133.         double[] result = new double[5000000];
  134.         try{
  135.             Class.forName("org.sqlite.JDBC");
  136.             Connection connection = DriverManager.getConnection("jdbc:sqlite:"+url);
  137.             Statement stmt  = connection.createStatement();
  138.             ResultSet rs    = stmt.executeQuery("SELECT " + select + " FROM "+ from);
  139.             while (rs.next()){
  140.                 result[i]=rs.getDouble(select);
  141.                 i++;
  142.             }
  143.             System.out.println("Pobrano z tabeli: "+from+" Dane dot.: "+select);
  144.         } catch (ClassNotFoundException e) {
  145.             e.printStackTrace();
  146.         } catch (SQLException e) {
  147.             System.out.println("Wielbłąd!" + e.getMessage());
  148.             e.printStackTrace();
  149.         }
  150.         return result;
  151.     }
  152.  
  153.     public String getStopName(int lp){
  154.         return stopName[lp];
  155.     }
  156.  
  157.     public int getStopGlobalId(int lp){
  158.         return stopGlobalId[lp];
  159.     }
  160.  
  161.     public int getStopRowId(int lp){
  162.         return stopRowIdFromStopsTable[lp];
  163.     }
  164.  
  165.     public int getCourseRowId(int lp){
  166.         return courseRowId[lp];
  167.     }
  168.  
  169.     public int getCourseRowMaxId(){
  170.         int max=0;
  171.         for (int i = 1; i < courseRowId.length; i++) {
  172.             if (courseRowId[i] > max) {
  173.                 max = courseRowId[i];
  174.             }
  175.         }
  176.         return max;
  177.     }
  178.  
  179.     public int getTrainNumber(int lp){
  180.         return trainNumber[lp];
  181.     }
  182.  
  183.     public int getDistanceSincePowerUpForEachStation(int lp){
  184.      int distance = 0;
  185.         for (int i=0;i<stopRowId.length;i++) {
  186.             if (stopRowId[i] == lp) {
  187.                 distance=distanceSincePowerUp[i];
  188.             }
  189.         }
  190.      return distance;
  191.     }
  192.  
  193.     public int getDistanceSinceProduced(int lp){
  194.         int distance = 0;
  195.         for (int i=0;i<stopRowId.length;i++) {
  196.             if (stopRowId[i] == lp) {
  197.                 distance=(distanceSinceProduced[i])/1000;
  198.             }
  199.         }
  200.         return distance;
  201.     }
  202.  
  203.     public double getGps1Longitude(int lp){
  204.         double gps = 0;
  205.         for (int i=0;i<stopRowId.length;i++) {
  206.             if (stopRowId[i] == lp) {
  207.                 gps=(gps1Longitude[i]);
  208.             }
  209.         }
  210.         return gps;
  211.     }
  212.  
  213.     public double getGps1Latitude(int lp){
  214.         double gps = 0;
  215.         for (int i=0;i<stopRowId.length;i++) {
  216.             if (stopRowId[i] == lp) {
  217.                 gps=(gps1Latitude[i]);
  218.             }
  219.         }
  220.         return gps;
  221.     }
  222.  
  223.     public double getGps2Longitude(int lp){
  224.         double gps = 0;
  225.         for (int i=0;i<stopRowId.length;i++) {
  226.             if (stopRowId[i] == lp) {
  227.                 gps=(gps2Longitude[i]);
  228.             }
  229.         }
  230.         return gps;
  231.     }
  232.  
  233.     public double getGps2Latitude(int lp){
  234.         double gps = 0;
  235.         for (int i=0;i<stopRowId.length;i++) {
  236.             if (stopRowId[i] == lp) {
  237.                 gps=(gps2Latitude[i]);
  238.             }
  239.         }
  240.         return gps;
  241.     }
  242.  
  243.     public int getFirstEventId(int lp){
  244.         return firstEventRowId[lp];
  245.     }
  246.  
  247.     public int getLastEventId(int lp){
  248.         return lastEventRowId[lp];
  249.     }
  250.  
  251.     public int getEventUnixTime(int lp){
  252.         return eventTimeUnix[lp];
  253.     }
  254.  
  255.     public int getEventCode(int lp){
  256.         return eventCode[lp];
  257.     }
  258.  
  259.     public int getEventSubCode(int lp){
  260.         return eventSubCode[lp];
  261.     }
  262.  
  263.     public static void main(String[] args) {
  264.         new zadanie();
  265.     }
  266.  
  267. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement