Skip to content

Commit

Permalink
Merge pull request #1177 from hiqua/fix_csv_exporter
Browse files Browse the repository at this point in the history
Use the value of the Entry during CSV export
  • Loading branch information
iSoron authored Nov 6, 2021
2 parents 181290a + 7776093 commit ba59dc7
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 15 deletions.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2015-01-25,0.0000
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
2015-01-25,2
2015-01-24,0
2015-01-23,1
2015-01-22,2
2015-01-21,2
2015-01-20,2
2015-01-19,1
2015-01-18,1
2015-01-17,2
2015-01-16,2
10 changes: 10 additions & 0 deletions uhabits-core/assets/test/csv_export/002 Wake up early/Scores.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
2015-01-25,0.2557
2015-01-24,0.2226
2015-01-23,0.1991
2015-01-22,0.1746
2015-01-21,0.1379
2015-01-20,0.0995
2015-01-19,0.0706
2015-01-18,0.0515
2015-01-17,0.0315
2015-01-16,0.0107
11 changes: 11 additions & 0 deletions uhabits-core/assets/test/csv_export/Checkmarks.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Date,Meditate,Wake up early,
2015-01-25,-1,2,
2015-01-24,-1,0,
2015-01-23,-1,1,
2015-01-22,-1,2,
2015-01-21,-1,2,
2015-01-20,-1,2,
2015-01-19,-1,1,
2015-01-18,-1,1,
2015-01-17,-1,2,
2015-01-16,-1,2,
3 changes: 3 additions & 0 deletions uhabits-core/assets/test/csv_export/Habits.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Position,Name,Question,Description,NumRepetitions,Interval,Color
001,Meditate,Did you meditate this morning?,,1,1,#FF8F00
002,Wake up early,Did you wake up before 6am?,,2,3,#00897B
11 changes: 11 additions & 0 deletions uhabits-core/assets/test/csv_export/Scores.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Date,Meditate,Wake up early,
2015-01-25,0.0000,0.2557,
2015-01-24,0.0000,0.2226,
2015-01-23,0.0000,0.1991,
2015-01-22,0.0000,0.1746,
2015-01-21,0.0000,0.1379,
2015-01-20,0.0000,0.0995,
2015-01-19,0.0000,0.0706,
2015-01-18,0.0000,0.0515,
2015-01-17,0.0000,0.0315,
2015-01-16,0.0000,0.0107,
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class HabitsCSVExporter(
checksWriter.write(sb.toString())
scoresWriter.write(sb.toString())
for (j in selectedHabits.indices) {
checksWriter.write(checkmarks[j][i].toString())
checksWriter.write(checkmarks[j][i].value.toString())
checksWriter.write(delimiter)
val score = String.format(Locale.US, "%.4f", scores[j][i].value)
scoresWriter.write(score)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,15 @@ import java.util.zip.ZipFile

class HabitsCSVExporterTest : BaseUnitTest() {
private lateinit var baseDir: File

@Before
@Throws(Exception::class)
override fun setUp() {
super.setUp()
habitList.add(fixtures.createShortHabit())
habitList.add(fixtures.createEmptyHabit())
baseDir = Files.createTempDirectory("csv").toFile()
}

@Throws(Exception::class)
override fun tearDown() {
FileUtils.deleteDirectory(baseDir)
super.tearDown()
baseDir.deleteOnExit()
}

@Test
Expand All @@ -63,14 +59,20 @@ class HabitsCSVExporterTest : BaseUnitTest() {
assertAbsolutePathExists(filename)
val archive = File(filename)
unzip(archive)
assertPathExists("Habits.csv")
assertPathExists("001 Meditate/Checkmarks.csv")
assertPathExists("001 Meditate/Scores.csv")
assertPathExists("002 Wake up early")
assertPathExists("002 Wake up early/Checkmarks.csv")
assertPathExists("002 Wake up early/Scores.csv")
assertPathExists("Checkmarks.csv")
assertPathExists("Scores.csv")
val filesToCheck = arrayOf(
"001 Meditate/Checkmarks.csv",
"001 Meditate/Scores.csv",
"002 Wake up early/Checkmarks.csv",
"002 Wake up early/Scores.csv",
"Checkmarks.csv",
"Habits.csv",
"Scores.csv"
)

for (file in filesToCheck) {
assertPathExists(file)
assertFileAndReferenceAreEqual(file)
}
}

@Throws(IOException::class)
Expand Down Expand Up @@ -104,4 +106,18 @@ class HabitsCSVExporterTest : BaseUnitTest() {
file.exists()
)
}

private fun assertFileAndReferenceAreEqual(s: String) {
val assetFilename = String.format("csv_export/%s", s)
val file = File.createTempFile("asset", "")
file.deleteOnExit()
copyAssetToFile(assetFilename, file)

assertTrue(
FileUtils.contentEquals(
file,
File(String.format("%s/%s", baseDir.absolutePath, s))
)
)
}
}

0 comments on commit ba59dc7

Please sign in to comment.