Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Math Calculation Help... Working with stripping Minutes 3

Status
Not open for further replies.

txgeekgirl1

Programmer
Sep 10, 2009
85
US
I have the NewDuratn rounding and calculating correctly. Here is the issue. My first 2 values are 1.00 and 2.00 - I need to further that and calculate minutes back into minutes.... example - I have a 1.94 which is like 110 min. I have to divide .94/60 and add it back on. In VFP 6 I don't have a lot of the newer options. I have tried string conversion then manipulating but with my first two values it's rounding something awful.

Code:
SELECT CONNECTOR, ;
	CliID, ;
	Duratn, ;
	ROUND(Duratn/60,2) AS NewDuratn ;
	FROM MyTimes_ ;	
	ORDER BY Connector ;
	INTO CURSOR Dura2_

This calculation is the middle piece I need. for the last piece below.

Code:
IIF(sv.SvcCode = "3104",VAL(RIGHT(Duratn,2)),IIF(VAL(RIGHT(Duratn, 2)) < 8.00, 0.00, IIF(VAL(RIGHT(Duratn, 2)) < 23.00, 0.25, ;
				IIF(VAL(RIGHT(Duratn, 2)) < 38.00, 0.50, IIF(VAL(RIGHT(Duratn, 2)) < 53.00, 0.75, 1.00))))) as dMin, ;
 
[&nbsp;]
I need to further that and calculate minutes back into minutes

I am totally confused here. If they are already minutes, why do you need to calculate them back into minutes?

I have a 1.94 which is like 110 min. I have to divide .94/60 and add it back on.

More confusion for me here. If you have 1.94 and that means about 110 minutes, then where does the .94/60 enter into the picture? 1.94 times 60 equals 116.4 minutes (1.94 * 60 = 116.4). So, why the division?

On the surface this seems like an easy conversion, but until we know exactly what you are trying to accomplish, it is going to be hard to give you any ideas on how to do it.

How about an example or two? Like what are your desired starting and ending numbers? What are you getting that you don't want to get?

How do the two pieces of code above interact? The only connection I see is that one of the variables Duratn is the same, but neither piece of code calls nor interacts with the other.

Code:
IIF(sv.SvcCode = "3104",VAL(RIGHT(Duratn,2)),
	IIF(VAL(RIGHT(Duratn, 2)) < 8.00, 0.00, 
	IIF(VAL(RIGHT(Duratn, 2)) < 23.00, 0.25, 
	IIF(VAL(RIGHT(Duratn, 2)) < 38.00, 0.50, 
	IIF(VAL(RIGHT(Duratn, 2)) < 53.00, 0.75, 1.00))))) as dMin, ;

Why do you use VAL in the above code? Duratn is obviously a string. Why not speed things up by not doing extra calculations? For example:

Code:
IIF(sv.SvcCode = "3104",VAL(RIGHT(Duratn,2)),
	IIF (RIGHT(Duratn, 2) < "08", 0.00, 
	IIF (RIGHT(Duratn, 2) < "23", 0.25, 
	IIF (RIGHT(Duratn, 2) < "38", 0.50, 
	IIF (RIGHT(Duratn, 2) < "53", 0.75, 1.00))))) as dMin, ;

You might be able to simply this calculation further depending on how you are using it and what you need to accomplish with it.

mmerlinn


"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond

Poor people do not hire employees. If you soak the rich, who are you going to work for?
 
You would be confused because you totally jacked the calculation.

More confusion for me here. If you have 1.94 and that means about 110 minutes, then where does the .94/60 enter into the picture? 1.94 times 60 equals 116.4 minutes (1.94 * 60 = 116.4). So, why the division?

I will baby talk it for you. A patient sees a provider for 74 minutes. That has to be broke into hours and minutes. You divide the whole sucker by 60 the first time and get 1.23. That .23 is a FRACTION of time - NOT MINUTES. I still have to get that 23 into a minute form for the last piece of that calculation to work.

I have tried converting NewDuratn to a STR - but because my first two values are 120 and 60 which when divided by 60 equal 2.00 and 1.00, I get 1 and 2 and it sets all my values to single digit STRs.
 
Is this what you mean?

TRANSFORM(RIGHT(TTOC(CTOT('0')+1.23*3600,1),6),'@r 99:99:99')

Cetin Basoz
MS Foxpro MVP, MCP
 
Or this?

int( Duration ) && hours
int( Duration * 60 ) % 60 && minutes

Cetin Basoz
MS Foxpro MVP, MCP
 
This might work....

nMin = 74
? LTRIM(STR(INT(nMin/60))) + ':' + LTRIM(STR(MOD(nMin,60)))
 
"You would be confused because you totally jacked the calculation.
I will baby talk it for you."


There was no reason to get rude. That is sometimes enough, if someone were to Red Flag your posting, to get a forum user 'tossed' out.
Whether mmerlinn successfully answered your question or not, at least he tried.

When I read your original posting I too didn't have a clue as to what you were trying to do.

Your original post stated your problem in a way that significantly 'muddied the waters' through the lack of clearly stating your problem and with wrong numerical calculations (e.g. trying to get minutes with I have to divide .94/60 and add it back on. when you should have been multiplying), etc.

My own questions about what you were trying to do, based on how you worded your question, were very much in line with mmerlinn's. So he wasn't the only one confused.

You could have just as easily apologized for not being clear the first time and restated the problem.

Regardless, I am glad that, once you explained your problem more clearly - where it was EASY to see your REAL problem, others were able to provide you with the answers that should lead you towards resolving your issue.

We are here to help you when we can, but you need to do your part in helping us want to help you.

Good Luck,
JRB-Bldr
 
txgeekgirl1,
"You would be confused because you totally jacked the calculation.

I will baby talk it for you."

I too will give JRB-Bldr a star for being so polite rather than red flag your post.
But let me baby talk something for you: If you're going to come here asking people for free help, don't be an a$$ when they take the time to offer it.


-Dave Summers-
[cheers]
Even more Fox stuff at:
 
[&nbsp;]
Ok, I think I understand the problem now. How about changing your last code to the following?

Code:
IIF(sv.SvcCode = "3104", VAL(Duratn % 60), ;
	IIF ((VAL(Duratn % 60) + 7)/15 < 4, .25 * INT((VAL(Duratn % 60) + 7)/15), ;
		1.00)) as dMin, ;

NOT TESTED.

This eliminates three levels of IIFs and simplifies the calculations. The main drawbacks are lack of readability and being hard to change if the requirements change.

Computers ONLY understand baby steps. If a programmer can't or won't think in baby steps, the programmer cannot reliably tell the computer what to do. Apology accepted.

KarenJB

Based on what I understand of the original requirements of the OP, you would need to pad the minutes for values less than 10.

mmerlinn


"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond

Poor people do not hire employees. If you soak the rich, who are you going to work for?
 
[&nbsp;]

Oops. Duratn is a string and I used it like a value. Try this instead.

Code:
IIF(sv.SvcCode = "3104", VAL(Duratn) % 60, ;
	IIF ((VAL(Duratn) % 60 + 7)/15 < 4, .25 * INT((VAL(Duratn) % 60 + 7)/15), ;
		1.00)) as dMin, ;

NOT TESTED.

mmerlinn


"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond

Poor people do not hire employees. If you soak the rich, who are you going to work for?
 
mmerlinn - I was taking your quote as something you were telling me - not something that autopops into your messages and it pissed me off. I was already late heading into a meeting that I found out at the last minute I was responsible for content when I was told it was a supervisors meeting and I was there for clarification of procedures.

The problem is still the same - I have another telling me to multiply NewDuratn *100 and strip off the value to work with... I am cranking Metallica and seeing what else I can break.

As for the time stacking to reach .25, .5, .75, 1.00 - that won't work because then they go into further calculations for Units.
 
[&nbsp;]

This can even be simplified a bit more:

Code:
IIF(sv.SvcCode = "3104", VAL(Duratn) % 60, ;
	IIF ((VAL(Duratn) % 60)/15 < 4, .25 * INT((VAL(Duratn) % 60 + 7)/15), ;
		1.00)) as dMin, ;

NOT TESTED.

mmerlinn


"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond

Poor people do not hire employees. If you soak the rich, who are you going to work for?
 
[&nbsp;]

I don't understand why it would not work, but then I don't know the whole problem.

All I did was take your IIF statement, which outputs dMin, and simplify the internal calculations using the same variable, Duratn, that you used without changing the output. Unless I misunderstood what the IIF statement is supposed to do, or I did not code correctly, my solution should work.

If that is not the actual calculation you are doing, then it will not work at all.

So, I guess the real question is, "Did you try it?" If you did, and it did not solve your problem, then you do indeed need to do it a different way.

mmerlinn


"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Raymond

Poor people do not hire employees. If you soak the rich, who are you going to work for?
 
mmerlinn - I have the whole rest of this thing working but stripping digits off NewDuratn in the last cursor. This program is way complicated... developed by someone who never noted jack. I have gone in and noted the program because I was constantly lost. The variables we start with come from a cursor with 35 entries where the time and units have to get added back into to be unioned with the next cursor.

I just want to strip off digits, man... like I can with time or a string. That's it. One would think it's been done before and the VFP library has something for working with numbers.... even if they are .00.

Code:
* Create cursor (connector, medrecno, duration) as catcher
* Append into cursor from GRPServ_
	CREATE CURSOR MyTimes_ (Connector n(8,0), CliID c(8), Duratn n(4,0))
		INDEX ON Connector TAG Connector
		
		SELECT GRPServ_
		SCAN
			INSERT INTO MyTimes_(Connector, CliID, Duratn) VALUES(GRPServ_.Connector, GRPServ_.medrecno, 0.00)
		SELECT GRPServ_
		ENDSCAN	
		

	
 	************************************************************************************************************************************
 	* Grab by connector (the glue for a group) the min StartTime and the Max EndTime. 												   *
 	************************************************************************************************************************************
 	SELECT connector, ;
 		MIN(StartTSM) AS FirstMin, ;
 		MAX(EndTSM) AS LastMin ;
 		FROM GRPServ_ ;
 		GROUP BY Connector ;
 		ORDER BY Connector ;
 		INTO CURSOR GetGRTimes_
		


	Local TimeArray(1500)

	* Run through each group
	SELECT GetGRTimes_
	SCAN
		* Flush the array (reset counters to 0)
		FOR I = 1 to 1500
			TimeArray(I) = 0
		Next I

		* Remember the start time for the overall group
		lnStMin = GetGRTimes_.FirstMin
		lnThisConnector = GetGRTimes_.Connector
		
		* Filter the total clients for groups down to just the ones for this group
		SELECT Connector AS CltConnector, ;
				medrecno, ;
				StartTSM, ;
				EndTSM ;
			FROM GRPServ_ ;
			WHERE GRPServ_.Connector = lnThisConnector ;
			INTO CURSOR CltSubSet_

		* Run through the clients in this group and increment the array for each minute
		* that the client was present.    I-lnStMin+1 gives the difference between the
		*									current client's minute to check and the 
		*       							start time of the group as an index to the 
		* 									array.
		SELECT CltSubSet_
		GOTO TOP
		SCAN
			FOR I = StartTSM TO EndTSM
				TimeArray(I - lnStMin + 1) = TimeArray(I - lnStMin + 1) + 1
			NEXT I
		ENDSCAN
		
		* Compute the client's share of each minute in the array
		SELECT CltSubSet_
		GOTO TOP
		SCAN
			lcMedRec = CltSubSet_.MedRecNo		
			myMin = 0.00
			FOR I = StartTSM TO EndTSM
				myMin = myMin + ROUND((1 * 1/TimeArray(I - lnStMin + 1)),2)
			NEXT I
			UPDATE MyTimes_ SET MyTimes_.Duratn = myMin ;
				WHERE MyTimes_.Connector = lnThisConnector AND MyTimes_.CliID = lcMedRec
			SELECT CltSubSet_
		ENDSCAN	

		SELECT GETGRTimes_
	ENDSCAN	

	*Divide min by 60 to get hour - min but then we need to round by billable rounding rules
		* 8-22 = .25
		* 23-37 = .5
		* 38-52 = .75
		* 53-67 = 1										
		SELECT CONNECTOR, ;
			CliID, ;
			Duratn, ;
			ROUND(Duratn/60,2) AS NewDuratn ;
			FROM MyTimes_ ;	
			ORDER BY Connector ;
			INTO CURSOR Dura2_
browse
 
I'm reading this and must agree you're not very helpful stating the problem in the first place.

From your posting of the comment

*Divide min by 60 to get hour - min but then we need to round by billable rounding rules
* 8-22 = .25
* 23-37 = .5
* 38-52 = .75
* 53-67 = 1

I see it this way:

You need to determine billable quarter hours and the rounding rule is meant to round to the nearest quarter, eg 8-22 minutes is 15-7 to 15+7.

You can actually do that by the round function in one shot, when using it to round to quarters and divide the result by 4: Round(Duratn/15)/4. That's all:

Code:
SELECT CONNECTOR, ;
            CliID, ;
            Duratn, ;
            ROUND(Duratn/15,0)/4 AS NewDuratn ;
            FROM MyTimes_ ;    
            ORDER BY Connector ;
            INTO CURSOR Dura2_

But nobody could see that from your description of the problem.

Bye, Olaf.
 
Thank you Olaf - That was step 2 that I needed to get the numbers into the rounding rules - but I still have NO true time. Accounting has to have both.

I wish I could upload a snapshot for you.... I have a list like 80,158,60,73,175,94 which are values divided by 60 to grab hours and min. I still need min. I still cannot strip off the right to let me manipulate and I still cannot STR it.

In every other program, we treat time like a STR - in this one program Time is a VAL.

My fault - if you looked at the code, I had to get start and stop values based on minutes since midnight. The passes grab a group that met and the clients who were there and for the time they were there.... divides the time per min by the number of attendees and then adds it all back together in minutes.
 
I am not sure if this what you are trying to do:

Code:
*Divide min by 60 to get hour - min but then we need
* to round by billable rounding rules
* 8-22 = .25
* 23-37 = .5
* 38-52 = .75
* 53-67 = 1
Create Cursor myTimes (timeID i Autoinc, tInHours Y, tInMinutes Y)
Insert Into myTimes (tInMinutes) Values (74)
Insert Into myTimes (tInMinutes) Values (110)
For ix = 60 To 120
  Insert Into myTimes (tInMinutes) Values (m.ix)
Endfor
UPDATE myTimes SET tInHours = tInMinutes / 60

Select ;
  timeID, ;
  tInMinutes as Duration1, ;
  CEILING((tInMinutes-7)/15)*0.25 as NewDuration1, ;
  tInHours, ;
  round(tInHours*60,0) as Duration2, ;
  CEILING((round(tInHours*60,0)-7)/15)*0.25 as NewDuration2 ;
  From MyTimes


Cetin Basoz
MS Foxpro MVP, MCP
 
What's so difficult ?

INT(Duratn/60) is hours
Duratn % 60 is minutes

Bye, Olaf.
 
My boss - the ObiWan of FoxPro - just got back from out of town - there is a little known function called the MOD function - He says archaic at best but definitely worth me not having a headache all day over this.

STR(INT(x/60)) + "." + RIGHT("00" + STR(MOD(x,60)),2)

I told him I actually went through the VFP Function dictionary and got through the I's looking for something.

He told me next time - wait for him and go work in VB - my happy place.

Thank you all for your suggestions. Olaf - thanks for the hyperspace jump to the end of the plan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top