Code Monkey home page Code Monkey logo

json-stat.java's Introduction

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

Status

Build Status Maven Central Javadoc Gitter Chat

Usage

Add json stat dependency into your project

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

Register the module

class Example {
    static {
        mapper = new ObjectMapper();
        mapper.registerModule(new JsonStatModule());
    }
}

Create a new json stat data set

class Example {
    static {
        Dataset.Builder builder = Dataset.create().withLabel("My dataset");

        builder.withDimension(
            Dimension.create("year")
                .withRole(Dimension.Roles.TIME)
                .withIndexedLabels(ImmutableMap.of("2003", "2003", "2004", "2004", "2005", "2005")
            )
        );

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

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

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

        builder.withDimension(
            Dimension.create("amount").withMetricRole()
                .withIndexedLabels(ImmutableMap.of("millions", "millions"))
        );

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

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

Deserialize a dataset

class Example {
    static {
        mapper = new ObjectMapper();
        
        mapper.registerModule(new GuavaModule());
        mapper.registerModule(new Jdk8Module());
        mapper.registerModule(new JavaTimeModule());
        
        mapper.registerModule(new JsonStatModule());

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

json-stat.java's People

Contributors

hadrienk avatar hamnis avatar trygu avatar dependabot[bot] avatar bjornandre avatar eivindgi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.