Search in sources :

Example 1 with Table

use of com.djrapitops.plan.extension.table.Table in project Plan by plan-player-analytics.

the class ExtensionsDatabaseTest method extensionServerAggregateQueriesWork.

@Test
default void extensionServerAggregateQueriesWork() {
    ExtensionSvc extensionService = extensionService();
    extensionService.register(new PlayerExtension());
    extensionService.updatePlayerValues(playerUUID, TestConstants.PLAYER_ONE_NAME, CallEvents.MANUAL);
    List<ExtensionData> ofServer = db().query(new ExtensionServerDataQuery(serverUUID()));
    assertFalse(ofServer.isEmpty());
    ExtensionData extensionData = ofServer.get(0);
    List<ExtensionTabData> tabs = extensionData.getTabs();
    // No tab defined, should contain 1 tab
    assertEquals(1, tabs.size());
    ExtensionTabData tabData = tabs.get(0);
    System.out.println(tabData.getValueOrder());
    OptionalAssert.equals("0.0", tabData.getPercentage("boolVal_aggregate").map(data -> data.getFormattedValue(Objects::toString)));
    OptionalAssert.equals("0.5", tabData.getPercentage("percentageVal_avg").map(data -> data.getFormattedValue(Objects::toString)));
    OptionalAssert.equals("0.5", tabData.getDouble("doubleVal_avg").map(data -> data.getFormattedValue(Objects::toString)));
    OptionalAssert.equals("0.5", tabData.getDouble("doubleVal_total").map(data -> data.getFormattedValue(Objects::toString)));
    OptionalAssert.equals("5", tabData.getNumber("value_avg").map(data -> data.getFormattedValue(Objects::toString)));
    OptionalAssert.equals("5", tabData.getNumber("value_total").map(data -> data.getFormattedValue(Objects::toString)));
    List<ExtensionTableData> tableData = tabData.getTableData();
    assertEquals(1, tableData.size());
    HtmlTable table = tableData.get(0).getHtmlTable();
    String result = table.toHtml();
    assertTrue(result.contains("<tbody><tr><td>Group</td><td>1</td></tr></tbody>"), result);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) com.djrapitops.plan.extension.annotation(com.djrapitops.plan.extension.annotation) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) Map(java.util.Map) RemoveUnsatisfiedConditionalServerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalServerResultsTransaction) DatabaseTestPreparer(com.djrapitops.plan.storage.database.DatabaseTestPreparer) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) ExtensionServerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery) TestConstants(utilities.TestConstants) NotReadyException(com.djrapitops.plan.extension.NotReadyException) ExtensionPlayerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery) Table(com.djrapitops.plan.extension.table.Table) ExtensionDataBuilder(com.djrapitops.plan.extension.builder.ExtensionDataBuilder) TestErrorLogger(utilities.TestErrorLogger) HtmlTable(com.djrapitops.plan.delivery.rendering.html.structure.HtmlTable) DataExtension(com.djrapitops.plan.extension.DataExtension) OptionalAssert(utilities.OptionalAssert) Color(com.djrapitops.plan.extension.icon.Color) ExtensionServerTableDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerTableDataQuery) Icon(com.djrapitops.plan.extension.icon.Icon) RemoveEverythingTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) Objects(java.util.Objects) List(java.util.List) Assertions(org.junit.jupiter.api.Assertions) CallEvents(com.djrapitops.plan.extension.CallEvents) RandomData(utilities.RandomData) com.djrapitops.plan.extension.implementation.results(com.djrapitops.plan.extension.implementation.results) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) RemoveUnsatisfiedConditionalPlayerResultsTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.results.RemoveUnsatisfiedConditionalPlayerResultsTransaction) HtmlTable(com.djrapitops.plan.delivery.rendering.html.structure.HtmlTable) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) ExtensionServerDataQuery(com.djrapitops.plan.extension.implementation.storage.queries.ExtensionServerDataQuery) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test)

Example 2 with Table

use of com.djrapitops.plan.extension.table.Table in project Plan by plan-player-analytics.

the class QueriedTables method toQueriedTabs.

public QueriedTabData toQueriedTabs() {
    QueriedTabData tabData = new QueriedTabData();
    for (Map.Entry<Integer, Map<Integer, Table.Factory>> entry : byPluginID.entrySet()) {
        Integer pluginID = entry.getKey();
        for (Table.Factory table : entry.getValue().values()) {
            // Extra Table information
            String tableName = TableAccessor.getTableName(table);
            Color tableColor = TableAccessor.getColor(table);
            // Extra tab information
            String tabName = TableAccessor.getTabName(table);
            ExtensionTabData.Builder tab = tabData.getTab(pluginID, tabName, () -> extractTabInformation(table));
            tab.putTableData(new ExtensionTableData(tableName, table.build(), tableColor));
        }
    }
    return tabData;
}
Also used : ExtensionTabData(com.djrapitops.plan.extension.implementation.results.ExtensionTabData) Table(com.djrapitops.plan.extension.table.Table) ExtensionTableData(com.djrapitops.plan.extension.implementation.results.ExtensionTableData) Color(com.djrapitops.plan.extension.icon.Color) Map(java.util.Map) HashMap(java.util.HashMap)

Example 3 with Table

use of com.djrapitops.plan.extension.table.Table in project Plan by plan-player-analytics.

the class DataValueGatherer method storePlayerTable.

private void storePlayerTable(Parameters parameters, Conditions conditions, TableDataValue data) {
    ProviderInformation information = data.getInformation();
    Table value = getValue(conditions, data, information);
    if (value == null)
        return;
    Database db = dbSystem.getDatabase();
    for (Icon icon : value.getIcons()) {
        if (icon != null)
            db.executeTransaction(new StoreIconTransaction(icon));
    }
    db.executeTransaction(new StoreTableProviderTransaction(information, parameters, value));
    db.executeTransaction(new StorePlayerTableResultTransaction(information, parameters, value));
}
Also used : StoreIconTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction) Table(com.djrapitops.plan.extension.table.Table) Database(com.djrapitops.plan.storage.database.Database) Icon(com.djrapitops.plan.extension.icon.Icon) ProviderInformation(com.djrapitops.plan.extension.implementation.ProviderInformation) StoreTableProviderTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreTableProviderTransaction)

Example 4 with Table

use of com.djrapitops.plan.extension.table.Table in project Plan by plan-player-analytics.

the class DataValueGatherer method storeTable.

private void storeTable(Parameters parameters, Conditions conditions, TableDataValue data) {
    ProviderInformation information = data.getInformation();
    Table value = getValue(conditions, data, information);
    if (value == null)
        return;
    Database db = dbSystem.getDatabase();
    for (Icon icon : value.getIcons()) {
        if (icon != null)
            db.executeTransaction(new StoreIconTransaction(icon));
    }
    db.executeTransaction(new StoreTableProviderTransaction(information, parameters, value));
    db.executeTransaction(new StoreServerTableResultTransaction(information, parameters, value));
}
Also used : StoreIconTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction) Table(com.djrapitops.plan.extension.table.Table) Database(com.djrapitops.plan.storage.database.Database) Icon(com.djrapitops.plan.extension.icon.Icon) ProviderInformation(com.djrapitops.plan.extension.implementation.ProviderInformation) StoreTableProviderTransaction(com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreTableProviderTransaction)

Example 5 with Table

use of com.djrapitops.plan.extension.table.Table in project Plan by plan-player-analytics.

the class HtmlTableTest method dynamicTableProducesSameHtmlAsOldCode.

@Test
void dynamicTableProducesSameHtmlAsOldCode() {
    // Produced by old code
    String expected = "<table class=\"table table-bordered table-striped table-hover player-plugin-table\" style=\"width: 100%\"><thead><tr><th><i class=\" fa fa-test\"></i> Col 1</th><th><i class=\" fa fa-test\"></i> Col 2</th><th><i class=\" fa fa-test\"></i> Col 3</th></tr></thead><tbody><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr>" + "<tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr>" + "<tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr><tr><td data-order=\"1\">1</td><td data-order=\"2\">2</td><td>three</td></tr></tbody></table>";
    Icon icon = Icon.called("test").build();
    Table.Factory buildingTable = Table.builder().columnOne("Col 1", icon).columnTwo("Col 2", icon).columnThree("Col 3", icon);
    for (int i = 0; i < 60; i++) {
        buildingTable.addRow("1", 2, "three");
    }
    String result = HtmlTable.fromExtensionTable(buildingTable.build(), Color.AMBER).toHtml();
    assertEquals(expected, result);
}
Also used : Table(com.djrapitops.plan.extension.table.Table) Icon(com.djrapitops.plan.extension.icon.Icon) Test(org.junit.jupiter.api.Test)

Aggregations

Table (com.djrapitops.plan.extension.table.Table)5 Icon (com.djrapitops.plan.extension.icon.Icon)4 Color (com.djrapitops.plan.extension.icon.Color)2 ProviderInformation (com.djrapitops.plan.extension.implementation.ProviderInformation)2 StoreIconTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.StoreIconTransaction)2 StoreTableProviderTransaction (com.djrapitops.plan.extension.implementation.storage.transactions.providers.StoreTableProviderTransaction)2 Database (com.djrapitops.plan.storage.database.Database)2 Map (java.util.Map)2 Test (org.junit.jupiter.api.Test)2 HtmlTable (com.djrapitops.plan.delivery.rendering.html.structure.HtmlTable)1 CallEvents (com.djrapitops.plan.extension.CallEvents)1 DataExtension (com.djrapitops.plan.extension.DataExtension)1 ExtensionSvc (com.djrapitops.plan.extension.ExtensionSvc)1 NotReadyException (com.djrapitops.plan.extension.NotReadyException)1 com.djrapitops.plan.extension.annotation (com.djrapitops.plan.extension.annotation)1 ExtensionDataBuilder (com.djrapitops.plan.extension.builder.ExtensionDataBuilder)1 com.djrapitops.plan.extension.implementation.results (com.djrapitops.plan.extension.implementation.results)1 ExtensionTabData (com.djrapitops.plan.extension.implementation.results.ExtensionTabData)1 ExtensionTableData (com.djrapitops.plan.extension.implementation.results.ExtensionTableData)1 ExtensionPlayerDataQuery (com.djrapitops.plan.extension.implementation.storage.queries.ExtensionPlayerDataQuery)1