Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Bacheloroppgave_2022
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eilert Tunheim
Bacheloroppgave_2022
Commits
c814f499
Commit
c814f499
authored
3 years ago
by
Eilert Tunheim
Browse files
Options
Downloads
Patches
Plain Diff
Implemented the Constants class
parent
74e773e2
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/com/application/DB/DB.java
+46
-10
46 additions, 10 deletions
src/main/java/com/application/DB/DB.java
target/classes/com/application/DB/DB.class
+0
-0
0 additions, 0 deletions
target/classes/com/application/DB/DB.class
with
46 additions
and
10 deletions
src/main/java/com/application/DB/DB.java
+
46
−
10
View file @
c814f499
...
@@ -12,6 +12,8 @@ import java.time.LocalDateTime;
...
@@ -12,6 +12,8 @@ import java.time.LocalDateTime;
import
java.time.format.DateTimeFormatter
;
import
java.time.format.DateTimeFormatter
;
import
java.util.*
;
import
java.util.*
;
import
static
com
.
application
.
DB
.
Constants
.*;
/**
/**
* This class is responsible for handling database related activities
* This class is responsible for handling database related activities
*
*
...
@@ -77,7 +79,7 @@ public class DB {
...
@@ -77,7 +79,7 @@ public class DB {
// we use to execute jobs on
// we use to execute jobs on
return
BigQueryOptions
.
newBuilder
().
return
BigQueryOptions
.
newBuilder
().
setCredentials
(
getCredentials
()).
setCredentials
(
getCredentials
()).
setProjectId
(
"sf-drying-optimization"
)
setProjectId
(
PROJECT_ID
)
.
build
().
getService
();
.
build
().
getService
();
}
}
...
@@ -279,7 +281,7 @@ public class DB {
...
@@ -279,7 +281,7 @@ public class DB {
// Sqlstatement for Valåsen(124)
// Sqlstatement for Valåsen(124)
final
String
sqlStatement
=
final
String
sqlStatement
=
"SELECT MAX(Name) as DryingSchedule, MAX(KilnName) as Kiln_name, DryingStarted, Max(CalculatedStop) as CalculatedStop\n"
+
"SELECT MAX(Name) as DryingSchedule, MAX(KilnName) as Kiln_name, DryingStarted, Max(CalculatedStop) as CalculatedStop\n"
+
"FROM `sf-drying-optimization.124.int_dk_valmaticsdryingbatches` \n"
+
"FROM `sf-drying-optimization.124.int_dk_valmaticsdryingbatches
_v2
` \n"
+
"WHERE KilnName = 5 \n"
+
"WHERE KilnName = 5 \n"
+
"AND DATE(DryingStarted) BETWEEN \"1990-08-17\" AND \"2022-08-17\"\n"
+
"AND DATE(DryingStarted) BETWEEN \"1990-08-17\" AND \"2022-08-17\"\n"
+
"AND DATE(CalculatedStop) BETWEEN \"1990-08-17\" AND \"2022-08-17\"\n"
+
"AND DATE(CalculatedStop) BETWEEN \"1990-08-17\" AND \"2022-08-17\"\n"
+
...
@@ -309,19 +311,52 @@ public class DB {
...
@@ -309,19 +311,52 @@ public class DB {
for
(
FieldValueList
row
:
result
.
iterateAll
())
{
for
(
FieldValueList
row
:
result
.
iterateAll
())
{
// Defining variables
// Defining variables
String
formatedInTidTork
;
String
formatedInTidTork
=
""
;
String
formatedUtTidTork
;
String
formatedUtTidTork
=
""
;
// Retrieving the data
// Retrieving the data
// DryingStarted:
// DryingStarted:
if
(!
row
.
get
(
"DryingStarted"
).
isNull
()){
if
(!
row
.
get
(
"DryingStarted"
).
isNull
()){
long
InTidTorkLong
=
row
.
get
(
"DryingStarted"
).
getTimestampValue
()/
1000
;
// Check if response is given in millis
// Formating the data from long to a string in the correct date format
if
(
row
.
get
(
"DryingStarted"
).
getValue
()
instanceof
Integer
)
{
formatedInTidTork
=
getDateFormat
().
format
(
InTidTorkLong
);
long
InTidTorkLong
=
row
.
get
(
"DryingStarted"
).
getTimestampValue
()/
1000
;
}
else
{
// Formating the data from long to a string in the correct date format
formatedInTidTork
=
""
;
formatedInTidTork
=
getDateFormat
().
format
(
InTidTorkLong
);
}
// Checks if response is given in a string date format
else
if
(
row
.
get
(
"DryingStarted"
).
getValue
()
instanceof
String
)
{
// stores the value
String
value
=
(
String
)
row
.
get
(
"DryingStarted"
).
getValue
();
// Splits the string based on 'T'
String
[]
splitValue
=
value
.
split
(
"T"
);
// Combines the values into a new format
formatedInTidTork
=
splitValue
[
0
]+
" "
+
splitValue
[
1
];
}
}
}
// CalculatedStop:
// DryingCompleted:
if
(!
row
.
get
(
"CalculatedStop"
).
isNull
()){
// Check if response is given in millis
if
(
row
.
get
(
"CalculatedStop"
).
getValue
()
instanceof
Integer
)
{
long
utTidTorkLong
=
row
.
get
(
"CalculatedStop"
).
getTimestampValue
()/
1000
;
// Formating the data from long to a string in the correct date format
formatedUtTidTork
=
getDateFormat
().
format
(
utTidTorkLong
);
}
else
if
(
row
.
get
(
"CalculatedStop"
).
getValue
()
instanceof
String
)
{
// stores the value
String
value
=
(
String
)
row
.
get
(
"CalculatedStop"
).
getValue
();
// Splits the string based on 'T'
String
[]
splitValue
=
value
.
split
(
"T"
);
// Combines the values into a new format
formatedUtTidTork
=
splitValue
[
0
]+
" "
+
splitValue
[
1
];
}
}
System
.
out
.
println
(
formatedInTidTork
);
System
.
out
.
println
(
formatedUtTidTork
+
"\n"
);
/*
// CalculatedStop:
// CalculatedStop:
// DryingCompleted:
// DryingCompleted:
if(!row.get("CalculatedStop").isNull()){
if(!row.get("CalculatedStop").isNull()){
...
@@ -331,9 +366,10 @@ public class DB {
...
@@ -331,9 +366,10 @@ public class DB {
} else {
} else {
formatedUtTidTork = "";
formatedUtTidTork = "";
}
}
*/
// Checks if intidtork or outtidtork is empty, if so they are ignored and not added to the list
// Checks if intidtork or outtidtork is empty, if so they are ignored and not added to the list
if
(!
formatedInTidTork
.
equals
(
""
)
&&
!
formatedUtTidTork
.
equals
(
""
)){
if
(!
formatedInTidTork
.
isEmpty
(
)
&&
!
formatedUtTidTork
.
isEmpty
(
)){
// Adds the data to the dates map
// Adds the data to the dates map
dates
.
put
(
formatedInTidTork
,
formatedUtTidTork
);
dates
.
put
(
formatedInTidTork
,
formatedUtTidTork
);
}
}
...
...
This diff is collapsed.
Click to expand it.
target/classes/com/application/DB/DB.class
+
0
−
0
View file @
c814f499
No preview for this file type
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment