Highchart Maps (Highmaps)- data - highcharts

http://www.highcharts.com/maps/demo/map-drilldown
In High chart Maps, I can click on state and all counties I can see. I want to click on county and see all zip codes within the county. Now the data for county is something like this
{ "id": "US.WI.069", "name": "Lincoln", "path": "M 441.2,105.3 L 441.6,111.1 L 434.2,111.6 L 433.9,107.9 L 433.9,107.2 L 433.7,104.3 L 441.0,103.8 Z" } if i can get path information(viz "path": "M 441.2,105.3 L 441.6,111.1 L 434.2,111.6 L 433.9,107.9 L 433.9,107.2 L 433.7,104.3 L 441.0,103.8 Z") for all zip codes in united states it will do the job. Would anyone know where I can find data for "path"

You need to add this information in the json, and then catch click event (to display it) or update tooltip formatter where this information will be extracted.

Related

Finding Current Win Streak Google Spreadsheets

I would like my spreadsheet to count the current win streak.
For example:
If DE match history looks like W W W L W W then I would like the current win streak to say W2. If DK match history looks like L L W L L L then I would like the current win streak to say L3.
Here is an example spreadsheet,
https://docs.google.com/spreadsheets/d/1NROEe3VOAXDDianHcLk3y6YSBLNGMAj3t9GC4WJDvwM/edit?usp=sharing
From Tom's comments, this worked for me:
=REGEXEXTRACT(JOIN("",D2:R2),"(L|W)*$") & LEN(REGEXEXTRACT(JOIN("",D2:R2),"(L*|W*)$"))
I suggest using a regex to find consecutive W's or L's at the end of the list:
=iferror(regexextract(textjoin("",true,E2:2),"W+$"),regexextract(textjoin("",true,E2:2),"L+$"))
This formula will ignore any empty cells.
Or to put it in W2, L2 format:
=iferror("W"&len(regexextract(textjoin("",true,E2:2),"W+$")),"L"&len(regexextract(textjoin("",true,E2:2),"L+$")))

Read a file and convert into an n-ary tree based nested list in Common Lisp?

For one of my projects, I am trying to use Common Lisp, specifically SBCL (in the process, learning it. This is one of the motivations.)
I need to read a file with questions and answers, basically like a Standardized test with mainly multiple choice question answers.
I have some sample questions marked with some section markers like "|" for start and "//s" for and of a section. The question paper will have a hierarchical structure like this: Section -> multiple sub-sections -> each sub-section with multiple questions -> each question will have multiple answers one of them being correct.
This hierarchical structure needs to be converted into a json file finally and pushed to an android app for downstream consumption.
STEP-1: After reading from the source Test paper, this is how my list will look like:
(("Test" . "t")
("0.1" . "v")
("today" . "d")
("General Knowledge" . "p")
("Science" . "s")
("what is the speed of light in miles per second?" . "q")
("Choose the best answer from the following" . "i")
("MCQ question" . "n")
("186000" . "c")
("286262" . "w")
("200000" . "w"))
[PS.1] See legend at the end of the post for the explanation of the cdar values like h, p, t , v etc.,
[PS.2] The source file sample attached at the end of this post
Each car of the consed pair representing the content and the cdr representing the section - which will corresponding to a section, sub-section or a question etc.,
STEP-2: Finally I need to convert this into the following format - an alist -
((:QANDA . "Test") (:VERSION . "0.1") (:DATE . "today")
(:SECTION
((:TITLE . "General Knowledge")
(:SUBSECTION
((:SSTITLE . "Science")
(:QUESTION
((:QUESTION . "what is the speed of light in miles per second?")
(:DIRECTIONS . "Choose the best answer from the following")
(:TYPE . "MCQ question")
(:CHOICES ((:CHOICE . "186000") (:CORRECT . "Y"))
((:CHOICE . "286000") (:CORRECT . "N"))
((:CHOICE . "200000") (:CORRECT . "N"))))))))))
to be consumed by cl-json.
STEP-3: cl-json will produce an appropriate json from this.
The json will look like this:
{
"qanda": "Test",
"version": "0.1",
"date": "today",
"section": [
{
"title": "General Knowledge",
"subsection": [
{
"sstitle": "Science",
"question": [
{
"question": "what is the speed of light in miles per second?",
"Directions": "Choose the best answer from the following",
"type": "MCQ question",
"choices": [
{
"choice": "186000",
"Correct": "Y"
},
{
"choice": "286000",
"Correct": "N"
},
{
"choice": "200000",
"Correct": "N"
}
]
}
]
}
]
}
]
}
I've been successful in reading the source file, generating the consed pair list. Where I am struggling is to create this nested list as shown above to feed it to cl-json.
I realized after a bit of struggle that this is more or less like an n-ary tree problem.
Here are my questions:
a) What is the right way to construct such an n-ary tree representation of the Test paper source file?
b) Or is there a better or easier data structure to represent this?
Here is what I tried, where qtree will be '() initially and kvlist is the consed pair list shown above. This is an incomplete code, as I tried push., consing and nconc (with unreliable results).
Step-1 and Step 3 are fine. Step-2 is where I need help.The problem is to how to add child nodes successively by iterating through the kvlist and find the right parent to add the child when more than one parent is there (e.g., adding a question to the second sub-section):
(defun build-qtree (qtree kvlist)
(cond
((eq '() kvlist) qtree)
((equal "h" (cdar kvlist))
(push (car kvlist) qtree)
(build-qtree qtree (cdr kvlist)))
((equal "p" (cdar kvlist))
(nconc (last qtree) '((:SECTION))))
(t
(qtree))))
[PS.1] Legend: This will be used in the conditions branches or may be a defstruct or a dictionary type of list etc.,
t - title, v - version, d - date, p - section, s - sub section, q - question, i - instructions, n - type of question, c - correct answer, w - wrong answer
[PS.2]Source File:
|Test//t
|0.1//v
|today//d
|General Knowledge//p
|Science//s
|what is the speed of light in miles per second?//q
|Choose the best answer from the following//i
|MCQ question//n
|186000//c
|286000//w
|200000//w
You have a simple problem with a complex example. It might be just a simple parsing problem: What you need is a grammar and a parser for it.
Example grammar. Terminal items are in upper case. * means one or more.
s = q
q = Q i*
i = I w*
w = W
Simple parser:
(defun example (sentence)
(labels ((next-item ()
(pop sentence))
(empty? ()
(null sentence))
(peek-item ()
(unless (empty?)
(first sentence)))
(expect-item (sym)
(let ((item (next-item)))
(if (eq item sym)
sym
(error "Parser error: next ~a, expected ~a" item sym))))
(star (sym fn)
(cons (funcall fn)
(loop while (eq (peek-item) sym)
collect (funcall fn)))))
(labels ((s ()
(q))
(q ()
(list (expect-item 'q) (star 'i #'i)))
(i ()
(list (expect-item 'i) (star 'w #'w)))
(w ()
(expect-item 'w)))
(s))))
Example:
CL-USER 10 > (example '(q i w w w i w w))
(Q
((I (W
W
W))
(I (W
W))))

How to do a left join on a non unique column/index in Deedle

I am trying to do a left join between two data frames in Deedle. Examples of the two data frames are below:
let workOrders =
Frame.ofColumns [
"workOrderCode" =?> series [ (20050,20050); (20051,20051); (20060,20060) ]
"workOrderDescription" =?> series [ (20050,"Door Repair"); (20051,"Lift Replacement"); (20060,"Window Cleaning") ]]
// This does not compile due to the duplicate Work Order Codes
let workOrderScores =
Frame.ofColumns [
"workOrderCode" => series [ (20050,20050); (20050,20050); (20051,20051) ]
"runTime" => series [ (20050,20100112); (20050,20100130); (20051,20100215) ]
"score" => series [ (20050,100); (20050,120); (20051,80) ]]
Frame.join JoinKind.Outer workOrders workOrderScores
The problem is that Deedle will not let me create a data frame with a non unique index and I get the following error: System.ArgumentException: Duplicate key '20050'. Duplicate keys are not allowed in the index.
Interestingly in Python/Pandas I can do the following which works perfectly. How can I reproduce this result in Deedle? I am thinking that I might have to flatten the second data frame to remove the duplicates then join and then unpivot/unstack it?
workOrders = pd.DataFrame(
{'workOrderCode': [20050, 20051, 20060],
'workOrderDescription': ['Door Repair', 'Lift Replacement', 'Window Cleaning']})
workOrderScores = pd.DataFrame(
{'workOrderCode': [20050, 20050, 20051],
'runTime': [20100112, 20100130, 20100215],
'score' : [100, 120, 80]})
pd.merge(workOrders, workOrderScores, on = 'workOrderCode', how = 'left')
# Result:
# workOrderCode workOrderDescription runTime score
#0 20050 Door Repair 20100112 100
#1 20050 Door Repair 20100130 120
#2 20051 Lift Replacement 20100215 80
#3 20060 Window Cleaning NaN NaN
This is a great question - I have to admit, there is currently no elegant way to do this with Deedle. Could you please submit an issue to GitHub to make sure we keep track of this and add some solution?
As you say, Deedle does not let you have duplicate values in the keys currently - although, your Pandas solution also does not use duplicate keys - you simply use the fact that Pandas lets you specify the column to use when joining (and I think this would be great addition to Deedle).
Here is one way to do what you wanted - but not very nice. I think using pivoting would be another option (there is a nice pivot table function in the latest source code - not yet on NuGet).
I used groupByRows and nest to turn your data frames into series grouped by the workOrderCode (each item now contains a frame with all rows that have the same work order code):
let workOrders =
Frame.ofColumns [
"workOrderCode" =?> Series.ofValues [ 20050; 20051; 20060 ]
"workOrderDescription" =?> Series.ofValues [ "Door Repair"; "Lift Replacement"; "Window Cleaning" ]]
|> Frame.groupRowsByInt "workOrderCode"
|> Frame.nest
let workOrderScores =
Frame.ofColumns [
"workOrderCode" => Series.ofValues [ 20050; 20050; 20051 ]
"runTime" => Series.ofValues [ 20100112; 20100130; 20100215 ]
"score" => Series.ofValues [ 100; 120; 80 ]]
|> Frame.groupRowsByInt "workOrderCode"
|> Frame.nest
Now we can join the two series (because their work order codes are the keys). However, then you get one or two data frames for each joined order code and there is quite a lot of work needed to outer join the rows of the two frames:
// Join the two series to align frames with the same work order code
Series.zip workOrders workOrderScores
|> Series.map(fun _ (orders, scores) ->
match orders, scores with
| OptionalValue.Present s1, OptionalValue.Present s2 ->
// There is a frame with some rows with the specified code in both
// work orders and work order scores - we return a cross product of their rows
[ for r1 in s1.Rows.Values do
for r2 in s2.Rows.Values do
// Drop workOrderCode from one series (they are the same in both)
// and append the two rows & return that as the result
yield Series.append r1 (Series.filter (fun k _ -> k <> "workOrderCode") r2) ]
|> Frame.ofRowsOrdinal
// If left or right value is missing, we just return the columns
// that are available (others will be filled with NaN)
| OptionalValue.Present s, _
| _, OptionalValue.Present s -> s)
|> Frame.unnest
|> Frame.indexRowsOrdinally
This might be slow (especially in the NuGet version). If you work on more data, please try building latest version of Deedle from sources (and if that does not help, please submit an issue - we should look into this!)

Charting and Comparing Prices in F# - Chart.Combine will not produce graph

I'm working through the charting and comparing prices tutorial on tryfsharp.org and my Chart.Combine function in Fsharp.Charting library will not work, but, other charts, such as Chart.Line will work! Code below.
// Helper function returns dates & closing prices from 2012
let recentPrices symbol =
let data = stockData symbol (DateTime(2012,1,1)) DateTime.Now
[ for row in data.Data -> row.Date.DayOfYear, row.Close ]
Chart.Line(recentPrices "AAPL", Name="Apple") //These two guys work when I try to plot them.
Chart.Line(recentPrices "MSFT", Name="Microsoft")
Chart.Combine( // This guy will not plot. Syntax found here: http://fsharp.github.io/FSharp.Charting/PointAndLineCharts.html
[ Chart.Line(recentPrices "AAPL", Name="Apple")
Chart.Line(recentPrices "MSFT", Name="Microsoft")])
I'd suggest you substituting your data generator function with something simpler and achieving correct plotting with this mockup first. For example, the following script:
#load #"<your path here>\Fsharp.Charting.fsx"
open System
open FSharp.Charting
let rand = System.Random
let recentPricesMock symbol =
[for i in 1..12 -> DateTime(2012,i,1),rand.Next(100)]
Chart.Combine (
[ Chart.Line(recentPricesMock "AAPL", Name="Apple")
Chart.Line(recentPricesMock "MSFT", Name="Microsoft")])
must plot combined mockup chart without any problems, as it does on my local box. From here you may drill down for the cause of original problem comparing your recentPrices with recentPricesMock.
EDIT: after getting to the full problematic source code I can point out two problems there that, as I was expecting, are in your choice of data rather, than in charting per se:
First, your definition of recentPrices converts dates into sequential day of year (row.Date.DayOfYear), so transition from 2012 into 2013 messes up your data and, consequently, charts. If you want to preserve your current functionality then it makes sense to redefine recentPrices as below
let recentPrices symbol =
let data = stockData symbol (DateTime(2012,1,1)) DateTime.Now
[ for row in data.Data -> row.Date, row.Close ]
Second, you chose a pair of stocks that doesn't scale well being combined on the single chart (AAPL in high hundreds $$, while MSFT in low tens $$), which adds to repetition of data points from first problem. After changing in your code AAPL to YHOO in addition to the recentPrices definition change described above
Chart.Combine ([
Chart.Line(recentPrices "YHOO", Name="Yahoo")
Chart.Line(recentPrices "MSFT", Name="Microsoft")
])
yields a beautiful smooth chart combo:

update all line of table in erlang

I have this table :
-record(person, {id, firstname, lastname, address}).
for example this table contains this values :
2 alen dumas paris
5 franco mocci parma
3 ali othmani london
Now I have the variable Key which contains this value 10
I want to develop a function in erlang which will modify all id of the table person
the new value of this id will be the previous value + the value of Key
mean the table person will became like this
12 alen dumas paris
15 franco mocci parma
13 ali othmani london
meaning each id will be added by 10 (is the value of Key) :(2+10) (5+10) (3+10)
I try with your code :
testmodify()->
Key=22,
[ P#person{id=P#person.id+Key} || P <- Persons ].
but I have this error in the sysntax : variable Persons is unbound
I try to resolve this problem with this code :
testmodify()->
Key=22,
[ P#person{id=P#person.id+Key} || P <- mnesia:table(person) ].
but I have this error :
1> model:testmodify().
** exception error: no function clause matching
model:'-testmodify/0-lc$^0/1-0-'({qlc_handle,
{qlc_table,
#Fun<mnesia.20.112329951>,
true,
#Fun<mnesia.21.62211129>,
#Fun<mnesia.22.75429001>,
#Fun<mnesia.23.26336897>,
#Fun<mnesia.26.62819299>,
#Fun<mnesia.25.51075493>,
#Fun<mnesia.24.47804912>,
'=:=',undefined,
no_match_spec}})
Assuming your table is stored as a list:
[ P#person{id=P#person.id+Key} || P <- Persons ].
UPDATE: For an Mnesia table, you can retrieve similar results with QLC:
-include_lib("stdlib/include/qlc.hrl").
⋮
[ P#person{id=P#person.id+Key} || P <- mnesia:table(person) ].
Note that this only gives you a list of transformed person records. To update the records, you'll probably have to remove the existing records and write the new records in a transaction, since a record with a modified key (assuming that's what id is) is treated as a different record — something like this:
mnesia:transaction(fun() ->
Old = [ P || P <- mnesia:table(person) ],
New = [ P#person{id=P#person.id+Key} || P <- Old ],
[ mnesia:delete({person, P#Person.id}) || P <- Old ],
[ mnesia:write(P) || P <- New ]
end)
You might be able to do this in a single pass with mnesia:foldr, but I don't know what happens if you issue mnesia:delete and mnesia:write inside mnesia:foldr. You might get stuck in an infinite loop (but don't quote me on that).

Resources