Sign in to follow this  
Followers 0
abberration

RAID Calculator

4 posts in this topic

#1 ·  Posted (edited)

I was using some online RAID calculators yesterday and thought it would be fun to program one in AutoIt. I did not find anyone else who created such a thing in the Example Scripts sections, this is my addition. I know there are more RAID classes, but I didn't want to muddy up the appearance with obsolete versions. I contemplated on leaving out RAID 6, but ultimately left it in.

I have always struggled to understand how Return in a function worked, but I figured it out while writing this script. I compared the accuracy with the online calcs and this one seems to be spot on.

Enjoy!

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GuiScrollBars.au3>

; Create main Gui
$mainGui = GUICreate("RAID Calculator", 313, 215)
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem2 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenu("Information")
$MenuItem4 = GUICtrlCreateMenuItem("Learn About RAID", $MenuItem3)
$MenuItem5 = GUICtrlCreateMenuItem("About", $MenuItem3)
GUIStartGroup()
$Label1 = GUICtrlCreateLabel("RAID Level", 16, 16, 87, 17)
GUICtrlSetTip(-1, "Learn more about various RAID configurations in the Information menu.")
$Radio1 = GUICtrlCreateRadio("RAID 0", 16, 40, 81, 17)
$Radio2 = GUICtrlCreateRadio("RAID 1", 16, 64, 81, 17)
$Radio3 = GUICtrlCreateRadio("RAID 5", 16, 88, 81, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Radio4 = GUICtrlCreateRadio("RAID 6", 16, 112, 81, 17)
$Radio5 = GUICtrlCreateRadio("RAID 10", 16, 136, 81, 17)
$Radio6 = GUICtrlCreateRadio("RAID 50", 16, 160, 81, 17)
$Label2 = GUICtrlCreateLabel("# Of Disks", 120, 16, 54, 17)
GUICtrlSetTip(-1, "Must be 2 or greater." & @CRLF & "Some configurations " & @CRLF & "require more than 2.")
$Input1 = GUICtrlCreateInput("", 120, 40, 57, 21)
GUICtrlSetTip(-1, "Must be 2 or greater." & @CRLF & "Some configurations " & @CRLF & "require more than 2.")
$Label3 = GUICtrlCreateLabel("Disk Size", 192, 16, 48, 17)
GUICtrlSetTip(-1, "Use whole numbers such as:" & @CRLF & "500 GB, or 2 TB.")
$Input2 = GUICtrlCreateInput("", 192, 40, 57, 21)
GUICtrlSetTip(-1, "Use whole numbers such as:" & @CRLF & "500 GB or 2 TB.")
GUIStartGroup()
$Radio7 = GUICtrlCreateRadio("GB", 256, 16, 41, 17)
$Radio8 = GUICtrlCreateRadio("TB", 256, 40, 41, 17)
GUICtrlSetState(-1, $GUI_CHECKED)
$Button1 = GUICtrlCreateButton("Calculate!", 216, 80, 75, 25, 0)
$Label4 = GUICtrlCreateLabel("Your array will be:", 120, 112, 95, 17)
$Label5 = GUICtrlCreateLabel("", 120, 136, 300, 17)
$Label6 = GUICtrlCreateLabel("", 120, 160, 176, 17)
GUISetState(@SW_SHOW)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1 ; If Caclulate button is pressed, read all controls and pass values to the CalcSize function
If GUICtrlRead($Radio1) = 1 Then
$raidLevel = "0"
ElseIf GUICtrlRead($Radio2) = 1 Then
$raidLevel = "1"
ElseIf GUICtrlRead($Radio3) = 1 Then
$raidLevel = "5"
ElseIf GUICtrlRead($Radio4) = 1 Then
$raidLevel = "6"
ElseIf GUICtrlRead($Radio5) = 1 Then
$raidLevel = "10"
Else
$raidLevel = "50"
EndIf
If GUICtrlRead($Radio7) = 1 Then
$GBTB = 0
Else
$GBTB = 1
EndIf
$numDisks = GUICtrlRead($Input1)
$diskSize = GUICtrlRead($Input2)
CalcSize($raidLevel, $GBTB, $numDisks, $diskSize)
Case $MenuItem2 ; From the menu, exit the program
Exit
Case $MenuItem4 ; From the menu, open the Learn More About RAID tutorial
LearnAboutRAID()
Case $MenuItem5 ; From the menu, open the About Raid Calculator dialog box
AboutRAIDCalc()
EndSwitch
WEnd

Func CalcSize($raidLevel, $GBTB, $numDisks, $diskSize) ; The function that crunches the numbers
Local $error
ErrorCheck($raidLevel, $numDisks, $diskSize) ; Function to check for bad values
If ErrorCheck($raidLevel, $numDisks, $diskSize) = 0 Then
$1GB = 1073741824 ; The number necessary to convert whole disk size numbers into formatted disk sizes. Ex: 1 TB = .93 TB formatted.
If $GBTB = 0 Then ; $GBTB is the variable for what was selected by user: GB or TB
$formatted = ($diskSize * 1000000000) ; TB was selected
Else
$formatted = ($diskSize * 1000000000 * 1000) ; GB was selected
EndIf
Switch $raidLevel ; Maths for the various levels of RAID
Case $raidLevel = 0
$ans = Round(($formatted * $numDisks), 2)
Case $raidLevel = 1
$ans = Round(($formatted * $numDisks) / 2, 2)
Case $raidLevel = 5
$ans = Round(($formatted * $numDisks) - $formatted, 2)
Case $raidLevel = 6
$ans = Round(($formatted * $numDisks) - (2 * $formatted), 2)
Case $raidLevel = 10
$ans = Round(($formatted * $numDisks / 2), 2)
Case $raidLevel = 50
$ans = Round(($formatted * $numDisks) - (2 * $formatted) , 2)
EndSwitch
If $GBTB = 1 Then ; Depending on whether user chose GB or TB, the output answer is displayed
$ans = $ans / 1000
GUICtrlSetData($Label5, $ans / 1000000000 & " TB (Unformatted)")
GUICtrlSetData($Label6, Round($ans / $1GB, 2) & " TB (Formatted)")
Else
GUICtrlSetData($Label5, $ans / 1000000000 & " GB (Unformatted)")
GUICtrlSetData($Label6, Round($ans / $1GB, 2) & " GB (Formatted)")
EndIf
Else
EndIf
EndFunc ;==>CalcSize

Func ErrorCheck($raidLevel, $numDisks, $diskSize) ; Error checking
Local $error = 0
GUICtrlSetData($Label5, "") ; This and next 3 lines resets previous data that may have been set.
GUICtrlSetData($Label6, "")
GUICtrlSetBkColor($Input1, 0xFFFFFF)
GUICtrlSetBkColor($Input2, 0xFFFFFF)
; Begin checks for incorrect amount of disk drives
If StringRegExp($numDisks, "[^0-9]") = 1 Then ; Checks for non-numbers in # of disks field
GUICtrlSetData($Label5, "Error: Invalid character in")
GUICtrlSetData($Label6, "the # Of Disks field.")
GUICtrlSetBkColor($Input1, 0xFFFF00)
$error = 1 ; These error levels are not currently being used; the returned values may be useful for future functionality.
ElseIf StringRegExp($diskSize, "[^0-9]") = 1 Then ; Checks for non-numbers in # of disks field
GUICtrlSetData($Label5, "Error: Invalid character in")
GUICtrlSetData($Label6, "the RAID Level field.")
GUICtrlSetBkColor($Input2, 0xFFFF00)
$error = 2
ElseIf $diskSize < 1 Then ; Checks to see if anything is entered at all
GUICtrlSetData($Label5, "Error: You did not enter anything")
GUICtrlSetData($Label6, "in the RAID Level field.")
GUICtrlSetBkColor($Input2, 0xFFFF00)
$error = 3
ElseIf $numDisks < 2 Then ; Less than 2 drives
GUICtrlSetData($Label5, "Error: You must have at leaset 2")
GUICtrlSetData($Label6, "disk drives to create an array.")
GUICtrlSetBkColor($Input1, 0xFFFF00)
$error = 4
ElseIf $numDisks > 2 AND $raidLevel = 1 Then ; RAID 1 requires exactly 2 drives
GUICtrlSetData($Label5, "Error: RAID 1 requires exactly 2 disk")
GUICtrlSetData($Label6, "drives to create the array.")
GUICtrlSetBkColor($Input1, 0xFFFF00)
$error = 5
ElseIf $numDisks < 3 AND $raidLevel = 5 Then ; RAID 5 requires 3 or more drives
GUICtrlSetData($Label5, "Error: RAID 5 requires a minimum of")
GUICtrlSetData($Label6, "3 disk drives to create the array.")
GUICtrlSetBkColor($Input1, 0xFFFF00)
$error = 6
ElseIf $numDisks < 4 AND $raidLevel = 6 Then ; RAID 6 requires 4 or more drives
GUICtrlSetData($Label5, "Error: RAID 6 requires a minimum of")
GUICtrlSetData($Label6, "4 disk drives to create the array.")
GUICtrlSetBkColor($Input1, 0xFFFF00)
$error = 7
ElseIf $numDisks < 4 AND $raidLevel = 10 Then ; RAID 10 requires 4 or more drives
GUICtrlSetData($Label5, "Error: RAID 10 requires a minimum of")
GUICtrlSetData($Label6, "4 disk drives to create the array.")
GUICtrlSetBkColor($Input1, 0xFFFF00)
$error = 8
ElseIf $numDisks < 6 AND $raidLevel = 50 Then ; RAID 50 requires 6 or more drives
GUICtrlSetData($Label5, "Error: RAID 10 requires a minimum of")
GUICtrlSetData($Label6, "6 disk drives to create the array.")
GUICtrlSetBkColor($Input1, 0xFFFF00)
$error = 9
EndIf
Return $error
EndFunc

Func LearnAboutRAID() ; The Learn More About RAID tutorial
$Form2 = GUICreate("Learn More About RAID", 413, 298)
$desc = "RAID 0 - Uses 2 or more striped disks for maximum disk space and maximum performance. This configuration has no redundancy and if any drive in the array fails, you will lose all of your data. Not recommended for storing important data." _
& @CRLF & @CRLF & "RAID 1 – Uses exactly two mirrored disks with little loss in performance. This configuration uses the most disk space for parity, leaving you with only half of the total hard drive space. It has redundancy, so you can lose up to one hard drive without losing data." _
& @CRLF & @CRLF & "RAID 5 - Uses 3 or more disks combined together with a slight loss in performance. This configuration uses the equivalency of one hard disk for parity. The more disks you use, the better ratio of usable hard disk space vs. parity space. It has redundancy, so you can lose up to one hard drive without losing any data." _
& @CRLF & @CRLF & "RAID 6 – Uses 4 or more disks combined together with little loss in performance. This configuration uses the equivalency of two hard disks for parity. The more disks you use, the better ratio of usable hard disk space vs. parity space. It has redundancy, so you can lose up to two hard drives without losing any data." _
& @CRLF & @CRLF & "RAID 10 (aka RAID 1+0) – Uses 4 or more disks in a combination of RAID 1 and RAID 0 with enhanced performance. This configuration uses the equivalency of half of all hard disks for parity. It creates RAID 1 blocks and stripes the data among them (that is the RAID 0 part of the name). It has redundancy, so you will not lose any data as long as you do not lose 2 drives in any of the RAID 1 blocks." _
& @CRLF & @CRLF & "RAID 50 (aka RAID 5+0) – Uses 6 or more disks in a combination of RAID 5 and RAID 0 with enhanced performance. This configuration uses the equivalency of two hard disks parity. It creates RAID 5 blocks and stripes the data among them (that is the RAID 0 part of the name). The more disks you use, the better ratio of usable hard disk space vs. parity space. It has redundancy, so you will not lose any data as long as you do not lose 2 drives in any of the RAID 5 blocks." _
& @CRLF & @CRLF & @CRLF & "Glossary of terms" _
& @CRLF & @CRLF & "Mirror: An exact copy of data." _
& @CRLF & @CRLF & "Parity: Data recovery information to rebuild data from lost hard disks." _
& @CRLF & @CRLF & "Redundancy: To have some kind of backup of data in case a hard drive fails." _
& @CRLF & @CRLF & "Stripe: To distribute data among 2 or more hard drives."
$Edit1 = GUICtrlCreateEdit("", 14, 8, 385, 281, BitOR($ES_MULTILINE, $WS_VSCROLL, $ES_AUTOVSCROLL))
GUICtrlSetData(-1, $desc)
GUICtrlSetState($Edit1, $GUI_FOCUS)
GUISetState(@SW_SHOW)

While 2
$nMsg2 = GUIGetMsg()
Switch $nMsg2
Case $GUI_EVENT_CLOSE ; Exit the tutorial
GUIDelete($Form2)
ExitLoop
EndSwitch
WEnd
EndFunc

Func AboutRAIDCalc() ; The About dialog box
$Form3 = GUICreate("About RAID Calculator", 324, 239)
GUISetIcon("D:006.ico")
$GroupBox1 = GUICtrlCreateGroup("", 8, 8, 305, 177)
$Labela = GUICtrlCreateLabel("RAID Caclulator", 32, 24, 255, 40, $WS_GROUP)
GUICtrlSetFont(-1, 24, 800, 2, "Arial")
GUICtrlSetColor(-1, 0x800000)
$Labelb = GUICtrlCreateLabel("Version 1.0", 128, 72, 57, 17, $WS_GROUP)
$Labelc = GUICtrlCreateLabel("http://www.autoitscript.com", 32, 152, 136, 17, $WS_GROUP)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetCursor (-1, 0)
$Labeld = GUICtrlCreateLabel("Program written in AutoIt scripting language", 32, 128, 220, 17, $WS_GROUP)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Buttona = GUICtrlCreateButton("&OK", 120, 200, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg3 = GUIGetMsg()
Switch $nMsg3
Case $GUI_EVENT_CLOSE
GUIDelete($Form3)
ExitLoop
Case $Labelc ; Opens the AutoIt website
ShellExecute("http://www.autoitscript.com")
Case $Buttona ; Exit the About dialog box
GUIDelete($Form3)
ExitLoop
EndSwitch
WEnd
EndFunc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;; Written by abberration ;;;;;;
;;;;;    Aug 3, 2012     ;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Edited by abberration
1 person likes this

RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites



A nice useful little tool to. Thanks


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

This is awesome, Brilliant. How can I write this in HTML or PHP or use it on my website.

Edited by isaa2k2

Share this post


Link to post
Share on other sites

this is pretty cool tool!

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0