Java Code Examples for com.csvreader.CsvReader#get()

The following examples show how to use com.csvreader.CsvReader#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CSVMatrixReaderTest.java    From sailfish-core with Apache License 2.0 6 votes vote down vote up
@Test
public void get() {
    try {
        CsvReader e = new CsvReader("src/test/resources/aml/iomatrix/testcsv.csv");
        e.readRecord();
        String val = e.get(0);
        Assert.assertEquals("1494574053", val);
        String val2 = e.get(100500);
        Assert.assertEquals("", val2);
        String val3 = e.get("SOME_COLUMN");
        Assert.assertEquals("", val3);
        
        System.out.println("finished");
        
    } catch (Exception ex) {
        fail(ex.getMessage());
    }
}
 
Example 2
Source File: CSPARQLAarhusTrafficStream.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public CSPARQLAarhusTrafficStream(String uri, String txtFile, EventDeclaration ed, Date start, Date end)
		throws IOException {
	super(uri);
	logger.info("IRI: " + this.getIRI().split("#")[1] + ed.getInternalQos());
	this.startDate = start;
	this.endDate = end;
	messageCnt = 0;
	byteCnt = 0;
	this.txtFile = txtFile;
	this.ed = ed;
	streamData = new CsvReader(String.valueOf(txtFile));
	streamData.setTrimWhitespace(false);
	streamData.setDelimiter(',');
	streamData.readHeaders();
	metaData = new CsvReader("dataset/MetaData/trafficMetaData.csv");
	metaData.readHeaders();
	streamData.readRecord();
	while (metaData.readRecord()) {
		if (streamData.get("REPORT_ID").equals(metaData.get("REPORT_ID"))) {
			// p1Street = metaData.get("POINT_1_STREET");
			// p1City = metaData.get("POINT_1_CITY");
			// p1Lat = metaData.get("POINT_1_LAT");
			// p1Lon = metaData.get("POINT_1_LNG");
			// p1Country = metaData.get("POINT_2_COUNTRY");
			// p2Street = metaData.get("POINT_2_STREET");
			// p2City = metaData.get("POINT_2_CITY");
			// p2Lat = metaData.get("POINT_2_LAT");
			// p2Lon = metaData.get("POINT_2_LNG");
			// p2Country = metaData.get("POINT_2_COUNTRY");
			distance = metaData.get("DISTANCE_IN_METERS");
			if (ed instanceof TrafficReportService)
				((TrafficReportService) ed).setDistance(Integer.parseInt(distance));

			// timestamp = metaData.get("TIMESTAMP");
			// id = metaData.get("extID");
			metaData.close();
			break;
		}
	}
}
 
Example 3
Source File: DataWrapper.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public static SensorObservation getAarhusTrafficObservation(CsvReader streamData, EventDeclaration ed) {
	try {
		// CsvReader streamData = (CsvReader) objData;
		AarhusTrafficObservation data;
		// if (!this.txtFile.contains("mean"))
		data = new AarhusTrafficObservation(Double.parseDouble(streamData.get("REPORT_ID")),
				Double.parseDouble(streamData.get("avgSpeed")), Double.parseDouble(streamData.get("vehicleCount")),
				Double.parseDouble(streamData.get("avgMeasuredTime")), 0, 0, null, null, 0.0, 0.0, null, null, 0.0,
				0.0, null, null, streamData.get("TIMESTAMP"));
		String obId = "AarhusTrafficObservation-" + streamData.get("_id");
		Double distance = Double.parseDouble(((TrafficReportService) ed).getDistance() + "");
		if (data.getAverageSpeed() != 0)
			data.setEstimatedTime(distance / data.getAverageSpeed());
		else
			data.setEstimatedTime(-1.0);
		if (distance != 0)
			data.setCongestionLevel(data.getVehicle_count() / distance);
		else
			data.setCongestionLevel(-1.0);
		data.setObId(obId);
		;
		// this.currentObservation = data;
		return data;
	} catch (NumberFormatException | IOException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 4
Source File: CQELSAarhusTrafficStream.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public CQELSAarhusTrafficStream(ExecContext context, String uri, String txtFile, EventDeclaration ed, Date start,
		Date end) throws IOException {
	super(context, uri);
	this.startDate = start;
	this.endDate = end;
	messageCnt = 0;
	byteCnt = 0;
	this.txtFile = txtFile;
	this.ed = ed;
	streamData = new CsvReader(String.valueOf(txtFile));
	streamData.setTrimWhitespace(false);
	streamData.setDelimiter(',');
	streamData.readHeaders();
	metaData = new CsvReader("dataset/MetaData/trafficMetaData.csv");
	metaData.readHeaders();
	streamData.readRecord();
	while (metaData.readRecord()) {
		if (streamData.get("REPORT_ID").equals(metaData.get("REPORT_ID"))) {
			// p1Street = metaData.get("POINT_1_STREET");
			// p1City = metaData.get("POINT_1_CITY");
			// p1Lat = metaData.get("POINT_1_LAT");
			// p1Lon = metaData.get("POINT_1_LNG");
			// p1Country = metaData.get("POINT_2_COUNTRY");
			// p2Street = metaData.get("POINT_2_STREET");
			// p2City = metaData.get("POINT_2_CITY");
			// p2Lat = metaData.get("POINT_2_LAT");
			// p2Lon = metaData.get("POINT_2_LNG");
			// p2Country = metaData.get("POINT_2_COUNTRY");
			distance = metaData.get("DISTANCE_IN_METERS");
			// timestamp = metaData.get("TIMESTAMP");
			// id = metaData.get("extID");
			metaData.close();
			break;
		}
	}
}
 
Example 5
Source File: ReadDocument.java    From Benchmark with GNU General Public License v3.0 5 votes vote down vote up
public static AarhusTrafficObservation getStreamData(String dataFile) throws NumberFormatException, IOException {
	CsvReader streamData = new CsvReader(String.valueOf(dataFile));
	streamData.readHeaders();
	// Reads csv document for traffic metadata
	try {
		CsvReader metaData = new CsvReader("dataset/MetaData/trafficMetaData.csv");
		metaData.readHeaders();
		AarhusTrafficObservation data = new AarhusTrafficObservation();
		while (streamData.readRecord()) {

			while (metaData.readRecord()) {
				if (streamData.get("REPORT_ID").equals(metaData.get("REPORT_ID"))) {
					data = new AarhusTrafficObservation(Double.parseDouble(streamData.get("REPORT_ID")),
							Double.parseDouble(streamData.get("avgSpeed")), Double.parseDouble(streamData
									.get("vehicleCount")), Double.parseDouble(streamData.get("avgMeasuredTime")),
							0, 0, metaData.get("POINT_1_STREET"), metaData.get("POINT_1_CITY"),
							Double.parseDouble(metaData.get("POINT_1_LAT")), Double.parseDouble(metaData
									.get("POINT_1_LNG")), metaData.get("POINT_2_STREET"),
							metaData.get("POINT_2_CITY"), Double.parseDouble(metaData.get("POINT_2_LAT")),
							Double.parseDouble(metaData.get("POINT_2_LNG")), metaData.get("POINT_1_COUNTRY"),
							metaData.get("POINT_2_COUNTRY"), metaData.get("TIMESTAMP"));
					Double distance = Double.parseDouble(metaData.get("DISTANCE_IN_METERS"));
					data.setEstimatedTime(distance / data.getAverageSpeed());
					data.setCongestionLevel(data.getVehicle_count() / distance);
				}
			}

		}
		streamData.close();
		metaData.close();
		return data;
	} catch (Exception e) {

		e.printStackTrace();
	}
	return null;
}
 
Example 6
Source File: FileOperation.java    From Benchmark with GNU General Public License v3.0 4 votes vote down vote up
public static void main(String[] args) throws IOException {
	// File trafficRawDirectory = new File("streams");
	// File[] trafficRawFiles = trafficRawDirectory.listFiles();
	// for (File tr : trafficRawFiles) {
	// System.out.println("renaming: " + tr.toPath());
	// File newTr;
	// if (tr.getName().contains("traffic")) {
	// newTr = new File("streams" + File.separator + "AarhusT"
	// + tr.getName().substring(1, tr.getName().length()));
	// tr.renameTo(newTr);
	// } else if (tr.getName().contains("pollution")) {
	// newTr = new File("streams" + File.separator + "AarhusP"
	// + tr.getName().substring(1, tr.getName().length()));
	// tr.renameTo(newTr);
	// }
	//
	// // Files.copy(tr.toPath(), newTr.toPath());
	// }
	CsvReader streamData = new CsvReader("dataset/aarhus_parking.csv");
	streamData.setTrimWhitespace(false);
	streamData.setDelimiter(',');
	streamData.readHeaders();

	List<String> streamNames = new ArrayList<String>();
	streamNames.add("NORREPORT");
	streamNames.add("BUSGADEHUSET");
	streamNames.add("BRUUNS");
	streamNames.add("SKOLEBAKKEN");
	streamNames.add("SCANDCENTER");
	streamNames.add("SALLING");
	streamNames.add("MAGASIN");
	streamNames.add("KALKVAERKSVEJ");

	Map<String, CsvWriter> writerMap = new HashMap<String, CsvWriter>();
	for (String s : streamNames)
		try {
			// use FileWriter constructor that specifies open for appending
			String outputFile = "dataset/AarhusParkingData-" + s + ".stream";
			boolean alreadyExists = new File(outputFile).exists();
			CsvWriter csvOutput = new CsvWriter(new FileWriter(outputFile, true), ',');

			// if the file didn't already exist then we need to write out the header line
			if (!alreadyExists) {
				csvOutput.write("vehiclecount");
				csvOutput.write("updatetime");
				csvOutput.write("_id");
				csvOutput.write("totalspaces");
				csvOutput.write("garagecode");
				csvOutput.write("streamtime");
				csvOutput.endRecord();
			}
			// }
			writerMap.put(s, csvOutput);
			// csvOutput.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

	while (streamData.readRecord()) {
		String code = streamData.get("garagecode");
		writerMap.get(code).write(streamData.get("vehiclecount"));
		writerMap.get(code).write(streamData.get("updatetime"));
		writerMap.get(code).write(streamData.get("_id"));
		writerMap.get(code).write(streamData.get("totalspaces"));
		writerMap.get(code).write(streamData.get("garagecode"));
		writerMap.get(code).write(streamData.get("streamtime"));
		writerMap.get(code).endRecord();
	}
	for (CsvWriter csv : writerMap.values())
		csv.close();
}
 
Example 7
Source File: CSPARQLAarhusTrafficStream.java    From Benchmark with GNU General Public License v3.0 4 votes vote down vote up
public CSPARQLAarhusTrafficStream(String uri, String txtFile, EventDeclaration ed) throws IOException {
	super(uri);
	String fileName = "";
	if (this.getIRI().split("#").length > 1)
		fileName = this.getIRI().split("#")[1];
	else
		fileName = this.getIRI();
	// logFile = new File("resultlog/" + fileName + ".csv");
	// fw = new FileWriter(logFile);
	// cw = new CsvWriter(fw, ',');
	// cw.write("time");
	// cw.write("message_cnt");
	// cw.write("byte_cnt");
	// cw.endRecord();heh
	// cw.flush();
	messageCnt = 0;
	byteCnt = 0;
	this.txtFile = txtFile;
	this.ed = ed;
	// time1 = time.getTime();
	streamData = new CsvReader(String.valueOf(txtFile));
	streamData.setTrimWhitespace(false);
	streamData.setDelimiter(',');
	streamData.readHeaders();
	// streamData.skipRecord();
	metaData = new CsvReader("dataset/MetaData/trafficMetaData.csv");
	metaData.readHeaders();
	streamData.readRecord();
	while (metaData.readRecord()) {
		if (streamData.get("REPORT_ID").equals(metaData.get("REPORT_ID"))) {
			// p1Street = metaData.get("POINT_1_STREET");
			// p1City = metaData.get("POINT_1_CITY");
			// p1Lat = metaData.get("POINT_1_LAT");
			// p1Lon = metaData.get("POINT_1_LNG");
			// p1Country = metaData.get("POINT_2_COUNTRY");
			// p2Street = metaData.get("POINT_2_STREET");
			// p2City = metaData.get("POINT_2_CITY");
			// p2Lat = metaData.get("POINT_2_LAT");
			// p2Lon = metaData.get("POINT_2_LNG");
			// p2Country = metaData.get("POINT_2_COUNTRY");
			distance = metaData.get("DISTANCE_IN_METERS");
			if (ed instanceof TrafficReportService)
				((TrafficReportService) ed).setDistance(Integer.parseInt(distance));

			// timestamp = metaData.get("TIMESTAMP");
			// id = metaData.get("extID");
			// stream(n(RDFFileManager.defaultPrefix + streamData.get("REPORT_ID")),
			// n(RDFFileManager.ctPrefix + "hasETA"), n(data.getEstimatedTime() + ""));
			// System.out.println("metadata: " + metaData.toString());
			metaData.close();
			break;
		}
	}
}
 
Example 8
Source File: CQELSAarhusTrafficStream.java    From Benchmark with GNU General Public License v3.0 4 votes vote down vote up
public CQELSAarhusTrafficStream(ExecContext context, String uri, String txtFile, EventDeclaration ed)
		throws IOException {
	super(context, uri);
	String fileName = "";
	if (this.getURI().split("#").length > 1)
		fileName = this.getURI().split("#")[1];
	else
		fileName = this.getURI();
	// logFile = new File("resultlog/" + fileName + ".csv");
	// fw = new FileWriter(logFile);
	// cw = new CsvWriter(fw, ',');
	// cw.write("time");
	// cw.write("message_cnt");
	// cw.write("byte_cnt");
	// cw.endRecord();
	// cw.flush();
	messageCnt = 0;
	byteCnt = 0;
	this.txtFile = txtFile;
	this.ed = ed;
	// time1 = time.getTime();
	streamData = new CsvReader(String.valueOf(txtFile));
	streamData.setTrimWhitespace(false);
	streamData.setDelimiter(',');
	streamData.readHeaders();
	// streamData.skipRecord();
	metaData = new CsvReader("dataset/MetaData/trafficMetaData.csv");
	metaData.readHeaders();
	streamData.readRecord();
	while (metaData.readRecord()) {
		if (streamData.get("REPORT_ID").equals(metaData.get("REPORT_ID"))) {
			// p1Street = metaData.get("POINT_1_STREET");
			// p1City = metaData.get("POINT_1_CITY");
			// p1Lat = metaData.get("POINT_1_LAT");
			// p1Lon = metaData.get("POINT_1_LNG");
			// p1Country = metaData.get("POINT_2_COUNTRY");
			// p2Street = metaData.get("POINT_2_STREET");
			// p2City = metaData.get("POINT_2_CITY");
			// p2Lat = metaData.get("POINT_2_LAT");
			// p2Lon = metaData.get("POINT_2_LNG");
			// p2Country = metaData.get("POINT_2_COUNTRY");
			distance = metaData.get("DISTANCE_IN_METERS");
			// timestamp = metaData.get("TIMESTAMP");
			// id = metaData.get("extID");
			// stream(n(RDFFileManager.defaultPrefix + streamData.get("REPORT_ID")),
			// n(RDFFileManager.ctPrefix + "hasETA"), n(data.getEstimatedTime() + ""));
			// System.out.println("metadata: " + metaData.toString());
			metaData.close();
			break;
		}
	}
}