Skip to content

Commit

Permalink
Update application internals regarding Amberdata change.
Browse files Browse the repository at this point in the history
  • Loading branch information
Conor Flynn committed Nov 29, 2022
1 parent b7c284c commit 6455738
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 39 deletions.
Binary file modified Data Engine/Documents/Internal Manual/Packet Spreadsheet.xlsx
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ private final String request(String tag, String sub_tag, String... data) {
}

// static request
System.out.println(String.format("%s%s%s%s%s", tag, delim, sub_tag, delim, formatted_data));
out.writeUTF(String.format("%s%s%s%s%s", tag, delim, sub_tag, delim, formatted_data));
return in.readUTF();
} catch (IOException e) {
Expand Down
5 changes: 5 additions & 0 deletions DeFi-Data-Engine/Testing Environment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
<artifactId>json</artifactId>
<version>20220320</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.2.0</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

public class LocalTest {

private static final String host = "localhost";
private static final String host = "defi-de.idea.rpi.edu";

public static void main(String[] args) throws UnknownHostException, IOException {
final Socket socket = SocketFactory.getDefault().createSocket(host, 61200);
Expand All @@ -41,11 +41,10 @@ public void run() {
+ "source=amber_data&"
+ "auth_data=key,UAK7ed69235426c360be22bfc2bde1809b6",
host));
//System.out.println(init);
System.out.println(init);
JSONObject json_init = new JSONObject(init);
String key = json_init.getString("data");

long s = System.nanoTime();
String rqst = request(String.format("http://%s:8080/defi/v1/rest/request_dated?"
+ "destination=%s&"
+ "key=%s&"
Expand All @@ -57,8 +56,19 @@ public void run() {
destination,
key,
"2022-08-01",
"2022-09-01"));
long e = System.nanoTime();
"2022-08-02"));
// String rqst = request(String.format("http://%s:8080/defi/v1/rest/request_dated?"
// + "destination=%s&"
// + "key=%s&"
// + "request=aave-protocol-dated&"
// + "query=aave-protocol-dated&"
// + "start_date=%s&"
// + "end_date=%s",
// host,
// destination,
// key,
// "2022-08-01",
// "2022-08-02"));
System.out.println(rqst);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void run() {
}
};
thread.start();

System.out.println("Requesting");
String sample = request("http://defi-de.idea.rpi.edu:8080/defi/v1/rest/source_exists?source=amber_data");
System.out.println(sample);
}
Expand Down
80 changes: 47 additions & 33 deletions DeFi-Data-Engine/Testing Environment/src/test/misc/Testing1.java
Original file line number Diff line number Diff line change
@@ -1,42 +1,56 @@
package test.misc;

import java.util.Arrays;
import java.io.IOException;

import org.json.JSONArray;
import org.json.JSONObject;

import okhttp3.OkHttpClient;
import okhttp3.Request;

public class Testing1 {

/* lis() returns the length of the longest
increasing subsequence in arr[] of size n */
static int lis(int arr[], int n)
{
int lis[] = new int[n];
int i, j, max = 0;

/* Initialize LIS values for all indexes */
for (i = 0; i < n; i++)
lis[i] = 1;

/* Compute optimized LIS values in
bottom up manner */
for (i = 1; i < n; i++)
for (j = 0; j < i; j++)
if (arr[i] > arr[j] && lis[i] < lis[j] + 1) {
lis[i] = lis[j] + 1;
System.out.println(Arrays.toString(lis));
}

/* Pick maximum of all LIS values */
for (i = 0; i < n; i++)
if (max < lis[i])
max = lis[i];

return max;
}

public static void main(String args[])
{
int arr[] = { 10, 22, 9, 33, 21, 50, 41, 60 };
int n = arr.length;
System.out.println("Length of lis is " + lis(arr, n)
+ "\n");
String url = String.format("https://web3api.io/api/v2/defi/lending/aavev2/protocol?startDate=%s&endDate=%s",
"2022-09-01T01:00:00",
"2022-09-02T01:00:00"
+ "&size=999");

recursiveCall(url);
System.out.println("Exit");
System.exit(0);
}

public static void recursiveCall(String url) {
System.out.println(url);
OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder()
.url(url)
.get()
.addHeader("accept", "application/json")
.addHeader("x-api-key", "UAK7ed69235426c360be22bfc2bde1809b6")
.build();

okhttp3.Response response;
try {
response = client.newCall(request).execute();
JSONObject json = new JSONObject(response.body().string());

JSONObject payload = json.getJSONObject("payload");
JSONArray arr = payload.getJSONArray("data");
for(int i = 0; i < arr.length(); i++) {
System.out.println(arr.get(i).toString());
}
System.out.println(arr.length());
if(arr.length() >= 999) {
JSONObject metadata = payload.getJSONObject("metadata");
if(metadata.has("next"))
recursiveCall(metadata.getString("next")+"&size=999");
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

0 comments on commit 6455738

Please sign in to comment.