Skip to content

Commit

Permalink
Merge branch 'dev' into ms/#794-differentiate-between-different-power…
Browse files Browse the repository at this point in the history
…-types
  • Loading branch information
staudtMarius authored Nov 19, 2024
2 parents 9bdec0d + 9e0871d commit c26063d
Show file tree
Hide file tree
Showing 13 changed files with 230 additions and 258 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Updated `ExtEvSimulationClasses` [#898](https://github.com/ie3-institute/simona/issues/898)
- Refactoring of `ThermalGrid.energyGrid` to distinguish between demand of house and storage [#928](https://github.com/ie3-institute/simona/issues/928)
- Refactoring to use zeroKW and zeroKWH in thermal grid unit tests [#1023](https://github.com/ie3-institute/simona/issues/1023)
- Refactor `ResultFileHierarchy` [#1031](https://github.com/ie3-institute/simona/issues/1031)

### Fixed
- Fix rendering of references in documentation [#505](https://github.com/ie3-institute/simona/issues/505)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ object ResultEventListener extends Transformer3wResultSupport {

filePathFuture.map { fileName =>
val finalFileName =
fileName match {
fileName.toString match {
case name if name.endsWith(".csv.gz") && enableCompression =>
name.replace(".gz", "")
case name if name.endsWith(".csv") => name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ import ch.qos.logback.core.filter.Filter
import com.typesafe.scalalogging.LazyLogging
import org.slf4j.LoggerFactory

import java.io.File
import java.nio.file.Path
import scala.jdk.CollectionConverters._

object LogbackConfiguration extends LazyLogging {

def default(logPath: String): Unit = {
def default(logPath: Path): Unit = {
LoggerFactory.getILoggerFactory match {
case loggerContext: LoggerContext =>
val rootLogger = loggerContext.getLogger("root")
val log = logPath.concat(File.separator).concat("simona.log")
val log = logPath.resolve("simona.log")
// stop all appenders
rootLogger.iteratorForAppenders().asScala.foreach(_.stop())
/* Identify the filters of existing rolling file appender */
Expand Down Expand Up @@ -58,7 +58,7 @@ object LogbackConfiguration extends LazyLogging {
}

private def fileAppender(
logPath: String,
logPath: Path,
appenderName: String,
maybeFilterList: Option[Seq[Filter[ILoggingEvent]]],
loggerContext: LoggerContext,
Expand All @@ -70,7 +70,7 @@ object LogbackConfiguration extends LazyLogging {
layoutEncoder.start()

val fileAppender = new FileAppender[ILoggingEvent]
fileAppender.setFile(logPath)
fileAppender.setFile(logPath.toString)
fileAppender.setEncoder(layoutEncoder)
fileAppender.setContext(loggerContext)
fileAppender.setName(appenderName)
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/edu/ie3/simona/main/RunSimona.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ trait RunSimona[T <: SimonaSetup] extends LazyLogging {

private def printGoodbye(
successful: Boolean,
outputPath: String = "",
logOutputDir: Path,
): Unit = {
val myWords = Array(
"\"Vielleicht ist heute ein besonders guter Tag zum Sterben.\" - Worf (in Star Trek: Der erste Kontakt)",
Expand All @@ -78,7 +78,7 @@ trait RunSimona[T <: SimonaSetup] extends LazyLogging {
// to ensure that the link to the log is printed last
Thread.sleep(1000)

val path = Path.of(outputPath).resolve("simona.log").toUri
val path = logOutputDir.resolve("simona.log").toUri

logger.error(
s"Simulation stopped due to the occurrence of an error! The full log can be found here: $path"
Expand Down
17 changes: 4 additions & 13 deletions src/main/scala/edu/ie3/simona/sim/setup/SetupHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -202,25 +202,21 @@ trait SetupHelper extends LazyLogging {
/** Build the result file hierarchy based on the provided configuration file.
* The provided type safe config must be able to be parsed as
* [[SimonaConfig]], otherwise an exception is thrown
*
* @param config
* the configuration file
* @param createDirs
* if directories of the result file hierarchy should be created or not
* @return
* the resulting result file hierarchy
*/
def buildResultFileHierarchy(
config: TypesafeConfig,
createDirs: Boolean = true,
): ResultFileHierarchy = {
def buildResultFileHierarchy(config: TypesafeConfig): ResultFileHierarchy = {

val simonaConfig = SimonaConfig(config)

/* Determine the result models to write */
val modelsToWrite =
SetupHelper.allResultEntitiesToWrite(simonaConfig.simona.output)

val resultFileHierarchy = ResultFileHierarchy(
ResultFileHierarchy(
simonaConfig.simona.output.base.dir,
simonaConfig.simona.simulationName,
ResultEntityPathConfig(
Expand All @@ -230,15 +226,10 @@ trait SetupHelper extends LazyLogging {
simonaConfig.simona.simulationName,
),
),
config = Some(config),
addTimeStampToOutputDir =
simonaConfig.simona.output.base.addTimestampToOutputDir,
createDirs = createDirs,
)

// copy config data to output directory
ResultFileHierarchy.prepareDirectories(config, resultFileHierarchy)

resultFileHierarchy
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/scala/edu/ie3/simona/sim/setup/SimonaSetup.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import org.apache.pekko.actor.typed.ActorRef
import org.apache.pekko.actor.typed.scaladsl.ActorContext
import org.apache.pekko.actor.{ActorRef => ClassicRef}

import java.nio.file.Path

/** Trait that can be used to set up a customized simona simulation by providing
* implementations for all setup information required by a
* [[edu.ie3.simona.sim.SimonaSim]]. Most of the time, using or extending
Expand All @@ -40,7 +42,7 @@ trait SimonaSetup {

/** Directory of the log output.
*/
def logOutputDir: String
def logOutputDir: Path

/** Creates the runtime event listener
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import org.apache.pekko.actor.typed.scaladsl.adapter.{
}
import org.apache.pekko.actor.{ActorRef => ClassicRef}

import java.nio.file.Path
import java.util.UUID
import java.util.concurrent.LinkedBlockingQueue
import scala.jdk.CollectionConverters._
Expand All @@ -68,7 +69,7 @@ class SimonaStandaloneSetup(
override val args: Array[String],
) extends SimonaSetup {

override def logOutputDir: String = resultFileHierarchy.logOutputDir
override def logOutputDir: Path = resultFileHierarchy.logOutputDir

override def gridAgents(
context: ActorContext[_],
Expand Down
Loading

0 comments on commit c26063d

Please sign in to comment.