如何比较和2数据集相匹配的文件名 [英] How to compare and match documents names with 2 datasets

查看:103
本文介绍了如何比较和2数据集相匹配的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做的PDF文件的批量上传。他们的名字的结构是这样的:

  MM / YYYY AAA BBBB.pdf


  • AAA是3个字母 PipeNameAbreviation

  • BBBB是3个或更多字母/数字 LocationAbbreviation

在plunker你会看到用户将在视图中选择本公司及日期。然后,他们将选择PDF文件。我需要做的是比较 PipeNameAbr 与数据库中的 PipeNameAbr 该文件,然后分配正确的 PipeId &安培; PipeName 到FORMDATA。这将是一个字母数一致; 3。我还需要在做的位置同样的事情,但我需要的 LocationId &安培; LocationAbr 的FORMDATA。所不同的是字母/数字的长度。所以,我需要比较和匹配的缩写的最后4

plunker

  VAR正则表达式= /^\\d+\\D\\d+\\s*?(\\S*)\\s*(\\S*)\\..*$/i;
$ scope.upload =功能(){
    var中的文件= $ scope.files;
    如果(文件和放大器;&安培; files.length){
        对于(VAR I = 0; I< files.length;我++){
            var文件=文件[I]            如果(regex.test(file.name)){
                VAR匹配= file.name.match(正则表达式);                    $ upload.upload({
                    网址:'/ API / apiBatchPipeLine',
                    字段:{                        TYPEID:1,
                        companyId':$ scope.companyId.CompanyId,
                        documentDate':$ scope.model.documentDate,
                        pipeId':$ scope.PipeId,
                        pipeName':$ scope.PipeName,
                        locationId':$ scope.LocationId,
                        locationAb':$ scope.LocationAb
                    },
                    文件:文件
                })。进度(功能(EVT){
                    VAR progressPercentage = parseInt函数(100.0 * evt.loaded / evt.total);
                    的console.log('进步:'+ progressPercentage +'%'+ evt.config.file.name);
                })。成功(功能(数据,状态,头,配置){
                    的console.log('文件'+ config.file.name +'上传响应:'+
                                JSON.stringify(数据));
                })错误(功能(错了,结果){
                    的console.log(ERR,结果);
                });            }        }
    }
};

JSON

  $ scope.pipes = [{的$ id:1,PipeId:1,PipeAb:ANR,PipeName:横加ANR管道,文档:空},{$标识:2,PipeId:2,PipeAb:CGT,PipeName:哥海湾传输,文档:空} {$标识:3,PipeId:3,PipeAb:CHA,PipeName:企业的渠道管道,文档:空},{$标识:4 PipeId:4,PipeAb:FGT,PipeName:能量转移佛罗里达州的天然气输送,文档:空},{$标识:5,PipeId:5, PipeAb:GAB,PipeName:安桥花园银行管道,文档:空},{$标识:6,PipeId:6,PipeAb:GLO PipeName:美国的中游凯莱管道,文档:空},{$标识:7,PipeId:7,PipeAb:GSO,PipeName:海滨湾南管道,文档:空},{$标识:8,PipeId:8,PipeAb:HIO,PipeName:企业高岛海上系统,文档:空},{$标识:9,PipeId:9,PipeAb:HIP,PipeName:美国的中游高点管道,文档:空},{的$ id :10,PipeId:10,PipeAb:HPL,PipeName:能量转移休斯顿管道,文档:空},{$标识:11,PipeId :11,PipeAb:TEJ,PipeName:金德 - 摩根Tejas的管道,文档:空},{$标识:12,PipeId:12,PipeAb: KIN,PipeName:Kinetica伙伴管道,文档:空},{的$ id:13,PipeId:13,PipeAb:NGP,PipeName:金德 - 摩根天然气管道,文档:空},{$标识:14,PipeId:14,PipeAb:SER,PipeName:能量转移海上罗宾管道公司 ,文档:空},{$标识:15,PipeId:15,PipeAb:SNT,PipeName:金德 - 摩根南方天然气公司,文档:空},{$标识:16,PipeId:16,PipeAb:SRY,PipeName:MCPO黄貂鱼管道公司,文档:空},{$标识: 17,PipeId:17,PipeAb:TGT,PipeName:金德 - 摩根田纳西州的天然气管道,文档:空},{$标识:18,PipeId :18,PipeAb:TET,PipeName:光谱能量德州东方管道,文档:空},{$标识:19,PipeId:19,PipeAb: TXG,PipeName:浮桥德克萨斯天然气输送,文档:空},{$标识:20,PipeId:20,PipeAb:TSC,PipeName: 威廉姆斯横贯大陆的天然气管道,文档:空},{$标识:21,PipeId:21,PipeAb:修订,PipeName:能量转移干线煤气公司 文档:空},{$标识:22,PipeId:22,PipeAb:VGS,PipeName:的Targa威尼斯采集系统,文档:空}];

JSON

  $ scope.locations = [{的$ id:1,LocationId:1,LocationAb:BS32,LOCATIONNAME:BravoSam 32 ,文档:空},{$标识:2,LocationId:2,LocationAb:MP46,LOCATIONNAME:MikePier 46,文档:空},{ $ ID:3,LocationId:3,LocationAb:MP140,LOCATIONNAME:MikePier 140,文档:空},{$标识:4,LocationId :4,LocationAb:VR16,LOCATIONNAME:VectorRoland 16,文档:空},{的$ id:5,LocationId:5,LocationAb:AP96 ,LOCATIONNAME:AlphaPass 96,文档:空},{的$ id:6,LocationId:6,LocationAb:DZ26,LOCATIONNAME:DeltaZulu 26 ,文档:空},{$标识:7,LocationId:7,LocationAb:SV963,LOCATIONNAME:SandmanViper 963,文档:空}];

我附上了什么我目前在看什么我现在截图。

我使用的测试的PDF文件被命名为


  

02-2015 HIP BS32.pdf


  
  

02-2015 HIP MP46.pdf


  
  

02-2015 HIP MP140.pdf


  
  

02-2015 TSC VR16.pdf


我有去除之日起关闭PDF名称和分离管道和位置正则表达式。我相信我会需要遍历文件阵列,但什么样的循环?我会用一个switch语句来比较?我创建了一个plunker从分贝JSON。

在这里更新是工作角版本

  $ scope.upload =功能(){
    var中的文件= $ scope.files;
    如果(文件和放大器;&安培; files.length){
        对于(VAR I = 0; I< files.length;我++){
            var文件=文件[I]            $ scope.pipeLookup = {};
            $ scope.locationLookup = {};            $ scope.pipes.map(功能(PIP){
                $ scope.pipeLookup [画中画['PipeAb'] =点子;
            });
            $ scope.locations.map(功能(LOC){
                $ scope.locationLookup [禄['LocationAb'] =禄;
            });            VAR匹配= file.name.match(/ ^ \\ D + \\ D \\ D + \\ S *(\\ S *)\\ S *(\\ S *)\\ ./我?);                $ scope.pipe = $ scope.pipeLookup [匹配[1];
                $ scope.loc = $ scope.locationLookup [匹配[2];                $ upload.upload({
                    网址:'/ API / apiBatchPipeLine',
                    字段:{                        TYPEID:1,
                        companyId':$ scope.companyId.CompanyId,
                        documentDate':$ scope.model.documentDate,
                        pipeId':$ scope.pipe.PipeId,
                        'pipeName':$ scope.pipe ['PipeName'],
                        '的companyName:$ scope.CompanyName,
                        'locationId':$ scope.loc ['LocationId'],
                        locationAb':$ scope.loc ['LocationAb']
                    },
                    文件:文件
                })。进度(功能(EVT){
                    VAR progressPercentage = parseInt函数(100.0 * evt.loaded / evt.total);
                    的console.log('进步:'+ progressPercentage +'%'+ evt.config.file.name);
                })。成功(功能(数据,状态,头,配置){
                    notificationFactory.success();
                })错误(功能(错了,结果){
                    notificationFactory.error();
                    的console.log(ERR,结果);
                });        }
    }
};


解决方案

如果您有配合缩写将永远是独一无二的,你希望做相当多的仰视。你可以选择用于通过JSON迭代一次并存储在管道/在具有缩写为关键的方法的位置:

  VAR pipeLookup = {};
变种locationLookup = {};$ scope.pipes.map(功能(PIP){
    pipeLookup [PIP ['PipeAb'] =点子;
});
$ scope.locations.map(功能(LOC){
    locationLookup [禄['LocationAb'] =禄;
});

所以在这里我要说,对于 $ scope.pipes 的每一个条目,我想在 pipeLookup 与作为管道的 PipeAb 的整个管道对象。在此之后,这些查找变量基本上包含HashMap,所以你可以很容易地找到与正则表达式匹配的捕获组,像这样的正确的管道:

  VAR的匹配= file.match(/ ^ \\ D + \\ D \\ D + \\ S *?(\\ S *)\\ S *(\\ S *?)\\ ./我) ;
VAR管= pipeLookup [匹配[1];
VAR LOC = locationLookup [匹配[2];

然后,你必须 pipe.PipeId pipe.PipeName loc.LocationId 和任何其他属性在您的处置存在分配给字段属性。的(无论你想使这些 pipeLookup locationLookup 瓦尔的 $作用域属性是由你,我不是非常熟悉AngularJS)

查找演示匹配正确的管道 / 位置属性在$ c分别文件名的精简版下面$ C-片段。的(这样做是不AngularJS为简单起见)

\r
\r

VAR管道= [{的$ id:1,PipeId :1,PipeAb:ANR,PipeName:横加ANR管道,文档:空},{的$ id:2,PipeId:2,PipeAb:CGT ,PipeName:哥海湾传输,文档:空},{$标识:3,PipeId:3,PipeAb:CHA,PipeName:企业频道管道,文档:空},{$标识:4,PipeId:4,PipeAb:FGT,PipeName:能量转移佛罗里达州的天然气输送,文档:空},{$标识:5,PipeId:5,PipeAb:GAB,PipeName:安桥花园银行管道,文档:空},{$ ID 6,PipeId:6,PipeAb:GLO,PipeName:美国的中游凯莱管道,文档:空},{$标识:7,PipeId 7,PipeAb:GSO,PipeName:海滨湾南复线,文档:空},{$标识:8,PipeId:8,PipeAb: HIO,PipeName:企业高岛海上系统,文档:空},{$标识:9,PipeId:9,PipeAb:HIP,PipeName: 美国中游高点管道,文档:空},{$标识:10,PipeId:10,PipeAb:HPL,PipeName:能量转移休斯顿管道 文档:空},{$标识:11,PipeId:11,PipeAb:TEJ,PipeName:金德 - 摩根Tejas的管道,文档:空},{ $标识:12,PipeId:12,PipeAb:KIN,PipeName:Kinetica合作伙伴管道,文档:空},{$标识:13, PipeId:13,PipeAb:NGP,PipeName:金德 - 摩根天然气管道,文档:空},{$标识:14,PipeId:14 PipeAb:SER,PipeName:能量转移海上罗宾管道公司,文档:空},{$标识:15,PipeId:15,PipeAb:SNT PipeName:金德 - 摩根南方天然气公司,文档:空},{$标识:16,PipeId:16,PipeAb:SRY,PipeName: MCPO魟管道公司,文档:空},{$标识:17,PipeId:17,PipeAb:TGT,PipeName:金德 - 摩根田纳西州的天然气管道,文档:空},{$标识:18,PipeId:18,PipeAb:TET,PipeName:光谱能量德州东方管道,文档:空},{ $标识:19,PipeId:19,PipeAb:TXG,PipeName:浮桥德克萨斯天然气输送,文档:空},{$标识:20 PipeId:20,PipeAb:TSC,PipeName:威廉姆斯横贯大陆的天然气管道,文档:空},{$标识:21,PipeId:21 PipeAb:修订,PipeName:能量转移干线煤气公司,文档:空},{$标识:22,PipeId:22,PipeAb:VGS PipeName:威尼斯的Targa采集系统,文档:空}];\r
VAR位置= [{的$ id:1,LocationId:1,LocationAb:BS32,LOCATIONNAME:BravoSam 32,文档:空},{$标识: 2,LocationId:2,LocationAb:MP46,LOCATIONNAME:MikePier 46,文档:空},{的$ id:3,LocationId:3, LocationAb:MP140,LOCATIONNAME:MikePier 140,文档:空},{的$ id:4,LocationId:4,LocationAb:VR16,LOCATIONNAME :VectorRoland 16,文档:空},{$标识:5,LocationId:5,LocationAb:AP96,LOCATIONNAME:AlphaPass 96,文档 :空},{$标识:6,LocationId:6,LocationAb:DZ26,LOCATIONNAME:DeltaZulu 26,文档:空},{$标识: 7,LocationId:7,LocationAb:SV963,LOCATIONNAME:SandmanViper 963,文档:空}];\r
\r
var中的文件= '02 -2015 HIP BS32.pdf','02 -2015 HIP MP46.pdf','02 -2015 HIP MP140.pdf','02 -2015 TSC VR16.pdf'];\r
\r
变种pipeLookup = {};\r
变种locationLookup = {};\r
\r
pipes.map(功能(PIP){\r
  pipeLookup [PIP ['PipeAb'] =点子;\r
});\r
locations.map(功能(LOC){\r
  locationLookup [禄['LocationAb'] =禄;\r
});\r
\r
的document.getElementById('出')。值= files.map(功能(文​​件){\r
  VAR匹配= file.match(/ ^ \\ D + \\ D \\ D + \\ S *(\\ S *)\\ S *(\\ S *)\\ ./我?);\r
  VAR管= pipeLookup [匹配[1];\r
  VAR LOC = locationLookup [匹配[2];\r
  返回文件+'\\ tPipeId:'+管['PipeId'] +\r
            '\\ tLocationId:'+ LOC ['LocationId'] +\r
            '\\ tPipeName:'+管['PipeName'];\r
})加入('\\ n');

\r

< textarea的ID =走出去行=10的风格=宽度:100%>< / textarea的>

\r

\r
\r

另一种方法是通过 $ scope.pipes $ scope.locations 来遍历每个文件。这意味着更少的可读性code和性能下降。

I am trying to do a batch upload of PDFs. Their names are structured like this:

mm/yyyy AAA BBBB.pdf

  • AAA is the 3 letter PipeNameAbreviation
  • BBBB is the 3 or more letters/numbers LocationAbbreviation

In the plunker you will see the user will select the Company and Date in the view. They will then select the PDFs. What I need to do is compare the PipeNameAbr of the file with the PipeNameAbr's in the database and then assign the correct PipeId & PipeName to the formdata. This will be a consistent number of letters, 3. I also need to the do the same thing with the Location, except I need the LocationId & LocationAbr for the formdata. The difference is the length of letters/numbers. So I need to compare and match with the last 4 of the Abbreviation.

plunker

 var regex = /^\d+\D\d+\s*?(\S*)\s*(\S*)\..*$/i;
$scope.upload = function () {
    var files = $scope.files;
    if (files && files.length) {
        for (var i = 0; i < files.length; i++) {
            var file = files[i];

            if (regex.test(file.name)) { 
                var matches = file.name.match(regex);

                    $upload.upload({
                    url: '/api/apiBatchPipeLine',
                    fields: {

                        'typeId': 1,
                        'companyId': $scope.companyId.CompanyId,
                        'documentDate': $scope.model.documentDate,
                        'pipeId': $scope.PipeId,
                        'pipeName': $scope.PipeName,
                        'locationId': $scope.LocationId,
                        'locationAb': $scope.LocationAb
                    },
                    file: file
                }).progress(function (evt) {
                    var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
                    console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name);
                }).success(function (data, status, headers, config) {
                    console.log('file ' + config.file.name + 'uploaded. Response: ' +
                                JSON.stringify(data));
                }).error(function (err, result) {
                    console.log(err, result);
                });

            }

        }
    }
};

JSON

$scope.pipes = [{"$id":"1","PipeId":1,"PipeAb":"ANR","PipeName":"Transcanada ANR Pipeline","Documents":null},{"$id":"2","PipeId":2,"PipeAb":"CGT","PipeName":"Columbia Gulf Transmission","Documents":null},{"$id":"3","PipeId":3,"PipeAb":"CHA","PipeName":"Enterprise Channel Pipeline","Documents":null},{"$id":"4","PipeId":4,"PipeAb":"FGT","PipeName":"Energy Transfer Florida Gas Transmission","Documents":null},{"$id":"5","PipeId":5,"PipeAb":"GAB","PipeName":"Enbridge Garden Banks Pipeline","Documents":null},{"$id":"6","PipeId":6,"PipeAb":"GLO ","PipeName":"American Midstream Gloria  Pipeline","Documents":null},{"$id":"7","PipeId":7,"PipeAb":"GSO","PipeName":"Boardwalk Gulf South Pipeline","Documents":null},{"$id":"8","PipeId":8,"PipeAb":"HIO","PipeName":"Enterprise High Island Offshore System","Documents":null},{"$id":"9","PipeId":9,"PipeAb":"HIP","PipeName":"American Midstream High Point Pipeline","Documents":null},{"$id":"10","PipeId":10,"PipeAb":"HPL","PipeName":"Energy Transfer Houston Pipeline","Documents":null},{"$id":"11","PipeId":11,"PipeAb":"TEJ","PipeName":"Kinder Morgan Tejas Pipeline","Documents":null},{"$id":"12","PipeId":12,"PipeAb":"KIN","PipeName":"Kinetica Partners Pipeline","Documents":null},{"$id":"13","PipeId":13,"PipeAb":"NGP","PipeName":"Kinder Morgan Natural Gas Pipeline","Documents":null},{"$id":"14","PipeId":14,"PipeAb":"SER","PipeName":"Energy Transfer Sea Robin Pipeline Company ","Documents":null},{"$id":"15","PipeId":15,"PipeAb":"SNT","PipeName":"Kinder Morgan Southern Natural Gas Company","Documents":null},{"$id":"16","PipeId":16,"PipeAb":"SRY","PipeName":"MCPO Stingray Pipeline Company","Documents":null},{"$id":"17","PipeId":17,"PipeAb":"TGT","PipeName":"Kinder Morgan Tennessee Gas Pipeline","Documents":null},{"$id":"18","PipeId":18,"PipeAb":"TET","PipeName":"Spectra Energy Texas Eastern Pipeline","Documents":null},{"$id":"19","PipeId":19,"PipeAb":"TXG","PipeName":"Boardwalk Texas Gas Transmission","Documents":null},{"$id":"20","PipeId":20,"PipeAb":"TSC","PipeName":"Williams Transcontinental Gas Pipeline","Documents":null},{"$id":"21","PipeId":21,"PipeAb":"TRK","PipeName":"Energy Transfer Trunkline Gas Company","Documents":null},{"$id":"22","PipeId":22,"PipeAb":"VGS","PipeName":"Targa Venice Gathering System","Documents":null}];

JSON

 $scope.locations = [{"$id":"1","LocationId":1,"LocationAb":"BS32","LocationName":"BravoSam 32","Documents":null},{"$id":"2","LocationId":2,"LocationAb":"MP46","LocationName":"MikePier 46","Documents":null},{"$id":"3","LocationId":3,"LocationAb":"MP140","LocationName":"MikePier 140","Documents":null},{"$id":"4","LocationId":4,"LocationAb":"VR16","LocationName":"VectorRoland 16","Documents":null},{"$id":"5","LocationId":5,"LocationAb":"AP96","LocationName":"AlphaPass 96","Documents":null},{"$id":"6","LocationId":6,"LocationAb":"DZ26","LocationName":"DeltaZulu 26","Documents":null},{"$id":"7","LocationId":7,"LocationAb":"SV963","LocationName":"SandmanViper 963","Documents":null}];

I am attaching a screenshot of what I am currently looking at with what I have right now.

The PDFs I am using for testing are named

02-2015 HIP BS32.pdf

02-2015 HIP MP46.pdf

02-2015 HIP MP140.pdf

02-2015 TSC VR16.pdf

I have a regex that strips the date off the pdf name and separates the Pipe and Location. I believe I would need to loop through the file array but what kind of loop? Would I use a switch statement to compare? I created a plunker with the json from the db.

UPDATE here is the working angular version

$scope.upload = function () {
    var files = $scope.files;
    if (files && files.length) {
        for (var i = 0; i < files.length; i++) {
            var file = files[i];

            $scope.pipeLookup = {};
            $scope.locationLookup = {};

            $scope.pipes.map(function (pip) {
                $scope.pipeLookup[pip['PipeAb']] = pip;
            });
            $scope.locations.map(function (loc) {
                $scope.locationLookup[loc['LocationAb']] = loc;
            });

            var matches = file.name.match(/^\d+\D\d+\s*?(\S*)\s*(\S*?)\./i);

                $scope.pipe = $scope.pipeLookup[matches[1]];
                $scope.loc = $scope.locationLookup[matches[2]];

                $upload.upload({
                    url: '/api/apiBatchPipeLine',
                    fields: {

                        'typeId': 1,
                        'companyId': $scope.companyId.CompanyId,
                        'documentDate': $scope.model.documentDate,
                        'pipeId': $scope.pipe.PipeId,
                        'pipeName': $scope.pipe['PipeName'],
                        'companyName': $scope.CompanyName,
                        'locationId': $scope.loc['LocationId'],
                        'locationAb': $scope.loc['LocationAb']
                    },
                    file: file
                }).progress(function (evt) {
                    var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
                    console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name);
                }).success(function (data, status, headers, config) {
                    notificationFactory.success();
                }).error(function (err, result) {
                    notificationFactory.error();
                    console.log(err, result);
                });

        }
    }
};

解决方案

If the abbreviations you have to match with will always be unique and you expect to do quite a bit of looking up. You could opt for iterating through the JSON once and storing the pipes/locations in a way that has the abbreviation as the key:

var pipeLookup = {};
var locationLookup = {};

$scope.pipes.map(function(pip) {
    pipeLookup[pip['PipeAb']] = pip;
});
$scope.locations.map(function(loc) {
    locationLookup[loc['LocationAb']] = loc;
});

So here I'm saying that for every entry of $scope.pipes, I want an entry in pipeLookup with as key the pipe's PipeAb and as value the entire pipe object. After that, these Lookup variables are essentially hashmaps so you can easily find the correct pipe with the regex match capture groups like so:

var matches = file.match(/^\d+\D\d+\s*?(\S*)\s*(\S*?)\./i);
var pipe = pipeLookup[matches[1]];
var loc = locationLookup[matches[2]];

Then you have pipe.PipeId, pipe.PipeName, loc.LocationId and whatever other properties exist at your disposal to assign to the fields properties. (Whether you wanna make these pipeLookup and locationLookup vars properties of $scope is up to you. I'm not terribly familiar with AngularJS)

Find a stripped down version that demos matching the correct Pipe/Location properties for each filename in the code-snippet below. (did it without AngularJS for simplicity)

var pipes = [{"$id":"1","PipeId":1,"PipeAb":"ANR","PipeName":"Transcanada ANR Pipeline","Documents":null},{"$id":"2","PipeId":2,"PipeAb":"CGT","PipeName":"Columbia Gulf Transmission","Documents":null},{"$id":"3","PipeId":3,"PipeAb":"CHA","PipeName":"Enterprise Channel Pipeline","Documents":null},{"$id":"4","PipeId":4,"PipeAb":"FGT","PipeName":"Energy Transfer Florida Gas Transmission","Documents":null},{"$id":"5","PipeId":5,"PipeAb":"GAB","PipeName":"Enbridge Garden Banks Pipeline","Documents":null},{"$id":"6","PipeId":6,"PipeAb":"GLO ","PipeName":"American Midstream Gloria  Pipeline","Documents":null},{"$id":"7","PipeId":7,"PipeAb":"GSO","PipeName":"Boardwalk Gulf South Pipeline","Documents":null},{"$id":"8","PipeId":8,"PipeAb":"HIO","PipeName":"Enterprise High Island Offshore System","Documents":null},{"$id":"9","PipeId":9,"PipeAb":"HIP","PipeName":"American Midstream High Point Pipeline","Documents":null},{"$id":"10","PipeId":10,"PipeAb":"HPL","PipeName":"Energy Transfer Houston Pipeline","Documents":null},{"$id":"11","PipeId":11,"PipeAb":"TEJ","PipeName":"Kinder Morgan Tejas Pipeline","Documents":null},{"$id":"12","PipeId":12,"PipeAb":"KIN","PipeName":"Kinetica Partners Pipeline","Documents":null},{"$id":"13","PipeId":13,"PipeAb":"NGP","PipeName":"Kinder Morgan Natural Gas Pipeline","Documents":null},{"$id":"14","PipeId":14,"PipeAb":"SER","PipeName":"Energy Transfer Sea Robin Pipeline Company ","Documents":null},{"$id":"15","PipeId":15,"PipeAb":"SNT","PipeName":"Kinder Morgan Southern Natural Gas Company","Documents":null},{"$id":"16","PipeId":16,"PipeAb":"SRY","PipeName":"MCPO Stingray Pipeline Company","Documents":null},{"$id":"17","PipeId":17,"PipeAb":"TGT","PipeName":"Kinder Morgan Tennessee Gas Pipeline","Documents":null},{"$id":"18","PipeId":18,"PipeAb":"TET","PipeName":"Spectra Energy Texas Eastern Pipeline","Documents":null},{"$id":"19","PipeId":19,"PipeAb":"TXG","PipeName":"Boardwalk Texas Gas Transmission","Documents":null},{"$id":"20","PipeId":20,"PipeAb":"TSC","PipeName":"Williams Transcontinental Gas Pipeline","Documents":null},{"$id":"21","PipeId":21,"PipeAb":"TRK","PipeName":"Energy Transfer Trunkline Gas Company","Documents":null},{"$id":"22","PipeId":22,"PipeAb":"VGS","PipeName":"Targa Venice Gathering System","Documents":null}];
var locations = [{"$id":"1","LocationId":1,"LocationAb":"BS32","LocationName":"BravoSam 32","Documents":null},{"$id":"2","LocationId":2,"LocationAb":"MP46","LocationName":"MikePier 46","Documents":null},{"$id":"3","LocationId":3,"LocationAb":"MP140","LocationName":"MikePier 140","Documents":null},{"$id":"4","LocationId":4,"LocationAb":"VR16","LocationName":"VectorRoland 16","Documents":null},{"$id":"5","LocationId":5,"LocationAb":"AP96","LocationName":"AlphaPass 96","Documents":null},{"$id":"6","LocationId":6,"LocationAb":"DZ26","LocationName":"DeltaZulu 26","Documents":null},{"$id":"7","LocationId":7,"LocationAb":"SV963","LocationName":"SandmanViper 963","Documents":null}];

var files = ['02-2015 HIP BS32.pdf', '02-2015 HIP MP46.pdf', '02-2015 HIP MP140.pdf', '02-2015 TSC VR16.pdf'];

var pipeLookup = {};
var locationLookup = {};

pipes.map(function(pip) {
  pipeLookup[pip['PipeAb']] = pip;
});
locations.map(function(loc) {
  locationLookup[loc['LocationAb']] = loc;
});

document.getElementById('out').value = files.map(function(file) {
  var matches = file.match(/^\d+\D\d+\s*?(\S*)\s*(\S*?)\./i);
  var pipe = pipeLookup[matches[1]];
  var loc = locationLookup[matches[2]];
  return file + '\tPipeId: ' + pipe['PipeId'] +
            '\tLocationId: ' + loc['LocationId'] + 
            '\tPipeName: ' + pipe['PipeName'];
}).join('\n');

<textarea id="out" rows="10" style="width:100%"></textarea>

The alternative is to iterate through $scope.pipes and $scope.locations for every file. Which means less readable code and diminished performance.

这篇关于如何比较和2数据集相匹配的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆