Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to use local files instead of download. #257

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,4 @@ testData/download
!testData/download/targetFolderExistsAndIsFile.zip

# Downloader productive folder
inputData/download
input/download
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Option to use local files instead of download [#256](https://github.com/ie3-institute/simBench2psdm/issues/256)


## [1.0.0] - 2021-08-03
### Added
- Basic functionality to convert SimBench data sets to [PowerSystemDataModel](https://github.com/ie3-institute/powersystemdatamodel)
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ext {

scalaVersion = '2.13'
scalaBinaryVersion = '2.13.14'
tscfgVersion = '0.9.986'
tscfgVersion = '1.0.0'
slf4jVersion = '2.0.13'

scriptsLocation = 'gradle' + File.separator + 'scripts' + File.separator //location of script plugins
Expand Down Expand Up @@ -87,8 +87,8 @@ dependencies {
implementation 'org.mockito:mockito-core:5.12.0' // mocking framework

// config //
implementation 'com.typesafe:config:+'
implementation "com.github.carueda:tscfg_2.13:${tscfgVersion}"
implementation 'com.typesafe:config:1.4.3'
implementation "com.github.carueda:tscfg_2.13:$tscfgVersion"

// cmd args parser //
implementation "com.github.scopt:scopt_${scalaVersion}:+"
Expand Down
2 changes: 1 addition & 1 deletion gradle/scripts/tscfg.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ task genConfigClass {
doLast {
def tscfgJarFile = project.file('build/tscfg-' + tscfgVersion + '.jar')
if (!tscfgJarFile.exists() || !tscfgJarFile.isFile()) {
download {
download.run {
src 'https://github.com/carueda/tscfg/releases/download/v' + tscfgVersion + '/tscfg-' + tscfgVersion + '.jar'
dest buildDir
}
Expand Down
File renamed without changes.
34 changes: 34 additions & 0 deletions input/config/localFileSourceConfig.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Simple config to convert only one simple lv grid
io {
input {
folder = "input/local/"

localFile = {
isZipped = true
}

csv = {
fileEncoding = "UTF-8"
fileEnding = ".csv"
separator = ";"
directoryHierarchy = false
}
}

output {
csv = {
fileEncoding = "UTF-8"
fileEnding = ".csv"
separator = ";"
directoryHierarchy = false
}

targetFolder = "convertedData/local/"
compress = false
}

# code for local files
simbenchCodes = [
"1-LV-rural1--0-no_sw"
]
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added input/local/1-LV-rural1--0-no_sw.zip
Binary file not shown.
15 changes: 12 additions & 3 deletions src/main/resources/config-template.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@ CsvConfig {
io {
simbenchCodes = ["String"]
input {
download.baseUrl = "String" | "http://141.51.193.167/simbench/gui/usecase/download"
download.folder = "String" | "inputData/download/"
download.failOnExistingFiles = "Boolean" | false
folder = "String" | "input/download/"

#@optional
localFile {
isZipped = "Boolean" | true
failOnExistingFiles = "Boolean" | false
}
#@optional
download {
baseUrl = "String" | "http://141.51.193.167/simbench/gui/usecase/download"
failOnExistingFiles = "Boolean" | false
}
csv = CsvConfig
}
output {
Expand Down
23 changes: 23 additions & 0 deletions src/main/scala/edu/ie3/simbench/config/ConfigValidator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ case object ConfigValidator {
@throws[SimbenchException]
private def checkValidity(io: SimbenchConfig.Io): Unit = {
checkSimbenchCodes(io.simbenchCodes)
checkFileSource(io.input)
}

/** Checks the validity of the provided codes with the help of the permissible
Expand All @@ -47,11 +48,33 @@ case object ConfigValidator {
*/
@throws[CodeValidationException]
private def checkSimbenchCodes(codes: List[java.lang.String]): Unit = {
if (codes.isEmpty) {
throw new SimbenchConfigException(s"No simbench codes were provided!")
}

for (code <- codes) {
SimbenchCode.isValid(code) match {
case Success(_) =>
case Failure(exception) => throw exception
}
}
}

@throws[SimbenchException]
private def checkFileSource(cfg: SimbenchConfig.Io.Input): Unit = {
val sources = Vector(
cfg.localFile,
cfg.download
).filter(_.isDefined)

sources.size match {
case 0 =>
throw new SimbenchConfigException(s"No file sources defined in: $cfg")
case 1 =>
case n =>
throw new SimbenchConfigException(
s"Too many file sources ($n) defined in: $cfg"
)
}
}
}
68 changes: 51 additions & 17 deletions src/main/scala/edu/ie3/simbench/config/SimbenchConfig.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// generated by tscfg 0.9.986 on Mon Aug 09 20:12:24 CEST 2021
// generated by tscfg 1.0.0 on Thu Aug 08 13:29:09 CEST 2024
// source: src/main/resources/config-template.conf

package edu.ie3.simbench.config
Expand Down Expand Up @@ -47,9 +47,8 @@ object SimbenchConfig {
$tsCfgValidator: $TsCfgValidator
): SimbenchConfig.Conversion = {
SimbenchConfig.Conversion(
removeSwitches = c.hasPathOrNull("removeSwitches") && c.getBoolean(
"removeSwitches"
)
removeSwitches =
c.hasPathOrNull("removeSwitches") && c.getBoolean("removeSwitches")
)
}
}
Expand All @@ -62,13 +61,14 @@ object SimbenchConfig {
object Io {
final case class Input(
csv: SimbenchConfig.CsvConfig,
download: SimbenchConfig.Io.Input.Download
download: scala.Option[SimbenchConfig.Io.Input.Download],
folder: java.lang.String,
localFile: scala.Option[SimbenchConfig.Io.Input.LocalFile]
)
object Input {
final case class Download(
baseUrl: java.lang.String,
failOnExistingFiles: scala.Boolean,
folder: java.lang.String
failOnExistingFiles: scala.Boolean
)
object Download {
def apply(
Expand All @@ -80,13 +80,30 @@ object SimbenchConfig {
baseUrl =
if (c.hasPathOrNull("baseUrl")) c.getString("baseUrl")
else "http://141.51.193.167/simbench/gui/usecase/download",
failOnExistingFiles =
c.hasPathOrNull("failOnExistingFiles") && c.getBoolean(
"failOnExistingFiles"
)
)
}
}

final case class LocalFile(
failOnExistingFiles: scala.Boolean,
isZipped: scala.Boolean
)
object LocalFile {
def apply(
c: com.typesafe.config.Config,
parentPath: java.lang.String,
$tsCfgValidator: $TsCfgValidator
): SimbenchConfig.Io.Input.LocalFile = {
SimbenchConfig.Io.Input.LocalFile(
failOnExistingFiles =
c.hasPathOrNull("failOnExistingFiles") && c.getBoolean(
"failOnExistingFiles"
),
folder =
if (c.hasPathOrNull("folder")) c.getString("folder")
else "inputData/download/"
isZipped = !c.hasPathOrNull("isZipped") || c.getBoolean("isZipped")
)
}
}
Expand All @@ -103,12 +120,29 @@ object SimbenchConfig {
parentPath + "csv.",
$tsCfgValidator
),
download = SimbenchConfig.Io.Input.Download(
if (c.hasPathOrNull("download")) c.getConfig("download")
else com.typesafe.config.ConfigFactory.parseString("download{}"),
parentPath + "download.",
$tsCfgValidator
)
download =
if (c.hasPathOrNull("download"))
scala.Some(
SimbenchConfig.Io.Input.Download(
c.getConfig("download"),
parentPath + "download.",
$tsCfgValidator
)
)
else None,
folder =
if (c.hasPathOrNull("folder")) c.getString("folder")
else "input/download/",
localFile =
if (c.hasPathOrNull("localFile"))
scala.Some(
SimbenchConfig.Io.Input.LocalFile(
c.getConfig("localFile"),
parentPath + "localFile.",
$tsCfgValidator
)
)
else None
)
}
}
Expand Down Expand Up @@ -208,7 +242,7 @@ object SimbenchConfig {
java.lang.String.valueOf(cv.unwrapped())
}

private final class $TsCfgValidator {
final class $TsCfgValidator {
private val badPaths =
scala.collection.mutable.ArrayBuffer[java.lang.String]()

Expand Down
1 change: 0 additions & 1 deletion src/main/scala/edu/ie3/simbench/io/Downloader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import edu.ie3.simbench.model.SimbenchCode

import scala.language.postfixOps
import scala.sys.process._
import scala.util.{Failure, Success, Try}

final case class Downloader(
downloadFolder: String,
Expand Down
8 changes: 7 additions & 1 deletion src/main/scala/edu/ie3/simbench/io/SimbenchReader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ final case class SimbenchReader(
* Await is okay here */
val modelClassToRawData = getFieldToValueMaps

if (modelClassToRawData.forall(_._2.isEmpty)) {
throw SimbenchDataModelException(
s"Model is empty. Please check the provided data."
)
}

/* Extracting all profiles */
val loadProfiles = buildModels(modelClassToRawData, LoadProfile)
val powerPlantProfiles = buildModels(modelClassToRawData, PowerPlantProfile)
Expand Down Expand Up @@ -330,7 +336,7 @@ final case class SimbenchReader(
read(clazz, fields)
}
),
Duration("10 s")
Duration("30 s")
)
.toMap
}
Expand Down
Loading