npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ts-data-model

v1.0.10

Published

Library for the data model objects used in VIDA

Downloads

24

Readme

ts-data-model library

Using the library

To install the library in your project

    yarn add "ts-data-model"

To use the library in your react project

import { DataModel, fromDhis2 } from "ts-data-model"

const x = DataModel({ input: data, adapter: fromDhis2 })

Library Documentation

The ts-data-model libary consists of 4 major modules:

  1. Data Adapters
  2. Data Transformations
  3. Data Formmaters
  4. Utils functions

Mapping

| Function | Function type | Functions used in implementation | | ----------------: | ------------------: | --------------------------------------: | | fromDhis2 | Data Adapter | findPosition, transpose, fromColumnDict | | fromColumnDict | Data Adapter | | | fromArrayOfArrays | Data Adapter | | | toColumnDict | Data Formatter | | | toArrayOfArrays | Data Formatter | | | apply | Data Transformation | | | map | Data Transformation | addColumns, apply | | agg | Data Transformation | | | join | Data Transformation | innerJoin, outerJoin | | filter | Data Transformation | buildFilterFn, evaluateOr, evaluateAnd | | addColumns | Data Transformation | | | fillNaN | Data Transformation | detectNaN | | dropNaN | Data Transformation | detectNaN | | selectColumns | Data Transformation | | | rename | Data Transformation | | | transpose | Utils | | | findPosition | Utils | | | innerJoin | Utils | | | outerJoin | Utils | |

Mapping diagram

Diagram

Data Adapters

Description: Data adapters are functions that convert output from different sources to the standard data model structure i.e. an array of objects

fromDhis2

Description: function to convert output from a dhis2 analytics query to the standard model structure i.e. an array of objects Example usage

import { DataModel } from "ts-data-model"
 const response = {
    headers: [
                { name: "dx", column: "Data", valueType: "TEXT", type: "java.lang.String", hidden: false, meta: true,},
                { name: "pe", column: "Period", valueType: "TEXT", type: "java.lang.String", hidden: false, meta: true,},
                { name: "ou", column: "Organisation unit", valueType: "TEXT", type: "java.lang.String", hidden: false, meta: true,},
                {name: "value", column: "Value", valueType: "NUMBER", type: "java.lang.Double", hidden: false, meta: false,},
                {name: "factor", column: "Factor", valueType: "NUMBER", type: "java.lang.Double", hidden: false, meta: false,},
                {name: "multiplier", column: "Multiplier", valueType: "NUMBER", type: "java.lang.Double", hidden: false, meta: false,},
                {name: "denominator", column: "Denominator", valueType: "NUMBER", type: "java.lang.Double", hidden: false, meta: false,},
                {name: "divisor", column: "Divisor", valueType: "NUMBER", type: "java.lang.Double", hidden: false, meta: false,},
              ]
    rows:
            [
               ['fbfJHSPpUQD', '202205', 'ARZ4y5i4reU', '18', '0', '0', '0', '0', '0'];
               ['fbfJHSPpUQD', '202201', 'YmmeuGbqOwR', '23', '0', '0', '0', '0', '0']
            ]
  }

const data = new DataModel({ input: response, adapter: fromDhis2 })

fromColumnDict

Description: You can create the data model object from a column dictionary using the fromColumnDict adapter Example usage

import { DataModel } from "ts-data-model"
const d2 = {
  "column 1": ["1", "2"],
  "column 2": ["3", "4"],
}

const data = new DataModel({ input: response, adapter: fromColumnDict })

Data Transformations

Description: functions that operate on a data model object, changing its columns or rows, but returning an object that keeps the structure of the data model. Transformations are categorizd into Aggregators, Selectors, Reducers, Mutators

Aggregators

Transformations implemented: agg Example usage

import { agg } from "ts-data-model"

const aggregations = [
  ["age", "sum"],
  ["age", "mean"],
]

const result = data.agg({ groupBy: ["city", "gender"], aggregations })

Reducers

Transformations implemented: filter Example usage:

import { filter } from "ts-data-model"

const filterCriteria = [
  "city",
  "=",
  ["London", "Paris"],
  "&&",
  "age",
  ">",
  30,
  "&&",
  "age",
  "<=",
  40,
]

const filteredData = data.filterData({ filterCriteria: filterCriteria })

Mutators

Transformations implemented: apply, fillNaN

apply

Example usage

const transformFn = (row) => {
  const bonus = row.salary * 0.1
  return { age: row.age * 2, salary: row.salary + bonus, name: row.name }
}

const transformedData = data.apply({ transformFn: transformFn })

fillNaN

Example usage

data.fillNaN()