Skip to content
This repository has been archived by the owner on Dec 3, 2021. It is now read-only.

Commit

Permalink
fix: Fix CSV format
Browse files Browse the repository at this point in the history
  • Loading branch information
aoudiamoncef committed Mar 14, 2018
1 parent eaa5f4b commit a7f8bba
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 42 deletions.
13 changes: 7 additions & 6 deletions app/src/main/java/science/apolline/models/IOIOData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class IOIOData : IntfSensorData {

enum class Units constructor(val value: String) {
CONCENTRATION_UG_M3("µg/m3"),
CONCENTRATION_ABOVE("#/0.1L"),
PERCENTAGE("%"),
TEMPERATURE_CELSIUS("°C"),
TEMPERATURE_KELVIN("°K");
Expand All @@ -119,12 +120,12 @@ class IOIOData : IntfSensorData {
addNestedJsonArray(obj, "pm.2_5.value", pm2_5Value, Units.CONCENTRATION_UG_M3)
addNestedJsonArray(obj, "pm.10.value", pm10Value, Units.CONCENTRATION_UG_M3)

addNestedJsonArray(obj, "pm.0_3.above", pm0_3Above, Units.CONCENTRATION_UG_M3)
addNestedJsonArray(obj, "pm.0_5.above", pm0_5Above, Units.CONCENTRATION_UG_M3)
addNestedJsonArray(obj, "pm.1.above", pm1Above, Units.CONCENTRATION_UG_M3)
addNestedJsonArray(obj, "pm.2_5.above", pm2_5Above, Units.CONCENTRATION_UG_M3)
addNestedJsonArray(obj, "pm.5.above", pm5Above, Units.CONCENTRATION_UG_M3)
addNestedJsonArray(obj, "pm.10.above", pm10Above, Units.CONCENTRATION_UG_M3)
addNestedJsonArray(obj, "pm.0_3.above", pm0_3Above, Units.CONCENTRATION_ABOVE)
addNestedJsonArray(obj, "pm.0_5.above", pm0_5Above, Units.CONCENTRATION_ABOVE)
addNestedJsonArray(obj, "pm.1.above", pm1Above, Units.CONCENTRATION_ABOVE)
addNestedJsonArray(obj, "pm.2_5.above", pm2_5Above, Units.CONCENTRATION_ABOVE)
addNestedJsonArray(obj, "pm.5.above", pm5Above, Units.CONCENTRATION_ABOVE)
addNestedJsonArray(obj, "pm.10.above", pm10Above, Units.CONCENTRATION_ABOVE)

addNestedJsonArray(obj, "temperature.c", tempCelcius, Units.TEMPERATURE_CELSIUS)
addNestedJsonArray(obj, "temperature.k", tempKelvin, Units.TEMPERATURE_KELVIN)
Expand Down
18 changes: 14 additions & 4 deletions app/src/main/java/science/apolline/utils/CheckUtility.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ import android.provider.Settings
import android.support.v4.content.ContextCompat
import android.support.v7.app.AlertDialog
import android.telephony.TelephonyManager
import android.text.format.DateFormat
import android.widget.Toast
import es.dmoral.toasty.Toasty
import org.jetbrains.anko.AnkoLogger
import org.jetbrains.anko.info
import java.text.SimpleDateFormat
import java.time.format.DateTimeFormatter
import java.util.*
import java.text.SimpleDateFormat


/**
* Created by sparow on 22/12/2017.
Expand Down Expand Up @@ -149,9 +148,20 @@ object CheckUtility : AnkoLogger {
return wf
}


fun newDate() : String {
val c = Calendar.getInstance().time
val df = SimpleDateFormat("dd-MMM-yyyy", Locale.FRANCE)
return df.format(c)
}

fun dateParser(timestamp: Long): String {
return Date(timestamp / 1000000).toString()
val c = Date(timestamp / 1000000)
val df = SimpleDateFormat("dd-MMM-yyyy HH:mm:ss", Locale.FRANCE)
return df.format(c)
}




}
7 changes: 4 additions & 3 deletions app/src/main/java/science/apolline/utils/DataExport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ object DataExport : AnkoLogger {
headerArray.add("Transport")

data!!.entrySet().iterator().forEach {
headerArray.add(it.key + "_" + it.value.asJsonArray[1].toString().replace("\"", ""))
val tmp = (it.key + "_" + it.value.asJsonArray[1]).replace(("\\.").toRegex(), "_")
headerArray.add(tmp.replace(("\"").toRegex(), ""))
}

return headerArray.toTypedArray()
Expand Down Expand Up @@ -76,7 +77,7 @@ object DataExport : AnkoLogger {
doAsync {
createCsv(sensorDao.dumpSensor())
uiThread {
val file = File(localFolder(), "data.csv")
val file = File(localFolder(), "data_${CheckUtility.newDate()}.csv")
val uri: Uri
uri = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
Uri.fromFile(file)
Expand All @@ -96,7 +97,7 @@ object DataExport : AnkoLogger {
}

private fun filename(extension: String): String {
return localFolder().toString() + "/" + "data.$extension"
return localFolder().toString() + "/" + "data_${CheckUtility.newDate()}.$extension"
}

private fun localFolder(): File {
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/ic_bluetooth_connected.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FFFF"
android:pathData="M7,12l-2,-2 -2,2 2,2 2,-2zM17.71,7.71L12,2h-1v7.59L6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 11,14.41L11,22h1l5.71,-5.71 -4.3,-4.29 4.3,-4.29zM13,5.83l1.88,1.88L13,9.59L13,5.83zM14.88,16.29L13,18.17v-3.76l1.88,1.88zM19,10l-2,2 2,2 2,-2 -2,-2z"/>
</vector>
29 changes: 0 additions & 29 deletions app/src/main/res/menu/menu_ioio.xml

This file was deleted.

0 comments on commit a7f8bba

Please sign in to comment.