Compare commits

...

5 Commits

@ -36,7 +36,7 @@ Updating gradle might fix this, so try again in the future to remove this and ru
If this doesn't produce any warning, try to remove it.
*/
kotlin {
jvmToolchain(11)
jvmToolchain(17)
}
android {
@ -79,11 +79,11 @@ android {
compileOptions {
isCoreLibraryDesugaringEnabled = true
targetCompatibility(JavaVersion.VERSION_11)
sourceCompatibility(JavaVersion.VERSION_11)
targetCompatibility(JavaVersion.VERSION_17)
sourceCompatibility(JavaVersion.VERSION_17)
}
kotlinOptions.jvmTarget = JavaVersion.VERSION_11.toString()
kotlinOptions.jvmTarget = JavaVersion.VERSION_17.toString()
buildFeatures.viewBinding = true
lint.abortOnError = false
}

@ -204,7 +204,7 @@ class RingView : View {
val res = StyledResources(context)
if (backgroundColor == null) backgroundColor = res.getColor(R.attr.cardBgColor)
if (inactiveColor == null) inactiveColor = res.getColor(R.attr.contrast100)
inactiveColor = setAlpha(inactiveColor!!, 0.1f)
inactiveColor = setAlpha(inactiveColor!!, 0.15f)
rect = RectF()
}

@ -126,8 +126,9 @@
<item name="highlightedBackgroundColor">@color/black</item>
<item name="contrast0">@color/black</item>
<item name="contrast20">@color/grey_900</item>
<item name="contrast60">@color/grey_700</item>
<item name="contrast80">@color/grey_700</item>
<item name="contrast40">@color/grey_800</item>
<item name="contrast60">@color/grey_500</item>
<item name="contrast80">@color/grey_400</item>
<item name="contrast100">@color/grey_200</item>
<item name="selectedBackground">@drawable/selected_box</item>
<item name="textColorAlertDialogListItem">@color/grey_100</item>

@ -0,0 +1 @@
Date,Value,Notes
1 Date Value Notes
1 Date Value Notes

@ -1 +1,2 @@
Date,Score
2015-01-25,0.0000

1 2015-01-25 Date 0.0000 Score
1 Date Score
2 2015-01-25 2015-01-25 0.0000 0.0000

@ -1,10 +1,11 @@
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
Date,Value,Notes
2015-01-25,YES_MANUAL,
2015-01-24,NO,Sick
2015-01-23,YES_AUTO,"Forgot to do it, really"
2015-01-22,YES_MANUAL,
2015-01-21,YES_MANUAL,
2015-01-20,YES_MANUAL,
2015-01-19,YES_AUTO,"""Vacation"""
2015-01-18,YES_AUTO,
2015-01-17,YES_MANUAL,
2015-01-16,YES_MANUAL,

1 2015-01-25 Date 2 Value Notes
2 2015-01-24 2015-01-25 0 YES_MANUAL
3 2015-01-23 2015-01-24 1 NO Sick
4 2015-01-22 2015-01-23 2 YES_AUTO Forgot to do it, really
5 2015-01-21 2015-01-22 2 YES_MANUAL
6 2015-01-20 2015-01-21 2 YES_MANUAL
7 2015-01-19 2015-01-20 1 YES_MANUAL
8 2015-01-18 2015-01-19 1 YES_AUTO "Vacation"
9 2015-01-17 2015-01-18 2 YES_AUTO
10 2015-01-16 2015-01-17 2 YES_MANUAL
11 2015-01-16 YES_MANUAL

@ -1,3 +1,4 @@
Date,Score
2015-01-25,0.2557
2015-01-24,0.2226
2015-01-23,0.1991

1 2015-01-25 Date 0.2557 Score
1 Date Score
2 2015-01-25 2015-01-25 0.2557 0.2557
3 2015-01-24 2015-01-24 0.2226 0.2226
4 2015-01-23 2015-01-23 0.1991 0.1991

@ -1,11 +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,
2015-01-25,UNKNOWN,YES_MANUAL,
2015-01-24,UNKNOWN,NO,
2015-01-23,UNKNOWN,YES_AUTO,
2015-01-22,UNKNOWN,YES_MANUAL,
2015-01-21,UNKNOWN,YES_MANUAL,
2015-01-20,UNKNOWN,YES_MANUAL,
2015-01-19,UNKNOWN,YES_AUTO,
2015-01-18,UNKNOWN,YES_AUTO,
2015-01-17,UNKNOWN,YES_MANUAL,
2015-01-16,UNKNOWN,YES_MANUAL,

1 Date Meditate Wake up early
2 2015-01-25 -1 UNKNOWN 2 YES_MANUAL
3 2015-01-24 -1 UNKNOWN 0 NO
4 2015-01-23 -1 UNKNOWN 1 YES_AUTO
5 2015-01-22 -1 UNKNOWN 2 YES_MANUAL
6 2015-01-21 -1 UNKNOWN 2 YES_MANUAL
7 2015-01-20 -1 UNKNOWN 2 YES_MANUAL
8 2015-01-19 -1 UNKNOWN 1 YES_AUTO
9 2015-01-18 -1 UNKNOWN 1 YES_AUTO
10 2015-01-17 -1 UNKNOWN 2 YES_MANUAL
11 2015-01-16 -1 UNKNOWN 2 YES_MANUAL

@ -1,3 +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
Position,Name,Type,Question,Description,FrequencyNumerator,FrequencyDenominator,Color,Unit,Target Type,Target Value,Archived?
001,Meditate,YES_NO,Did you meditate this morning?,,1,1,#FF8F00,,,,false
002,Wake up early,YES_NO,Did you wake up before 6am?,,2,3,#00897B,,,,false

1 Position Name Type Question NumRepetitions Description Interval FrequencyNumerator FrequencyDenominator Color Unit Target Type Target Value Archived?
2 001 Meditate YES_NO Did you meditate this morning? 1 1 1 1 #FF8F00 false
3 002 Wake up early YES_NO Did you wake up before 6am? 2 3 2 3 #00897B false

@ -24,7 +24,7 @@ plugins {
kotlin {
jvm().withJava()
jvmToolchain(11)
jvmToolchain(17)
sourceSets {
val commonMain by getting {

@ -18,6 +18,7 @@
*/
package org.isoron.uhabits.core.io
import com.opencsv.CSVWriter
import org.isoron.uhabits.core.models.Entry
import org.isoron.uhabits.core.models.EntryList
import org.isoron.uhabits.core.models.Habit
@ -32,7 +33,6 @@ import java.io.FileOutputStream
import java.io.FileWriter
import java.io.IOException
import java.io.Writer
import java.util.ArrayList
import java.util.LinkedList
import java.util.Locale
import java.util.zip.ZipEntry
@ -109,11 +109,14 @@ class HabitsCSVExporter(
var oldest = today
val known = habit.computedEntries.getKnown()
if (known.isNotEmpty()) oldest = known[known.size - 1].timestamp
val csv = CSVWriter(out)
csv.writeNext(arrayOf("Date", "Score"), false)
for ((timestamp1, value) in habit.scores.getByInterval(oldest, today)) {
val timestamp = dateFormat.format(timestamp1.unixTime)
val score = String.format(Locale.US, "%.4f", value)
out.write(String.format("%s,%s\n", timestamp, score))
csv.writeNext(arrayOf(timestamp, score), false)
}
csv.close()
out.close()
}
@ -122,10 +125,20 @@ class HabitsCSVExporter(
val out = FileWriter(exportDirName + filename)
generatedFilenames.add(filename)
val dateFormat = DateFormats.getCSVDateFormat()
for ((timestamp, value) in entries.getKnown()) {
val date = dateFormat.format(timestamp.toJavaDate())
out.write(String.format(Locale.US, "%s,%d\n", date, value))
val csv = CSVWriter(out)
csv.writeNext(arrayOf("Date", "Value", "Notes"), false)
for (entry in entries.getKnown()) {
val date = dateFormat.format(entry.timestamp.toJavaDate())
csv.writeNext(
arrayOf(
date,
entry.formattedValue,
entry.notes
),
false
)
}
csv.close()
out.close()
}
@ -167,7 +180,7 @@ class HabitsCSVExporter(
checksWriter.write(sb.toString())
scoresWriter.write(sb.toString())
for (j in selectedHabits.indices) {
checksWriter.write(checkmarks[j][i].value.toString())
checksWriter.write(checkmarks[j][i].formattedValue)
checksWriter.write(delimiter)
val score = String.format(Locale.US, "%.4f", scores[j][i].value)
scoresWriter.write(score)

@ -23,6 +23,16 @@ data class Entry(
val value: Int,
val notes: String = ""
) {
val formattedValue: String
get() = when (value) {
YES_MANUAL -> "YES_MANUAL"
YES_AUTO -> "YES_AUTO"
NO -> "NO"
SKIP -> "SKIP"
UNKNOWN -> "UNKNOWN"
else -> value.toString()
}
companion object {
/**
* Value indicating that the habit is not applicable for this timestamp.

@ -22,6 +22,7 @@ import com.opencsv.CSVWriter
import java.io.IOException
import java.io.Writer
import java.util.LinkedList
import java.util.Locale
import javax.annotation.concurrent.ThreadSafe
/**
@ -182,24 +183,34 @@ abstract class HabitList : Iterable<Habit> {
val header = arrayOf(
"Position",
"Name",
"Type",
"Question",
"Description",
"NumRepetitions",
"Interval",
"Color"
"FrequencyNumerator",
"FrequencyDenominator",
"Color",
"Unit",
"Target Type",
"Target Value",
"Archived?"
)
val csv = CSVWriter(out)
csv.writeNext(header, false)
for (habit in this) {
val (numerator, denominator) = habit.frequency
val cols = arrayOf(
String.format("%03d", indexOf(habit) + 1),
String.format(Locale.US, "%03d", indexOf(habit) + 1),
habit.name,
habit.type.name,
habit.question,
habit.description,
numerator.toString(),
denominator.toString(),
habit.color.toCsvColor()
habit.color.toCsvColor(),
if (habit.isNumerical) habit.unit else "",
if (habit.isNumerical) habit.targetType.name else "",
if (habit.isNumerical) habit.targetValue.toString() else "",
habit.isArchived.toString()
)
csv.writeNext(cols, false)
}

@ -35,6 +35,10 @@ class HabitFixtures(private val modelFactory: ModelFactory, private val habitLis
true, false, false, true, true, true, false, false, true, true
)
private var NON_DAILY_HABIT_NOTES = arrayOf(
"", "Sick", "Forgot to do it, really", "", "", "", "\"Vacation\"", "", "", ""
)
fun createEmptyHabit(
name: String = "Meditate",
color: PaletteColor = PaletteColor(3),
@ -141,10 +145,10 @@ class HabitFixtures(private val modelFactory: ModelFactory, private val habitLis
habit.frequency = Frequency(2, 3)
saveIfSQLite(habit)
var timestamp = getToday()
for (c in NON_DAILY_HABIT_CHECKS) {
for (i in NON_DAILY_HABIT_CHECKS.indices) {
var value = Entry.NO
if (c) value = Entry.YES_MANUAL
habit.originalEntries.add(Entry(timestamp, value))
if (NON_DAILY_HABIT_CHECKS[i]) value = Entry.YES_MANUAL
habit.originalEntries.add(Entry(timestamp, value, NON_DAILY_HABIT_NOTES[i]))
timestamp = timestamp.minus(1)
}
habit.recompute()

@ -18,7 +18,6 @@
*/
package org.isoron.uhabits.core.io
import org.apache.commons.io.FileUtils
import org.apache.commons.io.IOUtils
import org.isoron.uhabits.core.BaseUnitTest
import org.isoron.uhabits.core.models.Habit
@ -30,6 +29,7 @@ import java.io.IOException
import java.nio.file.Files
import java.util.*
import java.util.zip.ZipFile
import kotlin.test.assertEquals
import kotlin.test.assertTrue
class HabitsCSVExporterTest : BaseUnitTest() {
@ -108,15 +108,12 @@ class HabitsCSVExporterTest : BaseUnitTest() {
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))
)
)
val actualFile = File(String.format("%s/%s", baseDir.absolutePath, s))
val expectedFile = File.createTempFile("asset", "")
expectedFile.deleteOnExit()
copyAssetToFile(assetFilename, expectedFile)
val actualContents = actualFile.readText()
val expectedContents = expectedFile.readText()
assertEquals(expectedContents, actualContents, "content mismatch for $s")
}
}

@ -202,13 +202,16 @@ class HabitListTest : BaseUnitTest() {
h2.description = ""
h2.frequency = Frequency(2, 3)
h2.color = PaletteColor(5)
val h3 = fixtures.createNumericalHabit()
list.add(h1)
list.add(h2)
list.add(h3)
val expectedCSV =
"""
Position,Name,Question,Description,NumRepetitions,Interval,Color
001,Meditate,Did you meditate this morning?,this is a test description,1,1,#FF8F00
002,Wake up early,Did you wake up before 6am?,,2,3,#AFB42B
Position,Name,Type,Question,Description,FrequencyNumerator,FrequencyDenominator,Color,Unit,Target Type,Target Value,Archived?
001,Meditate,YES_NO,Did you meditate this morning?,this is a test description,1,1,#FF8F00,,,,false
002,Run,NUMERICAL,How many miles did you run today?,,1,1,#E64A19,miles,AT_LEAST,2.0,false
003,Wake up early,YES_NO,Did you wake up before 6am?,,2,3,#AFB42B,,,,false
""".trimIndent()
val writer = StringWriter()

Loading…
Cancel
Save