Java 如何使用不同的长度为CSV中的值分配索引。(爪哇)

Java 如何使用不同的长度为CSV中的值分配索引。(爪哇),java,arrays,csv,arraylist,Java,Arrays,Csv,Arraylist,我正在尝试将两个不同CSV文件中的值与索引对齐。一个CSV每秒有一个unix时间戳,另一个每分钟有一个。此外,我还需要标记不同长度数据的索引 例如,我需要用索引0标记1-20分和1-1200秒,然后用索引1标记21-25分钟1260-1500分,用索引2标记26-42分钟1560-2520分,等等 长度将根据数据的不同而变化,可能是一个数组,它保存了我正在使用的长度的不同值,因此我希望通过编程来实现这一点。我不知道如何解决这个问题。任何帮助都将不胜感激 希望这有助于澄清一些问题 我在一个CSV中

我正在尝试将两个不同CSV文件中的值与索引对齐。一个CSV每秒有一个unix时间戳,另一个每分钟有一个。此外,我还需要标记不同长度数据的索引

例如,我需要用索引0标记1-20分和1-1200秒,然后用索引1标记21-25分钟1260-1500分,用索引2标记26-42分钟1560-2520分,等等

长度将根据数据的不同而变化,可能是一个数组,它保存了我正在使用的长度的不同值,因此我希望通过编程来实现这一点。我不知道如何解决这个问题。任何帮助都将不胜感激

希望这有助于澄清一些问题

我在一个CSV中有关于音频的信息,另一个CSV中有关于生物测量数据的信息。它们都有一个带有unix时间戳的列。音频CSV中的数据为每秒,生物测量数据为每分钟

我想在CSV中添加一个具有相同索引键值的额外行,以便数据在两个文件之间具有公共链接。如果调用索引1,我希望从索引为1的两个文件中获取数据

音频文件的长度将决定按键的开始和停止位置。因此,如果我有一个2分钟长的音频文件,bio metric CSV中的2行将具有0键,120行音频CSV将具有0键


如果该音频文件的长度为3分钟,则bio metric CSV的前3行的密钥为0,音频CSV的前180行的密钥为0。

您可以打开这两个文件,请阅读第一行以查看时间戳,然后从具有较早时间戳的文件中读取行,直到不再具有较早时间戳,或结束

如果这是by-minute.csv:

这是by-second.csv:

然后这个Java代码:

import java.io.*;
import java.text.*;
import java.util.*;

public class Foo {

    public static void main(String[] args)
    throws Exception
    {
        BufferedReader byMinute = new BufferedReader(
            new InputStreamReader(
            new FileInputStream("by-minute.csv")));

        BufferedReader bySecond = new BufferedReader(
            new InputStreamReader(
            new FileInputStream("by-second.csv")));

        String byMinuteLine = byMinute.readLine();
        String bySecondLine = bySecond.readLine();

        while (byMinuteLine != null || bySecondLine != null) {

            /* If either file is done, print lines from the other file */
            if (byMinuteLine == null) {
                System.out.println(indicize(bySecondLine));
                bySecondLine = bySecond.readLine();
            } else if (bySecondLine == null) {
                System.out.println(indicize(byMinuteLine));
                byMinuteLine = byMinute.readLine();
            } else {
                /* Otherwise print the earlier entry */
                long minuteTime = getTimeStamp(byMinuteLine);
                long secondTime = getTimeStamp(bySecondLine);

                if (secondTime < minuteTime) {
                    System.out.println(indicize(bySecondLine));
                    bySecondLine = bySecond.readLine();
                } else {
                    System.out.println(indicize(byMinuteLine));
                    byMinuteLine = byMinute.readLine();
                }
            }
        }

    }

    static long getTimeStamp(String line) {
        return Long.valueOf(line.split(",")[0]);
    }

    static String indicize(String line) {
        return ((getTimeStamp(line) - 1394589660) / 20)
            + line.substring(line.indexOf(","));
    }

}

现在我知道这不是你想要的,但我希望这足以让你开始

我不确定人们是否能理解你的想法question@RafaEl我想我只是需要更多coffee@user2310289不,你没有。也许OP是需要帮助的人it@user2310289我真的需要更多的咖啡!我编辑了这篇文章,所以我确信它现在已经一清二楚了。
1394589659,second -1
1394589660,second 0
1394589661,second 1
1394589662,second 2
1394589663,second 3
1394589664,second 4
…
1394589718,second 58
1394589719,second 59
1394589720,second 60
1394589721,second 61
import java.io.*;
import java.text.*;
import java.util.*;

public class Foo {

    public static void main(String[] args)
    throws Exception
    {
        BufferedReader byMinute = new BufferedReader(
            new InputStreamReader(
            new FileInputStream("by-minute.csv")));

        BufferedReader bySecond = new BufferedReader(
            new InputStreamReader(
            new FileInputStream("by-second.csv")));

        String byMinuteLine = byMinute.readLine();
        String bySecondLine = bySecond.readLine();

        while (byMinuteLine != null || bySecondLine != null) {

            /* If either file is done, print lines from the other file */
            if (byMinuteLine == null) {
                System.out.println(indicize(bySecondLine));
                bySecondLine = bySecond.readLine();
            } else if (bySecondLine == null) {
                System.out.println(indicize(byMinuteLine));
                byMinuteLine = byMinute.readLine();
            } else {
                /* Otherwise print the earlier entry */
                long minuteTime = getTimeStamp(byMinuteLine);
                long secondTime = getTimeStamp(bySecondLine);

                if (secondTime < minuteTime) {
                    System.out.println(indicize(bySecondLine));
                    bySecondLine = bySecond.readLine();
                } else {
                    System.out.println(indicize(byMinuteLine));
                    byMinuteLine = byMinute.readLine();
                }
            }
        }

    }

    static long getTimeStamp(String line) {
        return Long.valueOf(line.split(",")[0]);
    }

    static String indicize(String line) {
        return ((getTimeStamp(line) - 1394589660) / 20)
            + line.substring(line.indexOf(","));
    }

}
0,second -1
0,minute 1
0,second 0
0,second 1
0,second 2
0,second 3
0,second 4
0,second 5
0,second 6
0,second 7
0,second 8
0,second 9
…
2,second 55
2,second 56
2,second 57
2,second 58
2,second 59
3,minute 2
3,second 60
3,second 61