Click here to Skip to main content
15,914,066 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
GeneralRe: Could there be a base class for customers, employees and suppliers? Pin
R. Giskard Reventlov14-Nov-11 1:51
R. Giskard Reventlov14-Nov-11 1:51 
GeneralRe: Could there be a base class for customers, employees and suppliers? Pin
RobCroll14-Nov-11 10:10
RobCroll14-Nov-11 10:10 
GeneralRe: Could there be a base class for customers, employees and suppliers? Pin
Nagy Vilmos14-Nov-11 11:43
professionalNagy Vilmos14-Nov-11 11:43 
GeneralRe: Could there be a base class for customers, employees and suppliers? Pin
nstk14-Nov-11 22:11
nstk14-Nov-11 22:11 
GeneralRe: Could there be a base class for customers, employees and suppliers? Pin
Nagy Vilmos14-Nov-11 22:36
professionalNagy Vilmos14-Nov-11 22:36 
GeneralRe: Could there be a base class for customers, employees and suppliers? Pin
RobCroll15-Nov-11 16:56
RobCroll15-Nov-11 16:56 
QuestionDesign decision in a larger class hierarchy Pin
CDP180221-Oct-11 3:10
CDP180221-Oct-11 3:10 
QuestionSliding Scale Solution Pin
kmoorevs17-Oct-11 11:11
kmoorevs17-Oct-11 11:11 
This solution to a real world problem just seems too easy to be foolproof, so I thought I would see if anyone can show a problem with it. Say I have the same item in two sizes, one cost $2.00, and the other $2.25. The summary tables used for reporting have only fields for the total quantity sold: 137, and the total cost: $286.50. The customer would like a monthly report/export showing quantity by price. The first approach was pulling the inforation directly from the transaction tables which contain millions of records. Though this approach provided the seperation, the performance hit made me search for a better solution. It made sense to me that only one correct combination of (x * 2.00) + (y * 2.25) could equal 286.50. So, how to get the correct combination? Examples in vbscript for simplicity/proof of concept.
VB
totalQuantity = 137
wantedResult = 286.5
premiumPrice = 2.25
standardPrice = 2.00
'x is always the higher priced quantity
for x = totalQuantity to 0 step -1
    y = totalQuantity - x
    if (x * premiumPrice) + (y * standardPrice) = wantedResult then exit for
next
'x and y should now be the correct values

This approach, even it the raw form, is much, much quicker than querying the transaction tables. The following revision finds the correct answer in 6 iterations. When I tested it for an extreme case of 1 million total (999,999 of standard price and 1 premium) it found the answer in 25 guesses.
VB
totalQuantity = 137
wantedResult = 286.5
premiumPrice = 2.25
standardPrice = 2.00
success = 1
'recursive halving for speed
currentSplit = Int(totalQuantity / 2)
a = currentSplit 
b = totalQuantity - a
counter = 0
currentresult = (a * premiumPrice) + (b * standardPrice)
counter = counter + 1
Do While currentresult <> wantedResult
    if currentSplit > 1 then
        currentSplit = Int(currentSplit / 2)
    end if
    if counter > totalQuantity then
        'safety net
        msgbox "result not found"
	success = -1
        exit do
    end if
    If currentresult < wantedResult Then
        a = a + currentSplit 
    Else
        a = a - currentSplit 
    End If
    counter = counter + 1
    b = totalQuantity - a
    currentresult = (a * premiumPrice) + (b * standardPrice)
Loop
if success = 1 then
	MsgBox a & " at " & premiumPrice & " and " & b & " at " & standardPrice & " in " & counter & " guesses"
end if

The point is, this function may keep me (or the customer) from having to ask the database vendor for a change to their summary tables. I am not asking for code testing, only opinions on the soundness of the concept. As far as I know, there will only ever be two price points for this single item and the highest total quantity would likely be around 5000 for a reporting range.
"Go forth into the source" - Neal Morse

AnswerRe: Sliding Scale Solution Pin
Paul Conrad17-Oct-11 11:38
professionalPaul Conrad17-Oct-11 11:38 
GeneralRe: Sliding Scale Solution Pin
kmoorevs18-Oct-11 4:21
kmoorevs18-Oct-11 4:21 
GeneralRe: Sliding Scale Solution Pin
Paul Conrad18-Oct-11 5:24
professionalPaul Conrad18-Oct-11 5:24 
GeneralRe: Sliding Scale Solution Pin
Bert Mitton18-Oct-11 7:43
professionalBert Mitton18-Oct-11 7:43 
GeneralRe: Sliding Scale Solution Pin
Paul Conrad18-Oct-11 14:31
professionalPaul Conrad18-Oct-11 14:31 
AnswerRe: Sliding Scale Solution Pin
jschell19-Oct-11 9:16
jschell19-Oct-11 9:16 
GeneralRe: Sliding Scale Solution Pin
Luc Pattyn19-Oct-11 12:38
sitebuilderLuc Pattyn19-Oct-11 12:38 
GeneralRe: Sliding Scale Solution Pin
kmoorevs19-Oct-11 13:51
kmoorevs19-Oct-11 13:51 
AnswerRe: Sliding Scale Solution Pin
Luc Pattyn19-Oct-11 14:26
sitebuilderLuc Pattyn19-Oct-11 14:26 
GeneralRe: Sliding Scale Solution Pin
kmoorevs20-Oct-11 6:48
kmoorevs20-Oct-11 6:48 
GeneralRe: Sliding Scale Solution Pin
Luc Pattyn20-Oct-11 7:01
sitebuilderLuc Pattyn20-Oct-11 7:01 
QuestionBest place to encrypt passwords Pin
Reiss7-Oct-11 0:51
professionalReiss7-Oct-11 0:51 
AnswerRe: Best place to encrypt passwords PinPopular
Wayne Gaylard7-Oct-11 1:58
professionalWayne Gaylard7-Oct-11 1:58 
GeneralRe: Best place to encrypt passwords Pin
CDP180221-Oct-11 3:37
CDP180221-Oct-11 3:37 
GeneralRe: Best place to encrypt passwords Pin
Wayne Gaylard21-Oct-11 4:16
professionalWayne Gaylard21-Oct-11 4:16 
GeneralRe: Best place to encrypt passwords Pin
CDP180221-Oct-11 4:32
CDP180221-Oct-11 4:32 
GeneralRe: Best place to encrypt passwords Pin
Wayne Gaylard21-Oct-11 4:40
professionalWayne Gaylard21-Oct-11 4:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.