Update code
This commit is contained in:
@@ -33,7 +33,6 @@ sequenceDiagram
|
|||||||
System->>Fingrid API: Get data
|
System->>Fingrid API: Get data
|
||||||
Fingrid API-->>System: Return data
|
Fingrid API-->>System: Return data
|
||||||
System->>Files: Store data in files
|
System->>Files: Store data in files
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
- The system provides a view of the power plant's energy generation and storage capacity, allowing operators to adjust the power plant's operation as needed. This view shows the data stored in the file.
|
- The system provides a view of the power plant's energy generation and storage capacity, allowing operators to adjust the power plant's operation as needed. This view shows the data stored in the file.
|
||||||
@@ -119,5 +118,7 @@ classDiagram
|
|||||||
+alertUser()
|
+alertUser()
|
||||||
+scanSystem(data: List[String])
|
+scanSystem(data: List[String])
|
||||||
}
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Video
|
||||||
|
|
||||||
```
|
|
||||||
@@ -88,17 +88,23 @@ object Main {
|
|||||||
): Unit = {
|
): Unit = {
|
||||||
// Read the energy sources
|
// Read the energy sources
|
||||||
println("Reading sources...")
|
println("Reading sources...")
|
||||||
val bufferedSource = Source.fromFile(energySources)
|
try {
|
||||||
def readSourcesHelper(lines: Iterator[String]): Unit = {
|
val bufferedSource = Source.fromFile(energySources)
|
||||||
if (lines.hasNext) {
|
def readSourcesHelper(lines: Iterator[String]): Unit = {
|
||||||
val line = lines.next()
|
if (lines.hasNext) {
|
||||||
val cols = line.split(",").map(_.trim)
|
val line = lines.next()
|
||||||
println(s"${cols(0)}\t${cols(1)}\t${cols(2)}")
|
val cols = line.split(",").map(_.trim)
|
||||||
readSourcesHelper(lines)
|
println(s"${cols(0)}\t${cols(1)}\t${cols(2)}")
|
||||||
|
readSourcesHelper(lines)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
readSourcesHelper(bufferedSource.getLines)
|
||||||
|
bufferedSource.close
|
||||||
|
} catch {
|
||||||
|
case e: Exception =>
|
||||||
|
println("No sources found")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
readSourcesHelper(bufferedSource.getLines)
|
|
||||||
bufferedSource.close
|
|
||||||
|
|
||||||
print("Enter your choice:\n1) Modify\n2) Exit\n")
|
print("Enter your choice:\n1) Modify\n2) Exit\n")
|
||||||
val choice = readLine()
|
val choice = readLine()
|
||||||
@@ -266,24 +272,30 @@ object Main {
|
|||||||
"Sources:\n1) Wind\n2) Hydro\n3) Nuclear\n4) All\n5) Exit\nEnter your choice: "
|
"Sources:\n1) Wind\n2) Hydro\n3) Nuclear\n4) All\n5) Exit\nEnter your choice: "
|
||||||
)
|
)
|
||||||
val choice = readLine()
|
val choice = readLine()
|
||||||
val bufferedSource = choice match {
|
try {
|
||||||
case "1" =>
|
val bufferedSource = choice match {
|
||||||
Source.fromFile("wind.csv")
|
case "1" =>
|
||||||
case "2" =>
|
Source.fromFile("wind.csv")
|
||||||
Source.fromFile("hydro.csv")
|
case "2" =>
|
||||||
case "3" =>
|
Source.fromFile("hydro.csv")
|
||||||
Source.fromFile("nuclear.csv")
|
case "3" =>
|
||||||
case "4" =>
|
Source.fromFile("nuclear.csv")
|
||||||
Source.fromFile("data.csv")
|
case "4" =>
|
||||||
case "5" =>
|
Source.fromFile("data.csv")
|
||||||
return null
|
case "5" =>
|
||||||
case _ =>
|
return null
|
||||||
println("Invalid choice")
|
case _ =>
|
||||||
|
println("Invalid choice")
|
||||||
|
null
|
||||||
|
}
|
||||||
|
val data = bufferedSource.getLines.toList
|
||||||
|
bufferedSource.close
|
||||||
|
data
|
||||||
|
} catch {
|
||||||
|
case e: Exception =>
|
||||||
|
println("File not found")
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
val data = bufferedSource.getLines.toList
|
|
||||||
bufferedSource.close
|
|
||||||
data
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort the data by timestamp or value
|
// Sort the data by timestamp or value
|
||||||
@@ -360,25 +372,30 @@ object Main {
|
|||||||
|
|
||||||
// Alert user if energy production is below the threshold
|
// Alert user if energy production is below the threshold
|
||||||
def alertUser(): Unit = {
|
def alertUser(): Unit = {
|
||||||
val sources = dataSources.values.toList.dropRight(1)
|
try {
|
||||||
sources.map { source =>
|
val sources = dataSources.values.toList.dropRight(1)
|
||||||
val bufferedSource = Source.fromFile(source)
|
sources.map { source =>
|
||||||
val data = bufferedSource.getLines.toList
|
val bufferedSource = Source.fromFile(source)
|
||||||
bufferedSource.close
|
val data = bufferedSource.getLines.toList
|
||||||
val alert = data.drop(1).foldLeft(false) { (acc, line) =>
|
bufferedSource.close
|
||||||
val cols = line.split(",").map(_.trim)
|
val alert = data.drop(1).foldLeft(false) { (acc, line) =>
|
||||||
val value = cols(2).toDouble
|
val cols = line.split(",").map(_.trim)
|
||||||
if (value < alertThreshold) {
|
val value = cols(2).toDouble
|
||||||
true
|
if (value < alertThreshold) {
|
||||||
} else {
|
true
|
||||||
acc
|
} else {
|
||||||
|
acc
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (alert) {
|
||||||
|
println(
|
||||||
|
s"ALERT: ${source} has production values below the threshold of ${alertThreshold}MW. Please scan system for details!"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (alert) {
|
} catch {
|
||||||
println(
|
case e: Exception =>
|
||||||
s"ALERT: ${source} has production values below the threshold of ${alertThreshold}MW. Please scan systems for details!"
|
return
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user