Update code

This commit is contained in:
AndrewTrieu
2023-05-03 12:48:41 +03:00
parent 0fdaceb28a
commit f2c272fb77
2 changed files with 62 additions and 44 deletions

View File

@@ -33,7 +33,6 @@ sequenceDiagram
System->>Fingrid API: Get data
Fingrid API-->>System: Return data
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.
@@ -119,5 +118,7 @@ classDiagram
+alertUser()
+scanSystem(data: List[String])
}
```
## Video

View File

@@ -88,6 +88,7 @@ object Main {
): Unit = {
// Read the energy sources
println("Reading sources...")
try {
val bufferedSource = Source.fromFile(energySources)
def readSourcesHelper(lines: Iterator[String]): Unit = {
if (lines.hasNext) {
@@ -99,6 +100,11 @@ object Main {
}
readSourcesHelper(bufferedSource.getLines)
bufferedSource.close
} catch {
case e: Exception =>
println("No sources found")
return
}
print("Enter your choice:\n1) Modify\n2) Exit\n")
val choice = readLine()
@@ -266,6 +272,7 @@ object Main {
"Sources:\n1) Wind\n2) Hydro\n3) Nuclear\n4) All\n5) Exit\nEnter your choice: "
)
val choice = readLine()
try {
val bufferedSource = choice match {
case "1" =>
Source.fromFile("wind.csv")
@@ -284,6 +291,11 @@ object Main {
val data = bufferedSource.getLines.toList
bufferedSource.close
data
} catch {
case e: Exception =>
println("File not found")
null
}
}
// Sort the data by timestamp or value
@@ -360,6 +372,7 @@ object Main {
// Alert user if energy production is below the threshold
def alertUser(): Unit = {
try {
val sources = dataSources.values.toList.dropRight(1)
sources.map { source =>
val bufferedSource = Source.fromFile(source)
@@ -376,10 +389,14 @@ object Main {
}
if (alert) {
println(
s"ALERT: ${source} has production values below the threshold of ${alertThreshold}MW. Please scan systems for details!"
s"ALERT: ${source} has production values below the threshold of ${alertThreshold}MW. Please scan system for details!"
)
}
}
} catch {
case e: Exception =>
return
}
}
// Scan data for anomalies