Not able to remove NaN from ruby array - ruby

I have an array of values
=> [0.0, 4.76, 0.0, Infinity, NaN, 2.63, 0.74, 10.0, NaN, NaN, NaN, NaN, 0.0, NaN, NaN, NaN, NaN, NaN, Infinity, 5.26, NaN, 0.0, NaN, 3.45, 2.5, NaN, 10.0, 0.0, NaN, 2.94, NaN, NaN, 0.0, 2.04, 0.0, 11.11, NaN, NaN, 1.23, NaN, NaN, 11.11, NaN, NaN, NaN, 0.0, 9.68, NaN, NaN, 10.0, 5.0, 3.7, 10.0, Infinity, 0.0, 0.0, 1.41, NaN, 3.45, NaN]
When I run this script to remove NaN's it removes some but not all NaN's.
def remove_from_array(numArray)
numArray.inject(0) do |i|
if numArray[i].nan?
numArray.delete_at(i)
end
i += 1
end
numArray
end
What am I missing?

If you delete an item and move to the next index, you’re moving two items ahead, because the item at the current index no longer exists.
Luckily, there’s a better way, using Array#reject!:
numArray.reject! &:nan?

Related

How to calculate line from a set of polygon points?

Let's say now I have an array that used to describe the shape of a polygon:
[
[0.0, 1.0],
[0.5, 1.0],
[0.5, 0.3],
[1.0, 0.3],
[1.0, 0.0],
[0.0, 0.0]
]
As shown on diagram above, the blue line(s) or vector points list is the result I was looking for.
Assuming the polygon only composed of one or more rectangular shapes, is there any way to extract/simplify the polygon to one or more lines?

How do I screen out NaNs when comparing floats in Ruby?

I'm using Rails 5 wiht Ruby 2.4. How do I determine if a variable is a number? I thought is_a?(Numeric) was the way to go, but apparently not with me. I have this code
puts "guesses arr: #{guesses_arr}"
guesses_arr.map!{|str| str.is_a?(Numeric) && str == guesses_arr.max ? str : 0}
which dies with
guesses arr: [NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN, NaN]
ArgumentError: comparison of Float with NaN failed
from /Users/davea/Documents/workspace/myproject/app/services/text_table_to_race_time_converter_service.rb:2121:in `max'
from /Users/davea/Documents/workspace/myproject/app/services/text_table_to_race_time_converter_service.rb:2121:in `block (2 levels) in guess_headers_from_data_cols'
from /Users/davea/Documents/workspace/myproject/app/services/text_table_to_race_time_converter_service.rb:2121:in `map!'
I'm unable to reproduce this in a console because I can't seem to produce an array with all those "NaN" values. The point is, how do I make sure those don't get compared in my loop?
You can produce an array of NaN values in the console like so:
[ 0.0 / 0.0 ] * 3
# => [NaN, NaN, NaN]
It's not entirely clear what your code is doing, but it might be worth noting that it's the max which is throwing the exception, and not the equality test. Incidentally, if you are trying to compare each array value against the maximum value - you might want to max outside of the map, to avoid having to evaluate it multiple times.
Building on top the other answer here on rejecting NaNs, you can put it all together to get something like:
# set up dummy data - 2 values and 3 NaNs
guesses_arr = [ 0.0 / 0.0 ] * 3 + [ 2.0, 3.0 ]
puts "guesses arr: #{guesses_arr}"
# => [NaN, NaN, NaN, 2.0, 3.0]
# remove NaNs in place
guesses_arr.reject!(&:nan?)
maximum = guesses_arr.max
guesses_arr.map!{|str| str.is_a?(Numeric) && str == maximum ? str : 0}
# => [ 0, 3.0 ]
Edit: if you have integers mixed up in the array, try converting them into floats first:
# set up dummy data - including floats and integers
guesses_arr = [ 0.0 / 0.0 ] * 3 + [ 2.0, 3.0, 0 ]
guesses_arr.map!(&:to_f).reject!(&:nan?)
# => [ 2.0, 3.0, 0.0 ]
You can get NaN by calling Float::NAN:
[7] pry(main)> Float::NAN
=> NaN
[8] pry(main)> Float::NAN.nan?
=> true
If you just want to remove NaN:
guesses_arr.reject! { |x| x.nan? }
For example:
[4] pry(main)> [1.0, Float::NAN].reject(&:nan?)
=> [1.0]
There are a couple of things that we can do. To answer the specific question.
arr = [1.0, Float::NAN, "1.0", "1"]
arr.map(&:to_f).reject(&:nan?)
would be a concise example around removing NaN
With a guess that you are trying to get a max value from inconsistent data, first we need to clean it up with a method like the following, which will convert a string or a integer to a float, or otherwise return nil.
def to_number(maybe_a_number)
Float(maybe_a_number)
rescue ArgumentError
nil
end
Assuming we have the above method
guesses_arr.map(&:to_number).max # or .min
That being said, the reason it's been hard to debug is the fact that you had a .map! that causes guesses_arr to be changing as you move over it. (Generally we avoid use of the standard libraries bang methods as they object errors can be hard to debug.

Ruby stepping through decimals and casting to Array produces unexpected results [duplicate]

This question already has answers here:
Is floating point math broken?
(31 answers)
Closed 5 years ago.
So.. I'm trying to refactor a piece of code, namely:
v = [0.0, 0.10, 0.20, 0.30, 0.40, 0.50, 0.60, 0.70, 0.80, 0.90, 1.0]
By using the .step method. Tried this but it's giving me some odd decimals for some of the numbers. Trying to figure out why this is?
0.0.step(by: 0.1, to: 1.0).to_a
Gives me this result:
=> [0.0,
0.1,
0.2,
0.30000000000000004,
0.4,
0.5,
0.6000000000000001,
0.7000000000000001,
0.8,
0.9,
1.0]
Ruby version: 2.3.0p0
How can I go about figuring out why this is happening? Each of those numbers returns a float.
Floats are inexact. Calculations (like adding) are more exact using Rationals. If you must use floats, convert to Floats after the calculations.
p 0.step(1, 1/10r).map(&:to_f) 3 =>[0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0]

Creating sliding windows of NaN padded elements off 1D NumPy array

I have a time series x[0], x[1], ... x[n-1], stored as a 1 dimensional numpy array. I would like to convert it to the following matrix:
NaN, ... , NaN , x[0]
NaN, ... , x[0], x[1]
.
.
NaN, x[0], ... , x[n-3],x[n-2]
x[0], x[1], ... , x[n-2],x[n-1]
I would like to use this matrix to speedup time-series calculations. Is there a function in numpy or scipy to do this? (I don't want to use for loop in python to do it)
One approach with np.lib.stride_tricks.as_strided -
def nanpad_sliding2D(a):
L = a.size
a_ext = np.concatenate(( np.full(a.size-1,np.nan) ,a))
n = a_ext.strides[0]
strided = np.lib.stride_tricks.as_strided
return strided(a_ext, shape=(L,L), strides=(n,n))
Sample run -
In [41]: a
Out[41]: array([48, 82, 96, 34, 93, 25, 51, 26])
In [42]: nanpad_sliding2D(a)
Out[42]:
array([[ nan, nan, nan, nan, nan, nan, nan, 48.],
[ nan, nan, nan, nan, nan, nan, 48., 82.],
[ nan, nan, nan, nan, nan, 48., 82., 96.],
[ nan, nan, nan, nan, 48., 82., 96., 34.],
[ nan, nan, nan, 48., 82., 96., 34., 93.],
[ nan, nan, 48., 82., 96., 34., 93., 25.],
[ nan, 48., 82., 96., 34., 93., 25., 51.],
[ 48., 82., 96., 34., 93., 25., 51., 26.]])
Memory efficiency with strides
As mentioned in the comments by #Eric, this strides based approach would be a memory efficient one as the output would be simply a view into the NaNs-padded 1D version. Let's test this out -
In [158]: a # Sample 1D input
Out[158]: array([37, 95, 87, 10, 35])
In [159]: L = a.size # Run the posted approach
...: a_ext = np.concatenate(( np.full(a.size-1,np.nan) ,a))
...: n = a_ext.strides[0]
...: strided = np.lib.stride_tricks.as_strided
...: out = strided(a_ext, shape=(L,L), strides=(n,n))
...:
In [160]: np.may_share_memory(a_ext,out) O/p might be a view into extended version
Out[160]: True
Let's confirm that the output is actually a view indeed by assigning values into a_ext and then checking out.
Initial values of a_ext and out :
In [161]: a_ext
Out[161]: array([ nan, nan, nan, nan, 37., 95., 87., 10., 35.])
In [162]: out
Out[162]:
array([[ nan, nan, nan, nan, 37.],
[ nan, nan, nan, 37., 95.],
[ nan, nan, 37., 95., 87.],
[ nan, 37., 95., 87., 10.],
[ 37., 95., 87., 10., 35.]])
Modify a_ext :
In [163]: a_ext[:] = 100
See the new out :
In [164]: out
Out[164]:
array([[ 100., 100., 100., 100., 100.],
[ 100., 100., 100., 100., 100.],
[ 100., 100., 100., 100., 100.],
[ 100., 100., 100., 100., 100.],
[ 100., 100., 100., 100., 100.]])
Confirms that it's a view.
Finally, let's test out the memory requirements :
In [131]: a_ext.nbytes
Out[131]: 72
In [132]: out.nbytes
Out[132]: 200
So, the output even though it shows as 200 bytes is actually just 72 bytes because of being a view into the extended array that has a size of 72 bytes.
One more approach with Scipy's toeplitz -
from scipy.linalg import toeplitz
out = toeplitz(a, np.full(a.size,np.nan) )[:,::-1]

Graphite, averaging algorithm while displaying data

I save data every second.
Here is definition of carbon's time series:
cat /etc/carbon/storage-schemas.conf
[requests]
pattern = ^requests\.
retentions = 1s:7d
For testing purposes I send to the graphite server values of step function:
setInterval(function() {
graphite.put('step', Math.round(Math.random()) );
}, 1000);
The function produces in a random way either 1 or 0 and puts it on requests.beryllium.step target.
Here is the graphite's graph shown for 1 minute:
/render?width=400&from=-2minutes&until=-1minute&height=250&target=requests.beryllium.step&_uniq=0.06224050732088515&title=requests.beryllium.step
On the graph there are 60 data points as expected. I checked this by getting json data:
/render?width=400&from=-2minutes&until=-1minute&height=250&target=requests.beryllium.step&_uniq=0.06224050732088515&title=requests.beryllium.step&format=json
Result (60 points in the array, checked):
[{"target": "requests.beryllium.step", "datapoints": [[1.0, 1472502764], [0.0, 1472502765], [1.0, 1472502766], [0.0, 1472502767], [1.0, 1472502768], [0.0, 1472502769], [1.0, 1472502770], [0.0, 1472502771], [1.0, 1472502772], [1.0, 1472502773], [0.0, 1472502774], [1.0, 1472502775], [0.0, 1472502776], [1.0, 1472502777], [1.0, 1472502778], [0.0, 1472502779], [1.0, 1472502780], [0.0, 1472502781], [1.0, 1472502782], [1.0, 1472502783], [0.0, 1472502784], [1.0, 1472502785], [0.0, 1472502786], [1.0, 1472502787], [0.0, 1472502788], [0.0, 1472502789], [1.0, 1472502790], [1.0, 1472502791], [0.0, 1472502792], [1.0, 1472502793], [0.0, 1472502794], [1.0, 1472502795], [0.0, 1472502796], [1.0, 1472502797], [0.0, 1472502798], [1.0, 1472502799], [1.0, 1472502800], [0.0, 1472502801], [0.0, 1472502802], [0.0, 1472502803], [1.0, 1472502804], [1.0, 1472502805], [1.0, 1472502806], [1.0, 1472502807], [1.0, 1472502808], [0.0, 1472502809], [0.0, 1472502810], [1.0, 1472502811], [1.0, 1472502812], [1.0, 1472502813], [0.0, 1472502814], [1.0, 1472502815], [1.0, 1472502816], [0.0, 1472502817], [0.0, 1472502818], [0.0, 1472502819], [0.0, 1472502820], [0.0, 1472502821], [0.0, 1472502822], [1.0, 1472502823]]}]
All the data points are zeroes or ones and this is what we see on the graph, too. Till now, all is ok.
Now, I draw a graph for 15 mins:
/render?width=400&from=-16minutes&until=-1minute&height=250&target=requests.beryllium.step&_uniq=0.06224050732088515&title=requests.beryllium.step&format=png
On the graph we can see points that are not ones or zeroes. Let's check what are in the points array:
/render?width=400&from=-16minutes&until=-1minute&height=250&target=requests.beryllium.step&_uniq=0.06224050732088515&title=requests.beryllium.step&format=json
The result:
[{"target": "requests.beryllium.step", "datapoints": [[1.0, 1472502324], [0.0, 1472502325], [0.0, 1472502326], [0.0, 1472502327], [1.0, 1472502328], [1.0, 1472502329], [1.0, 1472502330], [0.0, 1472502331], [1.0, 1472502332], [1.0, 1472502333], [0.0, 1472502334], [1.0, 1472502335], [0.0, 1472502336], [0.0, 1472502337], [0.0, 1472502338], [0.0, 1472502339], [0.0, 1472502340], [1.0, 1472502341], [1.0, 1472502342], [1.0, 1472502343], [1.0, 1472502344], [0.0, 1472502345], [1.0, 1472502346], [1.0, 1472502347], [1.0, 1472502348], [1.0, 1472502349], [1.0, 1472502350], [0.0, 1472502351], [0.0, 1472502352], [1.0, 1472502353], [1.0, 1472502354], [0.0, 1472502355], [1.0, 1472502356], [1.0, 1472502357], [0.0, 1472502358], [0.0, 1472502359], [1.0, 1472502360], [1.0, 1472502361], [1.0, 1472502362], [1.0, 1472502363], [1.0, 1472502364], [0.0, 1472502365], [0.0, 1472502366], [1.0, 1472502367], [0.0, 1472502368], [0.0, 1472502369], [0.0, 1472502370], [0.0, 1472502371], [1.0, 1472502372], [1.0, 1472502373], [0.0, 1472502374], [1.0, 1472502375], [1.0, 1472502376], [0.0, 1472502377], [0.0, 1472502378], [1.0, 1472502379], [0.0, 1472502380], [0.0, 1472502381], [1.0, 1472502382], [1.0, 1472502383], [1.0, 1472502384], [1.0, 1472502385], [0.0, 1472502386], [0.0, 1472502387], [1.0, 1472502388], [1.0, 1472502389], [0.0, 1472502390], [1.0, 1472502391], [0.0, 1472502392], [1.0, 1472502393], [0.0, 1472502394], [1.0, 1472502395], [1.0, 1472502396], [1.0, 1472502397], [0.0, 1472502398], [1.0, 1472502399], [1.0, 1472502400], [0.0, 1472502401], [0.0, 1472502402], [0.0, 1472502403], [1.0, 1472502404], [1.0, 1472502405], [0.0, 1472502406], [1.0, 1472502407], [0.0, 1472502408], [1.0, 1472502409], [1.0, 1472502410], [0.0, 1472502411], [0.0, 1472502412], [0.0, 1472502413], [null, 1472502414], [0.0, 1472502415], [0.0, 1472502416], [1.0, 1472502417], [1.0, 1472502418], [1.0, 1472502419], [1.0, 1472502420], [0.0, 1472502421], [1.0, 1472502422], [1.0, 1472502423], [0.0, 1472502424], [1.0, 1472502425], [0.0, 1472502426], [1.0, 1472502427], [0.0, 1472502428], [0.0, 1472502429], [1.0, 1472502430], [1.0, 1472502431], [0.0, 1472502432], [1.0, 1472502433], [1.0, 1472502434], [0.0, 1472502435], [1.0, 1472502436], [0.0, 1472502437], [0.0, 1472502438], [1.0, 1472502439], [0.0, 1472502440], [1.0, 1472502441], [0.0, 1472502442], [1.0, 1472502443], [1.0, 1472502444], [0.0, 1472502445], [1.0, 1472502446], [0.0, 1472502447], [1.0, 1472502448], [0.0, 1472502449], [1.0, 1472502450], [0.0, 1472502451], [0.0, 1472502452], [0.0, 1472502453], [0.0, 1472502454], [0.0, 1472502455], [0.0, 1472502456], [0.0, 1472502457], [0.0, 1472502458], [1.0, 1472502459], [0.0, 1472502460], [1.0, 1472502461], [0.0, 1472502462], [1.0, 1472502463], [0.0, 1472502464], [0.0, 1472502465], [1.0, 1472502466], [0.0, 1472502467], [0.0, 1472502468], [0.0, 1472502469], [0.0, 1472502470], [0.0, 1472502471], [0.0, 1472502472], [0.0, 1472502473], [1.0, 1472502474], [1.0, 1472502475], [0.0, 1472502476], [1.0, 1472502477], [1.0, 1472502478], [1.0, 1472502479], [1.0, 1472502480], [0.0, 1472502481], [1.0, 1472502482], [0.0, 1472502483], [1.0, 1472502484], [1.0, 1472502485], [1.0, 1472502486], [1.0, 1472502487], [0.0, 1472502488], [0.0, 1472502489], [1.0, 1472502490], [1.0, 1472502491], [1.0, 1472502492], [0.0, 1472502493], [0.0, 1472502494], [1.0, 1472502495], [1.0, 1472502496], [0.0, 1472502497], [1.0, 1472502498], [1.0, 1472502499], [0.0, 1472502500], [1.0, 1472502501], [1.0, 1472502502], [0.0, 1472502503], [0.0, 1472502504], [1.0, 1472502505], [1.0, 1472502506], [1.0, 1472502507], [1.0, 1472502508], [1.0, 1472502509], [1.0, 1472502510], [1.0, 1472502511], [1.0, 1472502512], [1.0, 1472502513], [1.0, 1472502514], [0.0, 1472502515], [1.0, 1472502516], [1.0, 1472502517], [0.0, 1472502518], [0.0, 1472502519], [1.0, 1472502520], [1.0, 1472502521], [0.0, 1472502522], [1.0, 1472502523], [0.0, 1472502524], [1.0, 1472502525], [0.0, 1472502526], [1.0, 1472502527], [0.0, 1472502528], [0.0, 1472502529], [0.0, 1472502530], [0.0, 1472502531], [1.0, 1472502532], [0.0, 1472502533], [0.0, 1472502534], [0.0, 1472502535], [1.0, 1472502536], [0.0, 1472502537], [0.0, 1472502538], [1.0, 1472502539], [0.0, 1472502540], [0.0, 1472502541], [0.0, 1472502542], [1.0, 1472502543], [0.0, 1472502544], [0.0, 1472502545], [1.0, 1472502546], [1.0, 1472502547], [0.0, 1472502548], [1.0, 1472502549], [0.0, 1472502550], [1.0, 1472502551], [1.0, 1472502552], [0.0, 1472502553], [0.0, 1472502554], [1.0, 1472502555], [0.0, 1472502556], [1.0, 1472502557], [1.0, 1472502558], [0.0, 1472502559], [0.0, 1472502560], [1.0, 1472502561], [1.0, 1472502562], [1.0, 1472502563], [0.0, 1472502564], [0.0, 1472502565], [1.0, 1472502566], [1.0, 1472502567], [1.0, 1472502568], [1.0, 1472502569], [1.0, 1472502570], [0.0, 1472502571], [1.0, 1472502572], [0.0, 1472502573], [1.0, 1472502574], [1.0, 1472502575], [0.0, 1472502576], [0.0, 1472502577], [0.0, 1472502578], [0.0, 1472502579], [1.0, 1472502580], [0.0, 1472502581], [0.0, 1472502582], [0.0, 1472502583], [1.0, 1472502584], [0.0, 1472502585], [1.0, 1472502586], [0.0, 1472502587], [1.0, 1472502588], [1.0, 1472502589], [1.0, 1472502590], [0.0, 1472502591], [0.0, 1472502592], [0.0, 1472502593], [1.0, 1472502594], [0.0, 1472502595], [1.0, 1472502596], [1.0, 1472502597], [1.0, 1472502598], [0.0, 1472502599], [0.0, 1472502600], [0.0, 1472502601], [1.0, 1472502602], [0.0, 1472502603], [0.0, 1472502604], [0.0, 1472502605], [1.0, 1472502606], [1.0, 1472502607], [1.0, 1472502608], [0.0, 1472502609], [1.0, 1472502610], [1.0, 1472502611], [1.0, 1472502612], [0.0, 1472502613], [0.0, 1472502614], [0.0, 1472502615], [1.0, 1472502616], [1.0, 1472502617], [1.0, 1472502618], [0.0, 1472502619], [1.0, 1472502620], [0.0, 1472502621], [1.0, 1472502622], [0.0, 1472502623], [0.0, 1472502624], [0.0, 1472502625], [0.0, 1472502626], [0.0, 1472502627], [1.0, 1472502628], [1.0, 1472502629], [0.0, 1472502630], [0.0, 1472502631], [0.0, 1472502632], [1.0, 1472502633], [1.0, 1472502634], [0.0, 1472502635], [1.0, 1472502636], [1.0, 1472502637], [0.0, 1472502638], [1.0, 1472502639], [1.0, 1472502640], [0.0, 1472502641], [1.0, 1472502642], [1.0, 1472502643], [1.0, 1472502644], [0.0, 1472502645], [1.0, 1472502646], [1.0, 1472502647], [0.0, 1472502648], [0.0, 1472502649], [1.0, 1472502650], [1.0, 1472502651], [1.0, 1472502652], [1.0, 1472502653], [1.0, 1472502654], [1.0, 1472502655], [1.0, 1472502656], [0.0, 1472502657], [1.0, 1472502658], [1.0, 1472502659], [0.0, 1472502660], [0.0, 1472502661], [0.0, 1472502662], [0.0, 1472502663], [1.0, 1472502664], [1.0, 1472502665], [1.0, 1472502666], [1.0, 1472502667], [1.0, 1472502668], [1.0, 1472502669], [1.0, 1472502670], [0.0, 1472502671], [1.0, 1472502672], [0.0, 1472502673], [0.0, 1472502674], [0.0, 1472502675], [1.0, 1472502676], [0.0, 1472502677], [1.0, 1472502678], [1.0, 1472502679], [0.0, 1472502680], [0.0, 1472502681], [1.0, 1472502682], [0.0, 1472502683], [1.0, 1472502684], [0.0, 1472502685], [0.0, 1472502686], [0.0, 1472502687], [1.0, 1472502688], [0.0, 1472502689], [1.0, 1472502690], [0.0, 1472502691], [0.0, 1472502692], [1.0, 1472502693], [1.0, 1472502694], [0.0, 1472502695], [1.0, 1472502696], [0.0, 1472502697], [1.0, 1472502698], [0.0, 1472502699], [1.0, 1472502700], [1.0, 1472502701], [0.0, 1472502702], [0.0, 1472502703], [1.0, 1472502704], [1.0, 1472502705], [1.0, 1472502706], [0.0, 1472502707], [0.0, 1472502708], [0.0, 1472502709], [1.0, 1472502710], [0.0, 1472502711], [1.0, 1472502712], [1.0, 1472502713], [1.0, 1472502714], [1.0, 1472502715], [0.0, 1472502716], [1.0, 1472502717], [1.0, 1472502718], [0.0, 1472502719], [1.0, 1472502720], [0.0, 1472502721], [1.0, 1472502722], [1.0, 1472502723], [1.0, 1472502724], [0.0, 1472502725], [0.0, 1472502726], [0.0, 1472502727], [1.0, 1472502728], [0.0, 1472502729], [1.0, 1472502730], [0.0, 1472502731], [0.0, 1472502732], [1.0, 1472502733], [1.0, 1472502734], [0.0, 1472502735], [1.0, 1472502736], [1.0, 1472502737], [0.0, 1472502738], [0.0, 1472502739], [0.0, 1472502740], [0.0, 1472502741], [1.0, 1472502742], [0.0, 1472502743], [0.0, 1472502744], [0.0, 1472502745], [0.0, 1472502746], [0.0, 1472502747], [1.0, 1472502748], [0.0, 1472502749], [0.0, 1472502750], [1.0, 1472502751], [1.0, 1472502752], [0.0, 1472502753], [0.0, 1472502754], [0.0, 1472502755], [0.0, 1472502756], [1.0, 1472502757], [1.0, 1472502758], [1.0, 1472502759], [0.0, 1472502760], [0.0, 1472502761], [1.0, 1472502762], [1.0, 1472502763], [1.0, 1472502764], [0.0, 1472502765], [1.0, 1472502766], [0.0, 1472502767], [1.0, 1472502768], [0.0, 1472502769], [1.0, 1472502770], [0.0, 1472502771], [1.0, 1472502772], [1.0, 1472502773], [0.0, 1472502774], [1.0, 1472502775], [0.0, 1472502776], [1.0, 1472502777], [1.0, 1472502778], [0.0, 1472502779], [1.0, 1472502780], [0.0, 1472502781], [1.0, 1472502782], [1.0, 1472502783], [0.0, 1472502784], [1.0, 1472502785], [0.0, 1472502786], [1.0, 1472502787], [0.0, 1472502788], [0.0, 1472502789], [1.0, 1472502790], [1.0, 1472502791], [0.0, 1472502792], [1.0, 1472502793], [0.0, 1472502794], [1.0, 1472502795], [0.0, 1472502796], [1.0, 1472502797], [0.0, 1472502798], [1.0, 1472502799], [1.0, 1472502800], [0.0, 1472502801], [0.0, 1472502802], [0.0, 1472502803], [1.0, 1472502804], [1.0, 1472502805], [1.0, 1472502806], [1.0, 1472502807], [1.0, 1472502808], [0.0, 1472502809], [0.0, 1472502810], [1.0, 1472502811], [1.0, 1472502812], [1.0, 1472502813], [0.0, 1472502814], [1.0, 1472502815], [1.0, 1472502816], [0.0, 1472502817], [0.0, 1472502818], [0.0, 1472502819], [0.0, 1472502820], [0.0, 1472502821], [0.0, 1472502822], [1.0, 1472502823], [1.0, 1472502824], [1.0, 1472502825], [0.0, 1472502826], [0.0, 1472502827], [1.0, 1472502828], [0.0, 1472502829], [1.0, 1472502830], [0.0, 1472502831], [0.0, 1472502832], [0.0, 1472502833], [1.0, 1472502834], [0.0, 1472502835], [1.0, 1472502836], [1.0, 1472502837], [1.0, 1472502838], [1.0, 1472502839], [1.0, 1472502840], [0.0, 1472502841], [1.0, 1472502842], [1.0, 1472502843], [0.0, 1472502844], [1.0, 1472502845], [1.0, 1472502846], [0.0, 1472502847], [1.0, 1472502848], [1.0, 1472502849], [0.0, 1472502850], [1.0, 1472502851], [0.0, 1472502852], [1.0, 1472502853], [0.0, 1472502854], [0.0, 1472502855], [0.0, 1472502856], [1.0, 1472502857], [1.0, 1472502858], [0.0, 1472502859], [0.0, 1472502860], [0.0, 1472502861], [0.0, 1472502862], [1.0, 1472502863], [1.0, 1472502864], [0.0, 1472502865], [1.0, 1472502866], [0.0, 1472502867], [1.0, 1472502868], [0.0, 1472502869], [0.0, 1472502870], [1.0, 1472502871], [1.0, 1472502872], [0.0, 1472502873], [0.0, 1472502874], [0.0, 1472502875], [1.0, 1472502876], [1.0, 1472502877], [1.0, 1472502878], [1.0, 1472502879], [0.0, 1472502880], [0.0, 1472502881], [0.0, 1472502882], [0.0, 1472502883], [0.0, 1472502884], [0.0, 1472502885], [1.0, 1472502886], [1.0, 1472502887], [1.0, 1472502888], [1.0, 1472502889], [1.0, 1472502890], [0.0, 1472502891], [0.0, 1472502892], [1.0, 1472502893], [1.0, 1472502894], [0.0, 1472502895], [1.0, 1472502896], [1.0, 1472502897], [0.0, 1472502898], [0.0, 1472502899], [1.0, 1472502900], [0.0, 1472502901], [0.0, 1472502902], [0.0, 1472502903], [0.0, 1472502904], [1.0, 1472502905], [0.0, 1472502906], [0.0, 1472502907], [1.0, 1472502908], [0.0, 1472502909], [1.0, 1472502910], [0.0, 1472502911], [0.0, 1472502912], [0.0, 1472502913], [1.0, 1472502914], [0.0, 1472502915], [1.0, 1472502916], [1.0, 1472502917], [0.0, 1472502918], [1.0, 1472502919], [0.0, 1472502920], [0.0, 1472502921], [1.0, 1472502922], [1.0, 1472502923], [1.0, 1472502924], [1.0, 1472502925], [1.0, 1472502926], [0.0, 1472502927], [0.0, 1472502928], [1.0, 1472502929], [1.0, 1472502930], [0.0, 1472502931], [1.0, 1472502932], [1.0, 1472502933], [1.0, 1472502934], [1.0, 1472502935], [0.0, 1472502936], [0.0, 1472502937], [1.0, 1472502938], [0.0, 1472502939], [0.0, 1472502940], [0.0, 1472502941], [1.0, 1472502942], [1.0, 1472502943], [0.0, 1472502944], [1.0, 1472502945], [0.0, 1472502946], [1.0, 1472502947], [0.0, 1472502948], [0.0, 1472502949], [0.0, 1472502950], [1.0, 1472502951], [1.0, 1472502952], [1.0, 1472502953], [0.0, 1472502954], [0.0, 1472502955], [1.0, 1472502956], [0.0, 1472502957], [0.0, 1472502958], [1.0, 1472502959], [0.0, 1472502960], [1.0, 1472502961], [0.0, 1472502962], [1.0, 1472502963], [1.0, 1472502964], [0.0, 1472502965], [0.0, 1472502966], [0.0, 1472502967], [0.0, 1472502968], [0.0, 1472502969], [0.0, 1472502970], [0.0, 1472502971], [0.0, 1472502972], [1.0, 1472502973], [1.0, 1472502974], [1.0, 1472502975], [1.0, 1472502976], [0.0, 1472502977], [0.0, 1472502978], [0.0, 1472502979], [0.0, 1472502980], [1.0, 1472502981], [1.0, 1472502982], [0.0, 1472502983], [0.0, 1472502984], [1.0, 1472502985], [0.0, 1472502986], [0.0, 1472502987], [1.0, 1472502988], [0.0, 1472502989], [1.0, 1472502990], [1.0, 1472502991], [1.0, 1472502992], [1.0, 1472502993], [0.0, 1472502994], [0.0, 1472502995], [1.0, 1472502996], [1.0, 1472502997], [1.0, 1472502998], [1.0, 1472502999], [0.0, 1472503000], [1.0, 1472503001], [1.0, 1472503002], [0.0, 1472503003], [1.0, 1472503004], [0.0, 1472503005], [0.0, 1472503006], [1.0, 1472503007], [1.0, 1472503008], [0.0, 1472503009], [0.0, 1472503010], [0.0, 1472503011], [0.0, 1472503012], [0.0, 1472503013], [1.0, 1472503014], [1.0, 1472503015], [1.0, 1472503016], [0.0, 1472503017], [0.0, 1472503018], [1.0, 1472503019], [0.0, 1472503020], [0.0, 1472503021], [0.0, 1472503022], [1.0, 1472503023], [1.0, 1472503024], [0.0, 1472503025], [0.0, 1472503026], [0.0, 1472503027], [0.0, 1472503028], [0.0, 1472503029], [1.0, 1472503030], [0.0, 1472503031], [0.0, 1472503032], [0.0, 1472503033], [0.0, 1472503034], [0.0, 1472503035], [1.0, 1472503036], [1.0, 1472503037], [1.0, 1472503038], [1.0, 1472503039], [0.0, 1472503040], [1.0, 1472503041], [0.0, 1472503042], [0.0, 1472503043], [1.0, 1472503044], [1.0, 1472503045], [1.0, 1472503046], [1.0, 1472503047], [0.0, 1472503048], [0.0, 1472503049], [1.0, 1472503050], [0.0, 1472503051], [1.0, 1472503052], [0.0, 1472503053], [1.0, 1472503054], [0.0, 1472503055], [1.0, 1472503056], [0.0, 1472503057], [1.0, 1472503058], [1.0, 1472503059], [0.0, 1472503060], [1.0, 1472503061], [1.0, 1472503062], [0.0, 1472503063], [0.0, 1472503064], [1.0, 1472503065], [0.0, 1472503066], [1.0, 1472503067], [1.0, 1472503068], [1.0, 1472503069], [0.0, 1472503070], [0.0, 1472503071], [0.0, 1472503072], [0.0, 1472503073], [1.0, 1472503074], [1.0, 1472503075], [1.0, 1472503076], [0.0, 1472503077], [1.0, 1472503078], [1.0, 1472503079], [1.0, 1472503080], [0.0, 1472503081], [0.0, 1472503082], [1.0, 1472503083], [1.0, 1472503084], [0.0, 1472503085], [1.0, 1472503086], [0.0, 1472503087], [0.0, 1472503088], [1.0, 1472503089], [1.0, 1472503090], [0.0, 1472503091], [1.0, 1472503092], [0.0, 1472503093], [1.0, 1472503094], [0.0, 1472503095], [1.0, 1472503096], [0.0, 1472503097], [1.0, 1472503098], [1.0, 1472503099], [0.0, 1472503100], [1.0, 1472503101], [0.0, 1472503102], [0.0, 1472503103], [1.0, 1472503104], [0.0, 1472503105], [1.0, 1472503106], [0.0, 1472503107], [1.0, 1472503108], [0.0, 1472503109], [1.0, 1472503110], [0.0, 1472503111], [0.0, 1472503112], [1.0, 1472503113], [0.0, 1472503114], [0.0, 1472503115], [1.0, 1472503116], [0.0, 1472503117], [0.0, 1472503118], [1.0, 1472503119], [1.0, 1472503120], [0.0, 1472503121], [1.0, 1472503122], [1.0, 1472503123], [0.0, 1472503124], [0.0, 1472503125], [1.0, 1472503126], [1.0, 1472503127], [0.0, 1472503128], [0.0, 1472503129], [1.0, 1472503130], [1.0, 1472503131], [0.0, 1472503132], [1.0, 1472503133], [0.0, 1472503134], [1.0, 1472503135], [1.0, 1472503136], [1.0, 1472503137], [1.0, 1472503138], [0.0, 1472503139], [1.0, 1472503140], [0.0, 1472503141], [0.0, 1472503142], [0.0, 1472503143], [0.0, 1472503144], [0.0, 1472503145], [1.0, 1472503146], [0.0, 1472503147], [1.0, 1472503148], [1.0, 1472503149], [0.0, 1472503150], [1.0, 1472503151], [0.0, 1472503152], [0.0, 1472503153], [0.0, 1472503154], [0.0, 1472503155], [1.0, 1472503156], [1.0, 1472503157], [1.0, 1472503158], [0.0, 1472503159], [1.0, 1472503160], [1.0, 1472503161], [1.0, 1472503162], [1.0, 1472503163], [1.0, 1472503164], [0.0, 1472503165], [1.0, 1472503166], [0.0, 1472503167], [0.0, 1472503168], [1.0, 1472503169], [0.0, 1472503170], [0.0, 1472503171], [0.0, 1472503172], [1.0, 1472503173], [0.0, 1472503174], [1.0, 1472503175], [1.0, 1472503176], [1.0, 1472503177], [1.0, 1472503178], [0.0, 1472503179], [1.0, 1472503180], [1.0, 1472503181], [0.0, 1472503182], [0.0, 1472503183], [1.0, 1472503184], [1.0, 1472503185], [0.0, 1472503186], [1.0, 1472503187], [0.0, 1472503188], [1.0, 1472503189], [1.0, 1472503190], [1.0, 1472503191], [0.0, 1472503192], [0.0, 1472503193], [0.0, 1472503194], [1.0, 1472503195], [0.0, 1472503196], [0.0, 1472503197], [0.0, 1472503198], [0.0, 1472503199], [0.0, 1472503200], [1.0, 1472503201], [0.0, 1472503202], [0.0, 1472503203], [1.0, 1472503204], [0.0, 1472503205], [1.0, 1472503206], [0.0, 1472503207], [1.0, 1472503208], [0.0, 1472503209], [0.0, 1472503210], [0.0, 1472503211], [0.0, 1472503212], [0.0, 1472503213], [0.0, 1472503214], [0.0, 1472503215], [1.0, 1472503216], [0.0, 1472503217], [1.0, 1472503218], [0.0, 1472503219], [0.0, 1472503220], [0.0, 1472503221], [1.0, 1472503222], [1.0, 1472503223]]}]
There are 900 points (15*60). Again, we can see that the data points are zeroes or ones only.
Therefore, there is some averaging algorithm that displays data on the graph which shows points that are not zeroes or ones.
I'm interested to know what calculation graphite does to draw graphs when I change time window from 1 min to some wider range.
Following the source code, here is the part responsible for calculation of how many points per pixel (best case 1 on 1):
def consolidateDataPoints(self):
numberOfPixels = self.graphWidth = self.area['xmax'] - self.area['xmin'] - (self.lineWidth + 1)
for series in self.data:
numberOfDataPoints = self.timeRange/series.step
minXStep = float( self.params.get('minXStep',1.0) )
divisor = self.timeRange / series.step
bestXStep = numberOfPixels / divisor
if bestXStep < minXStep:
drawableDataPoints = int( numberOfPixels / minXStep )
pointsPerPixel = math.ceil( float(numberOfDataPoints) / float(drawableDataPoints) )
series.consolidate(pointsPerPixel)
series.xStep = (numberOfPixels * pointsPerPixel) / numberOfDataPoints
else:
series.xStep = bestXStep
As you may note - adding minXStep=NUMBER to the query string can extend consolidation window. The default consolidation method is average.

Resources