Skip to content

Commit

Permalink
add: use betterfiles for writing outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
anonymax25 committed Jan 9, 2022
1 parent 09a4331 commit b61ab04
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 27 deletions.
6 changes: 5 additions & 1 deletion projet/funprog-al/src/main/scala/progfun/InputLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package fr.esgi.al.funprog
import better.files._
import fr.esgi.al.funprog._

final case class DonneesIncorectesException(
val message: String
) extends Exception(message)

@SuppressWarnings(Array("org.wartremover.warts.Throw"))
class InputLoader(filePath: String) {

Expand Down Expand Up @@ -60,7 +64,7 @@ class InputLoader(filePath: String) {
l(1).split("").toList.map(s => Action.getActionFromString(s))

new Mower(
index,
index + 1,
new Point(
coords(0).toInt,
coords(1).toInt
Expand Down
28 changes: 6 additions & 22 deletions projet/funprog-al/src/main/scala/progfun/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,14 @@ package fr.esgi.al.funprog
import com.typesafe.config.{Config, ConfigFactory}
import play.api.libs.json._
import fr.esgi.al.funprog._
import java.io._

final case class DonneesIncorectesException(
val message: String
) extends Exception(message)
import better.files._

object Main extends App {

def writeFile(filename: String, s: String): Unit = {
val file = new File(filename)
val bw = new BufferedWriter(new FileWriter(file))
bw.write(s)
bw.close()
}

val conf: Config = ConfigFactory.load()

val inputLoader = new InputLoader(conf.getString("application.input-file"))

val inputs = inputLoader.parseInput()

val x: Int = inputs._1
val y: Int = inputs._2
val mowers: List[Mower] = inputs._3
Expand All @@ -38,12 +25,9 @@ object Main extends App {

val executed = Environnement.execute(env)

writeFile(
conf.getString("application.output-json-file"),
Json.prettyPrint(executed.toJson)
)
writeFile(
conf.getString("application.output-csv-file"),
CSVExporter.export(executed.mowers)
)
val json = File(conf.getString("application.output-json-file"))
json.createIfNotExists().overwrite(Json.prettyPrint(executed.toJson))

val csv = File(conf.getString("application.output-csv-file"))
csv.createIfNotExists().overwrite(CSVExporter.export(executed.mowers))
}
4 changes: 2 additions & 2 deletions projet/funprog-al/tmp/output.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
numéro,début_x,début_y,début_direction,fin_x,fin_y,fin_direction,instructions
0,1,2,N,1,3,N,GAGAGAGAA
1,3,3,E,5,1,E,AADAADADDA
1,1,2,N,1,3,N,GAGAGAGAA
2,3,3,E,5,1,E,AADAADADDA
4 changes: 2 additions & 2 deletions projet/funprog-al/tmp/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"y" : 5
},
"tondeuse" : [ {
"id" : 0,
"id" : 1,
"debut" : {
"point" : {
"x" : 1,
Expand All @@ -21,7 +21,7 @@
"direction" : "N"
}
}, {
"id" : 1,
"id" : 2,
"debut" : {
"point" : {
"x" : 3,
Expand Down

0 comments on commit b61ab04

Please sign in to comment.