Skip to content

Commit

Permalink
Más refactor de codigo y test
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Almora committed May 25, 2018
1 parent 96758c7 commit 43739e6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
10 changes: 1 addition & 9 deletions src/main/java/mx/itam/Backend/DataServices.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ private void fetchHistoricData(Symbol symbol, Interval interval, int limit) thro
OkHttpClient client = new OkHttpClient();
//Se hace la consulta.
Request request = new Request.Builder()
.url(ENDPOINT + "api/v1/klines?symbol=" + symbol.getSymbol() + "&interval=" + interval.getTimeCode() + "&startTime=" + calculateTimeLapseInMilis(interval, limit) + "&limit=" + selectedLimit)
.url(ENDPOINT + "api/v1/klines?symbol=" + symbol.getSymbol() + "&interval=" + interval.getTimeCode() + "&startTime=" +Utils.calculateTimeLapseInMilis(interval, limit) + "&limit=" + selectedLimit)
.get()
.build();
Response response = client.newCall(request).execute();
Expand Down Expand Up @@ -389,13 +389,5 @@ public void setSelectedLimit(int selectedLimit) {
this.selectedLimit = selectedLimit;
}

/**
* @param interval
* @param limit
* @return El tiempo transcurrido, en milisegundos, desde el inicio del intervalo hasta el momento actual en formato para la API
*/
private long calculateTimeLapseInMilis(Interval interval, int limit) {
return System.currentTimeMillis() - interval.getTimeInMilis() * limit;
}
}

8 changes: 8 additions & 0 deletions src/main/java/mx/itam/Backend/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,12 @@ public static String currencyFormat(double currency, int decimals) {
public static String getDateFromEpoch(long time) {
return new SimpleDateFormat("dd/MM/yyyy").format(new Date(time));
}
/**
* @param interval
* @param limit
* @return El tiempo transcurrido, en milisegundos, desde el inicio del intervalo hasta el momento actual en formato para la API
*/
public static long calculateTimeLapseInMilis(Interval interval, int limit) {
return System.currentTimeMillis() - interval.getTimeInMilis() * limit;
}
}
11 changes: 11 additions & 0 deletions test/mx/itam/Backend/UtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,15 @@ public void getDateFromEpoch() {
long timeInMilis = 0;
assertEquals("Fecha",Utils.getDateFromEpoch(timeInMilis));
}

@Test
public void calculateTimeLapseInMilis() {
long tiempo=0;
int limit = 1;
int min = 1;
int hour = 1;
int day = 1;

assertEquals(tiempo,Utils.calculateTimeLapseInMilis(new Interval("x",min,hour,day),limit));
}
}

0 comments on commit 43739e6

Please sign in to comment.