Clean up
This commit is contained in:
@@ -6,6 +6,7 @@ import scala.io.Source
|
||||
|
||||
val API_KEY = Source.fromFile("apiKey.txt").getLines().mkString
|
||||
|
||||
object Main {
|
||||
def collectData(
|
||||
dataSources: Map[Int, String]
|
||||
): Unit = {
|
||||
@@ -14,6 +15,7 @@ def collectData(
|
||||
val startTime = now.minusMonths(3).toString().concat("Z")
|
||||
val endTime = now.toString.concat("Z")
|
||||
|
||||
println("Collecting data...")
|
||||
for ((k, v) <- dataSources) {
|
||||
val url = new URL(
|
||||
s"https://api.fingrid.fi/v1/variable/$k/events/csv?start_time=$startTime&end_time=$endTime"
|
||||
@@ -42,9 +44,11 @@ def collectData(
|
||||
)
|
||||
}
|
||||
}
|
||||
println("Collection completed")
|
||||
}
|
||||
|
||||
def readData(filePath: String): Unit = {
|
||||
println("Reading data...")
|
||||
val bufferedSource = io.Source.fromFile(filePath)
|
||||
for (line <- bufferedSource.getLines) {
|
||||
val cols = line.split(",").map(_.trim)
|
||||
@@ -53,13 +57,8 @@ def readData(filePath: String): Unit = {
|
||||
bufferedSource.close
|
||||
}
|
||||
|
||||
def checkSources(filePath: String): Unit = {
|
||||
val bufferedSource = io.Source.fromFile(filePath)
|
||||
for (line <- bufferedSource.getLines) {
|
||||
val cols = line.split(",").map(_.trim)
|
||||
println(s"${cols(0)}\t${cols(1)}\t${cols(2)}")
|
||||
}
|
||||
bufferedSource.close
|
||||
def modifySources(filePath: String): Unit = {
|
||||
readData(filePath)
|
||||
|
||||
print("Enter your choice:\n1) Modify\n2) Exit\n")
|
||||
val choice = readLine()
|
||||
@@ -69,46 +68,30 @@ def checkSources(filePath: String): Unit = {
|
||||
"Choose the source to modify:\n1) Wind\n2) Hydro\n3) Nuclear\n4) Exit\n"
|
||||
)
|
||||
val choice2 = readLine()
|
||||
print("Enter the new value: ")
|
||||
val newValue = readLine()
|
||||
val lines = Source.fromFile(filePath).getLines.toList
|
||||
val temp = lines(1).split(",")
|
||||
val pw = new java.io.PrintWriter(filePath)
|
||||
choice2 match {
|
||||
case "1" =>
|
||||
print("Enter the new value: ")
|
||||
val newValue = readLine()
|
||||
val lines = Source.fromFile(filePath).getLines.toList
|
||||
val temp = lines(1).split(",")
|
||||
val newLines = lines.updated(1, s"$newValue,${temp(1)},${temp(2)}")
|
||||
val pw = new java.io.PrintWriter(filePath)
|
||||
newLines.foreach(pw.println)
|
||||
pw.close()
|
||||
println("Value updated")
|
||||
case "2" =>
|
||||
print("Enter the new value: ")
|
||||
val newValue = readLine()
|
||||
val lines = Source.fromFile(filePath).getLines.toList
|
||||
val temp = lines(1).split(",")
|
||||
val newLines = lines.updated(1, s"${temp(0)},$newValue,${temp(2)}")
|
||||
val pw = new java.io.PrintWriter(filePath)
|
||||
newLines.foreach(pw.println)
|
||||
pw.close()
|
||||
println("Value updated")
|
||||
case "3" =>
|
||||
print("Enter the new value: ")
|
||||
val newValue = readLine()
|
||||
val lines = Source.fromFile(filePath).getLines.toList
|
||||
val temp = lines(1).split(",")
|
||||
val newLines = lines.updated(1, s"${temp(0)},${temp(1)},$newValue")
|
||||
val pw = new java.io.PrintWriter(filePath)
|
||||
newLines.foreach(pw.println)
|
||||
pw.close()
|
||||
println("Value updated")
|
||||
case "4" =>
|
||||
println("Exiting...")
|
||||
System.exit(0)
|
||||
return
|
||||
case _ =>
|
||||
println("Invalid choice")
|
||||
}
|
||||
pw.close()
|
||||
println("Value updated")
|
||||
case "2" =>
|
||||
println("Exiting...")
|
||||
System.exit(0)
|
||||
return
|
||||
case _ =>
|
||||
println("Invalid choice")
|
||||
}
|
||||
@@ -125,25 +108,8 @@ def main(args: Array[String]): Unit = {
|
||||
|
||||
choice match {
|
||||
case "1" =>
|
||||
// println("Energy sources:")
|
||||
// println("1) Wind\n2) Hydro\n3) Nuclear\n4) All")
|
||||
// print("Enter your choice: ")
|
||||
// val choice2 = readLine()
|
||||
// choice2 match {
|
||||
// case "1" =>
|
||||
// println("Wind")
|
||||
// case "2" =>
|
||||
// println("Hydro")
|
||||
// case "3" =>
|
||||
// println("Nuclear")
|
||||
// case "4" =>
|
||||
// println("All")
|
||||
// case _ =>
|
||||
// println("Invalid choice")
|
||||
// }
|
||||
checkSources("sources.csv")
|
||||
modifySources("sources.csv")
|
||||
case "2" =>
|
||||
println("Collecting data...")
|
||||
collectData(
|
||||
Map(
|
||||
188 -> "nuclear.csv",
|
||||
@@ -152,9 +118,7 @@ def main(args: Array[String]): Unit = {
|
||||
192 -> "data.csv"
|
||||
)
|
||||
)
|
||||
println("Collection completed")
|
||||
case "3" =>
|
||||
println("Viewing data...")
|
||||
readData("data.csv")
|
||||
case "4" =>
|
||||
println("Analyzing data...")
|
||||
@@ -166,3 +130,4 @@ def main(args: Array[String]): Unit = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user