当前位置: 首页>>代码示例>>Python>>正文


Python Utility.calculate_distance方法代码示例

本文整理汇总了Python中utility.Utility.calculate_distance方法的典型用法代码示例。如果您正苦于以下问题:Python Utility.calculate_distance方法的具体用法?Python Utility.calculate_distance怎么用?Python Utility.calculate_distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utility.Utility的用法示例。


在下文中一共展示了Utility.calculate_distance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: geo_drift_check

# 需要导入模块: from utility import Utility [as 别名]
# 或者: from utility.Utility import calculate_distance [as 别名]
    def geo_drift_check(cls, geo_anchor, gps_scan, threshold, device_id):
        """Fire alarm if distance between points exceeds threshold.

        Args:
            geo_anchor (dict): Geographic anchor point, usually stored in an
                instance variable and passed in via the `correlate()` method.
            gps_scan (dict): Same format as geo_anchor, expects the same format
                as `geo_anchor`.
            threshold (int): Alerting threshold in km.

        Returns:
            list: list of alerts (usually just one) or an empty list of there
                are no alerts.
        """
        lat_1 = geo_anchor["location"]["coordinates"][1]
        lon_1 = geo_anchor["location"]["coordinates"][0]
        lat_2 = gps_scan["location"]["coordinates"][1]
        lon_2 = gps_scan["location"]["coordinates"][0]
        current_distance = Utility.calculate_distance(lon_1, lat_1,
                                                      lon_2, lat_2)
        if current_distance < threshold:
            return []
        else:
            message = "Possible GPS spoofing attack! %d delta from anchor at %s / %s %s !" % (current_distance, gps_scan["site_name"], gps_scan["sensor_name"], Utility.create_gmaps_link(lat_1, lon_1))  # NOQA
            alert = AlertManager(device_id).build_alert(300, message,
                                                        gps_scan["location"])
            return[alert]
开发者ID:sitch-io,项目名称:sensor,代码行数:29,代码来源:geo_correlator.py

示例2: correlate

# 需要导入模块: from utility import Utility [as 别名]
# 或者: from utility.Utility import calculate_distance [as 别名]
    def correlate(self, scan_bolus):
        """Entrypoint for the CGI correlation component.

        Args:
            scan_bolus (tuple):  scan_bolus[0] contains the scan type.  If
                the type is 'gps', it will set the correlator's geo location.
                For other scan types, we expect them to look like
                gsm_modem_channel events, and they are compared against the
                feed database as well as state history, tracking things
                like the current active cell's CGI.

        Returns:
            list: Returns a list of tuples, representing alerts.  If no alerts
                fire, the list will be empty.
        """
        retval = []
        if scan_bolus[0] == "gps":
            self.state = scan_bolus[1]["location"]
        elif scan_bolus[0] == "cell":
            retval = self.check_scan_document(scan_bolus[1])
            scan_bolus[1]["location"] = self.state
            retval.append(scan_bolus)
        elif scan_bolus[0] != "gsm_modem_channel":
            print("CgiCorrelator: Unsupported scan type: %s" % str(scan_bolus[0]))  # NOQA
            pass
        else:
            channel = scan_bolus[1]
            if channel["mcc"] in ["", None]:
                return retval  # We don't correlate incomplete CGIs...
            # Here's the feed comparison part:
            channel["feed_info"] = self.get_feed_info(channel["mcc"],
                                                      channel["mnc"],
                                                      channel["lac"],
                                                      channel["cellid"])
            chan, here = CgiCorrelator.build_chan_here(channel, self.state)
            channel["distance"] = Utility.calculate_distance(chan["lon"],
                                                             chan["lat"],
                                                             here["lon"],
                                                             here["lat"])
            channel["location"] = self.state
            # In the event we have incomplete information, bypass comparison.
            skip_feed_comparison = CgiCorrelator.should_skip_feed(channel)
            if skip_feed_comparison is False:
                if channel["mcc"] not in self.mcc_list:
                    msg = ("MCC %s should not be observed by sensor at %s / %s. ARFCN: %s CGI: %s Cell Priority: %s" %  # NOQA
                           (channel["mcc"], channel["site_name"],
                            channel["sensor_name"], channel["arfcn"],
                            channel["cgi_str"], channel["cell"]))
                    alert = self.alerts.build_alert(130, msg, self.state)
                    alert[1]["site_name"] = channel["site_name"]
                    alert[1]["sensor_name"] = channel["sensor_name"]
                    alert[1]["sensor_id"] = channel["sensor_id"]
                    retval.append(alert)
                feed_comparison_results = self.feed_comparison(channel)
                for feed_alert in feed_comparison_results:
                    retval.append(feed_alert)
            retval.append(scan_bolus)
        return retval
开发者ID:sitch-io,项目名称:sensor,代码行数:60,代码来源:cgi_correlator.py

示例3: is_in_range

# 需要导入模块: from utility import Utility [as 别名]
# 或者: from utility.Utility import calculate_distance [as 别名]
 def is_in_range(cls, item_gps, state_gps):
     """Return True if items are within 40km."""
     state_gps_lat = state_gps["coordinates"][1]
     state_gps_lon = state_gps["coordinates"][0]
     max_range = 40000  # 40km
     state_lon = state_gps_lon
     state_lat = state_gps_lat
     item_lon = item_gps["lon"]
     item_lat = item_gps["lat"]
     distance = Utility.calculate_distance(state_lon, state_lat,
                                           item_lon, item_lat)
     if distance > max_range:
         return False
     else:
         return True
开发者ID:sitch-io,项目名称:sensor,代码行数:17,代码来源:arfcn_correlator.py


注:本文中的utility.Utility.calculate_distance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。