Git Product home page Git Product logo

statistics's Introduction

Statistics

Statistics is a Swift package for interacting with Statistics Sweden's Open Data API.

Swift


Installation

Statistics is available through Swift Package Manager. To install it, simply include it in your package dependency list:

dependencies: [
    .package(url: "https://github.com/devmaximilian/Statistics.git", from: "1.0.0"),
]

– alternatively using Xcode via File > Swift Packages > Add Package Dependency...

Usage

Fetch topics by subject area 🗃

let client = Statistics.defaultClient

// Get root navigation structure
client.navigationPublisher(for: .root)
    .assertNoFailure()
    .map(\.text)
    .sink { links in {
        print(links) // -> ["Labour market", "Population", ...]
    }

Retrieve filtered statistics by a given subject 📊

// Get table (population by region, only total population)
client.tablePublisher(for: "BE0101A", subject: "BefolkningNy")
    .configureRequest { builder in
        builder.select("BE0101N1")
            .filter("Region", by: "00")
    }
    .assertNoFailure()
    .sink { table in {
        print(table) // -> Table...
    }

Only want/need data within a given interval? 📅

// Get table (population by region, only total population between 1970 – 1980)
client.tablePublisher(for: "BE0101A", subject: "BefolkningNy")
    .configureRequest { builder in
        builder.select("BE0101N1")
            .filter("Region", by: "00")
            .between("1970", "1980")
    }
    .assertNoFailure()
    .sink { table in {
        print(table) // -> Table...
    }

Legal disclaimer

The developer and this package are not affiliated with or endorsed by Statistics Sweden. Any products and services provided through this package are not supported or warrantied by Statistics Sweden.

License

See LICENSE for license details concerning this package. Read more about using Statistics Sweden's Open Data API here for details concerning the data provided by their API and license information.

statistics's People

Contributors

devmaximilian avatar

Stargazers

 avatar  avatar

Watchers

 avatar

statistics's Issues

Consider implementing support for the json-stat response format

Implement support for the json-stat response format.

Example request

curl -X POST https://api.scb.se/OV0104/v1/doris/sv/ssd/BE/BE0101/BE0101A/BefolkningNy -d '{
  "query": [],
  "response": {
    "format": "json-stat"
  }
}'

Example response

{
  "dataset": {
    "status": {
      "52": ".."
    },
    "dimension": {
      "Region": {
        "label": "region",
        "category": {
          "index": {
            "00": 0
          },
          "label": {
            "00": "Riket"
          }
        }
      },
      "ContentsCode": {
        "label": "tabellinnehåll",
        "category": {
          "index": {
            "BE0101N1": 0,
            "BE0101N2": 1
          },
          "label": {
            "BE0101N1": "Folkmängd",
            "BE0101N2": "Folkökning"
          },
          "unit": {
            "BE0101N1": {
              "base": "antal",
              "decimals": 0
            },
            "BE0101N2": {
              "base": "antal",
              "decimals": 0
            }
          }
        }
      },
      "Tid": {
        "label": "år",
        "category": {
          "index": {
            "1968": 0,
          },
          "label": {
            "1968": "1968"
          }
        }
      },
      "id": [
        "Region",
        "ContentsCode",
        "Tid"
      ],
      "size": [
        1,
        2,
        52
      ],
      "role": {
        "metric": [
          "ContentsCode"
        ],
        "time": [
          "Tid"
        ]
      }
    },
    "label": "Folkmängden efter region, tabellinnehåll och år",
    "source": "SCB",
    "updated": "2021-01-07T11:26:00Z",
    "value": [
      7931193
    ]
  }
}

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.