package com.lyz.storm.trident.operator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.lyz.storm.trident.model.DiagnosisEvent;
import storm.trident.operation.BaseFunction;
import storm.trident.operation.TridentCollector;
import storm.trident.tuple.TridentTuple;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class CityAssignment extends BaseFunction {
private static final long serialVersionUID = 1L;
private static final Logger LOG = LoggerFactory.getLogger(CityAssignment.class);
private static Map<String, double[]> CITIES = new HashMap<String, double[]>();
{ // Initialize the cities we care about.
double[] phl = { 39.875365, -75.249524 };
CITIES.put("PHL", phl);
double[] nyc = { 40.71448, -74.00598 };
CITIES.put("NYC", nyc);
double[] sf = { -31.4250142, -62.0841809 };
CITIES.put("SF", sf);
double[] la = { -34.05374, -118.24307 };
CITIES.put("LA", la);
}
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
DiagnosisEvent diagnosis = (DiagnosisEvent) tuple.getValue(0);
double leastDistance = Double.MAX_VALUE;
String closestCity = "NONE";
for (Entry<String, double[]> city : CITIES.entrySet()) {
double R = 6371; // km
double x = (city.getValue()[0] - diagnosis.lng) * Math.cos((city.getValue()[0] + diagnosis.lng) / 2);
double y = (city.getValue()[1] - diagnosis.lat);
double d = Math.sqrt(x * x + y * y) * R;
if (d < leastDistance) {
leastDistance = d;
closestCity = city.getKey();
}
}
List<Object> values = new ArrayList<Object>();
values.add(closestCity);
LOG.debug("Closest city to lat=[" + diagnosis.lat + "], lng=[" + diagnosis.lng + "] == [" + closestCity
+ "], d=[" + leastDistance + "]");
collector.emit(values);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
storm.zip (77个子文件)
storm
.project 1KB
pom.xml 4KB
target
storm.jar 12KB
test-classes
maven-archiver
pom.properties 111B
maven-status
maven-compiler-plugin
compile
default-compile
createdFiles.lst 0B
inputFiles.lst 416B
testCompile
default-testCompile
inputFiles.lst 0B
generated-sources
annotations
lib
log4j-slf4j-impl-2.8.2.jar 23KB
log4j-api-2.8.2.jar 223KB
kryo-3.0.3.jar 279KB
storm-core-1.1.1.jar 22.54MB
minlog-1.3.0.jar 6KB
clojure-1.7.0.jar 3.66MB
log4j-1.2.17.jar 478KB
servlet-api-2.5.jar 103KB
objenesis-2.1.jar 41KB
log4j-over-slf4j-1.6.6.jar 20KB
ring-cors-0.1.5.jar 6KB
log4j-core-2.8.2.jar 1.34MB
slf4j-api-1.7.21.jar 40KB
reflectasm-1.10.1.jar 20KB
asm-5.0.3.jar 52KB
slf4j-log4j12-1.7.2.jar 9KB
disruptor-3.3.2.jar 78KB
classes
log4j.properties 912B
META-INF
maven
com.lyz
storm
pom.xml 4KB
pom.properties 210B
MANIFEST.MF 236B
com
lyz
storm
trident
state
OutbreakTrendBackingMap.class 3KB
OutbreakTrendFactory.class 949B
OutbreakTrendState.class 636B
spout
DiagnosisEventSpout.class 2KB
DefaultCoordinator.class 2KB
DiagnosisEventEmitter.class 3KB
model
DiagnosisEvent.class 656B
topology
OutbreakDetectionTopology.class 3KB
operator
CityAssignment.class 3KB
HourAssignment.class 2KB
DispatchAlert.class 1KB
OutbreakDetector.class 2KB
DiseaseFilter.class 2KB
.settings
.jsdtscope 575B
org.eclipse.wst.common.component 581B
org.eclipse.wst.validation.prefs 338B
org.eclipse.jdt.core.prefs 736B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.m2e.core.prefs 90B
org.eclipse.wst.jsdt.ui.superType.name 6B
src
test
resources
java
main
resources
log4j.properties 912B
spring
java
com
lyz
storm
trident
state
OutbreakTrendBackingMap.java 1KB
OutbreakTrendFactory.java 520B
OutbreakTrendState.java 281B
spout
DefaultCoordinator.java 848B
DiagnosisEventSpout.java 929B
DiagnosisEventEmitter.java 1KB
model
DiagnosisEvent.java 505B
topology
OutbreakDetectionTopology.java 2KB
operator
HourAssignment.java 1KB
OutbreakDetector.java 776B
CityAssignment.java 2KB
DiseaseFilter.java 899B
DispatchAlert.java 596B
webapp
WEB-INF
lib
META-INF
MANIFEST.MF 39B
.classpath 1KB
logs
workers-artifacts
word-count-topology-1-1516341944
1024
worker.yaml 116B
1027
worker.yaml 116B
word-count-topology-1-1516342030
1024
worker.yaml 116B
1027
worker.yaml 116B
word-count-topology-1-1516347174
1024
worker.yaml 116B
1027
worker.yaml 116B
word-count-topology-1-1516349286
1024
worker.yaml 116B
1027
worker.yaml 116B
word-count-topology-1-1516342070
1024
worker.yaml 116B
1027
worker.yaml 116B
word-count-topology-1-1516355321
1024
worker.yaml 116B
1027
worker.yaml 116B
共 77 条
- 1
资源评论
冰河
- 粉丝: 23w+
- 资源: 131
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功