D3 graph not updating on click - d3.js

My line chart is not updating with new data once I click the black button and I'm not sure what I could possibly be doing wrong.
Block here:

Let's look at your NaN errors:
<path class="line" d="M0,324.19471776281716L0,NaNL155,NaNL155,270L310,270L310,353.84774728120146L465,353.84774728120146" transform="translate(78.1818,0)"></path>
Seems that we are missing two y values, we can see this if we split the path data into its x,y pairs:
M0,324.19471776281716
L0,NaN
L155,NaN
L155,270
L310,270
L310,353.84774728120146
L465,353.84774728120146
So, we need to check two things, one is the y scale, and the other is the data used in the y scale. The y scale looks ok, if it failed on one number it should fail on all numbers. Let's look at the csv data:
education,number
Bachelor's degree,2367
Degree in medicine, dentistry, veterinary medicine or optometry,5763
Earned doctorate,3862
Master's degree,1549
Here's our problem: we have a comma separated file type with lots of extra commas on the second row (not counting the column headers). We can see that is causing issues with the name of the second column in the alternate data: "Degree in medicine", the portion of the name beyond the comma is dropped. Let's entomb that data with quotations so that the commas won't count as delimiters:
education,number
Bachelor's degree,2367
"Degree in medicine, dentistry, veterinary medicine or optometry",5763
Earned doctorate,3862
Master's degree,1549

You're code in your update function is selecting #body when #body (id="body") doesn't seem to exist. Could you be meaning to use body instead to select the html body?

Related

Split Two decimals After Dot in Google Sheets Formula

I've two sets of corrupted numbers where two columns of data got merged.
1.504.99
4.604.97
18.955.00
1.154.85
0.301.82
And Like this:
0.0514.29%
0.1530.00%
0.2583.33%
0.000.00%
1.30185.71%
I want to split the each column two digits after the first dot for example 1.30185.71% as 1.30 | 185.71%
I tried split and regexreplace inside arrayformula as a noob as much as I can but as of now, nothing is working. Is there any way to make this work? Please help. Sheet is attached here
Try
1st
=arrayformula(if(A2:A="",,regexextract(A2:A,"\d+\.\d{2}")))
and 2nd
=arrayformula(if(A2:A="",,regexextract(A2:A,"\d+\.\d{2}(.*)")))
edit
you can add value to tranform in numeric, 1st
=arrayformula(if(A2:A="",,value(regexextract(A2:A,"\d+\.\d{2}"))))
and 2nd
=arrayformula(if(A2:A="",,value(regexextract(A2:A,"\d+\.\d{2}(.*)"))))

Extracting data from text file in AMPL without adding indexes

I'm new to AMPL and I have data in a text file in matrix form from which I need to use certain values. However, I don't know how to use the matrices directly without having to manually add column and row indexes to them. Is there a way around this?
So the data I need to use looks something like this, with hundreds of rows and columns (and several more matrices like this), and I would like to use it as a parameter with index i for rows and j for columns.
t=1
0.0 40.95 40.36 38.14 44.87 29.7 26.85 28.61 29.73 39.15 41.49 32.37 33.13 59.63 38.72 42.34 40.59 33.77 44.69 38.14 33.45 47.27 38.93 56.43 44.74 35.38 58.27 31.57 55.76 35.83 51.01 59.29 39.11 30.91 58.24 52.83 42.65 32.25 41.13 41.88 46.94 30.72 46.69 55.5 45.15 42.28 47.86 54.6 42.25 48.57 32.83 37.52 58.18 46.27 43.98 33.43 39.41 34.0 57.23 32.98 33.4 47.8 40.36 53.84 51.66 47.76 30.95 50.34 ...
I'm not aware of an easy way to do this. The closest thing is probably the table format given in section 9.3 of the AMPL Book. This avoids needing to give indices for every term individually, but it still requires explicitly stating row and column indices.
AMPL doesn't seem to do a lot with position-based input formats, probably because it defaults to treating index sets as unordered so the concept of "first row" etc. isn't meaningful.
If you really wanted to do it within AMPL, you could probably put together a work-around along these lines:
declare a single-index param with length equal to the total size of your matrix (e.g. if your matrix is 10 x 100, this param has length 1000)
edit the beginning and end of your "matrix" data file to turn it into appropriate format for a single-index parameter indexed from 1 to n
then define your matrix something like this:
param m{i in 1..nrows,j in 1..ncols} := x[j+i*(ncols-1)];
(not tested, I won't promise that I have rows and columns the right way around there!)
But you're probably better off editing the input file into one of the standard AMPL matrix formats. AMPL isn't really designed for data wrangling - you can do it in a pinch but if you're doing this kind of thing repeatedly it may be less trouble to code it in a general-purpose language e.g. Python.

Algorithm for translating MLB play-by-play records into descriptive text

I'm trying to collect a dataset that could be used for automatically generating baseball articles.
I have play-by-play records of MLB games from retrosheet.org that I would like to be written out to plain text, as those that could possibly appear as part of a recap news article.
Here are some examples of the play-by-play records:
play,2,0,semim001,32,.CBFFFBBX,9/F
play,2,0,phegj001,01,FX,S7/G
play,2,0,martn003,01,CX,3/G
play,2,1,youne003,00,,NP
The following is what I would like to achieve:
For the first example
play,2,0,semim001,32,.CBFFFBBX,9/F,
I want it to be written out as something like:
"semim001 (Marcus Semien) was on three balls and two strikes in the second inning as the away player. He hit the ball into play after one called strike, one ball, three fouls, and another two balls. The fly ball was caught by the right outfielder."
The plays are formatted in the following way:
The first field is the inning, an integer starting at 1.
The second field is either 0 (for visiting team) or 1 (for home team).
The third field is the Retrosheet player id of the player at the plate.
The fourth field is the count on the batter when this particular event (play) occurred. Most Retrosheet games do not have this information, and in such cases, "??" appears in this field.
The fifth field is of variable length and contains all pitches to this batter in this plate appearance and is described below. If pitches are unknown, this field is left empty, nothing is between the commas.
The sixth field describes the play or event that occurred.
Explanations for all the symbols in the fifth and sixth field can be found on this Retrosheet page.
With Python 3, I've been able to format all the info of invariable length into a formatted sentence, which is all but the last two fields. I'm having difficulty in thinking of an efficient way to unparse (correct me if this is the wrong term to use here) the fifth and sixth fields, the pitches and the events that occurred, due to their variable length and wide variety of things that can occur.
I think I could write out all the rules based on the info on the Retrosheet website, but I'm looking for suggestions for a smarter way to do this. I wrote natural language processing as tags, hoping this could be a trivial problem in that field. Any pointers will be greatly appreciated!

Reporting Multiple Values & Sorting

Having a bit of an issue and unsure if it's actually possible to do.
I'm working on a file that I will enter target progression vs actual target reporting the % outcome.
PAGE 1
¦NAME ¦TAR 1 %¦TAR 2 %¦TAR 3 %¦TAR 4 %¦OVERALL¦SUB 1¦SUB 2¦SUB 3¦
¦NAME1¦ 114%¦ 121%¦ 100%¦ 250%¦ 146%¦ 2¦ 0¦ 0%¦
¦NAME2¦ 88%¦ 100%¦ 90%¦ 50%¦ 82%¦ 0¦ 1¦ 0%¦
¦NAME3¦ 82%¦ 54%¦ 64%¦ 100%¦ 75%¦ 6¦ 6¦ 15%¦
¦NAME4¦ 103%¦ 64%¦ 56%¦ 43%¦ 67%¦ 4¦ 4¦ 24%¦
¦NAME5¦ 87%¦ 63%¦ 89%¦ 0%¦ 60%¦ 3¦ 2¦ 16%¦
Now I already have it sorting all rows by the Overall % column so I can quickly see at a glance but I am creating a second page that I need to reference points.
So on the second page I would like to somehow sort and reference different columns for example
PAGE 2
TOP TAR 1¦Name of top %¦Top %¦
TOP TAR 2¦Name of top %¦Top %¦
Is something like this possible to do?
Essentially I'm creating an Employee of the Month form that automatically works out who has topped what.
I'm willing to drop a paypal donation for whoever can figure this out for me as I've been doing it manually every month and would appreciate the time saved
I don't think a complicated array formula is necessary for this - I am suggesting a fairly standard Index/Match approach.
First set up the row titles - you can just copy and transpose them from Page 1, or use a formula in A2 of Page 2 like
=transpose('Page 1'!B1:E1)
The use them in an index/match to get the data in the corresponding column of the main sheet and find its maximum (in C2)
=max(index('Page 1'!A:E,0,match(A2,'Page 1'!A$1:E$1,0)))
Finally look up the maximum in the main sheet to find the corresponding name:
=index('Page 1'!A:A,match(C2,index('Page 1'!A:E,0,match(A2,'Page 1'!A$1:E$1,0)),0))
If you think there could be a tie for first place with two or more people getting the same score, you could use a filter to get the different names:
So if the max score is in B8 this time (same formula)
=max(index('Page 1'!A:E,0,match(A8,'Page 1'!A$1:E$1,0)))
the different names could be spread across the corresponding row using transpose (in C8)
=ArrayFormula(TRANSPOSE(filter('Page 1'!A:A,index('Page 1'!A:E,0,match(A8,'Page 1'!A$1:E$1,0))=B8)))
I have changed the test data slightly to show these different scenarios
Results

Google Sheets COUNTIF syntax across different tabs

I am currently trying to work out how to make the current Google Sheets version of COUNTIF properly count how many times the value of a cell (C3) is higher than the value if another cell (E3), according to the following formula:
=COUNTIF('4'!$C$3,">'4'!$E$3")
You'll note that the formula is run in a different tab than the one where the cells being counted are located in (which is named "4"). The formula returns a zero '0', when it should be returning a one '1', as the value in '4'!$C$3 actually is higher than the value in '4'!$E$3.
Clearly, I am doing something wrong.
So, the user I'-'I (stackoverflow.com/users/8404453/i-i) suggested the following edit:
=COUNTIF('4'!$C$3,">'4'!$E$3") --> COUNTIF('4'!$C$3,">"&'4'!$E$3)
This suggestion resolved my issue.

Resources