OK I've attached a screen shot of the current report and my code. Here is what I need to do, and fucked if I know if I can do it.
In the screen shot you can see that everything in the description field is Red Oak except one (which is White Oak). This can change to anything.
For example we could have a batch of Cherry and then one Hard Maple in the batch.
So what I need to somehow do is get a majority of the type of wood it is and ignore the minority. Pretty complicated....
<!--- Count how many of each wood type is used... ---> <cfset WoodTypes = [] /> <cfloop query="batch_report3"> <cfset WoodName = extractWoodName(Description) /> <cfif StructKeyExists(WoodTypes,WoodName)> <cfset WoodTypes[WoodName]++ /> <cfelse> <cfset WoodTypes[WoodName] = 0 /> </cfif> </cfloop> <!--- Work out what the most common wood type is... ---> <cfset MaxCount = 0 /> <cfset MaxType = "" /> <cfloop item="CurType" collection=#WoodTypes#> <cfif WoodTypes[CurType] GT MaxCount > <cfset MaxCount = WoodTypes[CurType] /> <cfset MaxType = CurType /> </cfif> </cfloop> <cfoutput> <p>Most common wood type is "<b>#MaxType#</b>".</p> </cfoutput> <!--- Extract the name from the description. (May need changing/expanding depending on other description formats.) ---> <cffunction name="extractWoodName" returntype="string" output="false" > <cfargument name="Text" type="string" required /> <cfset var Name = rereplace(Arguments.Text,'^\d/\d x RW','') /> <cfset Name = rereplace(Arguments.Text,'(?:prime|\da?)? (?:common|boards|unselected|blocking) green') /> <cfreturn Trim(Name) /> </cffunction>
Yeah there is no doubt my code isn't nice.
I think I've found the easiest way. There is a product id table that seems to have the types in some kind of unique code. I'll take that approach.
Thanks man!
If you have a decent editor, spaces do allow configurable indenting. Plus they guarantee consistency of appearance, which is important when you're working with other people on a file and there is a mandated maximum line length.
(honestly though I don't care much - if I download some sample code that uses tab characters I just do :retab in Vim to convert them to spaces. Consistency is what's important)
Can't get it to work, but that's OK because I've confused myself to the point that I'm not sure what I'm trying to accomplish.
Fuck my head hurts!
error. but I'm stuck on trying to figure out how to approach this.
I have the needed info in the database. So I just need to compare or count and that's where I'm stuck atm.
<CFQUERY NAME="count" DATASOURCE="isiswood"> SELECT COUNT(*) AS WoodType FROM ProductionDetail WHERE rudID='041811BD' AND rudCategory='Produced' AND rudProductID LIKE '%RO%'; </cfquery>
<CFQUERY NAME="count" DATASOURCE="isiswood"> SELECT rudID AS WoodType, COUNT(*) AS WoodCount FROM ProductionDetail WHERE rudCategory='Produced' AND rudProductID LIKE '%RO%' GROUP BY rudID </cfquery>
SELECT SUBSTRING(rudProductID,6,2) AS WoodType, COUNT(*) AS WoodCount FROM ProductionDetail WHERE rudCategory='Produced' GROUP BY SUBSTRING(rudProductID,6,2)