Index  | Recent Threads  | Unanswered Threads  | Who's Active  | Guidelines  | Search
 

Quick Go »
No member browsing this thread
Thread Status: Active
Total posts in this thread: 17
Posts: 17   Pages: 2   [ 1 2 | Next Page ]
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 4131 times and has 16 replies Next Thread
jonnieb-uk
Ace Cruncher
England
Joined: Nov 30, 2011
Post Count: 6105
Status: Offline
Project Badges:
Reply to this Post  Reply with Quote 
Playing around with stats

I want to use some of the wealth of statistical data available on WGC to do some comparisons on runtimes etc (for my own interest).

Can one of the long established crunching Guru's help get me started by answering an Excel spreadsheet related question?

Runtime is reported in the format y:ddd:hh:mm:ss which is not a format recognised in Excel. So how do I handle the data? For example if I want to add

0:048:22:43:27 + 0:002:01:15:08 = 0:050:23:58:35

or subtract

0:050:23:58:35 - 0:002:01:15:08 = 0:048:22:43:27

what's the formulae?

I've managed to work it by breaking the data down into its component parts, converting to everything to seconds and then reassembling the result in the original format but it's longwinded and inelegant. I'm sure there's a better way!
----------------------------------------

To Join follow this link: Join the UK Team All Welcome! UK Team thread
----------------------------------------
[Edit 1 times, last edit by jonnieb-uk at Jan 10, 2012 1:36:13 AM]
[Jan 10, 2012 1:34:55 AM]   Link   Report threatening or abusive post: please login first  Go to top 
Sgt.Joe
Ace Cruncher
USA
Joined: Jul 4, 2006
Post Count: 7850
Status: Offline
Project Badges:
Reply to this Post  Reply with Quote 
Re: Playing around with stats

I had the same solution you did. It was a pain in the neck to set up, but got the job done.

Cheers
----------------------------------------
Sgt. Joe
*Minnesota Crunchers*
[Jan 10, 2012 2:28:58 AM]   Link   Report threatening or abusive post: please login first  Go to top 
deltavee
Ace Cruncher
Texas Hill Country
Joined: Nov 17, 2004
Post Count: 4894
Status: Offline
Project Badges:
Reply to this Post  Reply with Quote 
Re: Playing around with stats

In Excel sometimes longwinded is the only way. I do the same thing using the Excel "MID" function, but I am by no means an Excel expert. I don't know of a y:ddd:hh:mm:ss Excel date format.
[Jan 10, 2012 2:34:02 AM]   Link   Report threatening or abusive post: please login first  Go to top 
wplachy
Senior Cruncher
Joined: Sep 4, 2007
Post Count: 423
Status: Offline
Reply to this Post  Reply with Quote 
Re: Playing around with stats

I've been playing around with this for about 4 years and haven't come up with an elegant way either. Because of the "60" carry the only way is to deal with each "segment" (years, days, hours, minutes, seconds) individually. I also break each down to seconds.

For what it's worth following is the code I use to convert from "display: format (Y:DDD:HH:MM:SS) to seconds and back again. It also can deal with formats like 79h,22:41 (79 hours, 22 minutes and 41 seconds)

Don't know if it "looks" any better than yours but it works just fine.

To Use:
A1	0:048:22:43:27
A2	0:002:01:15:08

A4	FmtTime(A1)		4229007
A5	FmtTime(A2)		177308
A6	FmtTime(SUM(A4:A5))	0:050:23:58:35


Public Function FmtTime(vaRTVal As Variant, Optional stRTBase As String = "S", _
Optional stRTFmt As String = "0:000:00:00:00") As Variant

'/*-------------------------------------------------------------------------*/
'/* Function to Format Time */
'/* */
'/* Parms: */
'/* vaRTVal = Time T/B Formatted */
'/* String = Time in Display Format - Returns Time Value as Double */
'/* Number = Time as Number - Returns Formatted Time String */
'/* */
'/* stRTBase = Number of as Double */
'/* Y = Time in Years */
'/* D = Time in Days */
'/* H = Time in Hours */
'/* M = Time in Minutes */
'/* S = Time in Seconds */
'/* */
'/* stRTFmt = Formatted Time Format String */
'/* Value Returns */
'/* As Years 0:000:00:00:00 Same */
'/* As Days 000:00:00:00 000d,00:00:00 */
'/* As Hours 00:00:00 00h,00:00 */
'/* As Minutes: 00:00 00m,00 */
'/* As Seconds 00 00s */
'/* */
'/* Notes: */
'/* Access Module uses Global Format array */
'/* Loaded at first use by FmtTimeLd(). */
'/* Procedure FmtTimeClr() resets */
'/* */
'/* Bill Plachy 02/04/2011 */
'/*-------------------------------------------------------------------------*/

'/*---------------------------------------------------------------------*/
'/* Declare some Numeric Values - Not Required I just Like it That Way */
'/*---------------------------------------------------------------------*/
const inMOne as integer = -1
const inZero as integer = 0
const inOne as integer = 1
const inTwo as integer = 2
const inThree as integer = 3
const inFour as integer = 4

const coTimeSep as string = ":"
const coCommaC as string = ","
const coDashC as string = "-"

Dim dbTotSec As Double
Dim dbTimeSgn As Double

Dim tIx As Integer
Dim bIx As Integer
Dim CSIx As Integer

Dim dbFmtTimeCVA(inFour) As Double 'Format Time Conversion Values Array
Dim dbRInt As Double

Dim vaSplitFmt As Variant

Dim stFmtTime As String
Dim stSplitFmt() As String

'/*-----------------------------------------*/
'/* Declare Run Time Conversion Constants */
'/*-----------------------------------------*/
Const coYrIx As Integer = 0
Const coDayIx As Integer = 1
Const coHrIx As Integer = 2
Const coMinIx As Integer = 3
Const coSecIx As Integer = 4

Const coYrToSec As Double = 31536000
Const coDayToSec As Double = 86400
Const coHrToSec As Double = 3600
Const coMinToSec As Double = 60

'/*-----------------------------------------*/
'/* FmtTime() Conversion Base/Return Values */
'/*-----------------------------------------*/
Const coFTBaseYr As String = "Y" 'Base/Return Time in Years
Const coFTBaseDay As String = "D" 'Base/Return Time in Days
Const coFTBaseHr As String = "H" 'Base/Return Time in Hours
Const coFTBaseMin As String = "M" 'Base/Return Time in Minutes
Const coFTBaseSec As String = "S" 'Base/Return Time in Seconds

Const coBaseCtl As String = coFTBaseYr & coFTBaseDay & _
coFTBaseHr & coFTBaseMin & _
coFTBaseSec 'Base/Return Validation Values

bIx = InStr(1, coBaseCtl, Left(stRTBase, inOne), vbTextCompare) 'Validate Base Value
bIx = bIx - inOne 'Index less One

If bIx < inZero Then 'Invalid Base Value
FmtTime = Null 'Return Null Value
Else 'Base is Valid
dbFmtTimeCVA(inZero) = coYrToSec '/*-----------------------*/
dbFmtTimeCVA(inOne) = coDayToSec '/* */
dbFmtTimeCVA(inTwo) = coHrToSec '/* Load Conversion Array */
dbFmtTimeCVA(inThree) = coMinToSec '/* */
dbFmtTimeCVA(inFour) = CDbl(1) '/*-----------------------*/

'/*---------------------------------------------*/
'/* What to Return is Based on What is Passed */
'/*---------------------------------------------*/
Select Case VarType(vaRTVal) 'Determine Type of Value
Case vbInteger, vbLong, vbSingle, vbDouble, _
vbCurrency, vbDecimal, vbByte 'Run Time is Numeric - Return Formatted String
If vaRTVal = inZero Then 'Value is Zero
FmtTime = stRTFmt 'Return Zero String
Else 'Value GT Zero
stSplitFmt = Split(stRTFmt, coTimeSep, _
inMOne, vbTextCompare) 'Split Format String
stFmtTime = vbNullString 'Clear Formatted Return
dbTotSec = vaRTVal * dbFmtTimeCVA(bIx) 'Convert to Seconds
CSIx = UBound(dbFmtTimeCVA) - UBound(stSplitFmt) 'Conversion Offset

If vaRTVal < inZero Then 'Negative Value
dbTotSec = dbTotSec * inMOne 'Make Positive
End If

For tIx = CSIx To UBound(dbFmtTimeCVA) Step inOne 'Format all Sections
If dbTotSec >= dbFmtTimeCVA(tIx) Then 'Total Remaining => Conversion
dbRInt = Fix(dbTotSec / dbFmtTimeCVA(tIx)) 'Divide Total Remaining by Conversion
Else 'Total Remaining < Conversion
dbRInt = inZero 'Quotient Whole Number is Zero
End If

stFmtTime = stFmtTime & _
Format(dbRInt, stSplitFmt(tIx - CSIx)) 'Store Formatted Segment

If tIx = CSIx And CSIx > inZero Then 'First Segment & Returning Less Than Full
stFmtTime = stFmtTime & _
Mid(coBaseCtl, tIx + inOne, inOne) & _
coCommaC 'Append Interval
Else 'Not First or Full
stFmtTime = stFmtTime & coTimeSep 'Append Seperator
End If

dbTotSec = dbTotSec - (dbRInt * dbFmtTimeCVA(tIx)) 'Seconds Left
Next tIx

If vaRTVal < inZero Then 'Negative Value
FmtTime = coDashC & _
Left(stFmtTime, Len(stFmtTime) - 1) 'Append Minus Sign
Else 'Positive Value
FmtTime = Left(stFmtTime, Len(stFmtTime) - 1) 'Return Formatted Value
End If
End If

Case vbString 'Run Time is String - Return Numeric Value
dbTotSec = inZero 'Clear Total Seconds

If Left(vaRTVal, inOne) = coDashC Then 'If Negative Value
stFmtTime = Right(vaRTVal, Len(vaRTVal) - inOne) 'Make Positive
dbTimeSgn = inMOne 'Store Sign
Else 'Positive Value
stFmtTime = vaRTVal 'Use As Is
dbTimeSgn = inOne 'Store Sign
End If

stSplitFmt = Split( _
Replace(stFmtTime, coCommaC, coTimeSep, inOne, inMOne, vbTextCompare), _
coTimeSep, inMOne, vbTextCompare) 'Split Runtime

CSIx = UBound(dbFmtTimeCVA) - UBound(stSplitFmt) 'Conversion Offset

For tIx = 0 To UBound(stSplitFmt) Step 1 'Compute Each Segment
dbTotSec = dbTotSec + (Val(stSplitFmt(tIx)) * _
dbFmtTimeCVA(tIx + CSIx)) 'Total Seconds
Next tIx

FmtTime = CDbl(dbTotSec / dbFmtTimeCVA(bIx)) * dbTimeSgn 'Return in Requested Interval

Case Else 'Invalid Time Value
FmtTime = Null 'Return Null
End Select
End If

End Function

----------------------------------------
Bill P

[Jan 10, 2012 2:41:28 AM]   Link   Report threatening or abusive post: please login first  Go to top 
jonnieb-uk
Ace Cruncher
England
Joined: Nov 30, 2011
Post Count: 6105
Status: Offline
Project Badges:
Reply to this Post  Reply with Quote 
Re: Playing around with stats

Thanks for all the comments.

wplachy your code gives me something to explore and utilise. Part of the problem is that my knowledge of Excel is 15 years out of date due to a major career change. But "you're never too old to learn" so thanks.
----------------------------------------

To Join follow this link: Join the UK Team All Welcome! UK Team thread
[Jan 10, 2012 9:13:13 AM]   Link   Report threatening or abusive post: please login first  Go to top 
Former Member
Cruncher
Joined: May 22, 2018
Post Count: 0
Status: Offline
Reply to this Post  Reply with Quote 
Re: Playing around with stats

Of great help for all of us I think , so many thanks for above contributions smile
[Jan 10, 2012 11:45:05 AM]   Link   Report threatening or abusive post: please login first  Go to top 
Hypernova
Master Cruncher
Audaces Fortuna Juvat ! Vaud - Switzerland
Joined: Dec 16, 2008
Post Count: 1908
Status: Offline
Project Badges:
Reply to this Post  Reply with Quote 
Re: Playing around with stats

There is also another issue if you play with stats for points or results.

The numbers are with the comma separation for thousands instead of an apostrophy:

Exemple WCG number: 123,765,456

Excel number should be: 123'765'456

It is impossible to do operations on the numbers with the WCG format.

I use the following formula to do the conversion:

=SUBSTITUE(H123;",";"'")

H123 means that the number to be converted issued by a copie paste from WCG is in the cell H123.
----------------------------------------

[Jan 10, 2012 1:36:33 PM]   Link   Report threatening or abusive post: please login first  Go to top 
jonnieb-uk
Ace Cruncher
England
Joined: Nov 30, 2011
Post Count: 6105
Status: Offline
Project Badges:
Reply to this Post  Reply with Quote 
Re: Playing around with stats

Two of the guys over at the MS Office Excel Forum have come up with formula for addition and subtraction of runtime data using the WGC format y:ddd:mm:hh:mm:ss.

It took a few attempts to get completely right but I've run them against some test data and they appear to work correctly. (Testing involved breaking down input data into it's constituent parts, coverting to seconds, adding or subtracting, then converting the result back to the WGC format. This was then compared with results obtained using the formula below and the results were identical.)

Data ( y:ddd:mm:hh:mm:ss) in Cell A5 and Cell B5; Formula in Cell C5:

Addition formula: (courtesy of Richard Buttrey ) =TEXT(LEFT(B5,FIND(":",B5)-1)+LEFT(A5,FIND(":",A5)-1)+IF(MID(A5,3,3)+MID(B5,3,3)>=365,1,0),"0")&":"&TEXT(MOD(MID(B5,3,3)+MID(A5,3,3),365)+IF(RIGHT(A5,8)+RIGHT(B5,8)>1,1,0),"000")&TEXT(MOD(RIGHT(B5,8)+RIGHT(A5,8),1),":hh:mm:ss")

Subtraction formula: (courtesy of Daddylonglegs)
=LEFT(B5,FIND(":",B5)-1)-LEFT(A5,FIND(":",A5)-1)-(RIGHT(A5,12)>RIGHT(B5,12))&":"&TEXT(MOD(MID(B5,FIND(":",B5)+1,3)-MID(A5,FIND(":",A5)+1,3)-(RIGHT(A5,8)>RIGHT(B5,8)),365),"000")&TEXT(MOD(RIGHT(B5,8)-RIGHT(A5,8),1),":hh:mm:ss")

Notes:
1. Copy/Paste the formula from here to an Excel spreadsheet should work ok.
2. Since I haven't, at this point in time, the knowledge to totally understand/verify the formulae, you should inspect the results produced to ensure correctness.
3. Because cells are text format, subtracting a higher value from a lower value will report a negative as in this example:
0:003:01:11:47 - 0:009:05:44:33 = -1:358:19:27:14
4. If the input data is obtained from an external data connection remember that it may have leading or trailing spaces, which may cause unexpected behaviour in the computation. I handle this by using the "=TRIM() " function on the raw data. Alternatively modify the addition and subtraction formulae to enclose each individual cell reference with TRIM()
5. The formulae assume year=365 days (i.e. No Leap Year)
6. To sort a table of Runtime data produced in this way its necessary to sort on Values, Order Z - A, to produce a table in descending order of magnitude (Because the data is formatted Text rather than Numeric.)
7. Following on from (6) there's a problem: The ddd:mm:hh:mm:ss part of the WGC format is fixed length but "y:" is floating. The sort operation in (6) only works where "y:" =< 9. To handle values of "y:" > 9 it is necessary to introduce leading 0's such that all the "y:" data in the table is of uniform length.

I hope the above proves useful to other people. I'm on a very steep learning curve to update my Excel knowledge so comments, criticism, amendments are most welcome.
----------------------------------------

To Join follow this link: Join the UK Team All Welcome! UK Team thread
----------------------------------------
[Edit 1 times, last edit by jonnieb-uk at Jan 10, 2012 10:32:35 PM]
[Jan 10, 2012 4:15:25 PM]   Link   Report threatening or abusive post: please login first  Go to top 
anhhai
Veteran Cruncher
Joined: Mar 22, 2005
Post Count: 839
Status: Offline
Project Badges:
Reply to this Post  Reply with Quote 
Re: Playing around with stats

jonnieb-uk,

The formula is over my head. I personally just use basic functions to do what is necessary. Believe it or not, there is a fairly simple solution available. My method allows for addition, substraction, sorting, and whatever else that comes to mind.

Here is a simple question for everyone. Why do you need to use "0:048:22:43:27"? Why can't it be Yrs=0, Days=48, Hrs=22,Min=43, and Sec=27? The first method is very hard for excel to understand. But the second, is very easy for excel to understand.

When you have a bunch of data in the y:ddd:mm:hh:mm:ss format, just copy it to notepad. Ideally, you would want 1 piece of data per line. Then open up the notepad file using excel. Excel will ask you some questions about how to format the file, one of the question is what are the delimeters, just make sure you choose ':' as a delimeter. The result will be easy to read and easy to modify as you see fit afterwards. All of the "years" data will be under column A. All of the "days" data will be under column B. All of the "hrs" data will be under column C. All of the "minutes" data will be under column D. All of the "seconds" data will be under column E.

Excel can actually handle this type of information. You can easily sort this information, however, if you want to add, subtract, and stuff with it, you will need a column F. Column F is basically column A-E in seconds. Most ppl probably already know how to create column F, but I will just type it out anyways.
In the F1 cell type "=A1*31536000+B1*86400+C1*3600+D1*60+E1"
then you can highlight the rest of the F column, and use fill down.
So now, you can do addition, subtraction or whatever you want since it all everything is in seconds. You will also want to reconvert things back into the y:ddd:mm:hh:mm:ss format using column K-N.

The principles of this idea should be fairly easy to understand with just the basic understand of how excel works. Modify the idea as you see fit
----------------------------------------

[Jan 10, 2012 11:13:12 PM]   Link   Report threatening or abusive post: please login first  Go to top 
jonnieb-uk
Ace Cruncher
England
Joined: Nov 30, 2011
Post Count: 6105
Status: Offline
Project Badges:
Reply to this Post  Reply with Quote 
Re: Playing around with stats

anhhai

Thanks for the reply.

I agree with your final paragraph

The principles of this idea should be fairly easy to understand with just the basic understand of how excel works. Modify the idea as you see fit

Had your method been available to me when I first started browsing the Forum I would probably have adopted it in toto. I waded through the FAQs but there was nothing relevant to someone like me who just wants to manipulate WGC data to satisfy a curiosity.

Being a newbie I was initially nervous about posting to a Forum predominately occupied by people who've been crunching for years.

As previously noted my Excel knowledge was somewhat dated but its been a worthwhile and enjoyable process learning some new Excel Functions and putting them into practice (even if it is a little like reinventing the wheel).

When it comes down to it, its a matter of personal preference how to handle the data. But if the discussion in this thread helps others in their quest to manipulate WGC data then we've both achieved something positive.
----------------------------------------

To Join follow this link: Join the UK Team All Welcome! UK Team thread
[Jan 10, 2012 11:44:48 PM]   Link   Report threatening or abusive post: please login first  Go to top 
Posts: 17   Pages: 2   [ 1 2 | Next Page ]
[ Jump to Last Post ]
Post new Thread