Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/main/java/gg/hoglin/sdk/models/experiment/ExperimentData.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gg.hoglin.sdk.models.experiment;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import gg.hoglin.sdk.Hoglin;
import lombok.Data;
Expand Down Expand Up @@ -55,6 +56,16 @@ public enum Trigger {
@JsonProperty("experiment_id")
private final String experimentId;

/** The internal ID of the visualization linked to this experiment */
@NotNull
@JsonProperty("visualization_id")
private final String visualizationId;

/** The goal of the experiment */
@NotNull
@JsonProperty("experiment_goal")
private final String goal;

/** A description explaining what this experiment is aimed to accomplish */
@Nullable
private final String description;
Expand Down Expand Up @@ -82,6 +93,37 @@ public enum Trigger {
@JsonProperty("experiment_variants")
private final Map<ExperimentVariant.Variant, ExperimentVariant> variants;

@JsonCreator
public ExperimentData(
@JsonProperty("id") @NotNull Integer id,
@JsonProperty("name") @NotNull String name,
@JsonProperty("created_at") @NotNull Instant createdAt,
@JsonProperty("server_id") @NotNull Integer serverId,
@JsonProperty("experiment_id") @NotNull String experimentId,
@JsonProperty("visualization_id") @NotNull String visualizationId,
@JsonProperty("experiment_goal") @NotNull String goal,
@JsonProperty("description") @Nullable String description,
@JsonProperty("enabled") @NotNull Boolean enabled,
@JsonProperty("rollout_percentage") @NotNull Integer rolloutPercentage,
@JsonProperty("allowlist") @NotNull List<UUID> allowlist,
@JsonProperty("experiment_trigger") @NotNull Trigger trigger,
@JsonProperty("experiment_variants") @NotNull Map<ExperimentVariant.Variant, ExperimentVariant> variants
) {
this.id = id;
this.name = name;
this.createdAt = createdAt;
this.serverId = serverId;
this.experimentId = experimentId;
this.visualizationId = visualizationId;
this.goal = goal;
this.description = description;
this.enabled = enabled;
this.rolloutPercentage = rolloutPercentage;
this.allowlist = allowlist;
this.trigger = trigger;
this.variants = variants;
}

/**
* Evaluates whether the specified experiment is currently enabled for this instance. This is a non-player-specific
* experiment evaluation and will only evaluate as true if its rollout percentage is set to 100. For player-specific
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package gg.hoglin.sdk.models.experiment;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import org.jetbrains.annotations.NotNull;

Expand All @@ -15,4 +17,13 @@ public class ExperimentEvaluationResponse {
/** The UUID of the player */
@NotNull
private UUID uuid;

@JsonCreator
public ExperimentEvaluationResponse(
@JsonProperty("inExperiment") @NotNull Boolean inExperiment,
@JsonProperty("uuid") @NotNull UUID uuid
) {
this.inExperiment = inExperiment;
this.uuid = uuid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import org.checkerframework.checker.units.qual.A;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;
Expand Down Expand Up @@ -40,6 +41,14 @@ public enum Action {
@NotNull
private String payload;

public ExperimentVariant(
@JsonProperty("action") @NotNull Action action,
@JsonProperty("payload") @NotNull String payload
) {
this.action = action;
this.payload = payload;
}

/** Format the payload, replacing the appropriate placeholders */
public String formatPayload(String playerName, UUID uuid, Variant variant) {
return payload.replace("{player}", playerName).replace("{uuid}", uuid.toString()).replace("{variant}", variant.name());
Expand Down
Loading