-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NSCv3: process Food, first load based on created_at
- Loading branch information
1 parent
10e8e32
commit d9c6cd6
Showing
25 changed files
with
603 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
adb connect 127.0.0.1:58526 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
core/ns-sdk/src/main/java/info/nightscout/sdk/localmodel/food/NSFood.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package info.nightscout.sdk.localmodel.food | ||
|
||
import info.nightscout.sdk.localmodel.entry.NsUnits | ||
|
||
data class NSFood( | ||
val date: Long, | ||
val device: String? = null, | ||
val identifier: String?, | ||
val units: NsUnits? = null, | ||
val srvModified: Long? = null, | ||
val srvCreated: Long? = null, | ||
val subject: String? = null, | ||
var isReadOnly: Boolean = false, | ||
val isValid: Boolean, | ||
var app: String? = null, | ||
var name: String, | ||
var category: String? = null, | ||
var subCategory: String? = null, | ||
// Example: | ||
// name="juice" portion=250 units="ml" carbs=12 | ||
// means 250ml of juice has 12g of carbs | ||
|
||
var portion: Double, // common portion in "units" | ||
var carbs: Int, // in grams | ||
var fat: Int? = null, // in grams | ||
var protein: Int? = null, // in grams | ||
var energy: Int? = null, // in kJ | ||
var unit: String = "g", | ||
var gi: Int? = null // not used yet | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
core/ns-sdk/src/main/java/info/nightscout/sdk/mapper/FoodMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package info.nightscout.sdk.mapper | ||
|
||
import info.nightscout.sdk.localmodel.food.NSFood | ||
import info.nightscout.sdk.remotemodel.RemoteFood | ||
|
||
/** | ||
* Convert to [RemoteFood] and back to [NSFood] | ||
* testing purpose only | ||
* | ||
* @return treatment after double conversion | ||
*/ | ||
fun NSFood.convertToRemoteAndBack(): NSFood? = | ||
toRemoteFood().toNSFood() | ||
|
||
internal fun RemoteFood.toNSFood(): NSFood? { | ||
when (type) { | ||
"food" -> | ||
return NSFood( | ||
date = date ?: 0L, | ||
device = device, | ||
identifier = identifier, | ||
unit = unit ?: "g", | ||
srvModified = srvModified, | ||
srvCreated = srvCreated, | ||
subject = subject, | ||
isReadOnly = isReadOnly ?: false, | ||
isValid = isValid ?: true, | ||
name = name, | ||
category = category, | ||
subCategory = subcategory, | ||
portion = portion, | ||
carbs = carbs, | ||
fat = fat, | ||
protein = protein, | ||
energy = energy, | ||
gi = gi | ||
) | ||
|
||
else -> return null | ||
} | ||
} | ||
|
||
internal fun NSFood.toRemoteFood(): RemoteFood = | ||
RemoteFood( | ||
type = "food", | ||
date = date, | ||
device = device, | ||
identifier = identifier, | ||
unit = unit, | ||
srvModified = srvModified, | ||
srvCreated = srvCreated, | ||
subject = subject, | ||
isReadOnly = isReadOnly, | ||
isValid = isValid, | ||
name = name, | ||
category = category, | ||
subcategory = subCategory, | ||
portion = portion, | ||
carbs = carbs, | ||
fat = fat, | ||
protein = protein, | ||
energy = energy, | ||
gi = gi | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
core/ns-sdk/src/main/java/info/nightscout/sdk/remotemodel/RemoteFood.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package info.nightscout.sdk.remotemodel | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
/** | ||
* Depending on the type, different other fields are present. | ||
* Those technically need to be optional. | ||
* | ||
* On upload a sanity check still needs to be done to verify that all mandatory fields for that type are there. | ||
* | ||
**/ | ||
internal data class RemoteFood( | ||
@SerializedName("type") val type: String, // we are interesting in type "food" | ||
@SerializedName("date") val date: Long?, | ||
@SerializedName("name") val name: String, | ||
@SerializedName("category") val category: String?, | ||
@SerializedName("subcategory") val subcategory: String?, | ||
@SerializedName("unit") val unit: String?, | ||
@SerializedName("portion") val portion: Double, | ||
@SerializedName("carbs") val carbs: Int, | ||
@SerializedName("gi") val gi: Int?, | ||
@SerializedName("energy") val energy: Int?, | ||
@SerializedName("protein") val protein: Int?, | ||
@SerializedName("fat") val fat: Int?, | ||
@SerializedName("identifier") | ||
val identifier: String?, // string Main addressing, required field that identifies document in the collection. The client should not create the identifier, the server automatically assigns it when the document is inserted. | ||
@SerializedName("isValid") | ||
val isValid: Boolean?, // A flag set by the server only for deleted documents. This field appears only within history operation and for documents which were deleted by API v3 (and they always have a false value) | ||
@SerializedName("isReadOnly") | ||
val isReadOnly: Boolean?, // A flag set by client that locks the document from any changes. Every document marked with isReadOnly=true is forever immutable and cannot even be deleted. | ||
@SerializedName("app") var app: String? = null, // Application or system in which the record was entered by human or device for the first time. | ||
@SerializedName("device") val device: String? = null, // string The device from which the data originated (including serial number of the device, if it is relevant and safe). | ||
@SerializedName("srvCreated") | ||
val srvCreated: Long? = null, // integer($int64) example: 1525383610088 The server's timestamp of document insertion into the database (Unix epoch in ms). This field appears only for documents which were inserted by API v3. | ||
@SerializedName("subject") | ||
val subject: String? = null, // string Name of the security subject (within Nightscout scope) which has created the document. This field is automatically set by the server from the passed token or JWT. | ||
@SerializedName("srvModified") | ||
val srvModified: Long? = null, // integer($int64) example: 1525383610088 The server's timestamp of the last document modification in the database (Unix epoch in ms). This field appears only for documents which were somehow modified by API v3 (inserted, updated or deleted). | ||
@SerializedName("modifiedBy") | ||
val modifiedBy: String? = null // string Name of the security subject (within Nightscout scope) which has patched or deleted the document for the last time. This field is automatically set by the server. | ||
) |
Oops, something went wrong.