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
c622d621
Commit
c622d621
authored
3 years ago
by
Eilert Tunheim
Browse files
Options
Downloads
Patches
Plain Diff
commented DB
parent
b454db99
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/com/application/DB/DB.java
+20
-57
20 additions, 57 deletions
src/main/java/com/application/DB/DB.java
with
20 additions
and
57 deletions
src/main/java/com/application/DB/DB.java
+
20
−
57
View file @
c622d621
...
@@ -13,36 +13,28 @@ import static com.application.DB.HelpingFunctions.getNoOfChambers;
...
@@ -13,36 +13,28 @@ import static com.application.DB.HelpingFunctions.getNoOfChambers;
* This class is responsible for handling database related activities
* This class is responsible for handling database related activities
*
*
* @author Eilert Tunheim, Karin Pettersen, Mads Arnesen
* @author Eilert Tunheim, Karin Pettersen, Mads Arnesen
* @version 1.0
* @version 1.0
.0
*/
*/
public
class
DB
{
public
class
DB
{
/**
/**
*
Launching the functions
*
This function gathers all input parameters from the user and search for data
*
*
* @
param args default param
* @
return a map containing drying cycles
* @throws Exception throws exception i
n case o
f error
* @throws Exception throws exception if error
occurs
*/
*/
public
static
void
main
(
String
[]
args
)
throws
Exception
{
//getKwh();
//getName();
//getZeroPointDate();
//System.out.println(setInputParameters());
//getNoOfChambers();
}
public
static
Map
<
Integer
,
Map
<
String
,
Number
>>
setInputParameters
()
throws
Exception
{
public
static
Map
<
Integer
,
Map
<
String
,
Number
>>
setInputParameters
()
throws
Exception
{
// Map to store data
Map
<
Integer
,
Map
<
String
,
Number
>>
allDryingPeriods
=
new
HashMap
<>();
Map
<
Integer
,
Map
<
String
,
Number
>>
allDryingPeriods
=
new
HashMap
<>();
// Variables to indicate if the parameters have been deleted or not
boolean
sawsetRemoved
=
false
;
boolean
sawsetRemoved
=
false
;
boolean
treespeciesRemoved
=
false
;
boolean
treespeciesRemoved
=
false
;
boolean
dimensionsRemoved
=
false
;
boolean
dimensionsRemoved
=
false
;
boolean
moistureRemoved
=
false
;
boolean
moistureRemoved
=
false
;
// Defining variables
HashMap
<
java
.
lang
.
String
,
java
.
lang
.
String
>
locationTables
=
null
;
HashMap
<
java
.
lang
.
String
,
java
.
lang
.
String
>
locationTables
=
null
;
ArrayList
<
Integer
>
valmeticsChamberIDS
=
null
;
ArrayList
<
Integer
>
valmeticsChamberIDS
=
null
;
ArrayList
<
Integer
>
kwhChamberIDS
=
null
;
ArrayList
<
Integer
>
kwhChamberIDS
=
null
;
...
@@ -76,11 +68,13 @@ public class DB {
...
@@ -76,11 +68,13 @@ public class DB {
getNoOfChambers
();
getNoOfChambers
();
int
chamberNo
=
1
;
int
chamberNo
=
1
;
// While loop that check for data
while
(
true
){
while
(
true
){
// Map to store data
Map
<
Integer
,
Map
<
String
,
Number
>>
intermediateHashMap
=
new
HashMap
<>();
Map
<
Integer
,
Map
<
String
,
Number
>>
intermediateHashMap
=
new
HashMap
<>();
// Iterating through all the sawmills
for
(
HashMap
.
Entry
<
Integer
,
HashMap
<
String
,
HashMap
<
String
,
String
>>>
location
:
Settings
.
getSawmills
().
entrySet
())
{
for
(
HashMap
.
Entry
<
Integer
,
HashMap
<
String
,
HashMap
<
String
,
String
>>>
location
:
Settings
.
getSawmills
().
entrySet
())
{
// Clears the extraInputs variable
// Clears the extraInputs variable
...
@@ -89,12 +83,9 @@ public class DB {
...
@@ -89,12 +83,9 @@ public class DB {
System
.
out
.
printf
(
"\nLocation ID: \t%s\t\t\tRest of map: \t%s\n"
,
location
.
getKey
(),
location
.
getValue
());
System
.
out
.
printf
(
"\nLocation ID: \t%s\t\t\tRest of map: \t%s\n"
,
location
.
getKey
(),
location
.
getValue
());
System
.
out
.
println
(
"Number of sawmills: "
+
Settings
.
getSawmills
().
size
());
System
.
out
.
println
(
"Number of sawmills: "
+
Settings
.
getSawmills
().
size
());
//allDryingPeriods = new TreeMap<>();
locationID
=
location
.
getKey
();
locationID
=
location
.
getKey
();
//System.out.println(location.getValue());
// If the location is 124, "Furu" is stored as "Fura" in the database, swedish
if
(
location
.
getKey
()
==
124
)
{
if
(
location
.
getKey
()
==
124
)
{
// If location is Valasen, then the database stores furu as fura, swedish.
// If location is Valasen, then the database stores furu as fura, swedish.
if
(
Constants
.
TREE_SPECIES
.
equalsIgnoreCase
(
"Furu"
))
{
if
(
Constants
.
TREE_SPECIES
.
equalsIgnoreCase
(
"Furu"
))
{
...
@@ -226,6 +217,7 @@ public class DB {
...
@@ -226,6 +217,7 @@ public class DB {
}
}
}
}
// Prints all the drying periods
System
.
out
.
println
(
allDryingPeriods
.
size
());
System
.
out
.
println
(
allDryingPeriods
.
size
());
for
(
Map
.
Entry
<
Integer
,
Map
<
String
,
Number
>>
entry
:
allDryingPeriods
.
entrySet
())
{
for
(
Map
.
Entry
<
Integer
,
Map
<
String
,
Number
>>
entry
:
allDryingPeriods
.
entrySet
())
{
System
.
out
.
printf
(
"Timestamp: \t%s\t\t\tkWh: \t%s\n"
,
entry
.
getKey
(),
entry
.
getValue
());
System
.
out
.
printf
(
"Timestamp: \t%s\t\t\tkWh: \t%s\n"
,
entry
.
getKey
(),
entry
.
getValue
());
...
@@ -283,7 +275,7 @@ public class DB {
...
@@ -283,7 +275,7 @@ public class DB {
finalResults
.
put
(
index
,
sortedData
);
finalResults
.
put
(
index
,
sortedData
);
index
+=
1
;
index
+=
1
;
//
entry.value burde matche med en av de og går igjennom all
e
//
checks for manual moistur
e
for
(
Map
.
Entry
<
String
,
String
>
moistureEntry
:
HelpingFunctions
.
getManMoist
().
entrySet
())
{
for
(
Map
.
Entry
<
String
,
String
>
moistureEntry
:
HelpingFunctions
.
getManMoist
().
entrySet
())
{
if
(
moistureEntry
.
getKey
().
equals
(
entry
.
getValue
())){
if
(
moistureEntry
.
getKey
().
equals
(
entry
.
getValue
())){
...
@@ -304,17 +296,7 @@ public class DB {
...
@@ -304,17 +296,7 @@ public class DB {
// Defining a treemap to sort the data incrementally
// Defining a treemap to sort the data incrementally
NavigableMap
<
Integer
,
Map
<
String
,
Number
>>
sortedFinalResults
=
new
TreeMap
<>(
finalResults
);
NavigableMap
<
Integer
,
Map
<
String
,
Number
>>
sortedFinalResults
=
new
TreeMap
<>(
finalResults
);
for
(
Map
.
Entry
<
Integer
,
Map
<
String
,
Number
>>
entry
:
sortedFinalResults
.
entrySet
())
{
// Prints the values
Map
<
String
,
Number
>
data
=
entry
.
getValue
();
for
(
Map
.
Entry
<
String
,
Number
>
moistureEntry
:
data
.
entrySet
())
{
//System.out.println("Data key: "+moistureEntry.getKey()); // Key = datetime: 2022-01-18 20:23:36
//System.out.println("Data Value: "+moistureEntry.getValue()); // Value = kwh: 5422
}
}
for
(
Map
.
Entry
<
Integer
,
Map
<
String
,
Number
>>
entry
:
sortedFinalResults
.
entrySet
())
{
for
(
Map
.
Entry
<
Integer
,
Map
<
String
,
Number
>>
entry
:
sortedFinalResults
.
entrySet
())
{
System
.
out
.
printf
(
"Timestamp: \t%s\t\t\tkWh: \t%s\n"
,
entry
.
getKey
(),
entry
.
getValue
());
System
.
out
.
printf
(
"Timestamp: \t%s\t\t\tkWh: \t%s\n"
,
entry
.
getKey
(),
entry
.
getValue
());
}
}
...
@@ -388,8 +370,6 @@ public class DB {
...
@@ -388,8 +370,6 @@ public class DB {
kilinID
+=
1
;
kilinID
+=
1
;
}
}
// Retrieves the results from the queryjob
// Retrieves the results from the queryjob
TableResult
result
=
HelpingFunctions
.
createQueryJob
(
sqlStatement
);
TableResult
result
=
HelpingFunctions
.
createQueryJob
(
sqlStatement
);
...
@@ -420,11 +400,6 @@ public class DB {
...
@@ -420,11 +400,6 @@ public class DB {
}
}
}
}
//System.out.println("Start: "+row.get("DryingStarted").getTimestampValue());
//System.out.println("Stop: "+row.get("DryingCompleted").getTimestampValue());
// Retrieving the data
// Retrieving the data
// DryingStarted:
// DryingStarted:
if
(!
row
.
get
(
"DryingStarted"
).
isNull
()){
if
(!
row
.
get
(
"DryingStarted"
).
isNull
()){
...
@@ -451,14 +426,8 @@ public class DB {
...
@@ -451,14 +426,8 @@ public class DB {
}
}
else
formatedInTidTork
=
row
.
get
(
"DryingStarted"
).
getValue
().
toString
();
else
formatedInTidTork
=
row
.
get
(
"DryingStarted"
).
getValue
().
toString
();
}
}
// Checks if response is given in a string date format
//if(row.get("DryingStarted").getValue().equals(Long.parseLong(row.get("DryingStarted").getValue().toString()))) {
}
}
// CalculatedStop:
// DryingCompleted:
// DryingCompleted:
// Check if response is given in millis
// Check if response is given in millis
try
{
try
{
...
@@ -481,8 +450,6 @@ public class DB {
...
@@ -481,8 +450,6 @@ public class DB {
}
}
// Getting manual measurement:
// Getting manual measurement:
// Adding days to search between
// Adding days to search between
String
date
=
formatedUtTidTork
.
split
(
" "
)[
0
];
String
date
=
formatedUtTidTork
.
split
(
" "
)[
0
];
...
@@ -529,18 +496,11 @@ public class DB {
...
@@ -529,18 +496,11 @@ public class DB {
*/
*/
//System.out.println("Inn formated: "+formatedInTidTork);
//System.out.println("Ut formated: "+formatedUtTidTork+"\n");
// 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
.
isEmpty
()
&&
!
formatedUtTidTork
.
isEmpty
()){
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
);
}
}
//System.out.printf("%s\t\t\t%s\n",formatedInTidTork,formatedUtTidTork);
}
}
// Defining a treemap to sort the data incrementally
// Defining a treemap to sort the data incrementally
...
@@ -566,6 +526,12 @@ public class DB {
...
@@ -566,6 +526,12 @@ public class DB {
}
}
/**
* This function push the manual moisture level
*
* @param moisture input parameter for measured value
* @throws Exception throws exception in case of error
*/
public
static
void
pushManMoisture
(
String
moisture
)
throws
Exception
{
public
static
void
pushManMoisture
(
String
moisture
)
throws
Exception
{
String
startTime
=
null
;
String
startTime
=
null
;
...
@@ -639,11 +605,8 @@ public class DB {
...
@@ -639,11 +605,8 @@ public class DB {
// Retrieves the results from the queryjob
// Retrieves the results from the queryjob
TableResult
result
=
HelpingFunctions
.
createQueryJob
(
sqlStatement
);
TableResult
result
=
HelpingFunctions
.
createQueryJob
(
sqlStatement
);
//System.out.println("InTidTork\t\t\tUtTidTork");
// Iterating through the results
// Iterating through the results
HelpingFunctions
.
iterateKwhValues
(
data
,
result
,
KWH_NAME_PARAMETER
,
KWH_TIMESTAMP_NAME_PARAMETER
);
HelpingFunctions
.
iterateKwhValues
(
data
,
result
,
KWH_NAME_PARAMETER
,
KWH_TIMESTAMP_NAME_PARAMETER
);
return
new
TreeMap
<>(
data
);
return
new
TreeMap
<>(
data
);
}
}
}
}
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