Re: Array Summary Sum Utility Method
Oh, David. Sorry - I didn't see you standing there... On Thu, Jun 22, 2017 at 3:27 PM, David Adams via 4D_Tech < 4d_tech@lists.4d.com> wrote: > > Adams banging the drum... > > You know that guy, the one on the bus that no one will sit next to? Just > saying. I'm given to enthusiasms. > > But seriously, I've used DataGrid off-and-on for years and it's proven to a > be a great help in a lot of situations. > ** > 4D Internet Users Group (4D iNUG) > FAQ: http://lists.4d.com/faqnug.html > Archive: http://lists.4d.com/archives.html > Options: http://lists.4d.com/mailman/options/4d_tech > Unsub: mailto:4d_tech-unsubscr...@lists.4d.com > ** > -- Kirk Brooks San Francisco, CA === *The only thing necessary for the triumph of evil is for good men to do nothing.* *- Edmund Burke* ** 4D Internet Users Group (4D iNUG) FAQ: http://lists.4d.com/faqnug.html Archive: http://lists.4d.com/archives.html Options: http://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **
Re: Array Summary Sum Utility Method
> Adams banging the drum... You know that guy, the one on the bus that no one will sit next to? Just saying. I'm given to enthusiasms. But seriously, I've used DataGrid off-and-on for years and it's proven to a be a great help in a lot of situations. ** 4D Internet Users Group (4D iNUG) FAQ: http://lists.4d.com/faqnug.html Archive: http://lists.4d.com/archives.html Options: http://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **
Re: Array Summary Sum Utility Method
Sannyasin, Ok - between your suggestion and Adams banging the drum I'm going to DL DataGrid and give it whirl - probably this weekend. Just from the website it does look pretty cool. On Thu, Jun 22, 2017 at 11:40 AM, Sannyasin Siddhanathaswami via 4D_Tech < 4d_tech@lists.4d.com> wrote: > Aloha Kirk! > > This is an awesome tip that I will use! In this case, I’m currently using > objects/json to output reports and lists to DataTables (www.datatables.net). > I’m really impressed with DataTables. I’m getting into using objects more > and more, and love them. > > Sannyasin Siddhanathaswami > > On Jun 20, 2017, 4:33 PM -1000, Kirk Brooks via 4D_Tech < > 4d_tech@lists.4d.com>, wrote: > 1) make an object array of each record. -- Kirk Brooks San Francisco, CA === *The only thing necessary for the triumph of evil is for good men to do nothing.* *- Edmund Burke* ** 4D Internet Users Group (4D iNUG) FAQ: http://lists.4d.com/faqnug.html Archive: http://lists.4d.com/archives.html Options: http://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **
Re: Array Summary Sum Utility Method
On Fri, Jun 23, 2017 at 4:40 AM, Sannyasin Siddhanathaswami via 4D_Tech < 4d_tech@lists.4d.com> wrote: > > This is an awesome tip that I will use! In this case, I’m currently using > objects/json to output reports and lists to DataTables (www.datatables.net). > I’m really impressed with DataTables. DataTables, so good. They're my go-to JavaScript grid. It's got a couple of impressive features, one of which is how easy it can be to use. With DataTables, you get an interactive grid with column sorting, searching, paging, and so on. But the thing is, you can start from a static HTML table and DataGrid can convert it on the fly. That's the basic, no setup approach. Static table + Magic = Dynamic grid. Pointlessly long post below... Short version: Dynamic static Web systems are a too-often overlooked strategy DataGrids = Good There are 3 zillion+ ways to do anything on the Web, but one of my go-to strategies has always been to produce rendered sites. Meaning, a complete site with links, etc. that is generated and can then stand alone. There are a remarkable number of times this is as good as or better than a live site with interactive server calls: * When you want to work with historical data. It's never going to change, why not pre-render it? * When you want to deploy a site behind an existing SSO login scheme. So, people have access to servers in a particular domain but you're not set up or allowed to run a dynamic host. (Long story.) Push out a site, drag the files over to an Apache directory and you're done. * When you don't have a reliable network connection. I could say a ton about this...a lot of my thinking comes from my personal programming history. I spent a lot of time 30 years ago in HyperCard, and I loved it. HyperCard got a lot of things right (the event propagation and control model was great, string processing was great) and some things wrong (I just so much hate 'natural language' programming languages. Too cute by half.) But what it was pure genius for was how beautifully it created interactive information spaces. Self-contained, rich spaces...like three-dimensional encyclopedias or something. There was nothing like it at the time outside of academia. (Ted Nelson was in the press talking about Xanadu around then and Jakob Nielson had already published HyperText and HyperMedia.) Apple had a set of design guidelines (I think I still have a xerox of the book) that were outstanding. HyperCard was a wonderful foundational experience for thinking about structured information spaces. Since there wasn't an Internet at the time and company networks were expensive...heck...even a computer was expensivethere was no notion of relying on a server. That probably shaped my style forever. And, given my location and interests, the idea of a ubiquitous, high-quality network connection always sounds like science fiction to me. It's a whole lot easier to fall of the grid than a lot of people realize. So, I like stand-alone systems that can be carried around. Anyway, I was deep, deep, deep into an ambitious blue sky project for internal use at 4D US (ACI US) when .com addresses were first made available. The beta for what was later called NetLink landed on my desk. And it spoke. Forrest Swilling and I spent a few months creating a 4D database where different departments could put in content (no markup), and we could push a button to spit out a fully rendered site with 100% accurate links, comprehensive index pages (remember those?) Since images were such a strain on the network (!), browsers had an option to turn off image display. So we figured, hey, why not render two versions? A bit of work, same button...now you could flip between the text-only and "multimedia" (cough-cough) version instantly. And the content was always 100% accurate. Nice project. Anyway, with that background, the idea of interactive, static sites appeals to me a whole lot. I find that many people never think of it because the Web has always been Browser+Network+Server. Nothing wrong with that, but it's also good to have the idea of a rich site *without* a server in mind. 4D is *fantastic* for this. Even when I spent nearly all of my time in other tools, I often still use 4D for that sort of work. 4D's Web server is fine too, I'm not arguing against it. There are plenty of situations where you need a live connection and anything else is a non-starter, no question. With that in mind, don't forget about Graham Langley's Lightning component: http://www.grahamlangley.co.uk/about.html Anyway, back to DataGrid. So, it can make static sites richly interactive. Include pre-rendered JSON files (for example) with data and you get fancy grids with searches. If *feels* like a live site, but it could be on a phone inside of a Faraday cage. Or you could to a live site, no problem there either. WIth DataGrid, you can go anywhere from simple HTML up through complex API callbacks and it will work. It's massively customizable and has a
Re: Array Summary Sum Utility Method
Aloha Nigel! Very interesting. I really haven’t used 2D arrays, I guess in part because I didn’t see a use. Summing a row of a 2D array is very slick. Thank you so much. I ended up just using sets and looping through each unique ID to build the summary array. Sannyasin Siddhanathaswami On Jun 21, 2017, 2:50 AM -1000, wrote: Surely here you could be utilizing 2D arrays? ** 4D Internet Users Group (4D iNUG) FAQ: http://lists.4d.com/faqnug.html Archive: http://lists.4d.com/archives.html Options: http://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **
Re: Array Summary Sum Utility Method
Aloha Kirk! This is an awesome tip that I will use! In this case, I’m currently using objects/json to output reports and lists to DataTables (www.datatables.net). I’m really impressed with DataTables. I’m getting into using objects more and more, and love them. Sannyasin Siddhanathaswami On Jun 20, 2017, 4:33 PM -1000, Kirk Brooks via 4D_Tech <4d_tech@lists.4d.com>, wrote: 1) make an object array of each record. ** 4D Internet Users Group (4D iNUG) FAQ: http://lists.4d.com/faqnug.html Archive: http://lists.4d.com/archives.html Options: http://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **
Re: Array Summary Sum Utility Method
> On Jun 21, 2017, at 2:59 AM, Nigel Greenlee via 4D_Tech > <4d_tech@lists.4d.com> wrote: > > You don’t say if you are displaying these arrays on screen-obviously the 2D > arrays can’t be displayed on screen. Each array of a 2D array can be a column in a listbox. John DeSoi, Ph.D. ** 4D Internet Users Group (4D iNUG) FAQ: http://lists.4d.com/faqnug.html Archive: http://lists.4d.com/archives.html Options: http://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **
Re: Array Summary Sum Utility Method
Sannyassin Surely here you could be utilizing 2D arrays? e.g Array (aInvoices)-1D array (aInvoiceItems)-1D array (ainvoiceValue)-1D Array (ainvoiceItemNumbers)-2D)-on row per invoice one column per item array (ainvoiceitemDescription)-2D Ditto Array(aInvoiceItemQuantitySold)-2D Ditto Array(aItemSoldAmount-2D You don’t say if you are displaying these arrays on screen-obviously the 2D arrays can’t be displayed on screen. With the above representation in a listbox on screen the ‘summarisation’ column could be a formula based column eg. Sum(aItemSoldAmount{rownumber}. You can insert the ‘summary’ column in dynamically. The following brief(unrelated) example shows how to insert a formula based column in a listbox $Formula:=“LB_SUMMARISE(->”+aItemSoldAmount+”)”) LISTBOX INSERT COLUMN FORMULA($area->;$ColumnNumber;$ColumnName;$Formula;$Type;$HeaderName;$ptr3->) There are a couple of limitations of formula based listbox columns though-cant have a footer and cant sort on them. > On 20 Jun 2017, at 23:25, Sannyasin Siddhanathaswami via 4D_Tech > <4d_tech@lists.4d.com> wrote: > > Aloha, > > Does anyone have a utility method for summarizing (and summing) a set of > arrays? > > For example with Invoice Line Items: > > Arrays: > aItemNumbers > aItemDescription > aQuantitySold > aExtendedSoldAmount > > Of course, with invoice line items there are multiple records with item > numbers. I want a summary array where there is only 1 element with an item > number, and the aQuantitySold, and aExtendedSoldAmount gets summed. > > I know there’s lots of ways to do this, but didn’t want to reinvent the wheel > if possible. > > Thanks! > > Sannyasin Siddhanathaswami > ** > 4D Internet Users Group (4D iNUG) > FAQ: http://lists.4d.com/faqnug.html > Archive: http://lists.4d.com/archives.html > Options: http://lists.4d.com/mailman/options/4d_tech > Unsub: mailto:4d_tech-unsubscr...@lists.4d.com > ** ** 4D Internet Users Group (4D iNUG) FAQ: http://lists.4d.com/faqnug.html Archive: http://lists.4d.com/archives.html Options: http://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **
Re: Array Summary Sum Utility Method
Sannyasin, The simple answer to the situation you describe is to loop through the records and build the arrays. I seem to recall you're working with v15+, so with that in mind here's how I'm handling these sorts of situations these days. 1) make an object array of each record. Depending on your structure you may just put each record into the array (think SELECTION TO JSON) or you may want to loop through the selection and pull the relevant bits from the invoice line arrays as well as any linked tables. The idea is to get all the data you may need to perform calculations in the object. In your example, if I understand it correctly, a give item may have more than one sales record of some sort associated with it. Using my scheme you could include the list of those items as arrays in the JSON object. 2) Populate your listbox. I tend to put these object arrays as the first column and hide it (you can't display an object column without using 4D Write and in this case you probably don't want to). The remainder of the list box a) can use all dynamic vars for the columns and b) can easily be inserted from user prefs. Or you can put them in yourself. The point is you can load each row from the data in the object array. Why is this helpful? For one thing you've got all the data you need encapsulated in the listbox. That's pretty cool. You may need to have a bunch of fields, some from different tables, in the data object and only need to have arrays for the data you actually need to display. Calculations are easy to write, debug and fast because they are all working on a c-obj in memory. Finally, it's quick and easy to look through the data array to create whatever sums and other totals you need. If you need to do something like make the listbox hierarchical you can opt to make the data col the last col. This just makes managing the user prefs a little more complicated but really not too much. In previous incarnations I've gone from included output forms (long time ago) and having the use Subtotal to array based listboxes with dozens of columns when only 5 or 6 would be displayed and this is by far the most effective approach I've found. And a big upside for me is this is a way to cache all the changes to the invoice in memory so the user could decide to cancel. Since all the data is being calculated and written to the c-obj for each row you can wait until the user gives it the OkeyDokey before writing to disk. This is an attractive option to starting a transaction, for example, when the record is opened. I don't do that sort of thing because it can cascade through the system as you touch more and more records plus it's a problem is someone gets halfway through an entry and goes to lunch. Hope this helps. On Tue, Jun 20, 2017 at 2:25 PM, Sannyasin Siddhanathaswami via 4D_Tech < 4d_tech@lists.4d.com> wrote: > Aloha, > > Does anyone have a utility method for summarizing (and summing) a set of > arrays? > > For example with Invoice Line Items: > > Arrays: > aItemNumbers > aItemDescription > aQuantitySold > aExtendedSoldAmount > > Of course, with invoice line items there are multiple records with item > numbers. I want a summary array where there is only 1 element with an item > number, and the aQuantitySold, and aExtendedSoldAmount gets summed. > > I know there’s lots of ways to do this, but didn’t want to reinvent the > wheel if possible. > > Thanks! > > Sannyasin Siddhanathaswami > ** > 4D Internet Users Group (4D iNUG) > FAQ: http://lists.4d.com/faqnug.html > Archive: http://lists.4d.com/archives.html > Options: http://lists.4d.com/mailman/options/4d_tech > Unsub: mailto:4d_tech-unsubscr...@lists.4d.com > ** -- Kirk Brooks San Francisco, CA === *The only thing necessary for the triumph of evil is for good men to do nothing.* *- Edmund Burke* ** 4D Internet Users Group (4D iNUG) FAQ: http://lists.4d.com/faqnug.html Archive: http://lists.4d.com/archives.html Options: http://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **
Array Summary Sum Utility Method
Aloha, Does anyone have a utility method for summarizing (and summing) a set of arrays? For example with Invoice Line Items: Arrays: aItemNumbers aItemDescription aQuantitySold aExtendedSoldAmount Of course, with invoice line items there are multiple records with item numbers. I want a summary array where there is only 1 element with an item number, and the aQuantitySold, and aExtendedSoldAmount gets summed. I know there’s lots of ways to do this, but didn’t want to reinvent the wheel if possible. Thanks! Sannyasin Siddhanathaswami ** 4D Internet Users Group (4D iNUG) FAQ: http://lists.4d.com/faqnug.html Archive: http://lists.4d.com/archives.html Options: http://lists.4d.com/mailman/options/4d_tech Unsub: mailto:4d_tech-unsubscr...@lists.4d.com **