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

groupbytime

v0.1.0

Published

Group an Array by time duration given. Allows the coder for example to group an array by 3.5 minute intervals into groups.

Downloads

26

Readme

Group By Time (Javascript/NODEJS)

I have been trying to find a way to group data together according to time without expensive algorithms and after a very long search decided to do it. The Problem addressed is that a set of data with a unix time stamp on each record is to be grouped by years, months, days, hours, minutes or seconds.

The main use of this was to be able to group times together after filtering from certian Databases and also keep the latency low. To be able to do so, data is set into an array and is processed really fast using only mathmatical operations and methods to generate timestamp hashes. You can take a look at the code and understand it more as an algorithm.

Usage

First install the module using npm

$ npm install groupbytime

Next you will need to require the module

var gb = require("groupbytime");

Finally you will need to use the function groupBy(dataArray, startingDateUnixTimeStamp, endDateUnixTimeStamp, groupByTime)

  • dataArray; should always contain a ts field with the records Unix Time Stamp
  • startingDateUnixTimeStamp; should be the start of the timestamp sequence where the data with be grouped by into it
  • endDateUnixTimeStamp; should be the when this set of data ends in unix time stamp format
  • groupByTime; is by how much time do you want to group by in seconds, example group By 3 Minutes (360) or group by 1.5 days (1.5246060)

Note: That the group by will generate a list of all times within the timeframe and will have data in it, if there is no data for a certain time then it will be empty.

var groupby = require("groupbytime");
//TS field added to all records, start and time date added, and asked to group by 5 minutes. 
console.log(
  groupby.groupBy(
    [
      {"id":1,"ts":1414415561,"data":"hi"},
      {"id":2,"ts":1414414561,"data":"hiiiii"}, 
      {"id":3,"ts":1414414559,"data":"new entry"},
      {"id":4,"ts":1414422033,"data":"End Date"},
      {"id":5,"ts":1414412033,"data":"Start Date"},
    ],1414412033,1414422033, 60*5)
);