136 lines
3.3 KiB
Java
136 lines
3.3 KiB
Java
package com.rubenvandeven.emotionhero;
|
|
|
|
import android.util.Log;
|
|
|
|
import com.affectiva.android.affdex.sdk.detector.Face;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* Created by ruben on 16/08/16.
|
|
*/
|
|
|
|
abstract public class Scenario {
|
|
|
|
float duration = 0;
|
|
|
|
ArrayList<Target> targets = new ArrayList<>();
|
|
|
|
abstract void createScenario();
|
|
|
|
class Target {
|
|
public Emotion emotion;
|
|
public float value;
|
|
public float timestamp;
|
|
}
|
|
|
|
ArrayList<Score> scores = new ArrayList<>();
|
|
|
|
class Score {
|
|
public float value;
|
|
/**
|
|
* Extra bonus given
|
|
*/
|
|
public boolean isSpotOn = false;
|
|
/**
|
|
* The target the score is awarded for
|
|
*/
|
|
public Target target;
|
|
}
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
public Scenario()
|
|
{
|
|
createScenario();
|
|
}
|
|
|
|
/**
|
|
* Add a target on given timestamp
|
|
* @param emotion
|
|
* @param value
|
|
* @param timestamp
|
|
*/
|
|
public void setTarget(Emotion emotion, float value, float timestamp)
|
|
{
|
|
Log.e("SET", Float.toString(timestamp) + " " + Float.toString(duration));
|
|
if(timestamp > duration)
|
|
{
|
|
duration = timestamp;
|
|
}
|
|
Target target = new Target();
|
|
target.timestamp = timestamp;
|
|
target.value = value;
|
|
target.emotion = emotion;
|
|
targets.add(target);
|
|
}
|
|
|
|
/**
|
|
* Add target after existing targets, give delta with last item instead of absolute time.
|
|
* @param emotion
|
|
* @param value
|
|
* @param interval
|
|
*/
|
|
public void addTarget(Emotion emotion, float value, float interval)
|
|
{
|
|
float timestamp;
|
|
if(targets.isEmpty()) {
|
|
timestamp = interval;
|
|
} else {
|
|
timestamp = targets.get(targets.size() - 1).timestamp + interval;
|
|
}
|
|
setTarget(emotion, value, timestamp);
|
|
}
|
|
|
|
public void validateFaceOnTime(Face face, float timestamp)
|
|
{
|
|
// TODO: interpolation of time
|
|
for (int i = targets.size() - 1; i >= 0; i--) {
|
|
Target target = targets.get(i);
|
|
if(target.timestamp > timestamp - 0.2 && target.timestamp < timestamp + 0.2) {
|
|
float scored_value = target.emotion.getValueFromFace(face);
|
|
float required_value = target.value;
|
|
Score score = new Score();
|
|
score.value = 100 - Math.abs(scored_value-required_value);
|
|
score.target = target;
|
|
scores.add(score);
|
|
}
|
|
}
|
|
}
|
|
|
|
public float getTotalScore()
|
|
{
|
|
float value = 0;
|
|
for (Score score : scores) {
|
|
value += score.value;
|
|
}
|
|
return value;
|
|
}
|
|
|
|
/**
|
|
* Check whether given timestamp is within duration of the scenario
|
|
* @param timestamp
|
|
* @return
|
|
*/
|
|
public boolean isWithinTime(float timestamp)
|
|
{
|
|
Log.e("TEST", Float.toString(timestamp) + " " + Float.toString(duration));
|
|
return timestamp <= duration;
|
|
}
|
|
|
|
}
|
|
|
|
class ScenarioAnger extends Scenario{
|
|
void createScenario()
|
|
{
|
|
Log.e("TESTING", "CREATE SCENARIO!!!!");
|
|
setTarget(Emotion.ANGER, 10, 1);
|
|
setTarget(Emotion.ANGER, 20, 2);
|
|
setTarget(Emotion.ANGER, 40, 3);
|
|
setTarget(Emotion.ANGER, 70, 4);
|
|
setTarget(Emotion.ANGER, 100, 5);
|
|
}
|
|
} |