Search in sources :

Example 1 with Unstructured

use of com.snowplowanalytics.snowplow.tracker.events.Unstructured in project Terasology by MovingBlocks.

the class TelemetryUtils method fetchMetricAndSend.

/**
 * Fetch metric in {@link org.terasology.context.Context} and send to the server.
 * This method could be used in the modules.
 * @param context The game context
 * @param metricClass The class of the metric which we want to track
 * @param nameSpace The name the class tracking this metric.
 */
public static void fetchMetricAndSend(Context context, Class metricClass, String nameSpace) {
    Emitter emitter = context.get(Emitter.class);
    Metrics metrics = context.get(Metrics.class);
    TelemetryConfiguration telemetryConfiguration = context.get(TelemetryConfiguration.class);
    if (emitter != null && metrics != null && telemetryConfiguration != null) {
        Optional<Metric> metricOptional = metrics.getMetric(metricClass);
        if (metricOptional.isPresent()) {
            Metric metric = metricOptional.get();
            Optional<Unstructured> unstructuredOptional = metric.getUnstructuredMetric();
            if (unstructuredOptional.isPresent()) {
                Unstructured unstructured = unstructuredOptional.get();
                trackMetric(emitter, nameSpace, unstructured, metric, telemetryConfiguration);
            }
        }
    } else {
        logger.error("Emitter or metrics or telemetryConfiguration is not in context");
    }
}
Also used : Emitter(com.snowplowanalytics.snowplow.tracker.emitter.Emitter) TelemetryConfiguration(org.terasology.config.facade.TelemetryConfiguration) Unstructured(com.snowplowanalytics.snowplow.tracker.events.Unstructured) Metric(org.terasology.telemetry.metrics.Metric)

Example 2 with Unstructured

use of com.snowplowanalytics.snowplow.tracker.events.Unstructured in project Terasology by MovingBlocks.

the class TelemetryUtils method fetchMetricAndSend.

/**
 * Fetch metric in {@link org.terasology.engine.context.Context} and send to the server.
 * This method could be used in the modules.
 * @param context The game context
 * @param metricClass The class of the metric which we want to track
 * @param nameSpace The name the class tracking this metric.
 */
public static void fetchMetricAndSend(Context context, Class metricClass, String nameSpace) {
    Emitter emitter = context.get(Emitter.class);
    Metrics metrics = context.get(Metrics.class);
    TelemetryConfiguration telemetryConfiguration = context.get(TelemetryConfiguration.class);
    if (emitter != null && metrics != null && telemetryConfiguration != null) {
        Optional<Metric> metricOptional = metrics.getMetric(metricClass);
        if (metricOptional.isPresent()) {
            Metric metric = metricOptional.get();
            Optional<Unstructured> unstructuredOptional = metric.getUnstructuredMetric();
            if (unstructuredOptional.isPresent()) {
                Unstructured unstructured = unstructuredOptional.get();
                trackMetric(emitter, nameSpace, unstructured, metric, telemetryConfiguration);
            }
        }
    } else {
        logger.error("Emitter or metrics or telemetryConfiguration is not in context");
    }
}
Also used : Emitter(com.snowplowanalytics.snowplow.tracker.emitter.Emitter) TelemetryConfiguration(org.terasology.engine.config.facade.TelemetryConfiguration) Unstructured(com.snowplowanalytics.snowplow.tracker.events.Unstructured) Metric(org.terasology.engine.telemetry.metrics.Metric)

Example 3 with Unstructured

use of com.snowplowanalytics.snowplow.tracker.events.Unstructured in project Terasology by MovingBlocks.

the class Metric method getUnstructuredMetric.

/**
 * Generates a snowplow unstructured event.
 * This method helps to implement abstract getUnstructuredMetric method.
 * You can find example in {@link org.terasology.engine.telemetry.metrics.ModulesMetric}
 * and {@link org.terasology.engine.telemetry.metrics.SystemContextMetric}
 * @param schema the snowplow event register schema.
 * @param mapSentToServer the map that contains the data sent to the server.
 * @return Null option if the mapSentToServer doesn't contain data.
 */
public Optional<Unstructured> getUnstructuredMetric(String schema, Map<String, Object> mapSentToServer) {
    Optional<Unstructured> optional = Optional.empty();
    if (!isEmpty()) {
        SelfDescribingJson modulesData = new SelfDescribingJson(schema, mapSentToServer);
        Unstructured unstructured = Unstructured.builder().eventData(modulesData).build();
        optional = Optional.of(unstructured);
    }
    return optional;
}
Also used : Unstructured(com.snowplowanalytics.snowplow.tracker.events.Unstructured) SelfDescribingJson(com.snowplowanalytics.snowplow.tracker.payload.SelfDescribingJson)

Example 4 with Unstructured

use of com.snowplowanalytics.snowplow.tracker.events.Unstructured in project Terasology by MovingBlocks.

the class TelemetryUtils method fetchMetricAndSend.

/**
 * fetch metric in {@link org.terasology.telemetry.Metrics} and send to the server.
 * @param metrics Metrics class in the game context.
 * @param metricClass The class of metric.
 * @param emitter Emitter sending telemetry to the server.
 * @param nameSpace The name the class tracking this metric.
 * @param bindingMap the binding map contains fields who has user's permission.
 */
public static void fetchMetricAndSend(Metrics metrics, Class metricClass, Emitter emitter, String nameSpace, Map<String, Boolean> bindingMap) {
    Optional<Metric> optional = metrics.getMetric(metricClass);
    if (optional.isPresent()) {
        Metric metric = optional.get();
        Optional<Unstructured> unstructuredOptional = metric.getUnstructuredMetric();
        if (unstructuredOptional.isPresent()) {
            Unstructured unstructured = unstructuredOptional.get();
            trackMetric(emitter, nameSpace, unstructured, metric, bindingMap);
        }
    }
}
Also used : Unstructured(com.snowplowanalytics.snowplow.tracker.events.Unstructured) Metric(org.terasology.telemetry.metrics.Metric)

Example 5 with Unstructured

use of com.snowplowanalytics.snowplow.tracker.events.Unstructured in project Terasology by MovingBlocks.

the class Metric method getUnstructuredMetric.

/**
 * Generates a snowplow unstructured event.
 * This method helps to implement abstract getUnstructuredMetric method.
 * You can find example in {@link org.terasology.telemetry.metrics.ModulesMetric} and {@link org.terasology.telemetry.metrics.SystemContextMetric}
 * @param schema the snowplow event register schema.
 * @param mapSentToServer the map that contains the data sent to the server.
 * @return Null option if the mapSentToServer doesn't contain data.
 */
public Optional<Unstructured> getUnstructuredMetric(String schema, Map<String, Object> mapSentToServer) {
    Optional<Unstructured> optional = Optional.empty();
    if (!isEmpty()) {
        SelfDescribingJson modulesData = new SelfDescribingJson(schema, mapSentToServer);
        Unstructured unstructured = Unstructured.builder().eventData(modulesData).build();
        optional = Optional.of(unstructured);
    }
    return optional;
}
Also used : Unstructured(com.snowplowanalytics.snowplow.tracker.events.Unstructured) SelfDescribingJson(com.snowplowanalytics.snowplow.tracker.payload.SelfDescribingJson)

Aggregations

Unstructured (com.snowplowanalytics.snowplow.tracker.events.Unstructured)6 Emitter (com.snowplowanalytics.snowplow.tracker.emitter.Emitter)2 SelfDescribingJson (com.snowplowanalytics.snowplow.tracker.payload.SelfDescribingJson)2 Metric (org.terasology.engine.telemetry.metrics.Metric)2 Metric (org.terasology.telemetry.metrics.Metric)2 TelemetryConfiguration (org.terasology.config.facade.TelemetryConfiguration)1 TelemetryConfiguration (org.terasology.engine.config.facade.TelemetryConfiguration)1