我有一列“ Fault”(故障)-從各種設備中提取故障代碼。 下面給出了某一天的故障代碼之一。
“逆變器逆變器20低於限制:0.96千瓦/逆變器(1.63千瓦的58.9%)在11/30/2019 7:30:00 AM(星期日:123.4 el:3.7)持續時間:4.00小時逆變器逆變器23低於限制:0.95千瓦/逆變器(1.63千瓦的57.9%)在11/30/2019 7:30:00 AM(太陽:123.4埃爾:3.7)持續時間:3.50小時“
我需要以以下格式提取詳細信息-列名稱:值
逆變器:20
低於限制(kW /逆變器):0.96
最大百分比:58.9%
日期11/30/2019
時間:7:30:00 AM
太陽角:123.4
海拔:3.7
持續時間(小時):4
如果第二台逆變器也有故障代碼(請參見上面故障代碼的第二行)
逆變器:23
低於限制(kW /逆變器):0.95
最大百分比:57.9%
日期11/30/2019
時間:7:30:00 AM
太陽角:123.4
海拔:3.7
持續時間(小時):3.50
有時可能有5或10個逆變器(共70個),它們可以在一行中給出相似的代碼。
你能告訴我如何完成這項工作嗎? 僅通過JSL嗎?還是可以使用公式? 無論哪種方式-我都需要幫助。
您應該可以使用公式編輯器在此方面取得很多進展-看一下WORD函數
戴夫
是的,如果我只有1或2個故障逆變器,那我可以,但是例如,如果我在同一行的一行中有23個故障代碼,那麼我需要分別創建這麼多列,然後為每個23個逆變器。 您能說明我是否了解您的解決方案。我還添加了另一行,總結了提取後分析的目標。
我不得不多次處理這樣的數據。我認為必須採取的方法是將所有數據從輸入文件中讀取到JMP數據表中,在該表中,每一行都被讀入單個列中。您將得到一個只有一列的數據表,並且行數等於輸入數據表中的行數。
接下來,您將創建一個包含3列的新表,標籤,值和行。然後,使用掃描一列中每一行內容的JSL,在新表中創建新行,並填充Label(即Inverter,低於限制(KW / Inverter)等),Value(即20)。 ,0.96等)和Line(行),它們只是當前行號..... Row()。可能還必須有一個附加的輸出列,該列基於該線路上的第一台逆變器或第二台逆變器.... etc。
可以使用While()函數結合Word()函數掃描“:”作為定界符來完成此操作。奇數編號的單詞將是標籤,偶數編號的將是值。
創建此新表後,您可以使用Tables => Split輕鬆地將每個逆變器移至一行。
吉姆
謝謝您的建議。 我會嘗試。 因為我是腳本新手,所以我將通過示例來弄清楚。
我有一些空閒時間...與Covid-19仍然沒有其他關係,因此我寫了一些JSL,應該為您提供一個良好的入門,以讀取數據
Names Default To Here( 1 );
dt = Open(
"Path to the data file",
columns( New Column( "c000001", Character, "Nominal" ) ),
Import Settings(
End Of Line( CRLF, CR, LF ),
End Of Field( CSV( 0 ) ),
Strip Quotes( 1 ),
Use Apostrophe as Quotation Mark( 0 ),
Use Regional Settings( 0 ),
Scan Whole File( 1 ),
Treat empty columns as numeric( 0 ),
CompressNumericColumns( 0 ),
CompressCharacterColumns( 0 ),
CompressAllowListCheck( 0 ),
Labels( 0 ),
Column Names Start( 1 ),
Data Starts( 1 ),
Lines To Read( "All" ),
Year Rule( "20xx" )
)
);
// Create the new output data table
dtLong = New Table( "Long Data",
New Column( "Label", character ),
New Column( "Value", character ),
New Column( "Line" ),
New Column( "Instance" )
);
// A function that returns the next word in the line and
// then removes the word from the front of the target line
getWord = Function( {},
theWord = Trim( Word( 1, target, " " ) );
target = Trim( Substr( target, Length( theWord ) + 1 ) );
theWord;
);
// Loop through all rows in the input data table
For( i = 1, i <= N Rows( dt ), i++,
instance = 0;
target = Column( dt, 1 )[i];
While( Word( 1, target, " " ) != "",
dtLong << add rows( 1 );
dtLong:line[N Rows( dtLong )] = i;
theWord = getWord();
Match( theWord,
"inverter",
instance++;
dtLong:Instance[N Rows( dtLong )] = instance;
dtLong:Label[N Rows( dtLong )] = theWord;
theWord = getWord();
theWord = getword();
dtLong:value[N Rows( dtLong )] = theWord;,
"below",
dtLong:Instance[N Rows( dtLong )] = instance;
dtLong:Label[N Rows( dtLong )] = theWord || " limit (KW/Inverter)";
theWord = getWord();
theWord = getWord();
dtLong:value[N Rows( dtLong )] = theWord;
// Get the % of Max
dtLong << Add Rows( 1 );
dtLong:line[N Rows( dtLong )] = i;
dtLong:Instance[N Rows( dtLong )] = instance;
theWord = getWord();
theWord = getWord();
dtLong:Label[N Rows( dtLong )] = "% of Max";
dtLong:value[N Rows( dtLong )] = Substr( theWord, 2 );
// Skip forward to the Date
For( k = 1, k <= 5, k++,
theWord = getWord()
);
// Get the Date
dtLong << add rows( 1 );
theWord = getWord();
dtLong:Instance[N Rows( dtLong )] = instance;
dtLong:line[N Rows( dtLong )] = i;
dtLong:Label[N Rows( dtLong )] = "Date";
dtLong:value[N Rows( dtLong )] = theWord;
// Get the Time
dtLong << add rows( 1 );
theWord = getWord();
dtLong:Instance[N Rows( dtLong )] = instance;
dtLong:line[N Rows( dtLong )] = i;
dtLong:Label[N Rows( dtLong )] = "Time";
dtLong:value[N Rows( dtLong )] = theWord || getWord();
// Get the Sun Az
dtLong << add rows( 1 );
theWord = getWord();
dtLong:Instance[N Rows( dtLong )] = instance;
dtLong:line[N Rows( dtLong )] = i;
dtLong:Label[N Rows( dtLong )] = Substr( theWord, 2 ) || " " || getWord();
dtLong:value[N Rows( dtLong )] = getWord();
// Get the Elevation
dtLong << add rows( 1 );
theWord = getWord();
dtLong:Instance[N Rows( dtLong )] = instance;
dtLong:line[N Rows( dtLong )] = i;
dtLong:Label[N Rows( dtLong )] = "Elevation";
dtLong:value[N Rows( dtLong )] = Word( -1, getWord(), ")" );,
"Duration:",
dtLong:Instance[N Rows( dtLong )] = instance;
dtLong:Label[N Rows( dtLong )] = theWord || " (hrs)";
dtLong:value[N Rows( dtLong )] = getWord();
theWord = getWord();
)
;
);
);驚人的! 它的工作原理。感謝您耐心編寫此長代碼以完成我的請求。 我正在嘗試將其實現到我擁有的其他Alert代碼。非常感謝。它為我節省了很多時間。