Esempio n. 1
0
	void reset() {
		Log.d(TAG, "reset EMABudgeter");
		
		resetMinTimes();
		resetBudgets();
		
		// reset the budgets at 4am
		Calendar cal = Calendar.getInstance();

		cal.set(Calendar.MINUTE, 0);
		cal.set(Calendar.SECOND, 0);
		cal.set(Calendar.MILLISECOND, 0);
		
		int hour=0;
		do {
    		cal.roll(Calendar.HOUR_OF_DAY, true);
    		hour = cal.get(Calendar.HOUR_OF_DAY);
    		if (hour == 0) {
    			cal.roll(Calendar.DAY_OF_YEAR, true);
    		}    		
		} while (hour != EMABudgeter.RESET_BUDGET_HOUR);

		
		timeToReset = cal.getTimeInMillis();
				
		String s = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG).format(cal.getTime());
		Log.d(TAG, "timeToReset = " + s);
	}
Esempio n. 2
0
	void updateBudget(String itemDesc, long timestamp) {
		if (timeToReset == 0 || timeToReset <= timestamp) {
			Log.d(TAG, "Resetting budgeter");
			reset();
		}
		
		remainingItemBudget.put(itemDesc, remainingItemBudget.get(itemDesc) - 1);
		remainingBudget--;
		lastTime = timestamp;
		
		Log.d(TAG, "Updating budget for " + itemDesc + " to " + remainingItemBudget.get(itemDesc));
		Log.d(TAG, "Updating total remaining budget to " + remainingBudget);
	}
	public void onSurfaceChanged(GL10 gl, int width, int height) {
		Log.d(TAG, "adusting for screen resolution (" + width + ", " + height + ")");
	     pixelWidth = width;
	     pixelHeight = height;
	    
	     resetWindowWidths();
	}
	public void receiveBuffer(int sensorID, int[] buffer, long[] timestamps,
			int startNewData, int endNewData) {
		if (Log.DEBUG) Log.d("FeatureCalculation", "sensor ID = " + sensorID);

		if (active) {
			if (mapping!=null && !mapping.isEmpty()) {
				if (featureRunner== null || !featureRunner.isAlive()) {
					Log.d("FeatureCalculation","Init FeatureRunner");
					featureRunner = FeatureRunner.getInstance();
					featureRunner.start();
				}
				
				featureRunner.addBuffer(new FeatureData(sensorID,buffer,timestamps));		
			}
		}
	}
Esempio n. 5
0
	void resetBudgets() {
		Log.d(TAG, "reseting budgets to initial amounts");
		remainingItemBudget.clear();
		Set<String> keys = totalItemBudget.keySet();
		for (String key : keys) {
			remainingItemBudget.put(key, totalItemBudget.get(key));
		}
		
		remainingBudget = totalBudget;
	}
	public void finalize() {
		active = false;
		INSTANCE = null;
		SensorBus.getInstance().unsubscribe(this);
		if(featureRunner!= null && featureRunner.isAlive()) {
			featureRunner.stop();
		}
		featureRunner= null;
		
		Log.d(TAG, "Destroyed FeatureCalculation");
	}
Esempio n. 7
0
	boolean checkBudget(String itemDesc) {
		long now = System.currentTimeMillis(); 
		if (timeToReset == 0 || timeToReset <= now) {
			Log.d(TAG, "Resetting budgeter");
			reset();
		}

		int itemBudget = 0;
		if (remainingItemBudget.containsKey(itemDesc)) {
			itemBudget = remainingItemBudget.get(itemDesc);
		}
		
		boolean pass = itemBudget > 0 && now > lastTime + minTimeBeforeNext && remainingBudget > 0;
		
		if (pass)
			Log.d(TAG, "budget check passed - can trigger " + itemDesc + " EMA");
		else 
			Log.d(TAG, "budget check failed - cannot trigger " + itemDesc + " EMA");
		
		return pass;
	}
Esempio n. 8
0
	void removeItem(String itemDesc) {
		Log.d(TAG, "Removing " + itemDesc);

		remainingItemBudget.remove(itemDesc);
		totalItemBudget.remove(itemDesc);
	}
Esempio n. 9
0
	void addOrUpdateItem(String itemDesc, int budget) {
		Log.d(TAG, "Adding " + itemDesc + " with budget of " + budget);
		this.totalItemBudget.put(itemDesc, budget);
		this.remainingItemBudget.put(itemDesc, budget);
	}
Esempio n. 10
0
	void setMinTimeBeforeNext(long minTimeBeforeNext) {
		Log.d(TAG, "At least " + minTimeBeforeNext + "ms before next EMA");
		this.minTimeBeforeNext = minTimeBeforeNext;
	}
Esempio n. 11
0
	void setTotalBudget(int totalBudget) {
		Log.d(TAG, "Total EMA budget set to " + totalBudget);
		this.totalBudget = totalBudget;
		remainingBudget = totalBudget;
	}
Esempio n. 12
0
	public void loadChargesFromDB() {
		
		dataLogger = null;
		
		// this is for loading and saving to db
		// only works with the db for now
  		File root = Environment.getExternalStorageDirectory();
  		if (Constants.LOGTODB) {
  			dataLogger = DatabaseLogger.getInstance(this); 
  		}
  		else {
  			return;
  		}

		try {
			
			Cursor c = dataLogger.readEMA(0, System.currentTimeMillis());

			if (c!=null) {
				if (c.moveToFirst()) {
					do {
						Calendar cal = Calendar.getInstance();
						cal.set(Calendar.MINUTE, 0);
						cal.set(Calendar.SECOND, 0);
						cal.set(Calendar.MILLISECOND, 0);
						
						int hour=0;
						do {
				    		cal.roll(Calendar.HOUR_OF_DAY, false);
				    		hour = cal.get(Calendar.HOUR_OF_DAY);
				    		if (hour == 23) {
				    			cal.roll(Calendar.DAY_OF_YEAR, false);
				    		}    		
						} while (hour != EMABudgeter.RESET_BUDGET_HOUR);

				    	
						long lastResetTime = cal.getTimeInMillis();
						
//						int trigger = c.getInt(c.getColumnIndex("trigger_type"));
//						if (trigger == EMALogConstants.TYPE_CONTEXT_CHANGE || trigger == EMALogConstants.TYPE_CONTEXT_TIME || trigger == EMALogConstants.TYPE_INTERRUPTED_BY_CONTEXT_CHANGE || trigger == EMALogConstants.TYPE_INTERRUPTED_BY_CONTEXT_TIME) {
							long timestamp = c.getLong(c.getColumnIndex("prompt_timestamp"));
							if (timestamp > lastResetTime) {
								String models = c.getString(c.getColumnIndex("context"));
								
								long now = System.currentTimeMillis();
								String[] modelsArray = models.split(" ");
								if (modelsArray.length == 1) {
									updateBudget("other", now);
								}
								else {
									updateBudget(modelsArray[0], now);
								}
							}	
					} while (c.moveToNext());
				}
				c.close();
			}		
		} catch (Exception e) {
			if (Log.DEBUG) Log.d("StressInferenceIncentiveManager", e.getLocalizedMessage());
		}

		Log.d(TAG, "Loaded budgets from DB");
		
		dataLogger = null;
		DatabaseLogger.releaseInstance(this);
	}
Esempio n. 13
0
	void resetMinTimes() {
		Log.d(TAG, "reset time since last EMA");
		lastTime = 0;
	}
Esempio n. 14
0
	void removeAllItems() {
		Log.d(TAG, "removing all items from budget");
		
		remainingItemBudget.clear();
		totalItemBudget.clear();
	}