-
Notifications
You must be signed in to change notification settings - Fork 46
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
CSVExport exports data do not follow the column header #1002
Comments
Can you transform the MWE into a test? Once it is in the test suite, I think I can fix it quickly, but I'd like to prevent further regressions as much as possible. |
Labels do not necessarily align with actual data (you might extract one value per node, and the number of nodes may vary during a simulation), so the proposed solution won't work. I think that the culprit here is the transition between Scala's and Java's maps, which kills iteration order. If you force a LinkedHashMap and add the elements in order, does the exporter work? I checked why the bug did not appear with Kotlin exporters, apparently, they use >>> (1..1000).map { it to "ciao" }.toMap()::class.java
res0: java.lang.Class<out kotlin.collections.Map<kotlin.Int, kotlin.String>> = class java.util.LinkedHashMap |
Ah, right, I hadn't thought of that.
Yes (In particular I used TreeMap, but it makes no difference). It sounds to me like a workaround, so I did not mention that.
It could be a good idea! BTW scala-java converters are quite "tricky". When I call the method
Interesting, Scala instead uses HashMap by default (when you pass more than four values, otherwise the factory returns a specialized implementation of Map like Map1, Map2, Map3, etc.). |
A reasonable way to face this is the following:
I don't see why the warning should not arrive when you use Scala: in the end, it won't find any supported type. But yes, the documentation needs to be updated anyway. |
Yes, this solution seems reasonable to me. Another solution came up in my mind: what do you think if we enforce correct For instance, we can define another interface that enforces SortedMap as the return for extractData method: interface SortedExtractor<E: Any> : Extractor<E> {
override fun <T> extractData(....): SortedMap<String, E>
val columnNames: List<String>
} Or something like that. |
It does, I do not want to force |
#1004 contains a fix for this issue. Still, I'd like to see a test before merging, so if you could create a PR with a regression test, I'd be happy to merge and release the fix. Ideally, create a test in a branch of yours and open two PRs: one with |
…verifies the column alignment problem of CSVExport
## [12.1.6](12.1.5...12.1.6) (2021-12-28) ### Bug Fixes * require predictable iteration order for extractors in CSVExporter, fixes [#1002](#1002) ([838236a](838236a))
🎉 This issue has been resolved in version 12.1.6 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Bug overview
CSVExport
accepts a List ofExport
. Each of them can extract some data from the current state of Alchemist simulation.To do that,
Export
implementations need to definecolumnNames
andextractData
. In particular,extractData
is a Map that should link each column name with a value.The problem here is that there is a mismatch in the file exported from CSVExport from column names and their value.
Example
Suppose you have implemented an
Export
with this column name:And then you have implemented the
extractData
method returning a Map for each temperature:I excepted that the CSV that use this kind of export is structured as:
But, the file produced is something like:
How to reproduce
Here there is an MWE where the problem is shown.
So:
1- clone the repository
2- run
./gradlew runAllBatch
3- look at data/ to verify that the export file is effectively wrong
Possible problem
CSVExport
prints the first line usingcolumnNames
but then it takes theextractData
result directly without following the sameorder of the
columnNames
value:column names part
extract data part
Possible solution
Mapping the column names with the output produced by the extractor.
Probably it is not the best solution in Kotlin so far, but it is just to underline the problem.
The text was updated successfully, but these errors were encountered: