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
a1f9e2b8
Commit
a1f9e2b8
authored
3 years ago
by
Eilert Tunheim
Browse files
Options
Downloads
Patches
Plain Diff
Started implementing the correct dates into kwh function
parent
33639486
No related branches found
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
+44
-10
44 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
44 additions
and
10 deletions
src/main/java/com/application/DB/DB.java
+
44
−
10
View file @
a1f9e2b8
...
...
@@ -48,9 +48,9 @@ public class DB {
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
//
getKwh();
getKwh
();
//getName();
getZeroPointDate
();
//
getZeroPointDate();
}
...
...
@@ -107,21 +107,38 @@ public class DB {
*/
public
static
Map
<
String
,
Number
>
getKwh
()
throws
Exception
{
/*
for (Map.Entry<String, String> entry : getZeroPointDate().entrySet()) {
//System.out.printf("Intid: \t%s\t\t\tOuttid: \t%s\n",entry.getKey(),entry.getValue());
// Preparing a query statement
final String sqlStatement = "SELECT TimeStamp, VariantValue " +
"FROM sf-drying-optimization.124.int_sd_winccsensordata " +
"WHERE TimeStamp BETWEEN " + entry.getKey() + " AND " + entry.getValue() +
"ORDER BY TimeStamp ASC";// Preparing a query statement
}
*/
// Initializing the data map to store the results
Map
<
String
,
Number
>
data
=
new
HashMap
<>();
// Preparing a query statement
final
String
sqlStatement
=
"SELECT TimeStamp, VariantValue "
+
"FROM sf-drying-optimization.124.int_sd_winccsensordata "
+
"WHERE TimeStamp BETWEEN \"2021-01-30 08:51:03\" "
+
"AND \"2021-02-15 11:10:09\" ORDER BY TimeStamp ASC"
;
// Creates a job configuration
queryJob
=
getJob
(
QueryJobConfiguration
.
newBuilder
(
sqlStatement
).
build
());
// Iterating through the results
TableResult
result
=
queryJob
.
getQueryResults
();
System
.
out
.
println
(
"
InTidTork \t UtTidTork
"
);
System
.
out
.
println
(
"
Timestamp \t KWh
"
);
for
(
FieldValueList
row
:
result
.
iterateAll
())
{
// Kwh
...
...
@@ -136,8 +153,11 @@ public class DB {
data
.
put
(
formatedTimeStamp
,
variantValue
);
}
//NavigableMap<String, Number> sortedData = new TreeMap<>(data);
return
data
;
for
(
Map
.
Entry
<
String
,
Number
>
entry
:
data
.
entrySet
())
{
System
.
out
.
printf
(
"Timestamp: \t%s\t\t\tKWh: \t%s\n"
,
entry
.
getKey
(),
entry
.
getValue
());
}
return
data
;
}
/**
...
...
@@ -183,6 +203,18 @@ public class DB {
//return data;
}
/**
* This function retrieves the intidtork and uttidtork dates from the database.
* This variables are not sorted and thus this function iterates through the data in order to
* find the last intidtork date and the corresponding uttidtork data.
* These values will be used to reset the kwh.
*
* A possible extention of this function could be to limit the number of dring periodes.
* This could be done with counting the number of entries in
*
* @return A hashmap containing the correct intidtork and outtidtork dates
* @throws Exception Throws exception if an error occurs
*/
private
static
Map
<
String
,
String
>
getZeroPointDate
()
throws
Exception
{
// Initializing a date format in the data type DateTimeFormatter
...
...
@@ -232,10 +264,12 @@ public class DB {
formatedUtTidTork
=
""
;
}
// Checks if intidtork or outtidtork is empty, if so they are ignored and not added to the list
if
(!
formatedInTidTork
.
equals
(
""
)
&&
!
formatedUtTidTork
.
equals
(
""
)){
// Adds the data to the dates map
dates
.
put
(
formatedInTidTork
,
formatedUtTidTork
);
}
//System.out.printf("%s\t\t\t%s\n",formatedInTidTork,formatedUtTidTork);
// Adds the data to the dates map
dates
.
put
(
formatedInTidTork
,
formatedUtTidTork
);
}
// Defining a treemap to sort through the data
...
...
@@ -265,7 +299,7 @@ public class DB {
// if so the current date is the last intidtork date and
// is the one we will use in order to reset the kwh.
if
(
next
.
compareTo
(
formatedDateNowPlus
)
>
0
){
// Storing the dates that will be used for resetting kwh
's
.
// Storing the dates that will be used for resetting kwh.
sortedDates
.
put
(
inTid
,
utTid
);
}
}
catch
(
NullPointerException
e
){
...
...
This diff is collapsed.
Click to expand it.
target/classes/com/application/DB/DB.class
+
0
−
0
View file @
a1f9e2b8
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