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