Skip to content

Commit

Permalink
latest pushes
Browse files Browse the repository at this point in the history
  • Loading branch information
RonaldsonBellande committed Jul 10, 2024
1 parent cf3d154 commit 5a99f0d
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,48 @@
import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;

import com.bellande_api.bellande_ram_usage.bellande_ram_usage_service;
import com.bellande_api.bellande_ram_usage.bellande_ram_usage_api;
import com.google.firebase.crashlytics.buildtools.reloc.com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.reflect.*;

import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.util.Map;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class bellande_ram_usage_activity extends AppCompatActivity {
private bellande_ram_usage_service bellande_ram_usage_service;
protected bellande_ram_usage_service ramUsageService;
protected String connectivityPasscode;

public bellande_ram_usage_activity(Context context) {
Map<String, Object> config = loadConfigFromFile(context);
String apiUrl = (String) config.get("url");
String endpointPath = (String) ((Map<String, Object>) config.get("endpoint_path")).get("2d");
Map<String, String> endpointPaths = (Map<String, String>) config.get("endpoint_path");
String inputEndpoint = endpointPaths.get("input_data");
String outputEndpoint = endpointPaths.get("output_data");
String apiAccessKey = (String) config.get("Bellande_Framework_Access_Key");
this.connectivityPasscode = (String) config.get("connectivity_passcode");

bellande_ram_usage_api bellande_ram_usage_api = new Retrofit.Builder()
.baseUrl(apiUrl + endpointPath)
bellande_ram_usage_api ramUsageApi = new Retrofit.Builder()
.baseUrl(apiUrl)
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(bellande_ram_usage_api.class);

bellande_ram_usage_service = new bellande_ram_usage_service(apiUrl, endpointPath, apiAccessKey, bellande_ram_usage_api);
ramUsageService = new bellande_ram_usage_service(apiUrl, inputEndpoint, outputEndpoint, apiAccessKey, ramUsageApi);
}

@SuppressLint("LongLogTag")
Map<String, Object> loadConfigFromFile(Context context) {
private Map<String, Object> loadConfigFromFile(Context context) {
try {
InputStream inputStream = context.getAssets().open("configs.json");
InputStreamReader reader = new InputStreamReader(inputStream);
Type type = new TypeToken<Map<String, Object>>() {}.getType();
Type type = new TypeToken<Map<String, Object>>(){}.getType();
return new Gson().fromJson(reader, type);
} catch (IOException e) {
Log.e("bellande_ram_usage_activity", "Error reading config file: " + e.getMessage());
Log.e("bellande_ram_usage_base_activity", "Error reading config file: " + e.getMessage());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,42 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
**/

*/
package com.bellande_api.bellande_ram_usage;

import com.google.gson.annotations.SerializedName;

import okhttp3.MultipartBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Multipart;
import retrofit2.http.Header;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.Url;

public interface bellande_ram_usage_api {
@POST("2d")
Call<BellandeResponse> getBellandeResponse(@Body RequestBody requestBody);
@POST
Call<BellandeResponse> getBellandeResponse(@Url String url, @Body RequestBody body, @Header("Bellande-Framework-Access-Key") String apiKey);

class RequestBody {
private final String inputText;
@POST
Call<BellandeResponse> sendBellandeResponse(@Url String url, @Body RequestBody body, @Header("Bellande-Framework-Access-Key") String apiKey);

public RequestBody(String inputText) { this.inputText = inputText; }
class RequestBody {
private final String input;
private final String connectivityPasscode;

public String getString() { return inputText; }
public RequestBody(String input, String connectivityPasscode) {
this.input = input;
this.connectivityPasscode = connectivityPasscode;
}
}

class BellandeResponse {
@SerializedName("response")
public String response;
private String cpuUsage;
private String status;

public String getCpuUsage() {
return cpuUsage;
}

public String getStatus() {
return status;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,45 @@
import retrofit2.converter.gson.GsonConverterFactory;

public class bellande_ram_usage_service {
private final bellande_ram_usage_api bellande_ram_usage_api;
private final bellande_ram_usage_api ramUsageApi;
private final String apiAccessKey;
private final String inputEndpoint;
private final String outputEndpoint;

public bellande_ram_usage_service(String apiUrl, String endpointPath, String apiAccessKey, bellande_ram_usage_api bellande_ram_usage_api) {
this.bellande_ram_usage_api = bellande_ram_usage_api;
public bellande_ram_usage_service(String apiUrl, String inputEndpoint, String outputEndpoint, String apiAccessKey, bellande_ram_usage_api ramUsageApi) {
this.ramUsageApi = ramUsageApi;
this.apiAccessKey = apiAccessKey;
this.inputEndpoint = inputEndpoint;
this.outputEndpoint = outputEndpoint;
}

Retrofit retrofit = new Retrofit.Builder()
.baseUrl(apiUrl + endpointPath)
.addConverterFactory(GsonConverterFactory.create())
.build();
public String getRamUsage(String connectivityPasscode) {
bellande_ram_usage_api.RequestBody apiRequestBody = new bellande_ram_usage_api.RequestBody("get_ram_usage", connectivityPasscode);

retrofit.create(bellande_ram_usage_api.class);
try {
Response<bellande_ram_usage_api.BellandeResponse> response = ramUsageApi.getBellandeResponse(inputEndpoint, apiRequestBody, apiAccessKey).execute();
if (response.isSuccessful() && response.body() != null) {
return response.body().getCpuUsage();
} else {
throw new RuntimeException("Error getting NETWORK usage: " + response.code() + " - " + response.message());
}
} catch (IOException e) {
throw new RuntimeException("Error getting NETWORK usage: " + e.getMessage());
}
}

public bellande_ram_usage_api.BellandeResponse getPrediction(String inputText) {
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), inputText);
bellande_ram_usage_api.RequestBody apiRequestBody = new bellande_ram_usage_api.RequestBody(
inputText
);
public String sendRamUsage(String cpuUsage, String connectivityPasscode) {
bellande_ram_usage_api.RequestBody apiRequestBody = new bellande_ram_usage_api.RequestBody(cpuUsage, connectivityPasscode);

try {
Response<bellande_ram_usage_api.BellandeResponse> response = bellande_ram_usage_api.getBellandeResponse(apiRequestBody).execute();
Response<bellande_ram_usage_api.BellandeResponse> response = ramUsageApi.sendBellandeResponse(outputEndpoint, apiRequestBody, apiAccessKey).execute();
if (response.isSuccessful() && response.body() != null) {
return response.body();
return response.body().getStatus();
} else {
throw new RuntimeException("Error getting prediction: " + response.code() + " - " + response.message());
throw new RuntimeException("Error sending NETWORK usage: " + response.code() + " - " + response.message());
}
} catch (IOException e) {
throw new RuntimeException("Error getting prediction: " + e.getMessage());
throw new RuntimeException("Error sending NETWORK usage: " + e.getMessage());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,58 +13,55 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
**/
*/
package com.bellande_api.bellande_storage_usage;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;

import com.bellande_api.bellande_storage_usage.bellande_storage_usage_usage_service;
import com.bellande_api.bellande_storage_usage.bellande_storage_usage_usage_api;
import com.google.firebase.crashlytics.buildtools.reloc.com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.google.gson.reflect.*;

import com.google.gson.reflect.TypeToken;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Type;
import java.util.Map;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class bellande_storage_usage_usage_activity extends AppCompatActivity {
private bellande_storage_usage_usage_service bellande_storage_usage_usage_service;
public class bellande_storage_usage_activity extends AppCompatActivity {
protected bellande_storage_usage_service storageUsageService;
protected String connectivityPasscode;

public bellande_storage_usage_usage_activity(Context context) {
public bellande_storage_usage_activity(Context context) {
Map<String, Object> config = loadConfigFromFile(context);
String apiUrl = (String) config.get("url");
String endpointPath = (String) ((Map<String, Object>) config.get("endpoint_path")).get("prediction");
Map<String, String> endpointPaths = (Map<String, String>) config.get("endpoint_path");
String inputEndpoint = endpointPaths.get("input_data");
String outputEndpoint = endpointPaths.get("output_data");
String apiAccessKey = (String) config.get("Bellande_Framework_Access_Key");
this.connectivityPasscode = (String) config.get("connectivity_passcode");

bellande_storage_usage_usage_api bellande_storage_usage_usage_api = new Retrofit.Builder()
.baseUrl(apiUrl + endpointPath)
bellande_storage_usage_api storageUsageApi = new Retrofit.Builder()
.baseUrl(apiUrl)
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(bellande_storage_usage_usage_api.class);
.create(bellande_storage_usage_api.class);

bellande_storage_usage_usage_service = new bellande_storage_usage_usage_service(apiUrl, endpointPath, apiAccessKey, bellande_storage_usage_usage_api);
storageUsageService = new bellande_storage_usage_service(apiUrl, inputEndpoint, outputEndpoint, apiAccessKey, storageUsageApi);
}

@SuppressLint("LongLogTag")
private Map<String, Object> loadConfigFromFile(Context context) {
try {
InputStream inputStream = context.getAssets().open("configs.json");
InputStreamReader reader = new InputStreamReader(inputStream);
Type type = new TypeToken<Map<String, Object>>() {}.getType();
Type type = new TypeToken<Map<String, Object>>(){}.getType();
return new Gson().fromJson(reader, type);
} catch (IOException e) {
Log.e("bellande_network_usage_activity", "Error reading config file: " + e.getMessage());
Log.e("bellande_storage_usage_base_activity", "Error reading config file: " + e.getMessage());
}
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,42 @@
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
**/

*/
package com.bellande_api.bellande_storage_usage;

import com.google.gson.annotations.SerializedName;

import okhttp3.MultipartBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Multipart;
import retrofit2.http.Header;
import retrofit2.http.POST;
import retrofit2.http.Part;
import retrofit2.http.Url;

public interface bellande_storage_usage_usage_api {
@Multipart
@POST("prediction")
Call<BellandeResponse> getPrediction(@Part MultipartBody.Part pointCloud);
public interface bellande_storage_usage_api {
@POST
Call<BellandeResponse> getBellandeResponse(@Url String url, @Body RequestBody body, @Header("Bellande-Framework-Access-Key") String apiKey);

class RequestBody {
private final MultipartBody.Part pointCloud;
@POST
Call<BellandeResponse> sendBellandeResponse(@Url String url, @Body RequestBody body, @Header("Bellande-Framework-Access-Key") String apiKey);

public RequestBody(MultipartBody.Part pointCloud) {
this.pointCloud = pointCloud;
}
class RequestBody {
private final String input;
private final String connectivityPasscode;

public MultipartBody.Part getPointCloud() {
return pointCloud;
public RequestBody(String input, String connectivityPasscode) {
this.input = input;
this.connectivityPasscode = connectivityPasscode;
}
}

class BellandeResponse {
@SerializedName("prediction")
public String prediction;
private String cpuUsage;
private String status;

public String getCpuUsage() {
return cpuUsage;
}

@SerializedName("confidence")
public double confidence;
public String getStatus() {
return status;
}
}
}
Loading

0 comments on commit 5a99f0d

Please sign in to comment.