Implement data gathering pipe for GraphHistoryPointsProvider

This commit is contained in:
Aurora Lahtela 2024-06-21 19:31:26 +03:00
parent 831c4665fa
commit 46f61e7403
5 changed files with 92 additions and 0 deletions

View File

@ -23,6 +23,8 @@ import com.djrapitops.plan.extension.annotation.Conditional;
import com.djrapitops.plan.extension.annotation.StringProvider;
import com.djrapitops.plan.extension.annotation.Tab;
import com.djrapitops.plan.extension.extractor.ExtensionMethod;
import com.djrapitops.plan.extension.graph.DataPoint;
import com.djrapitops.plan.extension.graph.HistoryStrategy;
import com.djrapitops.plan.extension.icon.Color;
import com.djrapitops.plan.extension.icon.Family;
import com.djrapitops.plan.extension.icon.Icon;
@ -288,6 +290,11 @@ public interface ValueBuilder {
*/
DataValue<String[]> buildGroup(Supplier<String[]> groups);
/**
* Lambda version for conditional return or throwing {@link com.djrapitops.plan.extension.NotReadyException}.
*/
DataValue<DataPoint[]> buildGraphHistoryPoints(Supplier<DataPoint[]> historyData, String methodName, HistoryStrategy appendStrategy);
/**
* Lambda version for conditional return or throwing {@link com.djrapitops.plan.extension.NotReadyException}.
* <p>

View File

@ -18,6 +18,7 @@ package com.djrapitops.plan.extension.implementation;
import com.djrapitops.plan.extension.FormatType;
import com.djrapitops.plan.extension.annotation.Conditional;
import com.djrapitops.plan.extension.graph.HistoryStrategy;
import com.djrapitops.plan.extension.icon.Color;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.results.ExtensionDescription;
@ -44,6 +45,7 @@ public class ProviderInformation extends ExtensionDescription {
private final Color tableColor; // can be null, TableProvider
private final boolean percentage; // affects where doubles are stored
private final boolean component; // affects where strings are stored
private final HistoryStrategy appendStrategy;
private ProviderInformation(ProviderInformation.Builder builder) {
super(
@ -64,6 +66,7 @@ public class ProviderInformation extends ExtensionDescription {
tableColor = builder.tableColor;
percentage = builder.percentage;
component = builder.component;
appendStrategy = builder.appendStrategy;
}
public static ProviderInformation.Builder builder(String pluginName) {
@ -110,6 +113,10 @@ public class ProviderInformation extends ExtensionDescription {
}
}
public Optional<HistoryStrategy> getAppendStrategy() {
return Optional.ofNullable(appendStrategy);
}
private String getTruncatedConditionName() {
return StringUtils.truncate(condition.value(), 50);
}
@ -159,6 +166,7 @@ public class ProviderInformation extends ExtensionDescription {
private Color tableColor; // can be null, TableProvider
private boolean percentage; // affects where doubles are stored
private boolean component; // affects where strings are stored
private HistoryStrategy appendStrategy;
public Builder(String pluginName) {
this.pluginName = pluginName;
@ -242,5 +250,10 @@ public class ProviderInformation extends ExtensionDescription {
public ProviderInformation build() {
return new ProviderInformation(this);
}
public Builder setAppendStrategy(HistoryStrategy appendStrategy) {
this.appendStrategy = appendStrategy;
return this;
}
}
}

View File

@ -25,6 +25,8 @@ import com.djrapitops.plan.extension.annotation.PluginInfo;
import com.djrapitops.plan.extension.builder.DataValue;
import com.djrapitops.plan.extension.builder.ValueBuilder;
import com.djrapitops.plan.extension.extractor.ExtensionMethod;
import com.djrapitops.plan.extension.graph.DataPoint;
import com.djrapitops.plan.extension.graph.HistoryStrategy;
import com.djrapitops.plan.extension.icon.Color;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.ProviderInformation;
@ -174,6 +176,15 @@ public class ExtValueBuilder implements ValueBuilder {
.build();
}
private ProviderInformation getGraphHistoryProviderInformation(String methodName, HistoryStrategy appendStrategy) {
return ProviderInformation.builder(pluginName)
.setName(methodName)
.setPriority(0)
.setTab(tabName)
.setAppendStrategy(appendStrategy)
.build();
}
@Override
public DataValue<Boolean> buildBoolean(boolean value) {
return new BooleanDataValue(value, getProviderInformation());
@ -254,6 +265,11 @@ public class ExtValueBuilder implements ValueBuilder {
return new GroupsDataValue(groups, getProviderInformation());
}
@Override
public DataValue<DataPoint[]> buildGraphHistoryPoints(Supplier<DataPoint[]> historyData, String methodName, HistoryStrategy appendStrategy) {
return new GraphHistoryPoints(historyData, getGraphHistoryProviderInformation(methodName, appendStrategy));
}
@Override
public DataValue<Table> buildTable(Table table, Color tableColor) {
return new TableDataValue(table, getTableProviderInformation(tableColor));

View File

@ -0,0 +1,35 @@
/*
* This file is part of Player Analytics (Plan).
*
* Plan is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License v3 as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Plan is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
*/
package com.djrapitops.plan.extension.implementation.builder;
import com.djrapitops.plan.extension.graph.DataPoint;
import com.djrapitops.plan.extension.implementation.ProviderInformation;
import java.util.function.Supplier;
/**
* @author AuroraLS3
*/
public class GraphHistoryPoints extends BuiltDataValue<DataPoint[]> {
public GraphHistoryPoints(DataPoint[] value, ProviderInformation information) {
super(value, information);
}
public GraphHistoryPoints(Supplier<DataPoint[]> supplier, ProviderInformation information) {
super(supplier, information);
}
}

View File

@ -26,6 +26,7 @@ import com.djrapitops.plan.extension.builder.DataValue;
import com.djrapitops.plan.extension.builder.ExtensionDataBuilder;
import com.djrapitops.plan.extension.extractor.ExtensionMethod;
import com.djrapitops.plan.extension.extractor.ExtensionMethods;
import com.djrapitops.plan.extension.graph.DataPoint;
import com.djrapitops.plan.extension.icon.Color;
import com.djrapitops.plan.extension.icon.Icon;
import com.djrapitops.plan.extension.implementation.ExtensionWrapper;
@ -163,6 +164,22 @@ public class DataValueGatherer {
if (brokenMethods.contains(provider)) continue;
addDataFromAnotherBuilder(dataBuilder, parameters, provider);
}
for (ExtensionMethod provider : methods.getGraphHistoryPointsProviders()) {
if (brokenMethods.contains(provider)) continue;
dataBuilder.addValue(DataPoint[].class, tryToBuildDataPoints(dataBuilder, parameters, provider));
}
}
private DataValue<DataPoint[]> tryToBuildDataPoints(ExtensionDataBuilder dataBuilder, Parameters parameters, ExtensionMethod provider) {
GraphHistoryPointsProvider annotation = provider.getExistingAnnotation(GraphHistoryPointsProvider.class);
try {
return dataBuilder.valueBuilder(provider.getMethodName())
.methodName(provider)
.buildGraphHistoryPoints(() -> callMethod(provider, parameters, DataPoint[].class), annotation.methodName(), annotation.strategy());
} catch (IllegalArgumentException e) {
logFailure(e, getPluginName(), provider.getMethodName());
return null;
}
}
private DataValue<Table> tryToBuildTable(ExtensionDataBuilder dataBuilder, Parameters parameters, ExtensionMethod provider) {
@ -382,6 +399,8 @@ public class DataValueGatherer {
.ifPresent(data -> storePlayerGroups(parameters, conditions, data));
pair.getValue(Table.class).flatMap(data -> data.getMetadata(TableDataValue.class))
.ifPresent(data -> storePlayerTable(parameters, conditions, data));
pair.getValue(DataPoint[].class).flatMap(data -> data.getMetadata(GraphHistoryPoints.class))
.ifPresent(data -> {/*TODO #2544 - Store data after the metadata tables are already done.*/});
} catch (DataExtensionMethodCallException methodError) {
logFailure(methodError);
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError unexpectedError) {
@ -406,6 +425,8 @@ public class DataValueGatherer {
.ifPresent(data -> storeComponent(parameters, conditions, data));
pair.getValue(Table.class).flatMap(data -> data.getMetadata(TableDataValue.class))
.ifPresent(data -> storeTable(parameters, conditions, data));
pair.getValue(DataPoint[].class).flatMap(data -> data.getMetadata(GraphHistoryPoints.class))
.ifPresent(data -> {/*TODO #2544 - Store data after the metadata tables are already done.*/});
} catch (DataExtensionMethodCallException methodError) {
logFailure(methodError);
} catch (RejectedExecutionException ignore) {