Skip to content
Snippets Groups Projects
Commit 83574509 authored by Eilert Tunheim's avatar Eilert Tunheim
Browse files

Retrieved the next date and managed to add extra days to check for

parent 9a7b4bc3
No related branches found
No related tags found
No related merge requests found
......@@ -6,8 +6,13 @@ import com.google.cloud.bigquery.*;
import java.io.File;
import java.io.FileInputStream;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.*;
/**
......@@ -101,17 +106,15 @@ public class DB {
// Initializing the data map to store the results
Map<String, Number> data = new HashMap<>();
List<List<Number>> listOfLists = new ArrayList<List<Number>>();
// Initializing the date format
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// Preparing a query statement
final String sqlStatement = "SELECT TimeStamp, VariantValue " +
"FROM sf-drying-optimization.124.int_sd_winccsensordata " +
"WHERE TimeStamp BETWEEN \"2021-01-25 08:51:03\" " +
"AND \"2021-03-04 11:10:09\" ORDER BY TimeStamp";
"AND \"2021-03-08 11:10:09\" ORDER BY TimeStamp ASC";
// Creates a job configuration
queryJob = getJob(QueryJobConfiguration.newBuilder(sqlStatement).build());
......@@ -121,20 +124,35 @@ public class DB {
System.out.println("InTidTork \t UtTidTork");
for (FieldValueList row : result.iterateAll()) {
// Kwh
int variantValue = row.get("VariantValue").getNumericValue().intValue();
// Retrieving the wanted data
long timeStamp = row.get("TimeStamp").getTimestampValue()/1000;
// Riktig format, men i string
String formatedTimeStamp = dateFormat.format(timeStamp);
// Format the date to LocalDateTime datatype
LocalDateTime date = LocalDateTime.parse(formatedTimeStamp, format);
// Creates a future date to compare against
LocalDateTime dateFuture = date.plusDays(1);
int variantValue = row.get("VariantValue").getNumericValue().intValue();
//System.out.println(date);
System.out.println(timeStamp);
data.put(formatedTimeStamp, variantValue);
}
NavigableMap<String, Number> sortedData = new TreeMap<>(data);
data.put(formatedTimeStamp, variantValue);
for (Map.Entry<String, Number> entry : sortedData.entrySet()) {
String key = entry.getKey();
String next = sortedData.higherEntry(entry.getKey()).getKey(); // next
listOfLists.add(new ArrayList<Number>());
System.out.println("Nå: "+key);
System.out.println("Neste: "+next);
}
return data;
return data;
}
/**
......@@ -153,6 +171,8 @@ public class DB {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
// Preparing a query statement
final String sqlStatement =
"SELECT Name, CalculatedStart, CalculatedStop FROM `sf-drying-optimization.124.int_dk_valmaticsdryingbatches`" +
......@@ -176,7 +196,10 @@ public class DB {
String formattedCalculatedStart = dateFormat.format(calculatedStart);
String formattedCalculatedStop = dateFormat.format(calculatedStop);
System.out.printf("%s\t\t\t%s\t\t\t%s\n",name, formattedCalculatedStart, formattedCalculatedStop);
java.sql.Timestamp timestamp = new Timestamp(calculatedStart);
System.out.println(timestamp);
//System.out.printf("%s\t\t\t%s\t\t\t%s\n",name, formattedCalculatedStart, formattedCalculatedStop);
}
//return data;
......
package com.application;
import com.application.DB.DB;
import javafx.application.Application;
import javafx.application.Application;
import javafx.scene.chart.LineChart;
import javafx.scene.control.MenuBar;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.ToggleGroup;
......@@ -13,14 +12,10 @@ import javafx.scene.image.ImageView;
import javafx.scene.layout.*;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
......
No preview for this file type
File deleted
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment