Skip to content

gitter-badger/json-stat.java

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Implementation of JSON Stat in Java - http://json-stat.org

Status

Build Status Maven Central Javadoc

Usage

Add json stat dependency into your project

<dependency>
            <groupId>no.ssb.jsonstat</groupId>
            <artifactId>json-stat</artifactId>
            <version>0.1.3</version>
</dependency>

Create a new json stat data set

Dataset.Builder builder = Dataset.create().withLabel("")
        .withDimension(Dimension.create("year")
                .withRole(Dimension.Roles.TIME)
                .withIndexedLabels(ImmutableMap.of("2003", "2003", "2004", "2004", "2005", "2005")))

        .withDimension(Dimension.create("month").withRole(Dimension.Roles.TIME)
                .withIndexedLabels(ImmutableMap.of("may", "may", "june", "june", "july", "july")))

        .withDimension(Dimension.create("week").withTimeRole()
                .withIndexedLabels(ImmutableMap.of("30", "30", "31", "31", "32", "32")))

        .withDimension(Dimension.create("population")
                .withIndexedLabels(ImmutableMap.of(
                        "A", "active population",
                        "E", "employment",
                        "U", "unemployment",
                        "I", "inactive population",
                        "T", "population 15 years old and over"
                )))
        .withDimension(Dimension.create("amount").withMetricRole()
                .withIndexedLabels(ImmutableMap.of("millions", "millions")))

        .withDimension(Dimension.create("percent").withMetricRole()
                .withIndexedLabels(ImmutableMap.of("%", "percent")));


Dataset dataset = builder.withMapper(
        dimensions -> newArrayList(
                dimensions.hashCode(),
                dimensions.hashCode())
);

Deserialize a dataset

mapper = new ObjectMapper();
mapper.registerModule(new JsonStatModule());

Dataset.Builder builder = mapper.readValue("{ ... }", Dataset.Builder.class);
// Or
Dataset dataset = mapper.readValue("{ ... }", Dataset.class);

About

Implementation of JSON Stat in Java

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%