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

DataManager

v1.1.0

Published

Abstraction into crossfilter using schemas.

Downloads

6

Readme

Managing data filtering, and grouping, simply.

A full interactive example can be found here

TODO: convert Makefile to gulpfile

Quick Example


var DM = dataManager() // create new data manaager
         .schema({
              quantity: { // this is the name of the field in the dataset.
                  type: 'integer' // convert the string to an integer (so summing works properly)
                , filter: null // no filtering.
              }
            , 'date' : { // filtering on the date field
                  type: 'date' // parse into a date
                , filter: 'reporting_dt' // filter is by date
                , group: {
                      day: { // this is the day grouping config. The name is arbitrary based on how you group your data.
                          reduce : 'sum' // reduce by summing
                        // If not specifying this field, then use the dimension filter field
                        //, map: 'reporting_dt' // group by date. Dates are by day anyhow
                        , sum: 'quantity' // sum the quantity field.
                      }
                    , week: {
                          reduce : 'sum' // reduce by summing
                        , map: 'week' // group by week field. This a string field in the data.
                        , sum: 'item_quantity' // This could also be a function that returns a value to be summed.
                      }
                  }
              }
            , 'object-class': { // this is an arbitrary name used to access this filter.
                  type: 'string'
                , filter: 'class_id' // this is the name of the field to filter by in the dataset
                , group: {
                      objects: {
                          reduce:'sum' // Want to sum in reduce.
                        , sum: 'quantity' // field to sum by.
                      }
                  }
              }
         })
         .setData(myData) // assumed myData is an array of objects containg the data.
         .filter('object-class','Fruit') // filter the object class by "Fruit"
         .filter('date',[new Date('2022-12-15'),new Date('2022-12-24')]) // filter also by date range

// Gets the total invoiced grouped by day between the 15th and 24th (inclusive) for only product class 1A
var dailyTotals = DM.group('date','day')
                    .all() // get all data for the group

API Summary

  • dataManager
    • schema(schema definition:Object) : dataManager

      Set the schema definition for this data manager instance.

    • setData(data:Object) : dataManager

      Set the data to be managed.

    • filter(field:String, filter:Array|String ) : dataManager

      Filter a field by some data. Single and multiple values, and ranges are supported. Single value : "abc" Multiple values : ["abc","def"] Value range : [[100,200]]

    • group(field:String, group:String ) : group

      Get the fields grouped set.

    • getDimension(field:String) : dimension

      Get the dimension configuration and access to the crossfilter dimension.

    • all() : groupSummary

      Get the reduced summary of the entire data set.

** Events supported by dataManager: Supported events: 'dataChanged','schemaChanged','filterChanged','dimensionCreated','groupCreated'

Example of using events:

    DM = new dataManager()
    DM.on('schemaChanged',function(oldSchema,newSchema){console.log('The schema changed %s',JSON.stringify(newSchema))})
    DM.on('dataChanged',function(field){console.log('Data changed')})
    DM.on('dimensionCreated',function(field){console.log('New dimension created for "%s"',field)})
    DM.schema({'a':{}}) // we're expecting a single field. No filters or grouping.
    // output to console: The schema changed {"a":{}}
    DM.setData([{a:'one'},{a:'two'},{a:'three'},{a:'ten'},{a:'four'},{a:'three'},{a:'six'},{a:'two'}])
    // output to console: Data changed
    DM.filter('a','two') // filter 'a' dimension by the value 'two'
    // output to console: New dimension created for "a"
    var filtered = DM.getDimension('a').top(Infinity) // get the 'a' dimension, with no limit to count.
    // data returned: ["{"a":"two"}", "{"a":"two"}"]
  • group

    • all()

      Get all data for the grouped set

    • order(value: Function)

      change the sort order function of the grouping

    • orderNatural()

      set the ordering using the natural return of the reduced value

    • reduce(add: Function, remove: Function, initial: Object)

      set the reduce functions (this is done automatically from the schema definition)

    • reduceCount() : void

      set the reduce function to count the number of rows in group.

    • reduceSum(value: String|Function)

      set the reduce function to sum a row, or call a function to return a value to add to the total.

    • size() : int

      Get the number of group keys.

    • top(num: int) : Array

      Get the top NUM records from the group based on the sort order.

  • dimension

    • column: String

      Name of the column in data set that this filter represents.

    • dimension: Object

      Direct access to the crossfilter dimension object.

    • filter(data:Array|String) : dimension

      Filter this dimension by the provided data. Single value : "abc" Multiple values : ["abc","def"] Value range : [[100,200]]

    • group: function (group:String) : group

      get grouping for this dimension by this object.