NYCJUG/2009-03-10/LeavingTraces-DocumentingbyShowingDevelopment

From J Wiki
Jump to navigation Jump to search

Leaving Traces - Documenting by Showing Development

Here's some finished code - how understandable is it?

NB.* BOWAddup.ijs: add up allocations in a book-of-work.
require '~addons/tara.ijs'

splitLastSpc=: 13 : '(ls{.y);y}.~>:ls=. ('' ''i:~])y'  NB. Split->2 at last spc
lead0Pt=: 13 : 'y,~''0''#~''.''={.y'              NB. Put 0 before "."
paren2sp=: 13 : 'p2s#^:_1 y#~p2s=. -.y e. ''()''' NB. Parens to spaces
lf2comma=: 13 : '(y=10{a.)}y,:'','''              NB. LF to comma
tp2c=: 13 : '(y='')'')}y,:'','''                  NB. Trailing paren to comma
rmdupc=: 13 : '('',,'';'','') replace y'          NB. Remove duplicate commas

addUpAllocations=: 3 : 0
   wksht=. 0 readxlsheets y
NB.   assert. 'RSOD' -: >0{,rsod NB. Assume 1st sheet OK
   bow=. >1{,wksht
   bowtit=. 1{bow             NB. Title row
   bow=. 2}.bow               NB. Book-of-work data, allocations
   allocs=. (bowtit i. <'Resources'){"1 bow
   allocs=. allocs#~0~:#&>allocs        NB. No empties
   allocs=. lf2comma&.>allocs-.&.>CR    NB. LF->',', no CRs
   allocs=. (rmdupc @: tp2c)&.>allocs   NB. ')'->',', no duplicate commas
   al2c=. >,&.>/crNameAllocCols&.>allocs NB. 2-cols: name;alloc
   al2c=. al2c#~0+./ . ~:|:#&>al2c      NB. No empty rows
   totalc=. +/&.>,&.>_99 ".&>&.>(0{"1 al2c)</.1{"1 al2c
   sumalc=. (~.0{"1 al2c),.totalc
   sumalc=. (y;'Totals'),sumalc /: 0{"1 sumalc
NB.EG sumalc=. addUpAllocations 'W:\bow\2009\RSOD_Q2.xls'
)

crNameAllocCols=: 3 : 0
   al1=. <;._1 ',',y     NB. Split by name, then change
NB. parens to spaces and remove excess spaces after separating
NB. names from allocations.
   al1=. (splitLastSpc @: dsp @: paren2sp)&>al1
   al1=. lead0Pt&.>al1   NB. Ensure leading zero if initial decimal
NB. Shift so all cols are name;number.
   al1=. (1 0*./ . ="1 isValNum&>al1)|."(0 1)al1
)

Here's some sample input:

SampleInputBOWblanked.png

Now here's a sample of the session in which the code was developed:

   load '~addons/tara.ijs'
   rsod=. 0 readxlsheets 'W:\bow\2009\RSOD_Q2.xls'
   $rsod
1 2
   $&.>rsod
+-+-----+
|4|25 18|
+-+-----+
   >0{,rsod
RSOD
   bow=. >1{,rsod
   3{.bow
+----------+--------+----+---------------+--------+-----------+------...
|          |        |    |               |        |           |      ...
+----------+--------+----+---------------+--------+-----------+------...
|item count|Business|2009|Engagement type|Projects|HP-PPM Code|Servic...
+----------+--------+----+---------------+--------+-----------+------...
|          |        |    |               |        |           |      ...
+----------+--------+----+---------------+--------+-----------+------...
   0{bow
++++++++++----------------++++--+----------------++++
||||||||||Onsite Resources||||OC|Project Offshore||||
++++++++++----------------++++--+----------------++++
   1{bow
+----------+--------+----+---------------+--------+-----------+--------+---------+...
|item count|Business|2009|Engagement type|Projects|HP-PPM Code|Services|Resources|...
+----------+--------+----+---------------+--------+-----------+--------+---------+...
   bowtit=. 1{bow
   bow=. 2}.bow
   bowtit i. <'Resources'
7
   $bow
23 18
   7{"1 bow
++------------------------------------------------+-------+-----------...
||Chintan (.1), Aksana (.1), Tejas Naik (1), .3 OC|OC (.3)|Vinita (1),...
++------------------------------------------------+-------+-----------...
   allocs=. (bowtit i. <'Resources'){"1 bow
   >0{allocs

   >1{allocs
Chintan (.1), Aksana (.1), Tejas Naik (1), .3 OC
   al1=. <;._1 ',',>1{allocs
   al1
+------------+------------+---------------+------+
|Chintan (.1)| Aksana (.1)| Tejas Naik (1)| .3 OC|
+------------+------------+---------------+------+
   ' 'i:~>0{al1
7
. . .
   splitLastSpc=: 13 : '(ls{.y);y}.~>:ls=. ('' ''i:~])y'
   splitLastSpc&>al1
+-----------+----+
|Chintan    |(.1)|
+-----------+----+
| Aksana    |(.1)|
+-----------+----+
| Tejas Naik|(1) |
+-----------+----+
| .3        |OC  |
+-----------+----+
   dsp&.>splitLastSpc&>al1
+----------+----+
|Chintan   |(.1)|
+----------+----+
|Aksana    |(.1)|
+----------+----+
|Tejas Naik|(1) |
+----------+----+
|.3        |OC  |
+----------+----+
   ". '00.1'
0.1
   (<'()')-.~&.>dsp&.>splitLastSpc&>al1
+----------+--+
|Chintan   |.1|
+----------+--+
|Aksana    |.1|
+----------+--+
|Tejas Naik|1 |
+----------+--+
|.3        |OC|
+----------+--+
   isValNum&>(<'()')-.~&.>dsp&.>splitLastSpc&>al1
0 0
0 0
0 1
0 0
   lead0Pt=: 13 : 'y,~''0''#~''.''={.y'
   lead0Pt&.>(<'()')-.~&.>dsp&.>splitLastSpc&>al1
+----------+---+
|Chintan   |0.1|
+----------+---+
|Aksana    |0.1|
+----------+---+
|Tejas Naik|1  |
+----------+---+
|0.3       |OC |
+----------+---+
   isValNum&>lead0Pt&.>(<'()')-.~&.>dsp&.>splitLastSpc&>al1
0 1
0 1
0 1
1 0
   al1=. lead0Pt&.>(<'()')-.~&.>dsp&.>splitLastSpc&>al1

   1 0*./ . ="1 isValNum&>al1
0 0 0 1
   (1 0*./ . ="1 isValNum&>al1)|."(0 1)al1
+----------+---+
|Chintan   |0.1|
+----------+---+
|Aksana    |0.1|
+----------+---+
|Tejas Naik|1  |
+----------+---+
|OC        |0.3|
+----------+---+
   al1=. (1 0*./ . ="1 isValNum&>al1)|."(0 1)al1
   crNameAllocCols=: 3 : 0
   al1=. <;._1 ',',y          NB. Split by name, then ensure
NB. leading zero if initial decimal, remove parens, separate
NB. names from allocations.
   al1=. lead0Pt&.>(<'()')-.~&.>dsp&.>splitLastSpc&>al1
NB. Ensure 2 cols are name;number.
   al1=. (1 0*./ . ="1 isValNum&>al1)|."(0 1)al1
)

   al2c=. crNameAllocCols&.>allocs
   $&>al2c
1 2
4 2
1 2
3 2
4 2
...
4 2
2 2
1 2
   $al2c=. >,&.>/crNameAllocCols&.>allocs
44 2
   _4{.al2c
+----------+---+
|Devon     |0.2|
+----------+---+
|Chintan.05|   |
+----------+---+
|Amlan.2   |   |
+----------+---+
|          |   |
+----------+---+
   #&.>_4{.al2c
+--+-+
|5 |3|
+--+-+
|10|0|
+--+-+
|7 |0|
+--+-+
|0 |0|
+--+-+

NB. Reset temporary...
   al1=. <;._1 ',',>1{allocs
   al1
+------------+------------+---------------+------+
|Chintan (.1)| Aksana (.1)| Tejas Naik (1)| .3 OC|
+------------+------------+---------------+------+
   al1=. (<'( ';') ')replace&.>splitLastSpc&>al1
   al1
+-----------+----+
|Chintan    |(.1)|
+-----------+----+
| Aksana    |(.1)|
+-----------+----+
| Tejas Naik|(1) |
+-----------+----+
| .3        |OC  |
+-----------+----+
   (13 : 'p2s#^:_1 y#~p2s=. -.y e. ''()''') &.>al1
+-----------+----+
|Chintan    | .1 |
+-----------+----+
| Aksana    | .1 |
+-----------+----+
| Tejas Naik| 1  |
+-----------+----+
| .3        |OC  |
+-----------+----+

   paren2sp=: 13 : 'p2s#^:_1 y#~p2s=. -.y e. ''()'''
   (dsp @:  paren2sp)&.>al1
+----------+--+
|Chintan   |.1|
+----------+--+
|Aksana    |.1|
+----------+--+
|Tejas Naik|1 |
+----------+--+
|.3        |OC|
+----------+--+
   $al2c=. >,&.>/crNameAllocCols&.>allocs
44 2
   _4{.al2c
+----------+---+
|Devon     |0.2|
+----------+---+
|Chintan.05|   |
+----------+---+
|Amlan.2   |   |
+----------+---+
|          |   |
+----------+---+
   crNameAllocCols=: 3 : 0
   al1=. <;._1 ',',y     NB. Split by name, then change
NB. parens to spaces and remove excess spaces after separating
NB. names from allocations.
   al1=. (dsp @: paren2sp)&.>splitLastSpc&>al1
   al1=. lead0Pt&.>al1   NB. Ensure leading zero if initial decimal
NB. Shift so all cols are name;number.
   al1=. (1 0*./ . ="1 isValNum&>al1)|."(0 1)al1
)

      $al2c=. >,&.>/crNameAllocCols&.>allocs
44 2
   _4{.al2c
+-----------+---+
|Devon      |0.2|
+-----------+---+
|Chintan .05|   |
+-----------+---+
|Amlan .2   |   |
+-----------+---+
|           |   |
+-----------+---+
   crNameAllocCols=: 3 : 0
   al1=. <;._1 ',',y     NB. Split by name, then change
NB. parens to spaces and remove excess spaces after separating
NB. names from allocations.
   al1=. (dsp @: splitLastSpc @: paren2sp)&>al1
   al1=. (dsp @: paren2sp)&.>splitLastSpc&>al1
   al1=. lead0Pt&.>al1   NB. Ensure leading zero if initial decimal
NB. Shift so all cols are name;number.
   al1=. (1 0*./ . ="1 isValNum&>al1)|."(0 1)al1
)

   $al2c=. >,&.>/crNameAllocCols&.>allocs
44 2 2

   al1=. <;._1 ',',>1{allocs
   (dsp @: splitLastSpc @: paren2sp)&>al1
+--------------+--+
|Chintan  .1   |  |
+--------------+--+
| Aksana  .1   |  |
+--------------+--+
| Tejas Naik  1|  |
+--------------+--+
| .3           |OC|
+--------------+--+
   (splitLastSpc @: dsp @: paren2sp)&>al1
+----------+--+
|Chintan   |.1|
+----------+--+
|Aksana    |.1|
+----------+--+
|Tejas Naik|1 |
+----------+--+
|.3        |OC|
+----------+--+
   crNameAllocCols=: 3 : 0
   al1=. <;._1 ',',y     NB. Split by name, then change
NB. parens to spaces and remove excess spaces after separating
NB. names from allocations.
   al1=. (splitLastSpc @: dsp @: paren2sp)&>al1
   al1=. lead0Pt&.>al1   NB. Ensure leading zero if initial decimal
NB. Shift so all cols are name;number.
   al1=. (1 0*./ . ="1 isValNum&>al1)|."(0 1)al1
)

   $al2c=. >,&.>/crNameAllocCols&.>allocs
44 2
   _4{.al2c
+-------+----+
|Devon  |0.2 |
+-------+----+
|Chintan|0.05|
+-------+----+
|Amlan  |0.2 |
+-------+----+
|       |    |
+-------+----+
   0+./ . ~:|:#&>al2c
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
   $al2c=. >,&.>/crNameAllocCols&.>allocs
44 2
   al2c=. al2c#~0+./ . ~:|:#&>al2c    NB. No empty rows
   $al2c
41 2

   ;&.>".&.>&.>(0{"1 al2c) </. 1{"1 al2c
+---------------------------------+---------------------------+-+----...
|0.1 0.65 0.05 0.05 0.05 0.05 0.05|0.1 0.2 0.3 0.1 0.1 0.1 0.1|1|0.3 ...
+---------------------------------+---------------------------+-+----...
   +/&>;&.>".&.>&.>(0{"1 al2c) </. 1{"1 al2c
1 1 1 9.9 1 0.5 1 0.65 1 0 1 0.6 0 0.4 0.2 1
   $+/&>;&.>".&.>&.>(0{"1 al2c) </. 1{"1 al2c
16
   $~.0{"1 al2c
16
   (~.0{"1 al2c),.<"0 +/&>;&.>".&.>&.>(0{"1 al2c) </. 1{"1 al2c
+----------+----+
|Chintan   |1   |
+----------+----+
|Aksana    |1   |
+----------+----+
|Tejas Naik|1   |
+----------+----+
|OC        |9.9 |
+----------+----+
...
|All       |0   |
+----------+----+
|Devon     |0.4 |
+----------+----+
|Pranav    |0.2 |
+----------+----+
|Srinivas  |1   |
+----------+----+
   1!:43 ''
C:\amisc\SP\RIC\Data
   (+/&>;&.>".&.>&.>(0{"1 al2c) </. 1{"1 al2c) writecsv 'c:\amisc\SP\QA\RSODBOWAllocs09Q2.csv'
78
   $+/&>;&.>".&.>&.>(0{"1 al2c) </. 1{"1 al2c
16
   sumalc=. (~.0{"1 al2c),.<"0 +/&>;&.>".&.>&.>(0{"1 al2c) </. 1{"1 al2c
   sumalc writecsv 'c:\amisc\SP\QA\RSODBOWAllocs09Q2.csv'
233
   load 'C:\amisc\SP\QA\BOWAddup.ijs'
   sumalc=. addUpAllocations 'W:\bow\2009\RSOD_Q2.xls'
|domain error: addUpAllocations
|   sumalc=.+/&>;&.>    ".&.>&.>(0{"1 al2c)</.1{"1 al2c
   $al2c
41 2
   (0{"1 al2c)</.1{"1 al2c
+------------------------------------+-----------------------------+-...
|+---+----+----++----+----+----+----+|+---+---+---+---+---+---+---+|+...
||0.1|0.65|0.05||0.05|0.05|0.05|0.05|||0.1|0.2|0.3|0.1|0.1|0.1|0.1|||...
|+---+----+----++----+----+----+----+|+---+---+---+---+---+---+---+|+...
+------------------------------------+-----------------------------+-...
   _99 ".&>&.>(0{"1 al2c)</.1{"1 al2c
+----+---------------------------+-+-----------------+-+---+-------+-...
| 0.1|0.1 0.2 0.3 0.1 0.1 0.1 0.1|1|0.3 0.3 3 3 3 0.3|1|0.5|0.8 0.2|0...
|0.65|                           | |                 | |   |       | ...
|0.05|                           | |                 | |   |       | ...
. . .
+----+---------------------------+-+-----------------+-+---+-------+-...
   $_99 ".&>&.>(0{"1 al2c)</.1{"1 al2c
16
   $&.>_99 ".&>&.>(0{"1 al2c)</.1{"1 al2c
+---+-+-+-+-+-+-+-+-+-+-+---+-+-+-+-+
|8 1|7|1|6|1|1|2|2|1|1|1|5 1|1|2|1|1|
+---+-+-+-+-+-+-+-+-+-+-+---+-+-+-+-+
   ,&.>_99 ".&>&.>(0{"1 al2c)</.1{"1 al2c
+-----------------------------------+---------------------------+-+--...
|0.1 0.65 0.05 0 0.05 0.05 0.05 0.05|0.1 0.2 0.3 0.1 0.1 0.1 0.1|1|0....
+-----------------------------------+---------------------------+-+--...
   +/&.>,&.>_99 ".&>&.>(0{"1 al2c)</.1{"1 al2c
+-+-+-+---+-+---+-+----+-+---+-+---+---+---+---+-+
|1|1|1|9.9|1|0.5|1|0.65|1|_99|1|0.6|_99|0.4|0.2|1|
+-+-+-+---+-+---+-+----+-+---+-+---+---+---+---+-+
. . .