Javascript 优化的EmEditor宏到元素拆分、排序、从最早日期到最长日期,&;摘录

Javascript 优化的EmEditor宏到元素拆分、排序、从最早日期到最长日期,&;摘录,javascript,regex,performance,emeditor,Javascript,Regex,Performance,Emeditor,我目前有一个这种格式的分离文件(2列选项卡“\t”分离),和“;”分离列中的所有元素) 我想了解有关优化宏(理想情况下为javascript)的任何想法,以创建以下输出文件: User\tEarliest\tLatest\tDates_with_Most_Occurences\tMost_Occurence_Number Alice Cooper\t21/11/2018\t07/11/2019\t26/11/2018;07/12/2018\t2 John Smith\

我目前有一个这种格式的分离文件(2列选项卡“\t”分离),和“;”分离列中的所有元素)

我想了解有关优化宏(理想情况下为javascript)的任何想法,以创建以下输出文件:

    User\tEarliest\tLatest\tDates_with_Most_Occurences\tMost_Occurence_Number

    Alice Cooper\t21/11/2018\t07/11/2019\t26/11/2018;07/12/2018\t2

    John Smith\t04/12/2018\t07/11/2019\t09/12/2018\t1

因此,中间步骤(我目前正在手动执行,但希望进入宏):

步骤1:在第1列中分离出Name元素

(给出类似这样的信息):


步骤2:将Col1 A-Z和col2从最旧到最新排序。现在,在第1列的基础上合并第2列元素(如下所示):


步骤3:现在为每一行获取Col2中的日期信息,并创建以下4个新列:EarliestDate、LatestDate、Dates\u with\u Most\u occurrence、Most\u occurrence\u Number(给出如下内容):


步骤4:删除Col2(日期):给出最终输出:

    User\tEarliestDate\tLatestDate\tDates_with_Most_Occurences\tMost_Occurence_Number

    Alice Cooper\t21/11/2018\t07/11/2019\t26/11/2018;07/12/2018\t2

    John Smith\t04/12/2018\t07/11/2019\t09/12/2018\t1

我只需要宏来创建最终输出,中间(上面的步骤1、2、3)只是显示了我尝试执行的逻辑。真正的源文件将有数千行,因此,如果可以以任何方式对其进行EmEditor优化,那就太棒了。

假设数据文件不包含空行,下面是脚本

document.ConvertCsv(2);//这假定您的选项卡格式是CSV/排序栏上的第二种格式
函数解析日期(个){
var split=s.split('/');
返回新日期(拆分[2],拆分[1]-1,拆分[0]);
}
var数据=[];
//读文件
var numberOfLines=document.GetLines();
if(numberOfLines>=2&&document.GetLine(2)=''){
numberOfLines=1;//CSV文档只有标题,没有数据
}
对于(变量行=1;行最常发生次数){
mostOccurrence={date:[k],发生时间:dates[k]}
}else if(日期[k]==最常发生){
最常发生日期推送(k);
}
}
用户[userKey]。MOSTOCCURENCE=[];
对于(var i=0;i

希望它能起作用,但如果不能,请告诉我。

你好,Makoto,谢谢你的回复。我想它需要稍微调整一下。目前,它正在为第一个用户(Alice Cooper)返回此信息:Alice Cooper\t21/11/2018\t7/11/2019\t26/11/2018\t2它应该返回“最频繁发生日期”的所有最大计数日期。因此,对于上面的原始示例,它应该返回这两个日期(按日期顺序),因为它们都发生在2018年11月26日两次;2018年12月7日),例如Alice Cooper\t21/11/2018\t7/11/2019\t26/11/2018;2018年12月7日\t2希望您可以调整。@Venturer我已经编辑了答案,以输出正确的日期和最常见的事件。太棒了。谢谢Makoto-在EmEditor中的大型数据集上运行非常完美,速度非常快!你好Makoto-快速查询。是否可以调整代码,添加最后一列“总计”,显示每个用户每个日期的计数?@Venturer-Sure;我把它贴在这里:
    User\tDate

    Alice Cooper\t07/11/2019

    John Smith\t07/11/2019

    Alice Cooper\t23/11/2018

    Alice Cooper\t21/11/2018

    Alice Cooper\t26/11/2018

    Alice Cooper\t26/11/2018

    Alice Cooper\t09/12/2018

    John Smith\t09/12/2018

    Alice Cooper\t09/12/2018

    John Smith\t09/12/2018

    Alice Cooper\t04/12/2018

    John Smith\t04/12/2018

    Alice Cooper\t07/12/2018

    Alice Cooper\t07/12/2018
    User\tDate


    Alice Cooper\t21/11/2018;23/11/2018;26/11/2018;26/11/2018;04/12/2018;07/12/2018;07/12/2018;09/12/2018;09/12/2018;07/11/2019;

    John Smith\t04/12/2018;09/12/2018;09/12/2018;07/11/2019;
    User\tDate

    Alice Cooper\t21/11/2018;23/11/2018;26/11/2018;26/11/2018;04/12/2018;07/12/2018;07/12/2018;09/12/2018;09/12/2018;07/11/2019;

    John Smith\t04/12/2018;09/12/2018;09/12/2018;07/11/2019;
    User\tEarliestDate\tLatestDate\tDates_with_Most_Occurences\tMost_Occurence_Number

    Alice Cooper\t21/11/2018\t07/11/2019\t26/11/2018;07/12/2018\t2

    John Smith\t04/12/2018\t07/11/2019\t09/12/2018\t1