I have a tree structure suppose. I know some conditions. I would like to give an example:
469 & 470 results 468
472 & 473 results 471
476 & 477 results 475
479 & 480 results 478
This is the round 1 suppose. In the next few rounds:
Round 2:
468 & 471 results 467
475 & 478 results 474
Round 3:
467 & 474 results 466
I need to arrange them as shown in image. Also I have one more thing that to arrange them I have made some ids in css so that they go in the appropriate position. So starting from the right most it should get 15 and then left to it 14, 13. I cannot post images so I am making a structure here itself:
469
468
470
467
472
471
473
466
476
475
477
474
479
478
480
Now the numbers each will get is:
1
9
2
13
3
10
4
15
5
11
6
14
7
12
8
Now my question is I get this things from database that these two numbers result into third. I need to write a piece of code that makes this arrangement automatic. I am getting an array of hashes for each number. Means a hash for 469, other for 470 and so on. In rails term what we call is ActiveRecord::Relation. Can anyone help me please.
More update:
I know always that 469 & 470 will results 468 and so on. Also suppose I am on 466 then it will have the detail that it has came from 467 & 474. In short it has the forward and backward both numbers. I want to run a loop on them and arrange them in the above order so that the left side schedules and right side schedules match. This can be assumed as a world cup match of any sport in which the two matches result in next match and so on. And finally I want to make a tree in my view.
I have solved the issue. What I have done is made a custom hash. For this I have ran a loop like this:
First took the last one i.e., in the above example it is 466. So I inserted it in hash:
{5 => {466}}
Then I know that 466 has come from 467 & 474. So I inserted these two in the same has as this:
{5 => {466}, 4=> {467, 474}}
Then for the next one I ran a loop on the hash[4] and first took the two schedules from 467 and inserted in the hash and then the two from 474 in the hash. This is how:
{5 => {466}, 4 => {467, 474}, 3 => {468, 471, 475, 478}}
and so on. And then in the view I looped on the hash according to the key and arranged them in the view. Suppose the hash is s. Then:
(4).downto(1).each do |i|
s[i].each do |x|
#code to display here
end
end
Hope this helps anyone else too if they need to do the same thing.
Related
Anyone got any ideas on how to do this?
I'm trying to build a spreadsheet that helps me monitor the performance of my blog articles. So if the article historically had >=100 visits at any point but subsequently gets <100 at any point I want to know about it.
The formula I've been playing with is:
=IF(((FILTER(C2:G2,C2:G2<>E2))>=100 AND (FILTER(C2:G2,C2:G2<>E2))<100, "Article Failing", ""))
I'm using Filter btw because I need to exclude column E, which is the delta between this month's & last month's numbers.
I know the formula isn't logically right but struggling to think of a way to do it.
Edit:
Here's a link to the spreadsheet with desired output https://docs.google.com/spreadsheets/d/1TeaQ6oUbJDeKxUi8tvvCWXtw0oK9d5IVO60j1UbQCK8/edit?usp=sharing
Here's a table showing the sample data and desired output:
Total users (last 30 days)
Total users (prev 30 days)
Delta - Total users
Total users last 30-60 days
Total users prev 60-90 days
Delta - Total users
Above 100
Article Failing
651
90
-417
772
249
523
Tweak Article
Failing
610
570
40
550
432
118
Tweak Article
OK
436
409
27
328
210
118
Tweak Article
OK
422
288
134
53
288
-235
Tweak Article
OK
95
476
-90
417
477
-60
Below100
Failing
337
179
158
129
182
-53
Tweak Article
OK
305
395
-90
318
343
-25
Tweak Article
OK
304
348
-44
299
253
46
Tweak Article
OK
302
277
25
283
317
-34
Tweak Article
OK
286
252
34
268
281
-13
Tweak Article
OK
213
193
20
221
168
53
Tweak Article
OK
157
138
19
132
166
-34
Tweak Article
OK
150
157
-7
110
68
42
Tweak Article
OK
I've made cells B2 & A6 be failing articles i.e. they were >=100 but have since gone below 100. The end column 'Article Failing' is where I'm trying to create the formula.
Hope that makes things a bit clearer.
This formula will match the desired results you show in the sample spreadsheet:
=if(
(max(A$2:A2) >= 100) * (A2 < 100)
+
(max(B$2:B2) >= 100) * (B2 < 100)
+
(row(B2) = row(B$2)) * (B2 < 100),
"Failing",
"OK"
)
I have a plotted spectral curve in google sheets. All points are real coordinates. As you can see, data is not provided for the slope below 614nm. I would like to extend the slope beyond the supplied data, so that it reaches 0. In a mathematically relevant way to follow the trajectory it was taking from when the slope started. Someone mentioned to me I would have to potentially use a linear regression? I'm not sure what that is. How would I go about extending this slope relevant to it's defined trajectory down to 0 in google sheets?
Here's the data
x-axis:
614
616
618
620
622
624
626
628
630
632
634
636
638
640
642
644
646
648
650
652
654
656
658
660
662
664
666
668
670
672
674
676
678
680
682
684
686
688
690
692
694
696
698
700
702
704
706
708
710
712
714
716
718
720
722
724
726
728
730
y-axis:
0.7101
0.7863
0.8623
0.9345
1.0029
1.069
1.1317
1.1898
1.2424
1.289
1.3303
1.3667
1.3985
1.4261
1.4499
1.47
1.4867
1.5005
1.5118
1.5206
1.5273
1.532
1.5348
1.5359
1.5355
1.5336
1.5305
1.5263
1.5212
1.5151
1.5079
1.4994
1.4892
1.4771
1.4631
1.448
1.4332
1.4197
1.4088
1.4015
1.3965
1.3926
1.388
1.3813
1.3714
1.359
1.345
1.3305
1.3163
1.303
1.2904
1.2781
1.2656
1.2526
1.2387
1.2242
1.2091
1.1937
1.1782
Thanks
I understand that you want The curve should be increased beyond the given data in a mathematically sound fashion until it approaches 0, In what follows, I'm going to show how it's done with the last 2 data points which make the filled data linear it might help, like this: take a look at this Sheet.
We need to
1 - Paste this SEQUENCE function formula in C3 to get the order of input
=SEQUENCE(COUNTA(B3:B),1,1,1)
2 - SORT the the input by pasting this formula in E3.
=SORT(A3:C61,3,0)
3 - In F62 after the last line of the sorted data paste this TREND function that Fits an ideal linear trend using the least squares approach to incomplete data about a linear trend and/or makes additional value predictions..
=TREND(F60:F61,E60:E61,E62:E101)
TREND takes
'known_data_y' set to F60:F61
'[known_data_x]' set to E61,E62 those are the 2 data point
[known_data_x] set to E62:E101, we get it by pasting E62:E101 after the last line of the sorted data in "x-axis:" in output table cell E62
4 - To see the newly genrated data in the red curve we need a new column that start from K62 till the very bottom of the data "y-axis:" in output table cell K62, by pasting this ArrayFormula in K62.
=ArrayFormula(E62:G101)
5 - Add a Serie in tne chart in chart editor > setup > Series > Add Serie.
I'm looking for the exact specifications of this file format. Anyone got a link? Or want to comment?
I have spent the better part of the day searching, yet I keep getting directed back to the GIMP online user-manual. It says "look at a .gpl file and you will see it is easy" to build manually with a text editor. I don't actually have GIMP, but I see examples online. Yep, easy. • EXCEPT:
• What meaning do the color names ultimately have? Are they purely semantic, or does a program rely on them? If the latter, then what if there are two (2) or more colors with the same name?
• What does the "Columns" line do?
I've seen examples that have no "Columns" line.
I've seen examples that have values of 0, 4, and 16; yet this does not in any way that I can see correspond to the color data. I see 3 columns of decimal-sRGB values, and an optional 4th column with the color-name; seems I remember the example with "Columns 4" had no color names, only the 3 RGB columns.
• Do columns of RGB values need to "line up"? Or will the following example from my output algorithm work? (from the Crayola palette):
159 129 112 Beaver
253 124 110 Bittersweet
0 0 0 Black
172 229 238 Blizzard Blue
31 117 254 Blue
162 162 208 Blue Bell
102 153 204 Blue Gray
13 152 186 Blue Green
• Does this format accept sRGBA colors? And if so, how is the "A" value defined (0-1, 0%-100%, 0-127, 0-255, etc.?) (seems I remember when creating .png files with PHP, the "A" value was 7-bit)?
• How exactly do you add comments / metadata?
Today I see an example that says lines that begin with # are comments, or anything after a # on a line is a comment. Yesterday I thought (maybe I'm confused) I saw an example that said that comment lines begin with ;
• Is any other data-format supported?
Originally I thought the text-line just before the color-data that I see in every example indicated the format: "#" signifying decimal-sRGB; until today when I see that is just a blank-line comment.
• What line ending character(s) can / must I use?
\n
\r
• What character-encodings can I use? ASCII only? ¿UTF-8 ☺ with extended ♪♫ charset (¡hopefully!)?
• Anything I'm missing? Any other options available?
Here is an example from http://gimpchat.com/viewtopic.php?f=8&t=3375#
GIMP Palette
Name: bugslife_final.png-10
Columns: 16
#
191 180 180 Index 0
163 158 157 Index 1
145 136 132 Index 2
130 125 112 Index 3
… … …
56 50 49 Index 29
41 38 38 Index 30
23 23 23 Index 31
242 245 213 Index 32
227 232 181 Index 33
210 217 147 Index 34
195 204 118 Index 35
… … …
0 0 0 Index 251
0 0 0 Index 252
0 0 0 Index 253
0 0 0 Index 254
0 0 0 Index 255
Aloha!
Looking at the source code:
Columns is just an indication for display in the palette editor
Comments must start with a #. In non-empty lines that don't, the first three tokens are parsed as numbers
There is no alpha support
I try to implement a simple ARMA model, however have serious difficulties getting it to run. When adding a parameter to the error term everything works fine (see the return x_m1 + a*e statement, commented out below), however if I add a parameter to the auto regressive part, I get a FloatingPointError or LinAlgError or PositiveDefiniteError, depending on the initialization method I use.
The code is also put into a gist you can find here. The model definition is replicated here:
with pm.Model() as model:
a = pm.Normal("a", 0, 1)
sigma = pm.Exponential('sigma', 0.1, testval=F(.1))
e = pm.Normal("e", 0, sigma, shape=(N-1,))
def x(e, x_m1, a):
# return x_m1 + a*e
return a*x_m1 + e
x, updates = theano.scan(
fn=x,
sequences=[e],
outputs_info=[tt.as_tensor_variable(data.iloc[0])],
non_sequences=[a]
)
x = pm.Deterministic('x', x)
lam = pm.Exponential('lambda', 5.0, testval=F(.1))
y = pm.StudentT("y", mu=x, lam=lam, nu=1, observed=data.values[1:]) #
with model:
trace = pm.sample(2000, init="NUTS", n_init=1000)
Here the errors respective to the initialization methods:
"ADVI" / "ADVI_MAP": FloatingPointError: NaN occurred in ADVI optimization.
"MAP": LinAlgError: 35-th leading minor not positive definite
"NUTS": PositiveDefiniteError: Scaling is not positive definite. Simple check failed. Diagonal contains negatives. Check indexes [ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71]
For details on the error messages, please look at this github issue posted at pymc3.
To be explicit, I really would like to have a scan-like solution which is easily extendable to for instance a full ARMA model. I know that one can represent the presented AR(1) model without scan by defining logP as already done in pymc3/distributions/timeseries.py#L18-L46, however I was not able to extend this vectorized style to a full ARMA model. The use of theano.scan seems preferable I think.
Any help is highly appriciated!
I would like to parse files with several sequences of data (same number of column, same content, ...) with Haskell.
My data sequences will be delimited by keywords before and after.
BEGIN
1 882
2 809
3 435
4 197
5 229
6 425
...
END
BEGIN
1 235 623 684
2 871 699 557
3 918 686 49
4 53 564 906
5 246 344 501
6 929 138 474
...
END
My problem is that after several tests with Parsec, I have the impression that Parsec is rather made to parse a file line by line and not the whole file.
Is Parsec the right way to make what I want or should I consider an other tool like Happy or Alex ?
Is there a website (or other ressource) providing examples of parsing complex text files with Parsec ?
Note : The example I give is a very simple one. Things would be more tricky in my files with many more keywords and combinations.
The format as you've described wouldn't be hard at all to handle in parsec.
As for learning how to use it: your first step should be to avoid whatever guide gave you the impression that parsec worked line-by-line. I recommend Chapter 16 of Real World Haskell as a good place to get started, and once you're comfortable with the basics the reference material at http://hackage.haskell.org/package/parsec is actually very clear.