jqplot - how to make 2 lines to scale same base - jqplot

lets say i have 2 sets of data:
1) 10 11 15 20
2) 1000 1200 1400 1500
now i wanna make them start in same point (like they were converted to same base %)
so:
1) 10 11 15 20
2) 10 12 14 15
i can do it in php BUT then value in hover box is wrong...
so to sum up - i wanna make 2 lines starting from exactly same point (like they were scaled to the base) but on hover or markers to show REAL numbers on both (idea is to compare growth of data A vs data B - which one did better in % values, not absolute)
thanks for any tips

ok, i think i found a so so solution:
i hide actual value of the second set, add extra data set (now its [date,value(scaled to base value of first line),real_value(the one i want to show on tooltip)].
but problem is - when you wanna use tooltip it always include 2nd value from dataset (in my case scaled valued), so i guess only solution is to make it invisible in css x.x.
marking as answered - its good enough and cant find anything better

Related

D3 Getting Y value of a trend line for current X

I'm drawing a line chart from database values of the current day, I'm also drawing a second "trend line" after some calculations to well... know how they day is going, this trend line has only 4 points for 6 a.m., 8 a.m., 12m. and 6 p.m. For example:
[Data]
06:00:00, 10
08:00:00, 30
12:00:00, 110
06:00:00, 320
I would like to check if my current value is below or above my trend line to display warnings or maybe send notifications (at any given time during the day, preferably the latest time read). I've tried several things but all I can get are the known 4 values(for those hours) of my trend line, nothing in between.

Generating Settlers of Catan Numbers?

I am trying to generate a Settlers of Catan game board and am stuck trying to create an efficient implementation of hex numbers.
The goal is to randomly generate a set of numbers from 2-12 (with only one instance of 2 and 12, and two instances of all numbers in between), ensuring that the values 6 and 8 they are not hexagonally (?) adjacent to one another. 6 & 8 are special because they are the numbers you are most likely to roll so the game does not want these next to one another as players get disproportionately higher resources of that kind. A 7 means you have to discard resources.
The expected result: http://imgur.com/Ng7Siy8
Right now I have a working brute force implementation that is very slow and I am hoping to optimize it, but I am not sure how. The implementation is in VBA, which has constrained the data structures I can use.
In pseudo code I am doing something like this:
For Each of the 19 hexes
Loop Until we have a valid number
Generate a random number between 1 and 12
Check
Have we already placed too many of that number?
Is the number equal to 6 or 8?
Is the number being placed on a hex next to another hex with 6 or 8 placed on it?
If valid
Place
If invalid
Regenerate random number
It's very manual and subject to the random generator function, which means it can be anywhere from being really short to being really really long (compounded over 19 hexes).
Note: How my numbers are being placed seems important. I start at the outside of the gameboard (see here http://imgur.com/Ng7Siy8) on the gray hex with number 6, and then move counter clockwise around the board inward. This means that my next hex is 2 light green, 4 light orange...continuing around to 9 dark green and then coming inwards to 4 light orange.
This pattern limits the number of comparisons I need to make.
There are several optimizations you can do - first of all you know exactly how many numbers are present prom each tile - you have 2,3,3,4,4,5,5,6,6,8,8,9,9,10,10,11,11,12. So start off with this set of numbers - you will eliminate the check if the number has been generated too many times. now you can do a random shuffle of this set of numbers and check if it is "valid". This will still result in too many negative checks I think but it should perform better than your current approach.
Place the 8 first, calculate which of the remaining tiles you'd be happy to place the 6 on (i.e. non-adjacent), then choose on at random for the 6. Then place the rest.

How to count how many times a rule appears in a specific month.Exce;

I want to count how many times in a specific month(for example:January) the red cell with the rule: equal or more than 15 days -> red cell , appears. How can I do that?
My table looks like this
A B
16.02.2013 15
17.01.2012 20
01.02.2013 4
26.04.2012 10
01.01.2012 21
20.04.2012 7
The answer for January is 2
How can I do if I want to make the count by month and year?
Thank you in advance!
Lygia
You can use the countifs function for this. (Link)
Assuming C1 holds start date you want to count from, and C2 holds end date you want to count too.
=COUNTIFS(A:A;">="&C1;A:A;"<="&C2;B:B;">15")
Not sure if you can tie the condition directly to the formating rule.
I'm guessing that entries in ColumnB greater than or equal to 15 have been formatted red. (Which could imply a flaw in #Taemyr's answer, where >15 should perhaps be >=15.) Also, that the likes of "(for example:January)" implies that a solution that works conveniently for many months would be appreciated, so suggest a PivotTable.
Due to PT constraints, identification of values greater than a cutoff is easier in the source data. In this case should only require filtering to select values that have already been formatted red, and adding a flag, say x, to these.
Then the PT could be filtered for x only and the ColumnA values (ROWS) Grouped by Years and Months. The sum of VALUES field being Count of B.

How to make the following "apply" function in R more efficient?

I am trying to bucket certain features into groups. The data.frame below (grouped) is my "key" (think Excel vlookup):
Original Grouped
1 Features Constant
2 PhoneService Constant
3 PhoneServices Constant
4 Surcharges Constant
5 CallingPlans Constant
6 Taxes Constant
7 LDUsage Noise
8 RegionalUsage Noise
9 LocalUsage Noise
10 Late fees Noise
11 SpecialServices Noise
12 TFUsage Noise
13 VoipUsage Noise
14 CCUsage Noise
15 Credits Credits
16 OneTime OneTime
I then reference my database which has a column (BillSection) that takes on a specific value from grouped$Original, and I want to group it according to grouped$Grouped. I am using the sapply function to perform this operation. Then I cbind the resulting output to my original data.frame.
grouper<-as.character(sapply(as.character(bill.data$BillSection[1:100]), # for the first 100 records of the data.frame bill.data
function(x)grouped[grouped$Original==x,2])) # take the second column, i.e. Grouped, for the corresponding "TRUE" value in Original
cbind(bill.data[1:100,],as.data.frame(grouper))
The above code works as expected, but it's slow when I apply it to my whole database, which exceeds 10,000,000 unique records. Is there an alternative to this method? I know I can use plyr, but it's even slower (I think) than sapply. I was trying to figure it out with data.table but no luck. Any suggestions would be helpful. I am open to coding this in Python, which I am new to, but heard is much faster than R, since I am dealing with large datasets very often. I wanted to know if R can do this fast enough to be useful.
Thanks!
I'm not sure I understand your question, but can you use merge()? i.e. something like...
merge(big.df, group.names.df, by.x='orginal.column.in.big.df',
by.y='original', all.x=T)
NB. Plyr has a parallel option...

Bowling Counting algorithm from InterviewStreet

I don't know if this is the right section... but here goes:
Last weeks contest on interviewstreet (Code Sprint 3) had a problem called bowling. (10 pin bowling, N frames). The point is to count the number of ways to score M points by playing N frames.
Problem Statement is here: http://pastebin.com/cyeLML8U
I'm pretty sure I've solved the problem using 2 dimensional DP. However, I get the 3rd sample data wrong (1 Frame, 25 points). The sample answer is 1, however I get 6.
This is their explanation of the sample answer:
For the third case, there is only 1 way. Score a strike in the first frame, score another strike with the first extra ball, and an additional 5 with the second extra ball.
However, can't you score a strike in the first (and only) frame, then score any of the following in the subsequent extra frames?
10 5
9 6
8 7
7 8
6 9
5 10
I can't wrap my head around why "1" is the right answer.... I've looked on wikipedia for the rules too.
Their answer is probably right, and I'm probably overlooking something REALLY obvious. Can anyone tell me what's wrong with my answer?
You cannot get 9 pins with the first extra ball and then 6 pins with the second extra ball because there is only 1 pin left standing when you bowl the second extra ball.
But if you don't get a strike on the second ball, you only have the opportunity to "pick up the spare." That is, you only get 10 pins. So if you get a strike on the first ball and then 9 pins on the second ball, the most you can get on the third ball is 1.
The way I read it, your answer is technically correct, but I don't think the question was asked correctly.
Within the constraints as set out in the link in your question, I can't see what's wrong with your solution. In real life, the pins won't actually be reset unless you've knocked them all down or have bowled twice (or both), so - as others have said - the only way you can score 25 from a 1 ball frame in real life is strike, strike, 5.
Basically, the question didn't give you the correct constraints. I don't think it's valid to say you got the answer wrong, because the question was poorly phrased.

Resources