Search in sources :

Example 1 with TelemetryCategory

use of org.terasology.telemetry.TelemetryCategory in project Terasology by MovingBlocks.

the class Metric method createTelemetryFieldList.

/**
 * Get a list of all the telemetry field names marked with {@link org.terasology.telemetry.TelemetryField} annotation in this class.
 * The field name is in the form telemetryCategory.id() + ":" fieldName.
 * @return the list of all the telemetry field names in this class.
 */
public List<String> createTelemetryFieldList() {
    TelemetryCategory telemetryCategory = this.getClass().getAnnotation(TelemetryCategory.class);
    List<String> fieldsList = new ArrayList<>();
    if (!telemetryCategory.isOneMapMetric()) {
        Set<Field> fields = ReflectionUtils.getFields(this.getClass(), ReflectionUtils.withAnnotation(TelemetryField.class));
        for (Field field : fields) {
            String fieldName = telemetryCategory.id() + ":" + field.getName();
            fieldsList.add(fieldName);
        }
    }
    return fieldsList;
}
Also used : TelemetryField(org.terasology.telemetry.TelemetryField) Field(java.lang.reflect.Field) TelemetryCategory(org.terasology.telemetry.TelemetryCategory) ArrayList(java.util.ArrayList) TelemetryField(org.terasology.telemetry.TelemetryField)

Example 2 with TelemetryCategory

use of org.terasology.telemetry.TelemetryCategory in project Terasology by MovingBlocks.

the class Metric method filterMetricMap.

/**
 * Filter the metric map by the binding map.
 * If the user doesn't want the field to be sent, its value will be covered by "Disabled Field".
 * @param bindingMap the binding map.
 * @return a new metric map that covers the field that the user doesn't want to send by "Disabled Field".
 */
protected Map<String, Object> filterMetricMap(Map<String, Boolean> bindingMap) {
    TelemetryCategory telemetryCategory = this.getClass().getAnnotation(TelemetryCategory.class);
    Context context = CoreRegistry.get(Context.class);
    DisplayDevice display = context.get(DisplayDevice.class);
    if (display.isHeadless() || telemetryCategory.isOneMapMetric()) {
        return telemetryFieldToValue;
    }
    Map<String, Object> metricMapAfterPermission = new HashMap<>();
    for (String fieldName : telemetryFieldToValue.keySet()) {
        String fieldNameWithID = telemetryCategory.id() + ":" + fieldName;
        if (bindingMap.containsKey(fieldNameWithID)) {
            if (bindingMap.get(fieldNameWithID)) {
                metricMapAfterPermission.put(fieldName, telemetryFieldToValue.get(fieldName));
            } else {
                metricMapAfterPermission.put(fieldName, "Disabled Field");
            }
        }
    }
    return metricMapAfterPermission;
}
Also used : Context(org.terasology.context.Context) TelemetryCategory(org.terasology.telemetry.TelemetryCategory) DisplayDevice(org.terasology.engine.subsystem.DisplayDevice) HashMap(java.util.HashMap)

Example 3 with TelemetryCategory

use of org.terasology.telemetry.TelemetryCategory in project Terasology by MovingBlocks.

the class Metric method filterMetricMap.

/**
 * Filter the metric map by the binding map.
 * If the user doesn't want the field to be sent, its value will be covered by "Disabled Field".
 * This method could be used in module since {@link org.terasology.config.facade.TelemetryConfiguration} is exposed to modules
 * @param telemetryConfiguration the telemetry configuration exposed modules
 * @return a new metric map that covers the field that the user doesn't want to send by "Disabled Field".
 */
protected Map<String, Object> filterMetricMap(TelemetryConfiguration telemetryConfiguration) {
    TelemetryCategory telemetryCategory = this.getClass().getAnnotation(TelemetryCategory.class);
    Context context = CoreRegistry.get(Context.class);
    DisplayDevice display = context.get(DisplayDevice.class);
    if (display.isHeadless() || telemetryCategory.isOneMapMetric()) {
        return telemetryFieldToValue;
    }
    Map<String, Object> metricMapAfterPermission = new HashMap<>();
    for (String fieldName : telemetryFieldToValue.keySet()) {
        String fieldNameWithID = telemetryCategory.id() + ":" + fieldName;
        if (telemetryConfiguration.containsField(fieldNameWithID)) {
            if (telemetryConfiguration.get(fieldNameWithID)) {
                metricMapAfterPermission.put(fieldName, telemetryFieldToValue.get(fieldName));
            } else {
                metricMapAfterPermission.put(fieldName, "Disabled Field");
            }
        }
    }
    return metricMapAfterPermission;
}
Also used : Context(org.terasology.context.Context) TelemetryCategory(org.terasology.telemetry.TelemetryCategory) DisplayDevice(org.terasology.engine.subsystem.DisplayDevice) HashMap(java.util.HashMap)

Aggregations

TelemetryCategory (org.terasology.telemetry.TelemetryCategory)3 HashMap (java.util.HashMap)2 Context (org.terasology.context.Context)2 DisplayDevice (org.terasology.engine.subsystem.DisplayDevice)2 Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 TelemetryField (org.terasology.telemetry.TelemetryField)1