Hello World

Hello world. This is the default post which is generated by the blogging framework. I just want to keep it as is.

Quick Start

Create a new post

$ hexo new "My New Post"

More info: Writing

Run server

$ hexo server

More info: Server

Generate static files

$ hexo generate

More info: Generating

Deploy to remote sites

$ hexo deploy

More info: Deployment


import net.sf.marineapi.nmea.parser.SentenceFactory;
import net.sf.marineapi.nmea.sentence.GGASentence;
import net.sf.marineapi.nmea.sentence.SentenceValidator;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

public class GPSBatchProcessor {
// Reuse factory instance
private static final SentenceFactory factory = SentenceFactory.getInstance();

// Configure batch size and thread count based on your system capabilities
private static final int BATCH_SIZE = 10000;
private static final int THREAD_COUNT = Runtime.getRuntime().availableProcessors();

public static void main(String[] args) throws Exception {
String filePath = "path/to/your/nmea/data.txt";
processBatch(filePath);
}

public static void processBatch(String filePath) throws IOException, InterruptedException {
ExecutorService executor = Executors.newFixedThreadPool(THREAD_COUNT);
List<Future<?>> futures = new ArrayList<>();

try (BufferedReader reader = new BufferedReader(new FileReader(filePath), 8192)) {
List<String> batch = new ArrayList<>(BATCH_SIZE);
String line;
long totalProcessed = 0;
long startTime = System.currentTimeMillis();

while ((line = reader.readLine()) != null) {
if (line.startsWith("$GPGGA") && SentenceValidator.isValid(line)) {
batch.add(line);

if (batch.size() >= BATCH_SIZE) {
List<String> currentBatch = new ArrayList<>(batch);
batch.clear();
futures.add(executor.submit(() -> processSentences(currentBatch)));
totalProcessed += currentBatch.size();

// Log progress periodically
if (totalProcessed % 1000000 == 0) {
System.out.println("Processed " + totalProcessed + " sentences...");
}
}
}
}

// Process remaining sentences
if (!batch.isEmpty()) {
futures.add(executor.submit(() -> processSentences(batch)));
totalProcessed += batch.size();
}

// Wait for all tasks to complete
for (Future<?> future : futures) {
future.get();
}

long endTime = System.currentTimeMillis();
System.out.println("Completed processing " + totalProcessed +
" sentences in " + (endTime - startTime) + "ms");
} catch (Exception e) {
e.printStackTrace();
} finally {
executor.shutdown();
}
}

private static void processSentences(List<String> sentences) {
for (String sentence : sentences) {
try {
GGASentence gga = (GGASentence) factory.createParser(sentence);

// Here you would do your processing with each GGA sentence
// Instead of printing, consider storing relevant data to a database
// or analyzing it in memory

// Example: extract the important data only
double latitude = gga.getPosition().getLatitude();
double longitude = gga.getPosition().getLongitude();
double altitude = gga.getAltitude();
int satellites = gga.getSatelliteCount();

// Process this data as needed (store in memory, DB, etc.)
// processGpsData(latitude, longitude, altitude, satellites);
} catch (Exception e) {
// Log error and continue with next sentence
System.err.println("Error processing: " + sentence);
}
}
}

// This method would contain your business logic for using the GPS data
private static void processGpsData(double lat, double lon, double alt, int satellites) {
// Your custom processing logic here
// For example: store to database, calculate statistics, etc.
}
}