Jump to content

Recommended Posts

Posted

Hi to all im writting a Rubik's Cube Time, it work nice. Now i would like to add on my application the Average time.

For example if i've this time

00:02.20
00:02.30
00:02.61
00:01.34
00:00.58
01:19.58

How i can calculate the total Averange?

And how i can recognize to application the best time?

How can i calculate Avg. 5, Avg. 10, 3 of 5:,10 of 12 ??

I would like to do an application like this :

Rubik's Cube Timer

Hi and thank's a lot for your help!

Posted (edited)

; get the times into an array (do this however you want)
Local $asTimes = StringSplit("00:02.20|00:02.30|00:02.61|00:01.34|00:00.58|01:19.58", "|")

; The result
Local $iResult = 0

; Convert to milliseconds then add to result
Local $asTemp
For $i = 1 To $asTimes[0]
    $asTemp = StringSplit($asTimes[$i], ":.") ; ":." splits on ":" OR "."

    ; Add it to the result
    $iResult += Int($asTemp[3])
    $iResult += 1000 * Int($asTemp[2])
    $iResult += 1000 * 60 * Int($asTemp[1])
Next

; Divide result by numbers of entries (mean)
$iResult = Round($iResult / $asTimes[0])

; Convert back
Local $iMins, $iSecs, $iMSecs

$iResult = Int($iResult / 1000)
$iResult = Mod($iResult, 3600)
$iMins = Int($iResult / 60)
$iSecs = Mod($iResult, 60)

MsgBox(0, "Test", $iMins & ":" & $iSecs & "." & $iResult)

Edited by Mat
Posted

Kk... I was wrong (slightly)

Here is a much better version that should be easier to use and does the last 5 and 10. I would do the other 2 averages but I'm not sure what they are supposed to do :mellow:

; get the times into an array (do this however you want)
Local $asTimes = StringSplit("00:02.20|00:02.30|00:02.61|00:01.34|00:00.58|01:19.58", "|")

; Average:
MsgBox(0, "Avg. All", _TimeToString(_CalcAvr($asTimes)))

; Average 5
If $asTimes[0] > 5 Then
    Local $asLast5[6]
    $asLast5[0] = 5

    For $i = 1 To 5
        $asLast5[$i] = $asTimes[$asTimes[0] - 5 + $i]
    Next

    MsgBox(0, "Avg. 5", _TimeToString(_CalcAvr($asLast5)))
EndIf

; Average 10
If $asTimes[0] > 10 Then
    Local $asLast10[11]
    $asLast10[0] = 10

    For $i = 1 To 10
        $asLast10[$i] = $asTimes[$asTimes[0] - 10 + $i]
    Next

    MsgBox(0, "Avg. 10", _TimeToString(_CalcAvr($asLast10)))
EndIf

Func _TimeFromString($sTime)
    Local $asTemp = StringSplit($sTime, ":.") ; ":." splits on ":" OR "."
    Local $iRet = 0

    $iRet += Int($asTemp[3]) * 10
    $iRet += Int($asTemp[2]) * 1000
    $iRet += Int($asTemp[1]) * 1000 * 60

    Return $iRet
EndFunc

Func _TimeToString($iTime) ; in ms
    Local $iMins, $iSecs

    $iMins = Int($iTime / (60 * 1000))
    $iTime -= $iMins * 60 * 1000

    $iSecs = Int($iTime / 1000)
    $iTime -= $iSecs * 1000

    $iTime = String(Round($iTime / 10))

    If StringLen($iMins) = 1 Then $iMins = "0" & $iMins
    If StringLen($iSecs) = 1 Then $iSecs = "0" & $iSecs
    If StringLen($iTime) = 1 Then $iTime = "0" & $iTime

    Return $iMins & ":" & $iSecs & "." & $iTime
EndFunc

Func _CalcAvr($asTimes)
    Local $iResult = 0

    For $i = 1 To $asTimes[0]
        $iResult += _TimeFromString($asTimes[$i])
    Next

    Return Round($iResult / $asTimes[0])
EndFunc
Posted

_ArraySort will sort them all into order for you, then you just read the first and last :mellow:

#include<Array.au3>

; get the times into an array (do this however you want)
Local $asTimes = StringSplit("00:02.20|00:02.30|00:02.61|00:01.34|00:00.58|01:19.58", "|")

; Average:
MsgBox(0, "Avg. All", _TimeToString(_CalcAvr($asTimes)))

; Average 5
If $asTimes[0] > 5 Then
    Local $asLast5[6]
    $asLast5[0] = 5

    For $i = 1 To 5
        $asLast5[$i] = $asTimes[$asTimes[0] - 5 + $i]
    Next

    MsgBox(0, "Avg. 5", _TimeToString(_CalcAvr($asLast5)))
EndIf

; Average 10
If $asTimes[0] > 10 Then
    Local $asLast10[11]
    $asLast10[0] = 10

    For $i = 1 To 10
        $asLast10[$i] = $asTimes[$asTimes[0] - 10 + $i]
    Next

    MsgBox(0, "Avg. 10", _TimeToString(_CalcAvr($asLast10)))
EndIf

; Order
_ArraySort($asTimes, 0, 1)

; Best time:
MsgBox(0, "Best Time", $asTimes[1])

; Worst time
MsgBox(0, "Worst Time", $asTimes[$asTimes[0]])

Func _TimeFromString($sTime)
    Local $asTemp = StringSplit($sTime, ":.") ; ":." splits on ":" OR "."
    Local $iRet = 0

    $iRet += Int($asTemp[3]) * 10
    $iRet += Int($asTemp[2]) * 1000
    $iRet += Int($asTemp[1]) * 1000 * 60

    Return $iRet
EndFunc

Func _TimeToString($iTime) ; in ms
    Local $iMins, $iSecs

    $iMins = Int($iTime / (60 * 1000))
    $iTime -= $iMins * 60 * 1000

    $iSecs = Int($iTime / 1000)
    $iTime -= $iSecs * 1000

    $iTime = String(Round($iTime / 10))

    If StringLen($iMins) = 1 Then $iMins = "0" & $iMins
    If StringLen($iSecs) = 1 Then $iSecs = "0" & $iSecs
    If StringLen($iTime) = 1 Then $iTime = "0" & $iTime

    Return $iMins & ":" & $iSecs & "." & $iTime
EndFunc

Func _CalcAvr($asTimes)
    Local $iResult = 0

    For $i = 1 To $asTimes[0]
        $iResult += _TimeFromString($asTimes[$i])
    Next

    Return Round($iResult / $asTimes[0])
EndFunc
Posted (edited)

Hi thank's a lot! I've another simple problem :mellow:

$Leggitempi = FileRead (@ScriptDir & "\Tempi.ini") ;I read times from .ini
For $i = 1 To _FileCountLines (@ScriptDir & "\Tempi.ini")
     _ArrayAdd ($Tempi,FileReadLine (@ScriptDir & "\Tempi.ini",$i))
 Next
_ArrayDelete ($Tempi,"")
$Tempiufficiali = StringSplit (_ArrayToString ($Tempi),"|")
_ArrayDisplay($Tempiufficiali)
If $Tempiufficiali[0] > 5 Then
    Local $Tempisu5[6]
    $Tempisu5[0] = 5
    For $i = 1 To 5
        $Tempisu5[$i] = $Tempiufficiali[$Tempiufficiali[0] - 5 + $i]
    Next
    MsgBox(0, "Avg. 5", _TimeToString(_CalcAvr($Tempisu5)))
EndIf
Func _TimeFromString($sTime)
    Local $asTemp = StringSplit($sTime, ":.") ; ":." splits on ":" OR "."
    Local $iRet = 0

    $iRet += Int($asTemp[3]) * 10
    $iRet += Int($asTemp[2]) * 1000
    $iRet += Int($asTemp[1]) * 1000 * 60

    Return $iRet
EndFunc

Func _TimeToString($iTime) ; in ms
    Local $iMins, $iSecs

    $iMins = Int($iTime / (60 * 1000))
    $iTime -= $iMins * 60 * 1000

    $iSecs = Int($iTime / 1000)
    $iTime -= $iSecs * 1000

    $iTime = String(Round($iTime / 10))

    If StringLen($iMins) = 1 Then $iMins = "0" & $iMins
    If StringLen($iSecs) = 1 Then $iSecs = "0" & $iSecs
    If StringLen($iTime) = 1 Then $iTime = "0" & $iTime

    Return $iMins & ":" & $iSecs & "." & $iTime
EndFunc

Func _CalcAvr($Tempi)
    Local $iResult = 0

    For $i = 1 To $Tempi[0]
        $iResult += _TimeFromString($Tempi[$i])
    Next

    Return Round($iResult / $Tempi[0])
EndFunc

The ini is formed like this :

00:02.56
00:01.93
00:01.57
00:01.94
ecc..

But now the averange is not correct why?

Edited by AuToItItAlIaNlOv3R
Posted

Is this what you wanted to do? I made bits of the code a bit neater, Array.au3 is only needed for _ArrayDisplay now.

#include<File.au3>
#include<Array.au3>

Local $Tempi[1] = [0]

_FileReadToArray(@ScriptDir & "\Tempi.ini", $Tempi)

$Tempiufficiali = $Tempi
_ArrayDisplay($Tempiufficiali)

If $Tempiufficiali[0] > 5 Then
    Local $Tempisu5[6]
    $Tempisu5[0] = 5

    For $i = 1 To 5
        $Tempisu5[$i] = $Tempiufficiali[$Tempiufficiali[0] - 5 + $i]
    Next

    MsgBox(0, "Avg. 5", _TimeToString(_CalcAvr($Tempisu5)))
EndIf


Func _TimeFromString($sTime)
    Local $asTemp = StringSplit($sTime, ":.") ; ":." splits on ":" OR "."
    Local $iRet = 0

    $iRet += Int($asTemp[3]) * 10
    $iRet += Int($asTemp[2]) * 1000
    $iRet += Int($asTemp[1]) * 1000 * 60

    Return $iRet
EndFunc   ;==>_TimeFromString

Func _TimeToString($iTime) ; in ms
    Local $iMins, $iSecs

    $iMins = Int($iTime / (60 * 1000))
    $iTime -= $iMins * 60 * 1000

    $iSecs = Int($iTime / 1000)
    $iTime -= $iSecs * 1000

    $iTime = String(Round($iTime / 10))

    If StringLen($iMins) = 1 Then $iMins = "0" & $iMins
    If StringLen($iSecs) = 1 Then $iSecs = "0" & $iSecs
    If StringLen($iTime) = 1 Then $iTime = "0" & $iTime

    Return $iMins & ":" & $iSecs & "." & $iTime
EndFunc   ;==>_TimeToString

Func _CalcAvr($Tempi)
    Local $iResult = 0

    For $i = 1 To $Tempi[0]
        $iResult += _TimeFromString($Tempi[$i])
    Next

    Return Round($iResult / $Tempi[0])
EndFunc   ;==>_CalcAvr
Posted

Is this what you wanted to do? I made bits of the code a bit neater, Array.au3 is only needed for _ArrayDisplay now.

#include<File.au3>
#include<Array.au3>

Local $Tempi[1] = [0]

_FileReadToArray(@ScriptDir & "\Tempi.ini", $Tempi)

$Tempiufficiali = $Tempi
_ArrayDisplay($Tempiufficiali)

If $Tempiufficiali[0] > 5 Then
    Local $Tempisu5[6]
    $Tempisu5[0] = 5

    For $i = 1 To 5
        $Tempisu5[$i] = $Tempiufficiali[$Tempiufficiali[0] - 5 + $i]
    Next

    MsgBox(0, "Avg. 5", _TimeToString(_CalcAvr($Tempisu5)))
EndIf


Func _TimeFromString($sTime)
    Local $asTemp = StringSplit($sTime, ":.") ; ":." splits on ":" OR "."
    Local $iRet = 0

    $iRet += Int($asTemp[3]) * 10
    $iRet += Int($asTemp[2]) * 1000
    $iRet += Int($asTemp[1]) * 1000 * 60

    Return $iRet
EndFunc   ;==>_TimeFromString

Func _TimeToString($iTime) ; in ms
    Local $iMins, $iSecs

    $iMins = Int($iTime / (60 * 1000))
    $iTime -= $iMins * 60 * 1000

    $iSecs = Int($iTime / 1000)
    $iTime -= $iSecs * 1000

    $iTime = String(Round($iTime / 10))

    If StringLen($iMins) = 1 Then $iMins = "0" & $iMins
    If StringLen($iSecs) = 1 Then $iSecs = "0" & $iSecs
    If StringLen($iTime) = 1 Then $iTime = "0" & $iTime

    Return $iMins & ":" & $iSecs & "." & $iTime
EndFunc   ;==>_TimeToString

Func _CalcAvr($Tempi)
    Local $iResult = 0

    For $i = 1 To $Tempi[0]
        $iResult += _TimeFromString($Tempi[$i])
    Next

    Return Round($iResult / $Tempi[0])
EndFunc   ;==>_CalcAvr

No i would like to have this script :

#include<Array.au3>

; get the times into an array (do this however you want)
Local $asTimes = StringSplit("00:02.20|00:02.30|00:02.61|00:01.34|00:00.58|01:19.58", "|")

; Average:
MsgBox(0, "Avg. All", _TimeToString(_CalcAvr($asTimes)))

; Average 5
If $asTimes[0] > 5 Then
    Local $asLast5[6]
    $asLast5[0] = 5

    For $i = 1 To 5
        $asLast5[$i] = $asTimes[$asTimes[0] - 5 + $i]
    Next

    MsgBox(0, "Avg. 5", _TimeToString(_CalcAvr($asLast5)))
EndIf

; Average 10
If $asTimes[0] > 10 Then
    Local $asLast10[11]
    $asLast10[0] = 10

    For $i = 1 To 10
        $asLast10[$i] = $asTimes[$asTimes[0] - 10 + $i]
    Next

    MsgBox(0, "Avg. 10", _TimeToString(_CalcAvr($asLast10)))
EndIf

; Order
_ArraySort($asTimes, 0, 1)

; Best time:
MsgBox(0, "Best Time", $asTimes[1])

; Worst time
MsgBox(0, "Worst Time", $asTimes[$asTimes[0]])

Func _TimeFromString($sTime)
    Local $asTemp = StringSplit($sTime, ":.") ; ":." splits on ":" OR "."
    Local $iRet = 0

    $iRet += Int($asTemp[3]) * 10
    $iRet += Int($asTemp[2]) * 1000
    $iRet += Int($asTemp[1]) * 1000 * 60

    Return $iRet
EndFunc

Func _TimeToString($iTime) ; in ms
    Local $iMins, $iSecs

    $iMins = Int($iTime / (60 * 1000))
    $iTime -= $iMins * 60 * 1000

    $iSecs = Int($iTime / 1000)
    $iTime -= $iSecs * 1000

    $iTime = String(Round($iTime / 10))

    If StringLen($iMins) = 1 Then $iMins = "0" & $iMins
    If StringLen($iSecs) = 1 Then $iSecs = "0" & $iSecs
    If StringLen($iTime) = 1 Then $iTime = "0" & $iTime

    Return $iMins & ":" & $iSecs & "." & $iTime
EndFunc

Func _CalcAvr($asTimes)
    Local $iResult = 0

    For $i = 1 To $asTimes[0]
        $iResult += _TimeFromString($asTimes[$i])
    Next

    Return Round($iResult / $asTimes[0])
EndFunc

But i would like that is load the time to a .ini file :P

My ini file is formed like that :

00:02.56
00:01.93
00:01.57
00:01.94
ecc...

How i can do that?

Mat thank's a lot for your precious help! :mellow:

Posted

Ok i've fixed you code with this :

#include<File.au3>
#include<Array.au3>
Local $asTimes[1] = [0]
_FileReadToArray(@ScriptDir & "\Tempi.ini", $asTimes)
MsgBox(0, "Avg. All", _TimeToString(_CalcAvr($asTimes)))

; Average 5
If $asTimes[0] > 5 Then
    Local $asLast5[6]
    $asLast5[0] = 5

    For $i = 1 To 5
        $asLast5[$i] = $asTimes[$asTimes[0] - 5 + $i]
    Next

    MsgBox(0, "Avg. 5", _TimeToString(_CalcAvr($asLast5)))
EndIf

; Average 10
If $asTimes[0] > 10 Then
    Local $asLast10[11]
    $asLast10[0] = 10

    For $i = 1 To 10
        $asLast10[$i] = $asTimes[$asTimes[0] - 10 + $i]
    Next

    MsgBox(0, "Avg. 10", _TimeToString(_CalcAvr($asLast10)))
EndIf

; Order
_ArraySort($asTimes, 0, 1)

; Best time:
MsgBox(0, "Best Time", $asTimes[1])

; Worst time
MsgBox(0, "Worst Time", $asTimes[$asTimes[0]])

Func _TimeFromString($sTime)
    Local $asTemp = StringSplit($sTime, ":.") ; ":." splits on ":" OR "."
    Local $iRet = 0

    $iRet += Int($asTemp[3]) * 10
    $iRet += Int($asTemp[2]) * 1000
    $iRet += Int($asTemp[1]) * 1000 * 60

    Return $iRet
EndFunc

Func _TimeToString($iTime) ; in ms
    Local $iMins, $iSecs

    $iMins = Int($iTime / (60 * 1000))
    $iTime -= $iMins * 60 * 1000

    $iSecs = Int($iTime / 1000)
    $iTime -= $iSecs * 1000

    $iTime = String(Round($iTime / 10))

    If StringLen($iMins) = 1 Then $iMins = "0" & $iMins
    If StringLen($iSecs) = 1 Then $iSecs = "0" & $iSecs
    If StringLen($iTime) = 1 Then $iTime = "0" & $iTime

    Return $iMins & ":" & $iSecs & "." & $iTime
EndFunc

Func _CalcAvr($asTimes)
    Local $iResult = 0

    For $i = 1 To $asTimes[0]
        $iResult += _TimeFromString($asTimes[$i])
    Next

    Return Round($iResult / $asTimes[0])
EndFunc

But the Avg. 5 and Avg. 10 don't work well.

I use this times :

00:02.71
00:05.14
00:03.21
00:03.27
00:03.85
00:03.94
00:04.69
00:07.73
00:02.89
00:02.98
00:09.64
00:22.48
00:16.53
00:22.59
00:16.32

The averange 5 time that give me the script is :

00:17.51

But if i use http://www.cubetimer.com/ with equal times it give me for Avg.5 this time:

00:03.63

Avg 10 time that give me the script is :

00:10.98

But if i use http://www.cubetimer.com/ with equal times it give me for Avg.10 this time:

00:04.04

How is possible?

Thank's :mellow:

Posted

Ah right, the avg 5 and 10 are the average for the TOP 5/10 not the LAST 5/10. Fix is simple:

#include<File.au3>
#include<Array.au3>
Local $asTimes[1] = [0]
_FileReadToArray(@ScriptDir & "\Tempi.ini", $asTimes)
MsgBox(0, "Avg. All", _TimeToString(_CalcAvr($asTimes)))

; Order
_ArraySort($asTimes, 0, 1)

; Average 5
If $asTimes[0] > 5 Then
    Local $asLast5[6]
    $asLast5[0] = 5

    For $i = 1 To 5
        $asLast5[$i] = $asTimes[$i]
    Next

    MsgBox(0, "Avg. 5", _TimeToString(_CalcAvr($asLast5)))
EndIf

; Average 10
If $asTimes[0] > 10 Then
    Local $asLast10[11]
    $asLast10[0] = 10

    For $i = 1 To 10
        $asLast10[$i] = $asTimes[$i]
    Next

    MsgBox(0, "Avg. 10", _TimeToString(_CalcAvr($asLast10)))
EndIf

; Best time:
MsgBox(0, "Best Time", $asTimes[1])

; Worst time
MsgBox(0, "Worst Time", $asTimes[$asTimes[0]])

Func _TimeFromString($sTime)
    Local $asTemp = StringSplit($sTime, ":.") ; ":." splits on ":" OR "."
    Local $iRet = 0

    $iRet += Int($asTemp[3]) * 10
    $iRet += Int($asTemp[2]) * 1000
    $iRet += Int($asTemp[1]) * 1000 * 60

    Return $iRet
EndFunc

Func _TimeToString($iTime) ; in ms
    Local $iMins, $iSecs

    $iMins = Int($iTime / (60 * 1000))
    $iTime -= $iMins * 60 * 1000

    $iSecs = Int($iTime / 1000)
    $iTime -= $iSecs * 1000

    $iTime = String(Round($iTime / 10))

    If StringLen($iMins) = 1 Then $iMins = "0" & $iMins
    If StringLen($iSecs) = 1 Then $iSecs = "0" & $iSecs
    If StringLen($iTime) = 1 Then $iTime = "0" & $iTime

    Return $iMins & ":" & $iSecs & "." & $iTime
EndFunc

Func _CalcAvr($asTimes)
    Local $iResult = 0

    For $i = 1 To $asTimes[0]
        $iResult += _TimeFromString($asTimes[$i])
    Next

    Return Round($iResult / $asTimes[0])
EndFunc

You just order it first :mellow:

Posted (edited)

Avg 10 and avg 5 are not more precise :P

For this times

00:01.10
00:01.90
00:01.82
00:02.09
00:02.37
00:06.44
00:07.53
00:05.42
00:05.76
00:07.53
00:05.64

Avg 5 on http://www.cubetimer.com/ is 00:01.85 , buton your code is 00:01.86, on avg 10 site report 00:04.19 and your script 00:04.01 :party:

hi!

Thak's for you help :mellow:

Edited by AuToItItAlIaNlOv3R
Posted

This is the source code of this site :

<script language="javascript"><!--
      function initialize() {
        reset_timer();
        session_restore();
        load_puzzle();
        generate_scramble();
      }

      function pushbutton() {
        if(timer.running()) {
          stop_timer();
        }
        else {
          if(session_get('insp_time') * 1) {
            inspection_running = true;
          }
          start_timer()
        }
      }

      function start_timer() {
        reset_timer();
        timer.start();
        show_time();
      }

      function stop_timer() {
        timer.stop();
        clearTimeout(timer.timer_id);

        if(! inspection_running) {
          add_time(timer.elapsed());
        }

        show_time();
        refresh_stats();
        generate_scramble();

        inspection_running = false;
      }

      function refresh_stats() {
        new_html = '';

        new_html += '<div style="height: 135px; overflow: auto; padding: 5px; margin: 10px; border: 1px solid #89c; background: #fff;">';

        var total = 0;
        var total_5 = 0;
        var total_10 = 0;
        var best = 'x'
        var worst = 'x'
        if(time_list.length > 0) {
          new_html += '<table cellpadding="0" cellspacing="0">';
          for(i = time_list.length - 1, count = 0; i >= 0; i--, count++) {
            new_html += '<tr>';
            new_html += '<td align="right"><strong><em>' + (i + 1) + ':</em></strong></td>';
            new_html += '<td style="padding: 0 20px;">' + format_time(time_list[i]) + '</td>';
            new_html += '<td><a href="javascript:remove_time(' + i + ')">x</a></td>';
            total += time_list[i] * 1;
            if(count < 5)  { total_5  += time_list[i] * 1; }
            if(count < 10) { total_10 += time_list[i] * 1; }
            if(best == 'x' || time_list[i] * 1 < best) { best = time_list[i] * 1; }
            if(worst == 'x' || time_list[i] * 1 > worst) { worst = time_list[i] * 1; }
            new_html += '</tr>';
          }
          new_html += '</table>';
        }

        new_html += '</div>';

        document.getElementById('times').innerHTML = new_html;

        var stats_list = new Array();

        stats_list['stat_avg'] = time_list.length >= 1 ? format_time(total / time_list.length) : '--:--.--';
        stats_list['stat_avg5'] = time_list.length >= 5 ? format_time(total_5 / 5) : stats_list['stat_avg'];
        stats_list['stat_avg10'] = time_list.length >= 10 ? format_time(total_10 / 10) : stats_list['stat_avg'];
        stats_list['stat_avg3of5'] = time_list.length >= 5 ? format_time(avg_with_discards(time_list, 5)) : '--:--.--';
        stats_list['stat_avg10of12'] = time_list.length >= 12 ? format_time(avg_with_discards(time_list, 12)) : '--:--.--';
        stats_list['stat_best'] = time_list.length >= 1 ? format_time(best) : '--:--.--';
        stats_list['stat_worst'] = time_list.length >= 1 ? format_time(worst) : '--:--.--';

        for(i in stats_list) {
          if(document.getElementById(i)) {
            document.getElementById(i).innerHTML = stats_list[i];
          }
        }

        new_html = ''

        document.getElementById('avg').innerHTML = new_html;
      }

      function show_time() {
        if(inspection_running) {
          seconds_left = Math.round( ( (session_get('insp_time') * 1000) - timer.elapsed() ) / 1000 )
          if(seconds_left > 0) {
            document.getElementById('elapsed_time').innerHTML = seconds_left;
            if(seconds_left <= 3 && session_get('insp_sound')) {
              soundManager.play('beep');
            }
            if(timer.running()) { timer.timer_id = setTimeout('show_time()', 1000); }
          }
          else {
            timer.stop();
            reset_timer();
            timer.start();

            if(session_get('insp_sound')) {
              soundManager.play('pop');
            }

            inspection_running = false;

            document.getElementById('elapsed_time').innerHTML = format_time(0);
            if(timer.running()) { timer.timer_id = setTimeout('show_time()', 15); }
          }
        }
        else {
          document.getElementById('elapsed_time').innerHTML = format_time(timer.elapsed());
          if(timer.running()) { timer.timer_id = setTimeout('show_time()', 15); }
        }
      }

      function format_time(time) {
        time *= 1;
        timer.time_segments[0] = lpad(Math.floor(time / 60000), 2, "0"); time %= 60000;
        timer.time_segments[1] = lpad(Math.floor(time / 1000), 2, "0"); time %= 1000;
        timer.time_segments[2] = lpad(Math.floor(time / 10), 2, "0", true);

        return timer.time_segments[0] + ":" + timer.time_segments[1] + "." + timer.time_segments[2];
      }

      function reset_timer() {
        if(!timer.running()) {
          for(var i = 0; i < timer.time_segments.length; i++) timer.time_segments[i] = "00";
          timer.reset();
          show_time();
        }
      }

      function lpad(s, l, c, t) {
        s += "";
        c = c || " ";
        while(s.length < l)
          s = c + s;
        return t && s.length > l ? s.substr(0, l) : s;
      }

      function add_time(time) {
        time_list[time_list.length] = time;
        save_time(time, selected_puzzle);
        session_save();
      }

      function remove_time(i) {
        time_list.splice(i, 1);
        refresh_stats();
        session_save();
      }

      function clear_times() {
        if(time_list.length && confirm('Drop ALL time entries from the this log? The logs for your other puzzles will remain unaffected.')) {
          eval('time_list = time_list_' + selected_puzzle + ' = new Array();');
          refresh_stats();
          session_save();
        }
      }

      function switch_puzzles() {
        var new_html = '<select style="width: 190px;" onchange="selected_puzzle = options[selectedIndex].value; load_puzzle();">';

        for(var i in puzzle_names) {
          new_html += '<option value="' + i + '"' + (i == selected_puzzle ? ' selected="selected"' : '') + '>' + puzzle_names[i] + '</option>';
        }

        new_html += '</select>';
        new_html += ' <a href="javascript:cancel_switch_puzzles()" style="font-size: 10px;">cancel</a>';
        document.getElementById('puzzle_selector').innerHTML = new_html;
      }

      function cancel_switch_puzzles() {
        document.getElementById('puzzle_selector').innerHTML = '<h3 style="margin: 0;">' + puzzle_names[selected_puzzle] + '</h3>';
      }
 
      function load_puzzle() {
        eval('time_list = time_list_' + selected_puzzle + ';');
        document.getElementById('puzzle_selector').innerHTML = '<h3 style="margin: 0;">' + puzzle_names[selected_puzzle] + '</h3>';
        refresh_stats();
        session_save();

        var scramble_supported = [ '222', '222bf', '333', '333bf', '333oh', '333ft', '444', '444bf', '555', '555bf' ];
        scramble_is_supported = false;
        for(i in scramble_supported) {
          if(selected_puzzle == scramble_supported[i]) {
            scramble_is_supported = true;
            break;
          }
        }
        generate_scramble();
        document.getElementById('scramble').style.display = scramble_is_supported ? '' : 'none';
      }

      function session_save() {
        for(i in puzzle_names) {
          eval('params[\'time_list_' + i + '\'] = time_list_' + i + '.join(\',\');');
        }
        params['selected_puzzle'] = selected_puzzle;
//        params['time_list'] = time_list.join(',');
        setCookie('cubetimer', params.toString(), 24 * 30);
      }

      function session_get(key) {
        return params[key];
      }

      function session_set(key, val) {
        params[key] = val;
        session_save();
      }

      function session_unset(key) {
        delete params[key];
      }

      function session_restore() {
        var cookie = readCookie('cubetimer');

        if(cookie) {
          params = new ParamString(cookie);

          if(params['time_list']) {
            time_list_333 = params['time_list'].split(',');
          }

          for(i in puzzle_names) {
            if(params['time_list_' + i]) {
              eval('time_list_' + i + ' = params[\'time_list_' + i + '\'].split(\',\');');
            }
            else if(i != 333) {
              eval('time_list_' + i + ' = new Array();');
            }
          }

          if(params['selected_puzzle']) {
            selected_puzzle = params['selected_puzzle'];
          }

          document.settings_form.insp_time.value = session_get('insp_time') ? session_get('insp_time') : '0';
          document.settings_form.insp_sound.checked = session_get('insp_sound') ? true : false;
        }
      }

      function save_settings() {
        session_set('insp_time', document.settings_form.insp_time.value);
        session_set('insp_sound', document.settings_form.insp_sound.checked ? '1' : '');
      }

      function show_info() {
        $('#short_info').hide('fast');
        $('#full_info').slideDown('slow');
      }

      function hide_info() {
        $('#full_info').slideUp('fast');
        $('#short_info').slideDown('fast');
      }

      function avg_with_discards(a, segment) {

        if(segment) { a = a.slice(-segment); }

        highest = lowest = null;
        total = 0;

        for(var i in a) {
          time = a[i] * 1;

          if(lowest == null || time < lowest) { lowest = time; }
          if(highest == null || time > highest) { highest = time; }

          total += time;
        }

        total -= (lowest + highest);
        count = (segment ? segment : a.length) - 2;

        return total / count;
      }

      function save_time(time, puzzle){
          var ajax_params = new Array();
          ajax_params['seconds'] = time / 1000;
          ajax_params['puzzle'] = puzzle;

          // call ajax
          ajax_call('timelog_insert', 'timelog_insert_cb', ajax_params);
      }

      function timelog_insert_cb(data){
          return true;
      }


      function Scramble(puzzle, turns) {
        this.puzzle = puzzle || 333;

        switch(puzzle) {
          case '444':
          case '444bf':
          case '555':
          case '555bf':
            this.turns = turns || (puzzle.indexOf('444') == 0 ? 40 : 60);
            this.faces = {
              'R'  : { 'allowed' : true, 'enables' : ['U', 'Uw', 'D', 'Dw', 'F', 'Fw', 'B', 'Bw'] },
              'Rw' : { 'allowed' : true, 'enables' : ['U', 'Uw', 'D', 'Dw', 'F', 'Fw', 'B', 'Bw'] },
              'L'  : { 'allowed' : true, 'enables' : ['U', 'Uw', 'D', 'Dw', 'F', 'Fw', 'B', 'Bw'] },
              'Lw' : { 'allowed' : true, 'enables' : ['U', 'Uw', 'D', 'Dw', 'F', 'Fw', 'B', 'Bw'] },
              'U'  : { 'allowed' : true, 'enables' : ['R', 'Rw', 'L', 'Lw', 'F', 'Fw', 'B', 'Bw'] },
              'Uw' : { 'allowed' : true, 'enables' : ['R', 'Rw', 'L', 'Lw', 'F', 'Fw', 'B', 'Bw'] },
              'D'  : { 'allowed' : true, 'enables' : ['R', 'Rw', 'L', 'Lw', 'F', 'Fw', 'B', 'Bw'] },
              'Dw' : { 'allowed' : true, 'enables' : ['R', 'Rw', 'L', 'Lw', 'F', 'Fw', 'B', 'Bw'] },
              'F'  : { 'allowed' : true, 'enables' : ['R', 'Rw', 'L', 'Lw', 'U', 'Uw', 'D', 'Dw'] },
              'Fw' : { 'allowed' : true, 'enables' : ['R', 'Rw', 'L', 'Lw', 'U', 'Uw', 'D', 'Dw'] },
              'B'  : { 'allowed' : true, 'enables' : ['R', 'Rw', 'L', 'Lw', 'U', 'Uw', 'D', 'Dw'] },
              'Bw' : { 'allowed' : true, 'enables' : ['R', 'Rw', 'L', 'Lw', 'U', 'Uw', 'D', 'Dw'] }
            };
            this.face_index = ['R', 'Rw', 'L', 'Lw', 'U', 'Uw', 'D', 'Dw', 'F', 'Fw', 'B', 'Bw'];
            break;

          case '222': case '222bf': case '333': case '333bf': case '333oh': case '333ft':
          default:
            this.turns = turns || 25;
            this.faces = {
              'R' : { 'allowed' : true, 'enables' : ['U', 'D', 'F', 'B'] },
              'L' : { 'allowed' : true, 'enables' : ['U', 'D', 'F', 'B'] },
              'U' : { 'allowed' : true, 'enables' : ['R', 'L', 'F', 'B'] },
              'D' : { 'allowed' : true, 'enables' : ['R', 'L', 'F', 'B'] },
              'F' : { 'allowed' : true, 'enables' : ['R', 'L', 'U', 'D'] },
              'B' : { 'allowed' : true, 'enables' : ['R', 'L', 'U', 'D'] }
            };
            this.face_index = ['R', 'L', 'U', 'D', 'F', 'B'];
            break;
        }
        this.scramble = [];
        this.generate()
      }
      Scramble.prototype.generate = Scramble_generate
      Scramble.prototype.toString = Scramble_toString

      function Scramble_generate() {
        this.scramble = [];

        for(i = 0; i < this.turns; i++) {
          do {
            rand = Math.floor(Math.random() * (this.face_index.length));
            face = this.face_index[rand];
          } while(! this.faces[face]['allowed'])

          this.faces[face]['allowed'] = false;

          for(f = 0; f < this.faces[face]['enables'].length; f++) {
            this.faces[this.faces[face]['enables'][f]]['allowed'] = true;
          }

          switch(Math.floor(Math.random() * 3)) {
            case 0: direction = "";  break;
            case 1: direction = "'"; break;
            case 2: direction = "2"; break;
          }

          this.scramble[i] = face + direction;
        }
      }

      function Scramble_toString() {
        return this.scramble.join(' ');
      }

      function get_scramble(puzzle, turns) {
        var puzzle = puzzle || selected_puzzle;
        return (new Scramble(puzzle, turns)).toString();
      }

      function generate_scramble() {
        s = get_scramble()
        s = s.replace(/ /g, ' &nbsp;')
        document.getElementById('scramble').innerHTML = 'Scramble:&nbsp;&nbsp;' + s
      }


      var timer = new StopWatch();
      timer.time_segments = new Array();
      timer.timer_id = 0;
      time_list = new Array();
      inspection_running = false;
      params = new ParamString('');
      var puzzle_names = {
        '222' : '2x2x2 Cube',
        '333' : 'Rubik\'s Cube',
        '444' : '4x4x4 Cube',
        '555' : '5x5x5 Cube',
        '666' : '6x6x6 Cube',
        '777' : '7x7x7 Cube',
        '333bf' : '3x3x3 Blindfolded',
        '333oh' : '3x3x3 One-Handed',
        '333ft' : '3x3x3 With Feet',
        'magic' : 'Rubik\'s Magic',
        'mmagic' : 'Rubik\'s Master Magic',
        'minx' : 'Megaminx',
        'pyram' : 'Pyraminx',
        'sq1' : 'Square-1',
        'skewb' : 'Skewb',
        'clock' : 'Rubik\'s Clock',
        '222bf' : '2x2x2 Blindfolded',
        '444bf' : '4x4x4 Blindfolded',
        '555bf' : '5x5x5 Blindfolded',
        'siam'  : 'Siamese Cube'
      }

      for(i in puzzle_names) {
        eval('time_list_' + i + ' = new Array();');
      }

      selected_puzzle = 333;

    //--></script>

I dont have understand all, you can decifrate that code?

Thanks :mellow:

Posted (edited)

@Mat

A my friend tells me that for avg 5 and avg 10 must be exclude the worst and the best time and then divide it by /5 or 10...how can do that? :mellow:

I would like to do random scramble but only with this letters :

["D ", "R ", "U ", "L " ,"F ", "B ", "D' ", "R' ", "U' ", "L' ", "F' ", "B' ", "D2 ", "R2 ", "U2 ", "L2 ", "F2 ", "B2 "]

How can i do it? A random scramble with only this letters, and i would like that the leght of scramble are variable :P

Can you help my?

I say thank's a lot for all your work :party:

Edited by AuToItItAlIaNlOv3R
Posted

A my friend tells me that for avg 5 and avg 10 must be exclude the worst and the best time and then divide it by /5 or 10...how can do that? :mellow:

Not sure... I'm getting very confused at all these numbers, my brains on holiday :party:

I would like to do random scramble but only with this letters :

["D ", "R ", "U ", "L " ,"F ", "B ", "D' ", "R' ", "U' ", "L' ", "F' ", "B' ", "D2 ", "R2 ", "U2 ", "L2 ", "F2 ", "B2 "]

How can i do it? A random scramble with only this letters, and i would like that the leght of scramble are variable :party:

Can you help my?

I say thank's a lot for all your work :party:

Thats a whole new issue :P _ArrayPermute won't let you find all permutations which would be my first way of doing it... I'll have a look.
Posted

i writing this script for scramble :

#include<Array.au3>
Global $Mosse[18] = ["D ", "R ", "U ", "L " ,"F ", "B ", "D' ", "R' ", "U' ", "L' ", "F' ", "B' ", "D2 ", "R2 ", "U2 ", "L2 ", "F2 ", "B2 "]
MsgBox (0,"",$Mosse [Random(0,17)]&  $Mosse [Random(0,17)] & $Mosse [Random(0,17)] &$Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)]& $Mosse [Random(0,17)])

This get 25 random letters contained in $Mosse array. But how can i modity it to put variable length of scramble ? (for example 15 random letters...or 30 random letters?

Thanks!

Posted

I've fix your script :

Global $Mosse[18] = ["D ", "R ", "U ", "L " ,"F ", "B ", "D' ", "R' ", "U' ", "L' ", "F' ", "B' ", "D2 ", "R2 ", "U2 ", "L2 ", "F2 ", "B2 "]
$Numeroscramble = InputBox ("Numero scramble","Seleziona il numero di scramble")
$sRet =""
For $i = 1 To $Numeroscramble
    $sRet &= $Mosse[Random(0, 17, 1)]
Next
MsgBox(0, "Scramble", $sRet)

And he work great! :blink:

You can't help me for avg 5 and 10...?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...