Commit e4e581be authored by José Soares's avatar José Soares

Changed values of division by time

parent 3ac8856c
......@@ -46,6 +46,7 @@ import com.senception.contextualmanager.services.ContextualManagerInterfaceServi
*/
public class ContextualManagerMainActivity extends Activity {
public final long TIMESTAMP = System.currentTimeMillis();
private static final String TAG = ContextualManagerMainActivity.class.getSimpleName();
int backButtonCount = 0;
private ContextualManagerService reportBoundService;
......
package com.senception.contextualmanager.inference;
import com.senception.contextualmanager.activities.ContextualManagerMainActivity;
import com.senception.contextualmanager.services.ContextualManagerCaptureService;
import java.util.ArrayList;
/**
......@@ -63,15 +66,15 @@ public class ContextualManagerAvailability {
}
//-1+30 = 30 --> 30/currentHour
else if ( usagePerHour1.get(i) == -1 && usagePerHour2.get(i) != -1){
res.add(usagePerHour2.get(i) / System.currentTimeMillis()/1000);
res.add(usagePerHour2.get(i) / (System.currentTimeMillis() - ContextualManagerCaptureService.TIMESTAMP)/60*1000);
}
//30+-1 = 30 --> 30/currentHour
else if (usagePerHour2.get(i) == -1 && usagePerHour1.get(i) != -1){
res.add(usagePerHour1.get(i) / System.currentTimeMillis()/1000);
res.add(usagePerHour1.get(i) / (System.currentTimeMillis() - ContextualManagerCaptureService.TIMESTAMP)/60*1000);
}
//30+30 = 60 --> 60/currentHour
else{
res.add((usagePerHour1.get(i) + usagePerHour2.get(i)) / System.currentTimeMillis()/1000); //todo optimize without dividing for the hour in the sumArrays method
else{ // Maybe we should use the time in hours instead of minutes
res.add((usagePerHour1.get(i) + usagePerHour2.get(i)) / ( (System.currentTimeMillis() - ContextualManagerCaptureService.TIMESTAMP)/60*1000)); //todo optimize without dividing for the hour in the sumArrays method
}
}
return res;
......
......@@ -73,6 +73,7 @@ public class ContextualManagerCaptureService extends Service {
private static AlarmReceiver alarmReceiverHourly;
private static AlarmReceiver alarmReceiverDaily;
private static ContextualManagerDataSource dataSource;
public static final long TIMESTAMP = System.currentTimeMillis();
@SuppressLint("NewApi")
@Override
......@@ -260,6 +261,7 @@ public class ContextualManagerCaptureService extends Service {
/*Availability Calculation:*/
// Captures the R (b*b*cpu*mem*storage) every hour (for tests: min)
rList.add(ContextualManagerAvailability.calculateR(energy.getUsagePerHour(), cpu.getUsagePerHour(), memory.getUsagePerHour(), storage.getUsagePerHour()));
//Log.d(TAG, "RList: " + rList);
// Calculates the A - availability (sum of all Rs) every hour (for tests: min)
availability = ContextualManagerAvailability.calculateA(rList);
Log.d(TAG, availability.toString());
......@@ -348,20 +350,20 @@ public class ContextualManagerCaptureService extends Service {
Log.d(TAG, "Captured the physical resource usage " + pru.getResourceType() + "with usage: " + level);
pru.getUsagePerHour().set(currentMinute, level);
break;
case CPU:
case CPU: //100d - because we want not the used but the available
double cpuUsage = ContextualManagerCPU.getCpuUsageStatistic();
Log.d(TAG, "Captured the physical resource usage " + pru.getResourceType() + "with usage: " + cpuUsage);
pru.getUsagePerHour().set(currentMinute, cpuUsage);
pru.getUsagePerHour().set(currentMinute, 100d - cpuUsage);
break;
case MEMORY:
double mem = ContextualManagerMemory.getCurrentRam(this);
Log.d(TAG, "Captured the physical resource usage " + pru.getResourceType() + "with usage: " + mem);
pru.getUsagePerHour().set(currentMinute, mem);
pru.getUsagePerHour().set(currentMinute, 100d - mem);
break;
case STORAGE:
double storageUsg = ContextualManagerStorage.getCurrentStorage();
Log.d(TAG, "Captured the physical resource usage " + pru.getResourceType() + "with usage: " + storageUsg);
pru.getUsagePerHour().set(currentMinute, storageUsg);
pru.getUsagePerHour().set(currentMinute, 100d - storageUsg);
break;
default:
Log.d(TAG, "THAT RESOURCE ISN'T RECOGNIZED.");
......@@ -461,4 +463,5 @@ public class ContextualManagerCaptureService extends Service {
}
return false;
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment