Loading ...
Sorry, an error occurred while loading the content.

Re: [Clip] How might I do this math with a clip?

Expand Messages
  • Alan C.
    On Tue, 04 Nov 2003 21:09:36 -0500, Don Passenger wrote: [ . . ] (bandwidth), see Don s post for context I also tinkered about sort/math -- I make a fool of
    Message 1 of 12 , Nov 4, 2003
    • 0 Attachment
      On Tue, 04 Nov 2003 21:09:36 -0500, Don Passenger wrote:
      [ . . ] (bandwidth), see Don's post for context

      I also tinkered about sort/math -- I make a fool of myself and include it (I'm known for *sometimes* turning something simple into rocket science) -- (watch, someone post a much simplified method) -- but, maybe not, as sometimes i get it -- like to pound/drive a nail - sometimes on target, sometimes not.

      calc function needed once, when tally up ie element + element + element

      otherwise, "If" does compares them (enclosed below)

      uses a scratch doc (i sometimes think it easier to use "find" in another separate doc.

      http://www.google.com/search?hl=en&lr=&ie=ISO-8859-1&q=top+down+algorithm&btnG=Google+Search

      (top means big_overall | down means to grab/take that big_overall and break_it_down_into_smaller_chunks)

      i only make mention of that since it the approach/premise of my tinkerings (each clip be a sub routine, each clip does one funtion) each clip is the "down" (broken down to smaller chunks from the topmost clip which is the main or global clip)

      Not even close to finished, not whatsoever. But fun to do it -- like a puzzle -- view the whole puzzle -- then begin to build pieces of it that when assembled together makes a completed puzzle

      the heart of it is para_formatr and sort_col_1

      I would first use and continue to build/develop those ttwo clips by themselves as they can do/work just one of this next

      270| �389|Chris Couturier|Beaverton|17:05.35|05:14.90|10:56.00|16:33.65
      299| �425|Josh Cann|Beaverton|17:10.70|05:15.45|10:54.85|16:37.40
      378| �536|Justin Fruchey|Beaverton|17:30.05|05:30.20|11:19.90|17:02.55
      531| �725|Chris Earls|Beaverton|18:09.00|05:30.35|11:26.00|17:37.70
      532| �727|Shawn Dorman|Beaverton|18:09.35|05:39.80|11:46.35|17:39.05
      559| �758|Jacob Sargent|Beaverton|18:17.35|05:41.80|11:47.15|17:41.90
      64| � 81|Nathan Mester|Beaverton|16:04.50|04:59.45|10:17.60|15:37.25

      once i got it performing on that, then I'd perfect it for multiples thereof etc.

      H="numbr_sort"

      ^!SetScreenUpdate OFF
      ^!Set %memidx%=^$GetDocIndex$
      ^!Menu File/New
      ^!Set %newidx%=^$GetDocIndex$

      :grab_a_para
      ^!Clip para_snagr


      H="_para_snagr"
      ^!SetDocIndex ^%memidx%
      ; method to select a paragraph
      ; $GetSelection into a GOTSEL variable
      ^!SetDocIndex ^%newidx%
      ^!Clip para_formatr

      H="_para_formatr"
      ; ^!InsertText GOTSEL variable (dump paragraph into scratch doc)
      ^!Set %line_count%=^$GetLineCount$
      ^!Jump DOC_START
      ^!SetDelimiter "|"
      :next_lead_digit
      ^!Set %grabbed1%=^$GetField(1;1)$
      ^!Append %accum_digits%=^%grabbed1%;
      ^!If ^$GetRow$ >= ^%line_count% time2sort
      ^!Jump +1
      ^!Goto next_lead_digit
      :time2sort
      ^!SetArray %col_1_items%=^%accum_digits%
      ; sort the column 1 digit items
      ^!Clip sort_col_1

      H="_sort_col_1"
      ; p_h (place_holder)
      ^!Set %p_h%=1
      ^!Set %Count%=^%col_1_items0%
      ^!Set %Index%=0
      :Loop
      ^!Inc %Index%
      ^!If ^%Index% > ^%Count% flag_it
      ^!If ^%col_1_items^%Index%% =< ^%p_h% skip
      ^!Set %p_h%=^%col_1_items^%Index%%
      ^!Goto Loop
      :flag_it
      ; mark or flag this smallest that's now been segregated out
      ; then goto loop again but do so with this flagged item somehow tested so it is excluded
      ; IOW, each time, segregate out, exclude the smallest
      ; in succession, each smallest will then become (a larger smallest) the successive order
      ; that is, the order of them from smallest to largest will be ultimate result

      ;-------------------------------------------
      ; then, need another clip to "find" from the scratch doc (each line in the proper, successive order) and append each these lines into a variable in that order then dump them back into doc in this sorted order

      --
      Alan.
    • hugo_paulissen
      Don, Alan, I haven t used Alans clip, i only saw his remark that there might be an alternative. This may be redundant; but here is one way to do it... Regards,
      Message 2 of 12 , Nov 5, 2003
      • 0 Attachment
        Don, Alan,

        I haven't used Alans clip, i only saw his remark that there might be
        an alternative. This may be redundant; but here is one way to do it...

        Regards,

        Hugo

        ^!Set %Line%=2
        ^!SetDelimiter "|"
        ^!Set %FirstFields%=""
        :FIRSTFIELDS
        ^!If ^%Line%=^$Calc(^$GetLineCount$+1)$ CALC
        ; STOP PROCESSING THE FILE ---------------------------
        ^!Set %Field%=^$GetField(^%Line%;1)$
        ^!If ^$StrSize("^%Field%")$=1 ^!Set %Field%=00^%Field%
        ^!If ^$StrSize("^%Field%")$=2 ^!Set %Field%=0^%Field%
        ; THESE LINES WERE NECESSARY BECAUSE SORTING ---------
        ; --------64 AND 203 PUTS 204 ON TOP -----------------
        ^!Append %FirstFields%="^%Field%"^%NL%
        ^!Inc %Line%
        ^!GoTo FIRSTFIELDS
        :CALC
        ^!Set %Fields%=^$StrSort("^%FirstFields%";False;True;False)$
        ^!SetArray %Fields%=^$StrReplace("^P";";";"^%Fields%";0;0)$
        ^!Set %LowestFive%=^%Fields1%+^%Fields2%+^%Fields3%+^%Fields4%+^%
        Fields5%
        ^!Set %Result%=^$Calc(^%LowestFive%)$
        :INSERTATTOP
        ^!Jump 1
        ^!Jump Line_End
        ^!InsertText " ^%LowestFive%=^%Result%"
      • Don Passenger
        Playing with this clip Hugo, thanks! I find it misbehaves when I have an empty line. It appears to put in a zero/null value as one of the five values. I
        Message 3 of 12 , Nov 5, 2003
        • 0 Attachment
          Playing with this clip Hugo, thanks! I find it misbehaves when I have
          an empty line. It appears to put in a zero/null value as one of the
          five values. I need to play some more, not sure if I have a blank line
          in there currently.

          hugo_paulissen wrote:

          > Don, Alan,
          >
          > I haven't used Alans clip, i only saw his remark that there might be
          > an alternative. This may be redundant; but here is one way to do it...
          >
          > Regards,
          >
          > Hugo
          >
          > ^!Set %Line%=2
          > ^!SetDelimiter "|"
          > ^!Set %FirstFields%=""
          > :FIRSTFIELDS
          > ^!If ^%Line%=^$Calc(^$GetLineCount$+1)$ CALC
          > ; STOP PROCESSING THE FILE ---------------------------
          > ^!Set %Field%=^$GetField(^%Line%;1)$
          > ^!If ^$StrSize("^%Field%")$=1 ^!Set %Field%=00^%Field%
          > ^!If ^$StrSize("^%Field%")$=2 ^!Set %Field%=0^%Field%
          > ; THESE LINES WERE NECESSARY BECAUSE SORTING ---------
          > ; --------64 AND 203 PUTS 204 ON TOP -----------------
          > ^!Append %FirstFields%="^%Field%"^%NL%
          > ^!Inc %Line%
          > ^!GoTo FIRSTFIELDS
          > :CALC
          > ^!Set %Fields%=^$StrSort("^%FirstFields%";False;True;False)$
          > ^!SetArray %Fields%=^$StrReplace("^P";";";"^%Fields%";0;0)$
          > ^!Set %LowestFive%=^%Fields1%+^%Fields2%+^%Fields3%+^%Fields4%+^%
          > Fields5%
          > ^!Set %Result%=^$Calc(^%LowestFive%)$
          > :INSERTATTOP
          > ^!Jump 1
          > ^!Jump Line_End
          > ^!InsertText " ^%LowestFive%=^%Result%"
          >
          >
          >
          >
          >
          > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
          >
          >
          >
        • Alan C.
          Hi, my clip I assumed that the lines sometimes came or were in an out of order fashion and that in such case, the lines would need to be reordered according to
          Message 4 of 12 , Nov 5, 2003
          • 0 Attachment
            Hi,

            my clip I assumed that the lines sometimes came or were in an out of order fashion and that in such case, the lines would need to be reordered according to the numbers/data in the first column.

            so you can disregard unless someone also has need to reorder the lines which is another task that's in addition to the task of Hugo's clip.

            --
            Alan.
          • Don Passenger
            Here is what I wound up with. To test it take the data from yesterday and repeat it a couple of times but changing field two for every successive set (and
            Message 5 of 12 , Nov 5, 2003
            • 0 Attachment
              Here is what I wound up with. To test it take the data from yesterday
              and repeat it a couple of times but changing field two for every
              successive set (and deleting the one word line at the top as I
              eventually insert that at the bottom.

              I used Hugo's method of building a variable with multiple lines, padding
              short numbers with zeros and then sorting before dumping into an array.
              There is an error in my clip because in several cases the last number
              is corrupted. I didn't track it down, I fixed those three or four
              problems manually. Because it was a corruption of the last number in
              the set, it was thrown out in almost all cases.

              ;Jump to Start
              ^!Jump TEXT_START
              ;Clear all Variables
              ^!ClearVariables

              ;set the delimiter to the pipe
              ;think a lot of this unneccessary but copied
              ;from Jody's noteblock clip
              ^!Set %Delimiter%=|
              ^!Set %Delimiter%=^$StrReplace("|";"^%Vbar%";"^%Delimiter%";0;0)$
              ^!SetDelimiter ^%Delimiter%

              ;Field1 is the field we check for school
              ;n is a counter
              ^!Set %n%=0; %Field1%=2

              ;make sure there is something there
              ^!IfTrue ^$IsEmpty(^$GetField(^$GetRow$;1)$)$ Oops
              ^!SetHintInfo Getting field...
              ^!SetScreenUpdate Off

              :NewTeam
              ;grab current cursor position
              ^!Set %CurCur%=^$GetRow$:^$GetCol$
              ;first time set team
              ^!Set %GrabField2%=^$GetField(^$GetRow$;2)$
              ^!Set %Team%=^$GetSelection$
              ^!ClearVariable %testarray%

              :Loop
              ;get place for this line
              ^!Set %GrabField1%=^$GetField(^$GetRow$;1)$
              ^!Set %Place%=^$GetSelection$
              ;get team for this line
              ^!Set %GrabField2%=^$GetField(^$GetRow$;2)$
              ;be sure that this line is for current team
              ;if not, go to ProcessTeam
              ;otherwise continue here
              ^!If "^%Team%" <> "^$GetSelection$" ProcessTeam
              ;use Hugo's ideas to get places and pad with zeros
              ^!Set %Field%=^$GetField(^$GetRow$;1)$
              ^!If ^$StrSize("^%Field%")$=1 ^!Set %Field%=00^%Field%
              ^!If ^$StrSize("^%Field%")$=2 ^!Set %Field%=0^%Field%
              ; THESE LINES WERE NECESSARY BECAUSE SORTING ---------
              ; --------64 AND 203 PUTS 204 ON TOP -----------------
              ;use Hugo's ideas to set the place variable
              ^!Append %FirstFields%="^%Field%"^%NL%
              ^!Jump +1
              ^!GoTo Loop

              :ProcessTeam
              ^!Set %Fields%=^$StrSort("^%FirstFields%";False;True;False)$
              ^!SetArray %Fields%=^$StrReplace("^P";";";"^%Fields%";0;0)$
              ^!Set %LowestFive%=^%Fields1%+^%Fields2%+^%Fields3%+^%Fields4%+^%Fields5%
              ^!Set %Result%=^$Calc(^%LowestFive%)$
              ^!Jump LINE_START
              ^!InsertText ^%Team%: ^%LowestFive%=^%Result%^P^%Team%|^%Result%^P
              ^!ClearVariables
              ^!Continue continue?

              ^!GoTo NewTeam
            • hugo_paulissen
              ... Don, If you re asking for feedback, I cannot give any; your clip doesn t work (Fields are not filled, so I end up with several plusses and error in
              Message 6 of 12 , Nov 5, 2003
              • 0 Attachment
                --- In ntb-clips@yahoogroups.com, Don Passenger <dpasseng@i...> wrote:
                > Here is what I wound up with.

                Don,

                If you're asking for feedback, I cannot give any; your clip doesn't
                work (Fields are not filled, so I end up with several plusses and
                error in expression...)

                Hugo
              • Don Passenger
                Feedback would be good. The clip worked for me with the one exception of groups where the highest data element was used because somehow I added extra s to
                Message 7 of 12 , Nov 5, 2003
                • 0 Attachment
                  Feedback would be good.
                  The clip worked for me with the one exception of groups where the
                  highest data element was used because somehow I added extra "'s to the
                  last element in my array. I think I maybe changed my data element order
                  from the prior example without realizing it.

                  Here is some data:

                  312|Albion| 445|Soltis Mike|17:14.15|05:20.65|10:59.90|16:39.25
                  318|Albion| 453|Tom Jurasek|17:14.95|05:12.80|10:54.60|16:44.00
                  344|Albion| 495|Chris Jurasek|17:23.60|05:21.45|11:06.45|16:49.40
                  509|Albion| 704|Aaron Parson|18:02.05|05:28.50|11:28.70|17:33.15
                  519|Albion| 716|Zakk Havens|18:05.65|05:22.50|11:26.50|17:29.95
                  601|Albion| 811|Christoff Russell|18:35.20|05:37.60|11:48.50|18:02.00
                  710|Albion| 931|Domonique Craig|19:49.15|05:55.30|12:31.80|19:09.60
                  140|Allendale| 195|Alex Hanes|16:34.45|05:23.50|10:50.65|16:08.15
                  172|Allendale| 255|Rob Klingeman|16:45.05|05:22.15|10:51.10|16:13.30
                  329|Allendale| 474|Jacob Betts|17:18.45|05:26.60|11:08.20|16:47.05
                  375|Allendale| 538|Clinton VanderMolen|17:30.30|05:26.05|11:09.75|16:57.25
                  469|Allendale| 654|Alex MacDonaold|17:51.00|05:37.90|11:34.95|17:20.70

                  Notice what it does with the one with only 5 entries (here Allendale).
                  Problem with the last element in the array.
                  I get this:
                  Allendale: 140+172+329+375+"469";=[error in expression]
                • Alan C.
                  ... ; ============here============================== ; (tagged thusly below) try either append line, watch difference ;
                  Message 8 of 12 , Nov 5, 2003
                  • 0 Attachment
                    On Wed, 05 Nov 2003 20:07:52 -0500, Don Passenger wrote:
                    >�Feedback would be good.
                    >�The clip worked for me with the one exception of groups where the
                    >�highest data element was used because somehow I added extra "'s to the
                    >�last element in my array.

                    ; ============here==============================
                    ; (tagged thusly below) try either append line, watch difference
                    ; ============here==============================

                    (the pair of quotes in the one append line)

                    +, cleaned out some unneeded set stuff that wasn't used after it was set
                    maybe you can un comment the screen update line again if you want.
                    --

                    ^!Jump TEXT_START
                    ;Clear all Variables
                    ^!ClearVariables
                    ^!Set %Delimiter%=|
                    ^!Set %Delimiter%=^$StrReplace("|";"^%Vbar%";"^%Delimiter%";0;0)$
                    ^!SetDelimiter ^%Delimiter%

                    ;make sure there is something there
                    ^!IfTrue ^$IsEmpty(^$GetField(^$GetRow$;1)$)$ Oops
                    ^!SetHintInfo Getting field...
                    ; ^!SetScreenUpdate Off

                    :NewTeam
                    ;first time set team
                    ^!Set %GrabField2%=^$GetField(^$GetRow$;2)$
                    ^!Set %Team%=^$GetSelection$

                    :Loop
                    ;get place for this line
                    ^!Set %GrabField1%=^$GetField(^$GetRow$;1)$
                    ^!Set %Place%=^$GetSelection$
                    ;get team for this line
                    ^!Set %GrabField2%=^$GetField(^$GetRow$;2)$
                    ;be sure that this line is for current team
                    ;if not, go to ProcessTeam
                    ;otherwise continue here
                    ^!If "^%Team%" <> "^$GetSelection$" ProcessTeam
                    ;use Hugo's ideas to get places and pad with zeros
                    ^!Set %Field%=^$GetField(^$GetRow$;1)$
                    ^!If ^$StrSize("^%Field%")$=1 ^!Set %Field%=00^%Field%
                    ^!If ^$StrSize("^%Field%")$=2 ^!Set %Field%=0^%Field%
                    ; THESE LINES WERE NECESSARY BECAUSE SORTING ---------
                    ; --------64 AND 203 PUTS 204 ON TOP -----------------
                    ;use Hugo's ideas to set the place variable


                    ; ============here==============================
                    ; ^!Append %FirstFields%="^%Field%"^%NL%
                    ^!Append %FirstFields%=^%Field%^%NL%
                    ^!Info ^%FirstFields%
                    ; ============here==============================


                    ^!Jump +1
                    ^!GoTo Loop

                    :ProcessTeam
                    ^!Set %Fields%=^$StrSort("^%FirstFields%";False;True;False)$
                    ^!SetArray %Fields%=^$StrReplace("^P";";";"^%Fields%";0;0)$
                    ^!Set %LowestFive%=^%Fields1%+^%Fields2%+^%Fields3%+^%Fields4%+^%Fields5%
                    ^!Set %Result%=^$Calc(^%LowestFive%)$
                    ^!Jump LINE_START
                    ^!InsertText ^%Team%: ^%LowestFive%=^%Result%^P^%Team%|^%Result%^P
                    ; ^!ClearVariables
                    ^!ClearVariable %FirstFields%
                    ^!Continue continue?

                    ^!GoTo NewTeam
                    ; ----<end

                    --
                    Alan.
                  • hugo_paulissen
                    Don, Alan, It has to do with the quotes... The last item of array ^%Fields% is incorrect. 312 ; 318 ; 344 ; 509 ; 519 ; 601 ; 710 ;
                    Message 9 of 12 , Nov 6, 2003
                    • 0 Attachment
                      Don, Alan,

                      It has to do with the quotes...

                      The last item of array ^%Fields% is incorrect.

                      "312";"318";"344";"509";"519";"601";""710";"
                      "140";"172";"329";"375";""469";"

                      If this happens with value 6 or 7 you will not notice this, since
                      these values are disregarded when you do the addition. Obviously
                      this will lead to the error reported if there are only five
                      rows/values.

                      ^!Append %FirstFields%="^%Field%"^%NL% adds a new line to the
                      last element of an array, and that's where the problem starts,
                      because the replace expression

                      ^!SetArray %Fields%=^$StrReplace("^P";";";"^%Fields%";0;0)$

                      puts a semicolon at the end of the line. Apparently the array
                      expects something new after this and (thus?) puts a quote around the
                      last real element. If you were to do the same replace operation with
                      the regular replace-box you would have this

                      "312";"318";"344";"509";"519";"601";"710";

                      which differs from the line at the top...

                      My option would be to delete the last semicolon before continuing.

                      If you add the following line

                      ^!Set %Fields%="^$strTrim(^%Fields%)$"

                      (quotes were needed) you strip off all the extra's. At the end you'll
                      find the new code for that part of your clip.

                      As Alan already mentioned there are some variables that you don't
                      use anymore (CurCur for instance) and there should be a nice way
                      to terminate the operation of the clip automatically (I used
                      getlinecount in the original version, but if there are empty lines
                      at the end there should happen some additional checking...).

                      :ProcessTeam
                      ^!Set %Fields%=^$StrSort("^%FirstFields%";False;True;False)$
                      ; -------------- ADDED -------------- start
                      ; Some ^!Info shows you what's happening with the values
                      ;^!Info var Fields is:^%NL%^%Fields%
                      ^!Set %Fields%="^$strTrim(^%Fields%)$"
                      ;^!Info trimmed var Fields is:^%NL% ^%Fields%
                      ; -------------- ADDED -------------- end
                      ^!SetArray %Fields%=^$StrReplace("^P";";";"^%Fields%";0;0)$
                      ^!Set %LowestFive%=^%Fields1%+^%Fields2%+^%Fields3%+^%Fields4%+^%
                      Fields5%
                      ;END INFO
                      ^!Set %Result%=^$Calc(^%LowestFive%)$
                      ^!Jump LINE_START
                      ^!InsertText ^%Team%: ^%LowestFive%=^%Result%^P^%Team%|^%Result%^P
                      ^!ClearVariables
                      ^!Continue continue?

                      Regards,

                      Hugo
                    • Don Passenger
                      ^!Append %FirstFields%= ^%Field% ^%NL% changed to ^!Append %FirstFields%=^%Field%^%NL% which I think corrects the problem I was having
                      Message 10 of 12 , Nov 6, 2003
                      • 0 Attachment
                        ^!Append %FirstFields%="^%Field%"^%NL%
                        changed to
                        ^!Append %FirstFields%=^%Field%^%NL%
                        which I think corrects the problem I was having
                      • hugo_paulissen
                        ... Ha! I do not remember why I inserted the quotes in the first place, but it did have something to do with the x ; y -like structure of an array. If it
                        Message 11 of 12 , Nov 6, 2003
                        • 0 Attachment
                          > ^!Append %FirstFields%="^%Field%"^%NL%
                          > changed to
                          > ^!Append %FirstFields%=^%Field%^%NL%
                          > which I think corrects the problem I was having

                          Ha! I do not remember why I inserted the quotes in the first place,
                          but it did have something to do with the "x";"y"-like structure of an
                          array.

                          If it works...

                          Hugo
                        Your message has been successfully submitted and would be delivered to recipients shortly.