Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6566405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:12:47+00:00 2026-05-25T14:12:47+00:00

So I have an array to be rendered and displayed in some charts, but

  • 0

So I have an array to be rendered and displayed in some charts, but say my dataset is going to be far too large, how can I take an array that is say 20,000 items in length and like either drop every other item until the array is 1,000 items or interpolate the array until it’s that size?

Example, say I have the following array (of hashes):

[ 
  {"timestamp"=>2011-09-05 14:30:00 UTC, "count"=>4488.0},
  {"timestamp"=>2011-09-05 14:45:00 UTC, "count"=>4622.0},
  {"timestamp"=>2011-09-05 15:00:00 UTC, "count"=>4655.0},
  {"timestamp"=>2011-09-05 15:15:00 UTC, "count"=>4533.0},
  {"timestamp"=>2011-09-05 15:30:00 UTC, "count"=>4439.0},
  {"timestamp"=>2011-09-05 15:45:00 UTC, "count"=>4468.0},
  {"timestamp"=>2011-09-05 16:00:00 UTC, "count"=>4419.0},
  {"timestamp"=>2011-09-05 16:15:00 UTC, "count"=>4430.0},
  {"timestamp"=>2011-09-05 16:30:00 UTC, "count"=>4429.0},
  {"timestamp"=>2011-09-05 16:45:00 UTC, "count"=>4502.0},
  {"timestamp"=>2011-09-05 17:00:00 UTC, "count"=>4497.0},
  {"timestamp"=>2011-09-05 17:15:00 UTC, "count"=>4468.0},
  {"timestamp"=>2011-09-05 17:30:00 UTC, "count"=>4510.0},
  {"timestamp"=>2011-09-05 17:45:00 UTC, "count"=>4547.0},
  {"timestamp"=>2011-09-05 18:00:00 UTC, "count"=>4471.0},
  {"timestamp"=>2011-09-05 18:15:00 UTC, "count"=>4501.0},
  {"timestamp"=>2011-09-05 18:30:00 UTC, "count"=>4451.0},
  {"timestamp"=>2011-09-05 18:45:00 UTC, "count"=>4453.0},
  {"timestamp"=>2011-09-05 19:00:00 UTC, "count"=>4593.0},
  {"timestamp"=>2011-09-05 19:15:00 UTC, "count"=>4540.0},
  {"timestamp"=>2011-09-05 19:30:00 UTC, "count"=>4516.0},
  {"timestamp"=>2011-09-05 19:45:00 UTC, "count"=>4494.0}
]

And I want an array of the intermediary values, either just dropped out of the array or somehow interpolated, like such:

[ 
  {"timestamp"=>2011-09-05 14:45:00 UTC, "count"=>4622.0},
  {"timestamp"=>2011-09-05 15:00:00 UTC, "count"=>4655.0},
  {"timestamp"=>2011-09-05 15:30:00 UTC, "count"=>4439.0},
  {"timestamp"=>2011-09-05 16:00:00 UTC, "count"=>4419.0},
  {"timestamp"=>2011-09-05 16:30:00 UTC, "count"=>4429.0},
  {"timestamp"=>2011-09-05 17:00:00 UTC, "count"=>4497.0},
  {"timestamp"=>2011-09-05 17:30:00 UTC, "count"=>4510.0},
  {"timestamp"=>2011-09-05 18:00:00 UTC, "count"=>4471.0},
  {"timestamp"=>2011-09-05 18:30:00 UTC, "count"=>4451.0},
  {"timestamp"=>2011-09-05 19:00:00 UTC, "count"=>4593.0},
  {"timestamp"=>2011-09-05 19:15:00 UTC, "count"=>4540.0},
  {"timestamp"=>2011-09-05 19:45:00 UTC, "count"=>4494.0}
]

Any thoughts or help on this would be greatly appreciated, I may just be missing the point here as well.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T14:12:48+00:00Added an answer on May 25, 2026 at 2:12 pm
    require 'pp'
    
    # Interval in seconds (30 min)
    INTERVAL = 1800
    
    # generate the data
    start = Time.mktime(2001, 9, 5, 14, 30)
    
    data = Array.new
    1000.times do |i|
      data << {:timestamp => start + i*INTERVAL, :count => rand(4000)}
    end
    
    # Plain data
    pp data
    
    puts # blank
    
    # Simply gets de data from the sample number 300 to 400
    pp data[300..400]
    
    puts # blank
    
    # For example, data from from the second hour, for 3 hours long
    pp data[2*60*60/INTERVAL..(2+3)*60*60/INTERVAL]
    
    puts # blank
    
    # Make it smaller (50%)
    # We need data.size * 0.5 elements
    # Calculate the step we need to iterate to get
    # 50% elements. In this case skipping one between two
    step = (data.size/(data.size * 0.5)).to_i
    
    # We use Range#step to get the array of indexes, and then
    # transform it using Enumerable#collect to get the array
    # of Hashes. and filter nils
    #
    # Probably there is a simpler way to do this. Too late to think
    pp (0..data.size).step(step.to_i).collect {|index| data[index]}.reject{|x| x.nil?}
    

    Also you may want to look a Enumerable#each_slice(n)

    (1..10).each_slice(3) {|a| p a}
        # outputs below
        [1, 2, 3]
        [4, 5, 6]
        [7, 8, 9]
        [10]
    

    You can reduce the set by making slices of n elements, and then creating a new element from each slice. The element in the middle, an average, etc.

    data.each_slice(3).collect { |slice| make_one_out_of_a_slice(slice) }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say you have an array that is rendered in a ul with an
Let's say I have array of bytes: byte[] arr = new byte[] { 0,
Have an array of chars like char members[255]. How can I empty it completely
Let's say, that we have: $pages = array( array( 'controller' => 'controller1', 'label' =>
i have the following array: $keyvisual_data = array( 'video_file' => $row->field_field_video[0]['rendered']['#item']['uri'], 'bild_file' => $row->field_field_bild[0]['rendered']['#item']['uri'],
I have array of select tag. <select id='uniqueID' name=status> <option value=1>Present</option> <option value=2>Absent</option> </select>
I have array like this: $path = array ( [0] => site\projects\terrace_and_balcony\mexico.jpg [1] =>
if i have array array[0] = jack; array[1] = jill; array[2] = lisa; array[2]
An array is defined of assumed elements like I have array like String[] strArray
VISUAL C++ Question Hi, I have array of 3 elements and I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.