http://www.jsoftware.com/pipermail/programming/2011-January/021609.html

In the thread mentioned above I was trying to extract information
corresponding to the following key tags from a file excerpted from there:
date, duration, gameNumber, moves, and result. Each "dict" group represents
a game of Freecell. I was able to do it with help from the forum, but it
being such a simple database, I wonder if you would show how to do it with
your 2 blog codes? Understand please that I may be asking much more than
you can provide, do feel free to decline.

Below is some code that I used on the data file. The code was only intended
for my own use, but maybe a cursory look could clarify what I did. At the
very bottom is a "demo" list of things I did with the dataset. I hope there
is enough meat and not too much fat for you to see what I was doing.



NB. freecellscore.ijs
NB. 1/25/11
NB. 10/3/13 revision

require 'xml/sax format/datefmt types/datetime'

saxclass 'pfreecell'


noba=: -.&' '
startDocument=: 3 : 0
  S=: ''
  Z=: i.0 2
)
endDocument=: 3 : 'Z'

startElement=: 4 : 0
  S=: S,<y
)

endElement=: 3 : 0
  S=: }:S
)

characters=: 3 : 0
  s2=. _2{.S
  if. s2 -: ;:'dict key' do. Z=:Z,y
  elseif. (1<#y) *. #noba y do. Z=:Z,  y
end.
)

coclass'base'
NB. td means time-date
tdmask=: 1 1,,6($,:)1 1j1 0
tdfromiso=: tdmask&(#!.' ')
tfromiso=: (]- 0 0 0,~1800 1 1-~3&{.)&(".@tdfromiso)
tdfmt=: ":!.13
td=: tdfmt@tsrep@(".@tdfromiso)
ti=: tdfmt@tsrep@tfromiso
arrayed=: _5&(;/\)
amend0=: 0&((".@tdfromiso each @{)`(,@[)`]}"0 1)
amend1=: 1&((tfromiso each @{)`(,@[)`]}"0 1)
clean=: }:@}.@('<' dropto&.|. '>' dropto ])

NB. create verbs for processing 5 input types
ti=: td=: ]
date=: td
duration=: ti
gameNumber=: moves=: result=: ]

Date=: tdfromiso@(0&pick"1)
Duration=: tfromiso@(1&pick"1)
Duration=: 24 60 60&#.@(_3&{.)@tfromiso@(1&pick"1)
GameNumber=: 2&pick"1
Moves=:  ".@(3&pick"1)
Result=: 4&pick"1

NB. execute verb,noun data pairs
ex=:    (],~'~',~[)&('''',],''''"_)&dtb/


freqcount=: (\: {:"1)@(~. ,. #/.~)
midpt=: -:@<:@#
median=: -:@(+/)@((<. , >.)@midpt { /:~)
mean=:+/ % #


Note 'demo'
load'plot'
load 'files'
NB. next line wraps
#indata=: fread
'/Users/brian/Library/Preferences/org.wasters.Freecell.history.plist'
indata=: '</dict>' dropto&.|. '<dict' dropto indata
NB. next line wraps
data=: }. _12 clean each@((0 0 1 0 1 0 1 0 1 0 1 0&#))\<;._2  indata,LF NB.
get data only
#u=. /:Date data      NB. sort order
sdata=: u{data
NB. next line wraps
between=: 100000,~0 0 30 24 60 60 #.2 tsDiff/\&.|.". Date sdata  NB.
seconds between Dates
threshold=: */2  60 60  NB. 2 hours
outliers=: 3600>Duration sdata  NB. really, games of less than 1 hour
freqcount #&>(between<:threshold)<;. 1 sdata NB. # games played per session?
NB. next line wraps
plot (#~0 1 $~ #)median @:Duration&>(outliers#between<:threshold)<;. 1
outliers#sdata
outliers=: 1000>Duration sdata  NB. really, games of less than 1000 secs
'dot' plot (Duration;~Moves)outliers#sdata
)




-- 
(B=)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to