Spalte aus einer CSV Datei ermitteln

  • Hallo erst mal...

    Ich versuche mich gerade etwas an Autoit.Gerne würde ich mit Autoit die CPU Temperatur auslesen.Hab mich durch einige Beitrag/Foren durch gelesen und hab festgestellt... so einfach geht es wohl nicht.

    Bin jetzt auf das Programm CoreTemp gestoßen, was eine CSV Log Datei anlegt.Da würde ich jetzt gerne ein paar Daten auslesen.

    Klappt auch alles soweit, nur wenn ich mit dem Script an mein Notebook gehe, ließt es nicht mehr die High Temp aus.Da die CSV Log Datei, die CoreTemp anlegt sich geändert hat.

    Starten man CoreTemp auf einem anderem System mit einer CPU der mehr oder weniger Kerne hat, ändert sich die Zeile im CSV File.

    Die Reihe kann ich mit ArraySearch ermitteln, wie kann ich aber die Zeile ermitteln?

    Spoiler anzeigen
    [autoit]

    #include <array.au3>
    ; Automatisches Erkennen der *.CSV datei in @ScriptDir&\coreTemp64\
    $FileFind = FileFindFirstFile("coreTemp64\ct-log*.csv")
    If @error > 0 Then
    ConsoleWrite("FileFindFirstFile Error: Fehler beim suchen der Datei!"&@Crlf)
    Else
    ConsoleWrite("FileFindFirstFile: File gefunden"&@Crlf)
    EndIf
    $Fp = FileFindNextFile($FileFind)
    If @error = 1 Then
    ConsoleWrite("FileFindNextFile Error: Fehler beim suchen der Datei!"&@Crlf)
    Else
    ConsoleWrite("FileFindNextFile: "&$Fp&" weiter geleitet"&@crlf)
    EndIf
    Local $sAdr = @ScriptDir&"\coretemp64\"
    Local $h = FileOpen($sAdr&$Fp, 0)
    ConsoleWrite("FileOpen "&$h&@CRLF&@CRLF)
    Local $aRet = _CSV2Array($h, ",", True, 1)
    ConsoleWrite($aRet&@CRLF)
    FileClose($h)
    ;**********ENDE********* Automatisches Erkennen der *.CSV datei
    ;~ _ArrayDisplay($aRet)
    ;Sucht nach der Reihe
    $Find0=_ArraySearch($aRet,"Processor",0,0,0,1,1)
    ConsoleWrite("Processor gefunden in Reihe "&$Find0&@CRLF)
    $Find1=_ArraySearch($aRet,"Revision",0,0,0,1,1)
    ConsoleWrite("Revision gefunden in Reihe "&$Find1&@CRLF)
    $Find2=_ArraySearch($aRet,"Lithography",0,0,0,1,1)
    ConsoleWrite("Lithography gefunden in Reihe "&$Find2&@CRLF&@CRLF)
    $Find3=_ArraySearch($aRet,"Core 0 temp.",0,0,0,1,1)
    ConsoleWrite("Core 0 Temp. gefunden in Reihe "&$Find3&@CRLF)
    $Find4=_ArraySearch($aRet,"High temp.",0,0,0,1,1) ;hier findet man zwar die Reihe, aber wie kann ich die Zeile ermitteln?
    ConsoleWrite("High Temp. gefunden in Reihe "&$Find4&@CRLF&@CRLF)
    for $i =0 To Ubound($aRet)-1
    For $k = 0 To UBound($aRet,2)-1
    $test0 = ($aRet[$find0][1]); find0 - find2 stehten immer in der selben Zeile
    $test1 = ($aRet[$find1][1])
    $test2 = ($aRet[$find2][1])
    $test3 = ($aRet[$i][1])
    $test4 = ($aRet[$i][6]) ;die High Temp steht je nachdem wie viele Cores die Cpu hat, in unterschiedlichen Zeilen
    Next
    Next
    MsgBox(0,"CoreTemp","CPU: "&$test0&@CRLF&"Revision: "&$test1&@CRLF&"Lithography: "&$test2&@CRLF&"CPU Temp: "&$test3&" °C"&@CRLF&"CPU High Temp: "&$test4&" °C"&@CRLF)
    ;~ ConsoleWrite("CPU: "&$test0&@CRLF&"Revision: "&$test1&@CRLF&"Lithography: "&$test2&@CRLF&@CRLF)

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ===================================================================
    ; Name ..........: _CSV2Array
    ; Description ...:
    ; AutoIt Version : V3.3.0.0
    ; Syntax ........: _CSV2Array($hFile[, $cSeperator = "auto"[, $bFilterString = True[, $iColumnMode = 0]]])
    ; Parameter(s): .: $hFile - Handle for the CSV file to Read
    ; $cSeperator - Optional: (Default = "auto") : Tries to find the separator char ;) or , or TAB or | or space)
    ; | Data-seperator-char
    ; | Empty-string = Opt("GUIDataSeparatorChar")
    ; $bFilterString - Optional: (Default = True) : Removes leading and trailing " or '
    ; $iColumnMode - Optional: (Default = 0) :
    ; | 0: Sets error if lines have different columns and @extended to the csv-line number
    ; | 1: returns lines with different columns numbers comparing to the first line, too
    ; | 2: removing all columns > column numbers in the first line
    ; Return Value ..: Success - 2-dim Array
    ; Failure - 0
    ; @ERROR - 1: error file read
    ; @ERROR - 2: different number of columns / @EXTENDED = CSV-line
    ; - 3: parameter error
    ; Author(s) .....: Thorsten Willert
    ; Date ..........: Mon Dec 07 18:54:35 CET 2009
    ; ==============================================================================
    Func _CSV2Array($hFile, $cSeperator = "auto", $bFilterString = True, $iColumnMode = 0)
    Local $s = FileRead($hFile)
    If @error Then Return SetError(1)
    If $cSeperator = Default Then $cSeperator = "auto"
    If Not $cSeperator Then $cSeperator = Opt("GUIDataSeparatorChar")
    ; searching the line-seperator and splitting the lines into an array
    Local $aLines
    If StringInStr($s, @CRLF) Then
    $aLines = StringSplit($s, @CRLF, 1)
    ElseIf StringInStr($s, @CR) Then
    $aLines = StringSplit($s, @CR)
    Else
    $aLines = StringSplit($s, @LF)
    EndIf
    ; searching the delimiter in the first line
    Local $aTMP
    If $cSeperator = "auto" Then
    Local $iMax = 0
    Local $iC[5] = [0, 0, 0, 0, 0]
    Local $sC[5] = [";", ",", @TAB, "|", " "]
    $aTMP = StringRegExp($aLines[1], ";", 3)
    If Not @error Then $iC[0] = UBound($aTMP)
    $aTMP = StringRegExp($aLines[1], ",", 3)
    If Not @error Then $iC[1] = UBound($aTMP)
    $aTMP = StringRegExp($aLines[1], "\t", 3)
    If Not @error Then $iC[2] = UBound($aTMP)
    $aTMP = StringRegExp($aLines[1], "\|", 3)
    If Not @error Then $iC[3] = UBound($aTMP)
    $aTMP = StringRegExp($aLines[1], "[ ]", 3)
    If Not @error Then $iC[4] = UBound($aTMP)
    For $i = 0 To UBound($sC) - 1
    If $iC[$i] > $iMax Then
    $iMax = $iC[$i]
    $cSeperator = $sC[$i]
    EndIf
    Next
    EndIf
    ; creating 2-dim array based on the number of data in the first line
    $aTMP = StringSplit($aLines[5], $cSeperator)
    Local $iCol = $aTMP[0]
    Local $aRet[$aLines[0]][$iCol]
    ; splitting and filling the lines
    For $i = 1 To $aLines[0]
    $aTMP = StringSplit($aLines[$i], $cSeperator)
    If @error Then ContinueLoop
    If $aTMP[0] > $iCol Then
    Switch $iColumnMode
    Case 0
    Return SetError(2, $i)
    Case 1
    ReDim $aRet[$aLines[0] - 1][$aTMP[0]]
    Case 2
    $aTMP[0] = $iCol
    Case Else
    Return SetError(3)
    EndSwitch
    EndIf
    For $j = 1 To $aTMP[0]
    $aTMP[$j] = StringStripWS($aTMP[$j], 3)
    If $bFilterString Then ; removing leading and trailing " or '
    $aTMP[$j] = StringRegExpReplace($aTMP[$j], '^("|'')(.*?)\1$', '$2')
    EndIf
    $aRet[$i - 1][$j - 1] = $aTMP[$j]
    Next ; /cols
    Next ; /lines
    Return $aRet
    EndFunc ;==>_CSV2Array

    [/autoit]

    Einmal editiert, zuletzt von Ironman (4. Januar 2012 um 12:14)

  • Du kannst auch die GetCoreTempInfo.dll anzapfen, wenn Core Temp läuft!

    Spoiler anzeigen
    [autoit]


    #cs
    Shared memory implementation in Core Temp:

    [/autoit] [autoit][/autoit] [autoit]

    Core Temp shares the following structure:

    [/autoit] [autoit][/autoit] [autoit]

    typedef struct core_temp_shared_data
    {
    unsigned int uiLoad[256];
    unsigned int uiTjMax[128];
    unsigned int uiCoreCnt;
    unsigned int uiCPUCnt;
    float fTemp[256];
    float fVID;
    float fCPUSpeed;
    float fFSBSpeed;
    float fMultipier;
    char sCPUName[100];
    unsigned char ucFahrenheit;
    unsigned char ucDeltaToTjMax;
    }CORE_TEMP_SHARED_DATA,*PCORE_TEMP_SHARED_DATA,**PPCORE_TEMP_SHARED_DATA;

    [/autoit] [autoit][/autoit] [autoit]

    unsigned int is a 32bit unsigned integer.
    unsigned char is 8bit (1 byte) in size.

    [/autoit] [autoit][/autoit] [autoit]

    ucFahrenheit and ucDeltaToTjMax represent boolean values. 0 = false, 1 = true.
    If ucFahrenheit is set, the temperature is reported in Fahrenheit.
    If ucDeltaToTjMax is set, the temperature reported respresents the distance from TjMax.

    [/autoit] [autoit][/autoit] [autoit]

    Core Temp's shared area is named: "CoreTempMappingObject".

    [/autoit] [autoit][/autoit] [autoit]

    C++ Dynamic Link Library:

    [/autoit] [autoit][/autoit] [autoit]

    This DLL was written in C++, and it can be easily used with most programming languages.
    There is only a single function. Here is the internal function declaration:

    [/autoit] [autoit][/autoit] [autoit]

    bool __declspec(dllimport) fnGetCoreTempInfo(CORE_TEMP_SHARED_DATA *&pData);

    [/autoit] [autoit][/autoit] [autoit]

    You can declare it in your program in the following manner:

    [/autoit] [autoit][/autoit] [autoit]

    typedef bool (*fnGetCoreTempInfo)(CORE_TEMP_SHARED_DATA *&pData);
    fnGetCoreTempInfo GetCoreTempInfo;

    [/autoit] [autoit][/autoit] [autoit]

    For compatibility with some programming languages a function was added.
    It uses Win32 API calling convention and is declared as follows:

    [/autoit] [autoit][/autoit] [autoit]

    bool WINAPI fnGetCoreTempInfoAlt(CORE_TEMP_SHARED_DATA *pData);

    [/autoit] [autoit][/autoit] [autoit]

    typedef bool (*fnGetCoreTempInfoAlt)(CORE_TEMP_SHARED_DATA *pData);
    fnGetCoreTempInfoAlt GetCoreTempInfo;

    [/autoit] [autoit][/autoit] [autoit]

    Usage:

    [/autoit] [autoit][/autoit] [autoit]

    * Declare a pointer to CORE_TEMP_SHARED_DATA structure and allocate it.
    It is also recommended to fill the allocated memory with NULL to avoid possible problems.
    * Call the function using the pointer to CORE_TEMP_SHARED_DATA structure as an argument.
    The function will fill the structure if the shared memory was successfully read.
    * The function returns 'true' if succeeded and 'false' if it failed. You can use GetLastError() in case the function fails.
    * In case the function fails due to an exception GetLastError() returns UNKNOWN_EXCEPTION (0x20000000)
    #ce
    #AutoIt3Wrapper_Run_Obfuscator=y
    #Obfuscator_Parameters=/sf /sv /om /cs=0 /cn=0
    #AutoIt3Wrapper_UseUpx=n
    #AutoIt3Wrapper_Run_After=upx.exe --ultra-brute "%out%"
    #AutoIt3Wrapper_Run_After=del /f /q GetCoreTempInfo_Obfuscated.au3

    [/autoit] [autoit][/autoit] [autoit]

    If Not FileExists(@ScriptDir & "\GetCoreTempInfo.dll") Or Not ProcessExists("Core Temp.exe") Then
    MsgBox(16,"Error", "Core Temp.exe läuft und/oder GetCoreTempInfo.dll existiert nicht", 20)
    Exit
    EndIf
    $dll = DllOpen(@ScriptDir & "\GetCoreTempInfo.dll")

    [/autoit] [autoit][/autoit] [autoit]

    $CORE_TEMP_SHARED_DATA = DllStructCreate("uint uiLoad[256];" & _
    "uint uiTjMax[128];" & _
    "uint uiCoreCnt;" & _
    "uint uiCPUCnt;" & _
    "float fTemp[256];" & _
    "float fVID;" & _
    "float fCPUSpeed;" & _
    "float fFSBSpeed;" & _
    "float fMultipier;" & _
    "char sCPUName[100];" & _
    "ubyte ucFahrenheit;" & _
    "ubyte ucDeltaToTjMax")

    [/autoit] [autoit][/autoit] [autoit]

    $call = DllCall($dll, "int", "fnGetCoreTempInfoAlt", "ptr", DllStructGetPtr($CORE_TEMP_SHARED_DATA))

    [/autoit] [autoit][/autoit] [autoit]

    $CPU_Name = DllStructGetData($CORE_TEMP_SHARED_DATA, "sCPUName")
    $CPU_Speed = Round(DllStructGetData($CORE_TEMP_SHARED_DATA, "fCPUSpeed"),0)
    $CPU_Cores = DllStructGetData($CORE_TEMP_SHARED_DATA, "uiCoreCnt")
    $CPU_FSB_Speed = Round(DllStructGetData($CORE_TEMP_SHARED_DATA, "fFSBSpeed"), 0)
    $CPU_Multiplicator = DllStructGetData($CORE_TEMP_SHARED_DATA, "fMultipier")
    $CPU_Temp = ""
    For $i = 1 To DllStructGetData($CORE_TEMP_SHARED_DATA, 'uiCoreCnt')
    $CPU_Temp &= DllStructGetData($CORE_TEMP_SHARED_DATA, "fTemp", $i) & ","
    Next
    $CPU_Temp = StringMid($CPU_Temp, 1 , StringLen($CPU_Temp) - 1)

    [/autoit] [autoit][/autoit] [autoit]

    MsgBox(0,"Core Temp", _
    "CPU Name: " & $CPU_Name & @CRLF & _
    "CPU Speed: " & $CPU_Speed & " MHz" & @CRLF & _
    "CPU Cores: " & $CPU_Cores & @CRLF & _
    "CPU FSB Speed: " & $CPU_FSB_Speed & " MHz" & @CRLF & _
    "CPU Multiplicator: " & $CPU_Multiplicator & @CRLF & _
    "CPU Temp: " & $CPU_Temp & " C", 30)

    [/autoit] [autoit][/autoit] [autoit]

    $CORE_TEMP_SHARED_DATA = 0
    DllClose($dll)

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • Hilft dir das weiter:

    [autoit]


    #include <Array.au3>
    $CPUTemp_Log = FileRead("CT-Log 2011-12-27 12-10-50.csv")
    $aCPUTemp_Log = StringRegExp($CPUTemp_Log, "(\d+:\d+:\d+\s\d+/\d+/\d+),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),(.*),", 4)
    $Anzahl_Messungen = UBound($aCPUTemp_Log)

    [/autoit][autoit][/autoit][autoit]

    ;alle Messungen anzeigen
    For $i = 0 To $Anzahl_Messungen - 1
    _ArrayDisplay($aCPUTemp_Log[$i])
    Next

    [/autoit][autoit][/autoit][autoit]

    ;Core Load % der 8. Messung in Spalte 13 anzeigen
    $aTemp = $aCPUTemp_Log[8]
    MsgBox(0, "Test", "Core Load % der 8. Messung: " & $aTemp[13] & " %")

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

  • wenn die log nicht zu groß ist, kannst du diese auch komplett in ein array einlesen!

    [autoit]


    $sFile = "c:\....\name.csv"
    If Not _FileReadToArray($sFile, $aArray) Then
    MsgBox(4096,"Error", " Error reading log to Array error:" & @error,1)
    Exit
    EndIf

    [/autoit][autoit][/autoit][autoit]

    ;_ArrayDisplay($aArray)

    [/autoit][autoit][/autoit][autoit]

    For $i = 1 To $aArray[0] -1

    [/autoit][autoit][/autoit][autoit]

    $wert = StringSplit ($aArray[$i],";")
    ;MsgBox(0,"", $wert[6])
    Next

    [/autoit][autoit][/autoit][autoit][/autoit]

    gruß gmmg