Skip to content

Commit ba59dc7

Browse files
authored
Merge pull request #1177 from hiqua/fix_csv_exporter
Use the value of the Entry during CSV export
2 parents 181290a + 7776093 commit ba59dc7

File tree

9 files changed

+77
-15
lines changed

9 files changed

+77
-15
lines changed

uhabits-core/assets/test/csv_export/001 Meditate/Checkmarks.csv

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2015-01-25,0.0000
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2015-01-25,2
2+
2015-01-24,0
3+
2015-01-23,1
4+
2015-01-22,2
5+
2015-01-21,2
6+
2015-01-20,2
7+
2015-01-19,1
8+
2015-01-18,1
9+
2015-01-17,2
10+
2015-01-16,2
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2015-01-25,0.2557
2+
2015-01-24,0.2226
3+
2015-01-23,0.1991
4+
2015-01-22,0.1746
5+
2015-01-21,0.1379
6+
2015-01-20,0.0995
7+
2015-01-19,0.0706
8+
2015-01-18,0.0515
9+
2015-01-17,0.0315
10+
2015-01-16,0.0107
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Date,Meditate,Wake up early,
2+
2015-01-25,-1,2,
3+
2015-01-24,-1,0,
4+
2015-01-23,-1,1,
5+
2015-01-22,-1,2,
6+
2015-01-21,-1,2,
7+
2015-01-20,-1,2,
8+
2015-01-19,-1,1,
9+
2015-01-18,-1,1,
10+
2015-01-17,-1,2,
11+
2015-01-16,-1,2,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Position,Name,Question,Description,NumRepetitions,Interval,Color
2+
001,Meditate,Did you meditate this morning?,,1,1,#FF8F00
3+
002,Wake up early,Did you wake up before 6am?,,2,3,#00897B
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Date,Meditate,Wake up early,
2+
2015-01-25,0.0000,0.2557,
3+
2015-01-24,0.0000,0.2226,
4+
2015-01-23,0.0000,0.1991,
5+
2015-01-22,0.0000,0.1746,
6+
2015-01-21,0.0000,0.1379,
7+
2015-01-20,0.0000,0.0995,
8+
2015-01-19,0.0000,0.0706,
9+
2015-01-18,0.0000,0.0515,
10+
2015-01-17,0.0000,0.0315,
11+
2015-01-16,0.0000,0.0107,

uhabits-core/src/jvmMain/java/org/isoron/uhabits/core/io/HabitsCSVExporter.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class HabitsCSVExporter(
167167
checksWriter.write(sb.toString())
168168
scoresWriter.write(sb.toString())
169169
for (j in selectedHabits.indices) {
170-
checksWriter.write(checkmarks[j][i].toString())
170+
checksWriter.write(checkmarks[j][i].value.toString())
171171
checksWriter.write(delimiter)
172172
val score = String.format(Locale.US, "%.4f", scores[j][i].value)
173173
scoresWriter.write(score)

uhabits-core/src/jvmTest/java/org/isoron/uhabits/core/io/HabitsCSVExporterTest.kt

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,15 @@ import java.util.zip.ZipFile
3434

3535
class HabitsCSVExporterTest : BaseUnitTest() {
3636
private lateinit var baseDir: File
37+
3738
@Before
3839
@Throws(Exception::class)
3940
override fun setUp() {
4041
super.setUp()
4142
habitList.add(fixtures.createShortHabit())
4243
habitList.add(fixtures.createEmptyHabit())
4344
baseDir = Files.createTempDirectory("csv").toFile()
44-
}
45-
46-
@Throws(Exception::class)
47-
override fun tearDown() {
48-
FileUtils.deleteDirectory(baseDir)
49-
super.tearDown()
45+
baseDir.deleteOnExit()
5046
}
5147

5248
@Test
@@ -63,14 +59,20 @@ class HabitsCSVExporterTest : BaseUnitTest() {
6359
assertAbsolutePathExists(filename)
6460
val archive = File(filename)
6561
unzip(archive)
66-
assertPathExists("Habits.csv")
67-
assertPathExists("001 Meditate/Checkmarks.csv")
68-
assertPathExists("001 Meditate/Scores.csv")
69-
assertPathExists("002 Wake up early")
70-
assertPathExists("002 Wake up early/Checkmarks.csv")
71-
assertPathExists("002 Wake up early/Scores.csv")
72-
assertPathExists("Checkmarks.csv")
73-
assertPathExists("Scores.csv")
62+
val filesToCheck = arrayOf(
63+
"001 Meditate/Checkmarks.csv",
64+
"001 Meditate/Scores.csv",
65+
"002 Wake up early/Checkmarks.csv",
66+
"002 Wake up early/Scores.csv",
67+
"Checkmarks.csv",
68+
"Habits.csv",
69+
"Scores.csv"
70+
)
71+
72+
for (file in filesToCheck) {
73+
assertPathExists(file)
74+
assertFileAndReferenceAreEqual(file)
75+
}
7476
}
7577

7678
@Throws(IOException::class)
@@ -104,4 +106,18 @@ class HabitsCSVExporterTest : BaseUnitTest() {
104106
file.exists()
105107
)
106108
}
109+
110+
private fun assertFileAndReferenceAreEqual(s: String) {
111+
val assetFilename = String.format("csv_export/%s", s)
112+
val file = File.createTempFile("asset", "")
113+
file.deleteOnExit()
114+
copyAssetToFile(assetFilename, file)
115+
116+
assertTrue(
117+
FileUtils.contentEquals(
118+
file,
119+
File(String.format("%s/%s", baseDir.absolutePath, s))
120+
)
121+
)
122+
}
107123
}

0 commit comments

Comments
 (0)