2つのTSV文字列, セル一致行の抽出
2つのTSV文字列, セル一致行の抽出 (Two Tsv Strings, Extract Cell-Matched Lines)

TSV文字列Aの特定列とBの特定列を比較し、Aに対してセル合致するBの行を抽出します。AとBが完全に一致する場合は、Bの全行が返されます。全面的に異なる場合は、空文字列が返されます。

2020-01-29 (C) Questetra, Inc. (MIT License)
https://support.questetra.com/ja/addons/two-tsv-strings-extract-cell-matched-lines/

Configs
  • A: TSV文字列をセットしてください * #{EL}
  • A-id: 比較する列のIDをセットしてください * #{EL}
  • B: TSV文字列をセットしてください * #{EL}
  • B-id: 比較する列のIDをセットしてください * #{EL}
  • C: 抽出TSV文字列が格納される文字列型データを選択してください (更新) *
Script
// (c) 2020, Questetra, Inc. (the MIT License)
// Notes:
// Compares cells and extracts lines.
// To extract the customers with whom they have on-going transactions in list A.
// Also for extracting sales records that are registered in product master A.
// Line sorting is NOT required.
// 
// Notes(ja):
// セルを比較し、行を抽出します。
// 前月取引先一覧Aにもリストされた継続取引先を抽出するといったケースに利用できます。
// 商品マスタAに登録されている商品売上レコードを抽出するといったケースにも利用できます。
// 行ソートされている必要はありません。


//////// START "main()" /////////////////////////////////////////////////////////////////
main();
function main(){ 

//// == Config Retrieving / 工程コンフィグの参照 ==
const strA    = configs.get( "conf_StrA" ) + "";     // config required
const idA     = configs.get( "conf_IdA" ) + "";      // config required
const strB    = configs.get( "conf_StrB" ) + "";     // config required
const idB     = configs.get( "conf_IdB" ) + "";      // config required
const dataIdC = configs.get( "conf_DataIdC" ) + "";  // config required

if( strA === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {Str A} is empty \n" );
}
if( strB === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {Str B} is empty \n" );
}

if( idA === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {ID A} is empty \n" );
}
if( idB === "" ){
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config {ID B} is empty \n" );
}
const zeroPositiveInt = /^([1-9]\d*|0)$/; // RegExp
let numIdA = -1;
if( zeroPositiveInt.test( idA ) ){
  numIdA = parseInt(idA, 10);
}else{
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config Number {ID A} must be a positive integer or zero \n" );
}
let numIdB = -1;
if( zeroPositiveInt.test( idB ) ){
  numIdB = parseInt(idB, 10);
}else{
  throw new Error( "\n AutomatedTask ConfigError:" +
                   " Config Number {ID B} must be a positive integer or zero \n" );
}


//// == Data Retrieving / ワークフローデータの参照 ==
// Nothing (except EL-expression Config)


//// == Calculating / 演算 ==
let twoDimArrayA = []; // for TSV-A
const arrStrA = strA.split("\n");
for( let i = 0; i < arrStrA.length; i++ ){
  twoDimArrayA[i] = arrStrA[i].split("\t");
}
let twoDimArrayB = []; // for TSV-B
const arrStrB = strB.split("\n");
for( let i = 0; i < arrStrB.length; i++ ){
  twoDimArrayB[i] = arrStrB[i].split("\t");
}
engine.log( " AutomatedTask MultilineString:" + 
            " TSV {A}, number of lines " + arrStrA.length );
engine.log( " AutomatedTask MultilineString:" + 
            " TSV {B}, number of lines " + arrStrB.length );

let strOutput = "";
for( let i = 0; i < arrStrB.length; i++ ){
  for( let j = 0; j < arrStrA.length; j++ ){
    if( twoDimArrayB[i][numIdB] === twoDimArrayA[j][numIdA] ){
      engine.log( " AutomatedTask Match:" +
                  " B[" + i + "][" + numIdB + "] ==" +
                  " A[" + j + "][" + numIdA + "]" );
      strOutput += arrStrB[i] + "\n";
      break;
    }
  }
}
strOutput = strOutput.replace(/[\n]*$/, "");


//// == Data Updating / ワークフローデータへの代入 ==
if( strOutput === "" ){
  engine.log( " AutomatedTask DataUpdating: Output Text empty" );
}
engine.setDataByNumber( dataIdC, strOutput );

} //////// END "main()" /////////////////////////////////////////////////////////////////

Download

Capture

TSV文字列Aの特定列とBの特定列を比較し、Aに対してセル合致するBの行を抽出します。AとBが完全に一致する場合は、Bの全行が返されます。全面的に異なる場合は、空文字列が返されます。

Notes

  • セルを比較し、行を抽出します。
  • 前月取引先一覧Aにもリストされた継続取引先を抽出するといったケースに利用できます。
  • 商品マスタAに登録されている商品売上レコードを抽出するといったケースにも利用できます。
  • 行ソートされている必要はありません。

See also

コメントを残す

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください

%d人のブロガーが「いいね」をつけました。