2013-11-09 62 views
-1

我正在製作一個小程序,用於通過AvayaCMS報告實時告知我當前有多少員工。即使CSV源不爲空,我的腳本仍然返回0

現在,它的設置方式是我有一個Avaya腳本來快速生成報告並將其導出到我的Autoit腳本使用的CSV中。

在調試方面,我覺得我錯過了一些東西,需要另一套眼睛。 啓動Staffing.au3會觸發我用於報告的CSV腳本。即使具有完全相同的數據我的消息框仍然報告 「0」

#include <Array.au3> 
#include <CSV.au3> 
$i_AgentCount = AvayaData(@ScriptDir & '\Report.csv', @ScriptDir & '\Name List.csv') 
MsgBox(0x40, "", $i_AgentCount) 
Func AvayaData($s_ReportSource, $s_NameList) 

$av_LiveData = _ParseCSV($s_ReportSource) 
If @error Then Return -1 

$av_NameList = _ParseCSV($s_NameList) 
If @error Then Return -1 

Local $i_AgentCount = 0 

For $i_RowCnt = 1 To (UBound($av_LiveData, 1) - 1) Step +1 

    For $i_AgtLst = 1 To (UBound($av_NameList) - 1) Step +1 

     If StringStripWS($av_LiveData[$i_RowCnt][1], 3) = StringStripWS($av_NameList[$i_AgtLst][0], 3) Then 

      $i_AgentCount += 1 

     EndIf 

    Next 

Next 

;Return the Agent Count 
Return $i_AgentCount 

EndFunc 

名稱List.csv

Agent Name 
"Doe, Jane" 
"Doe, John" 

Report.csv

,Agent Name,Login ID,Extn,AUX Reason,State,Split/Skill,Time,VDN Name 
5,"Doe, John",5930001,1000001,7,AUXOUT,999,51:32:00, 
2,"Doe, Jane",5930002,1000002,7,AUXOUT,999,52:32:00, 
+0

你想查詢的「名稱List.csv」一個名稱是否在另一個CSV?以及如果發現該怎麼辦? – Xenobiologist

+0

正確,如果名稱在名稱列表中找到,並且也在另一個報告中,它會告訴我發現的名稱目前正在打出。因此,對於匹配的人數,我使用msgbox進行了設置。我發佈的示例報告應該返回2,但不是。 –

+0

您是否嘗試過我發佈的代碼? – Xenobiologist

回答

1

測試!它效果很好與所提供的文件(複製他們,他們的名字在你的腳本)

請注意以下事項

  • _ParseCsv()已被重寫添加類似$ Dchar作爲分隔符等參數(請參閱腳本)
  • 請注意我如何在文件中找到名稱(您可以輕鬆添加功能來擴展搜索,但不會過期)
  • msgboxes僅用於說明目的;註釋出來,如果不再需要它們不需要
  • array.au3

,代碼:

$i_AgentCount = AvayaData(@ScriptDir & '\Report.csv', @ScriptDir & '\Name List.csv') 
MsgBox(0x40, "", $i_AgentCount) 
Func AvayaData($s_ReportSource, $s_NameList) 


$av_LiveData = _ParseCSV($s_ReportSource,",","oops...",True) 
If @error Then Return -1 

$av_NameList = _ParseCSV($s_NameList,",","oops: 2",True) 
If @error Then Return -1 

MsgBox(0,default,"$av_NameList (Number of lines) -> " & $av_NameList[0][0]) 
MsgBox(0,default,"$av_NameList (Number of data in each line) -> " & $av_NameList[0][1]) 

    MsgBox(0,default,"$av_LiveData (Number of lines) -> " & $av_LiveData[0][0]) 
MsgBox(0,default,"$av_LiveData (Number of data in each line) -> " & $av_LiveData[0][1]) 

    Local $i_AgentCount = 0 
for $i = 1 to $av_NameList[0][0] Step 1 


For $j= 1 To $av_LiveData[0][0] Step 1 

    ;we can have names from $av_NameList as well from $av_LiveData but in Live Data 2nd abd 3rd values are the names 
    MsgBox(0,default,$av_NameList[$i][1] & $av_NameList[$i][2] & " <------------> " & $av_LiveData[$j][2] & $av_LiveData[$j][3]) 

    ;~ let's compare them if matched with any of the liveData lines 
    If StringCompare($av_NameList[$i][1] & $av_NameList[$i][2],$av_LiveData[$j][2] & $av_LiveData[$j][3]) == 0 Then 
    $i_AgentCount += 1 
    MsgBox(0,default,"Match found: counter: " & $i_AgentCount) 
    EndIf  
Next 
Next 

;Return the Agent Count 
Return $i_AgentCount 

EndFunc 

Func _ParseCSV($f,$Dchar,$error,$skip) 

    Local $array[500][500] 
    Local $line = "" 

    $i = 0 
    $file = FileOpen($f,0) 
    If $file = -1 Then 
    MsgBox(0, "Error", $error) 
    Return False 
    EndIf 

    ;skip 1st line (since it is the header) 
    If $skip Then $line = FileReadLine($file) 

While 1 
$i = $i + 1 
Local $line = FileReadLine($file) 
If @error = -1 Then ExitLoop 
    ;skip 1st line 
     $row_array = StringSplit($line,$Dchar) 
     If $i == 1 Then $row_size = UBound($row_array) 
     If $row_size <> UBound($row_array) Then MsgBox(0, "Error", "Row: " & $i & " has different size ") 
     $row_size = UBound($row_array) 
     $array = _arrayAdd_2d($array,$i,$row_array,$row_size) 

WEnd 
FileClose($file) 
$array[0][0] = $i-1 ;stores number of lines 
$array[0][1] = $row_size -1 ; stores number of data in a row (data corresponding to index 0 is the number of data in a row actually that's way the -1) 
Return $array 

EndFunc 
Func _arrayAdd_2d($array,$inwhich,$row_array,$row_size) 
    For $i=1 To $row_size -1 Step 1 
    $array[$inwhich][$i] = $row_array[$i] 
Next 
Return $array 
EndFunc 
0
#region ;************ Includes ************ 
#include "csv.au3" 
#include <Array.au3> 
#endregion ;************ Includes ************ 
$i_AgentCount = AvayaData(@ScriptDir & '\Report.csv', @ScriptDir & '\Name List.csv') 
MsgBox(0x40, "", $i_AgentCount) 

Func AvayaData($s_ReportSource, $s_NameList) 
    Local $i_AgentCount = 0 
    Local $s = FileRead($s_NameList) 
    Local $loggedInNames = FileRead($s_ReportSource) 

    $av_NameList = _ParseCSV($s_NameList) 
    If @error Then Return -1 
;~ _ArrayDisplay($av_NameList) 

    ConsoleWrite($s & @CRLF) 

    For $i = 1 To UBound($av_NameList) - 1 
     ConsoleWrite($i & " " & $av_NameList[$i][0] & @CRLF) 
     If StringInStr($s, $av_NameList[$i][0]) <> 0 Then 
      $i_AgentCount += 1 
     EndIf 
    Next 
    Return $i_AgentCount 
EndFunc ;==>AvayaData 
相關問題