Skip to content

Commit

Permalink
Set the record_date for drink events
Browse files Browse the repository at this point in the history
  • Loading branch information
patfreeman committed Jun 25, 2020
1 parent 866b886 commit 5d740ec
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion kegtab/src/main/java/org/kegbot/api/KegbotApiImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ public Drink recordDrink(String tapName, long volumeMl, long ticks,
try {
paramBuilder.put("record_date", recordDate); // new API
} catch (IllegalArgumentException e) {
// Ignore.
Log.d(TAG,"Illegal Argument given to record date: " + recordDate);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ Drink recordDrink(String tapName, long volumeMl, long ticks, @Nullable String sh
values.put(COLUMN_DRINK_SHOUT, shout);
values.put(COLUMN_DRINK_USERNAME, username); // TODO
values.put(COLUMN_DRINK_VOLUME_ML, Long.valueOf(volumeMl));
if(!Strings.isNullOrEmpty(recordDate)) {
values.put(COLUMN_DRINK_TIME, recordDate);
}
if (!Strings.isNullOrEmpty(pictureUrl)) {
values.put(COLUMN_DRINK_PICTURE_URL, pictureUrl);
}
Expand Down Expand Up @@ -766,7 +769,7 @@ private Drink drinkFromCursor(final Cursor cursor) {
final Drink drink = Drink.newBuilder()
.setId(drinkId)
.setSessionId(0)
.setTime("") // TODO
.setTime(cursor.getString(cursor.getColumnIndex(COLUMN_DRINK_TIME)))
.setVolumeMl(cursor.getFloat(cursor.getColumnIndex(COLUMN_DRINK_VOLUME_ML)))
.setTicks((int) cursor.getLong(cursor.getColumnIndex(COLUMN_DRINK_TICKS)))
.setShout(cursor.getString(cursor.getColumnIndex(COLUMN_DRINK_SHOUT)))
Expand Down
12 changes: 12 additions & 0 deletions kegtab/src/main/java/org/kegbot/core/SyncManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@
import org.kegbot.proto.Models.ThermoSensor;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -360,6 +364,9 @@ private void postPour(final PendingPour pour) throws KegbotApiException {
} catch (NotFoundException e) {
Log.w(TAG, "Tap does not exist, dropping pour.");
return;
} catch (KegbotApiException e) {
Log.w(TAG, "API error");
throw new KegbotApiException(e);
} catch (BackendException e) {
// TODO: Handle error.
Log.w(TAG, "Other error.");
Expand Down Expand Up @@ -641,6 +648,10 @@ private boolean syncNow() {
}

private static RecordDrinkRequest getRequestForFlow(final Flow ended) {
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss+00:00");
df.setTimeZone(tz);
String nowAsISO = df.format(new Date());
return RecordDrinkRequest.newBuilder()
.setTapName(ended.getTap().getMeter().getName())
.setTicks(ended.getTicks())
Expand All @@ -651,6 +662,7 @@ private static RecordDrinkRequest getRequestForFlow(final Flow ended) {
.setSpilled(false)
.setShout(ended.getShout())
.setTickTimeSeries(ended.getTickTimeSeries().asString())
.setRecordDate(nowAsISO)
.buildPartial();
}

Expand Down

0 comments on commit 5d740ec

Please sign in to comment.