Added Steps
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="SeniorAssistant" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="SeniorAssistant" external.system.module.version="1.0-SNAPSHOT" type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/out" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id="SeniorAssistant" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="SeniorAssistant" external.system.module.version="1.0-SNAPSHOT" type="JAVA_MODULE" version="4">
|
||||
<component name="EclipseModuleManager">
|
||||
<conelement value="org.eclipse.buildship.core.gradleclasspathcontainer" />
|
||||
<src_description expected_position="0">
|
||||
<src_folder value="file://$MODULE_DIR$/src/main/java" expected_position="0" />
|
||||
<src_folder value="file://$MODULE_DIR$/src/test/java" expected_position="1" />
|
||||
</src_description>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
||||
</content>
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="inheritedJdk" />
|
||||
</component>
|
||||
</module>
|
||||
@@ -1,5 +1,4 @@
|
||||
import manage.AuthFITBIT;
|
||||
import manage.FITBITData.*;
|
||||
import manage.FITBITData.FitBit;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
package manage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.api.client.auth.oauth2.AuthorizationCodeFlow;
|
||||
import com.google.api.client.auth.oauth2.BearerToken;
|
||||
import com.google.api.client.auth.oauth2.Credential;
|
||||
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
|
||||
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
|
||||
import com.google.api.client.http.*;
|
||||
import com.google.api.client.http.BasicAuthentication;
|
||||
import com.google.api.client.http.GenericUrl;
|
||||
import com.google.api.client.http.HttpRequest;
|
||||
import com.google.api.client.http.HttpRequestFactory;
|
||||
import com.google.api.client.http.HttpResponse;
|
||||
import com.google.api.client.http.HttpTransport;
|
||||
import com.google.api.client.http.javanet.NetHttpTransport;
|
||||
import com.google.api.client.json.GenericJson;
|
||||
import com.google.api.client.json.JsonFactory;
|
||||
@@ -14,11 +22,6 @@ import com.google.api.client.json.JsonObjectParser;
|
||||
import com.google.api.client.json.jackson2.JacksonFactory;
|
||||
import com.google.api.client.util.store.DataStoreFactory;
|
||||
import com.google.api.client.util.store.FileDataStoreFactory;
|
||||
import manage.FITBITData.Device;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class AuthFITBIT {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package manage.FITBITData;
|
||||
|
||||
import manage.AuthFITBIT;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import manage.AuthFITBIT;
|
||||
|
||||
public class FitBit {
|
||||
|
||||
public static final String BASIC_URL = "https://api.fitbit.com/";
|
||||
@@ -14,7 +14,7 @@ public class FitBit {
|
||||
private static final long MINUTE = 60000; /* 5 minutes in millisec */
|
||||
|
||||
private final AuthFITBIT auth;
|
||||
private final Map<Class, Long> latestRequest = new HashMap<>();
|
||||
private final Map<Class<?>, Long> latestRequest = new HashMap<>();
|
||||
private final Calendar calendar = Calendar.getInstance();
|
||||
|
||||
private HeartRate heart = null;
|
||||
@@ -32,15 +32,14 @@ public class FitBit {
|
||||
}
|
||||
|
||||
/* passi */
|
||||
//https://api.fitbit.com/1/user/-/activities/steps/date/today.json
|
||||
public int getSteps() throws IOException {
|
||||
if(shouldUpdateFor(Steps.class)) {
|
||||
long currentMillisec = System.currentTimeMillis();
|
||||
|
||||
steps = auth.run(BASIC_URL + "1" + USER + "activities/steps/date/today.json", Steps.class);
|
||||
latestRequest.put(steps.getClass(), currentMillisec);
|
||||
|
||||
steps = auth.run(BASIC_URL + "1" + USER + "activities/steps/date/today/1w.json", Steps.class);
|
||||
latestRequest.put(steps.getClass(), currentMillisec);
|
||||
}
|
||||
return 0;
|
||||
return steps.getSteps();
|
||||
}
|
||||
|
||||
/* battito */
|
||||
@@ -71,7 +70,7 @@ public class FitBit {
|
||||
return sleep.getMinutesAsleep();
|
||||
}
|
||||
|
||||
private boolean shouldUpdateFor(Class type) {
|
||||
private boolean shouldUpdateFor(Class<?> type) {
|
||||
try {
|
||||
long current = System.currentTimeMillis();
|
||||
long latest = latestRequest.get(type);
|
||||
|
||||
@@ -1,5 +1,30 @@
|
||||
package manage.FITBITData;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Steps {
|
||||
|
||||
private int steps=0;
|
||||
|
||||
@JsonProperty("activities-steps")
|
||||
public void setSteps(Map<String, String>[] array) {
|
||||
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date now = new Date();
|
||||
String strDate = sdfDate.format(now);
|
||||
|
||||
for(Map<String, String> map : array)
|
||||
if(map.get("dateTime").equals(strDate))
|
||||
steps = Integer.parseInt(map.get("value"))+1;
|
||||
}
|
||||
|
||||
public int getSteps() {
|
||||
return steps;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user