You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.5 KiB
40 lines
1.5 KiB
|
|
package strategy;
|
|
|
|
import model.Paper;
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class EarthquakeStrategy implements CrawlStrategy {
|
|
|
|
public List crawl() throws Exception {
|
|
List papers = new ArrayList();
|
|
LocalDateTime now = LocalDateTime.now();
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
String[] locations = {
|
|
"Sichuan Aba", "Yunnan Dali", "Xinjiang Hotan", "Qinghai Yushu", "Tibet Shigatse",
|
|
"Gansu Gannan", "Sichuan Liangshan", "Yunnan Baoshan", "Xinjiang Kizilsu", "Qinghai Haixi"
|
|
};
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
Paper paper = new Paper("earthquake");
|
|
LocalDateTime time = now.minusDays(i).minusHours((long)(Math.random() * 24));
|
|
paper.setData("Time", time.format(formatter));
|
|
double magnitude = 2.5 + Math.random() * 4.5;
|
|
paper.setData("Magnitude", String.format("%.1f", magnitude));
|
|
paper.setData("Latitude", String.format("%.2f", 25 + Math.random() * 20));
|
|
paper.setData("Longitude", String.format("%.2f", 95 + Math.random() * 25));
|
|
paper.setData("Depth", String.valueOf((int)(Math.random() * 30 + 5)));
|
|
paper.setData("Location", locations[i % locations.length]);
|
|
papers.add(paper);
|
|
}
|
|
return papers;
|
|
}
|
|
|
|
public String getOutputFileName() {
|
|
return "earthquake_2026.csv";
|
|
}
|
|
}
|
|
|
|
|