-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEarthQuakeClient2.java
121 lines (113 loc) · 5.54 KB
/
EarthQuakeClient2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import java.util.*;
import edu.duke.*;
public class EarthQuakeClient2 {
public EarthQuakeClient2() {
// TODO Auto-generated constructor stub
}
public ArrayList<QuakeEntry> filter(ArrayList<QuakeEntry> quakeData, Filter f) {
ArrayList<QuakeEntry> answer = new ArrayList<QuakeEntry>();
for(QuakeEntry qe : quakeData) {
if (f.satisfies(qe)) {
answer.add(qe);
}
}
return answer;
}
public void quakesWithFilter () {
EarthQuakeParser parser = new EarthQuakeParser();
// String source = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.atom";
String source = "E:/Coursera/nov20quakedata.atom";
ArrayList<QuakeEntry> list = parser.read(source);
System.out.println("read data for " + list.size() + " quakes");
// Filter f = new MinMagFilter(4.0);
// Filter f1 = new MagnitudeFilter(4.0, 5.0);
// Filter f2 = new DepthFilter(-35000.0, -12000.0);
// Location japan = new Location(35.42, 139.43);
// Filter f1 = new DistanceFilter(japan, 10000000.0);
// Filter f2 = new PhraseFilter("end", "Japan");
// Location colorade = new Location(39.7392, -104.9903);
// Filter f1 = new DistanceFilter(colorade, 1000000.0);
// Filter f2 = new PhraseFilter("end", "a");
Location DenverColorado = new Location(39.7392, -104.9903);
Filter f1 = new DistanceFilter(DenverColorado, 1000000.0, "");
Filter f2 = new PhraseFilter("end", "a");
ArrayList<QuakeEntry> m7 = filter(list, f1);
m7 = filter(m7, f2);
for (QuakeEntry qe: m7) {
System.out.println(qe);
}
System.out.println("Found " + m7.size() + " quakes that match that criteria\n");
}
public void quakesWithFilter2() {
EarthQuakeParser parser = new EarthQuakeParser();
// String source = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.atom";
String source = "E:/Coursera/nov20quakedata.atom";
ArrayList<QuakeEntry> list = parser.read(source);
System.out.println("read data for " + list.size() + " quakes");
// Filter f = new MinMagFilter(4.0);
// Filter f1 = new MagnitudeFilter(4.0, 5.0);
// Filter f2 = new DepthFilter(-35000.0, -12000.0);
// Location japan = new Location(35.42, 139.43);
// Filter f1 = new DistanceFilter(japan, 10000000.0);
// Filter f2 = new PhraseFilter("end", "Japan");
// Location colorade = new Location(39.7392, -104.9903);
// Filter f1 = new DistanceFilter(colorade, 1000000.0);
// Filter f2 = new PhraseFilter("end", "a");
Filter f1 = new MagnitudeFilter(3.5, 4.5);
Filter f2 = new DepthFilter(-55000.0, -20000.0);
ArrayList<QuakeEntry> m7 = filter(list, f1);
m7 = filter(m7, f2);
for (QuakeEntry qe: m7) {
System.out.println(qe);
}
System.out.println("Found " + m7.size() + " quakes that match that criteria\n");
}
public void createCSV() {
EarthQuakeParser parser = new EarthQuakeParser();
String source = "E:/Coursera/nov20quakedatasmall.atom";
// String source = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.atom";
ArrayList<QuakeEntry> list = parser.read(source);
dumpCSV(list);
System.out.println("# quakes read: " + list.size());
}
public void dumpCSV(ArrayList<QuakeEntry> list) {
System.out.println("Latitude,Longitude,Magnitude,Info");
for(QuakeEntry qe : list){
System.out.printf("%4.2f,%4.2f,%4.2f,%s\n", qe.getLocation().getLatitude(), qe.getLocation().getLongitude(), qe.getMagnitude(), qe.getInfo());
}
}
public void testMatchAllFilter(){
EarthQuakeParser parser = new EarthQuakeParser();
// String source = "../data/nov20quakedata.atom";
String source = "E:/Coursera/nov20quakedata.atom";
// String source = "http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_week.atom";
ArrayList<QuakeEntry> list = parser.read(source);
System.out.println("read data for " + list.size() + " quakes");
MatchAllFilter maf = new MatchAllFilter();
maf.addFilter(new MagnitudeFilter(1.0, 4.0));
maf.addFilter(new DepthFilter( -180000.0, -30000.0));
maf.addFilter(new PhraseFilter("any", "o"));
ArrayList<QuakeEntry> m7 = filter(list, maf);
for (QuakeEntry qe: m7) {
System.out.println(qe);
}
System.out.println("Found " + m7.size() + " quakes that match that criteria\n");
}
public void testMatchAllFilter2() {
EarthQuakeParser parser = new EarthQuakeParser();
String source = "E:/Coursera/nov20quakedata.atom";
ArrayList<QuakeEntry> list = parser.read(source);
System.out.println("read data for " + list.size() + " quakes");
MatchAllFilter maf = new MatchAllFilter();
maf.addFilter(new MagnitudeFilter(0.0, 5.0));
Location BillundDenmark = new Location(55.7308, 9.1153);
maf.addFilter(new DistanceFilter(BillundDenmark, 3000000.0, ""));
maf.addFilter(new PhraseFilter("any", "e"));
ArrayList<QuakeEntry> m7 = filter(list, maf);
for (QuakeEntry qe : m7) {
System.out.println(qe);
}
System.out.println("Found " + m7.size() + " quakes that match that criteria");
System.out.println("Filters used are: " + maf.getName() + "\n");
}
}