<commit_before>#!/usr/bin/python

import BaseHTTPServer, sys, urlparse
import mimetypes
from optparse import OptionParser
import sys, os
import pwd
import re
import signal
import simplejson
import time
import datetime
import urllib
import math

import parsedatetime as pdt

from graphserver.core import Graph, Link, State
from graphserver.ext.gtfs import GTFSLoadable
from graphserver.engine import TripPlanEngine
import transitfeed


LOGFILE = '/var/log/openrp.log'
PIDFILE = '/var/run/openrp.pid'


def calc_latlng_distance(src_lat, src_lng, dest_lat, dest_lng):
  # fixme: use a less ridiculous calculation
  # this one from: http://www.zipcodeworld.com/samples/distance.cs.html
  theta = src_lng - dest_lng
  dist = math.sin(math.radians(src_lat)) * math.sin(math.radians(dest_lat)) + math.cos(math.radians(src_lat)) * math.cos(math.radians(dest_lat)) * math.cos(math.radians(theta))
  dist = math.acos(dist)
  dist = math.degrees(dist)
  dist = dist * 60 * 1.1515 * 1.609344 * 1000
  return dist


class ResultEncoder(simplejson.JSONEncoder):
  def default(self, obj):
    try:
      iterable = iter(obj)
    except TypeError:
      pass
    else:
      return list(iterable)
    return simplejson.JSONEncoder.default(self, obj)

class ScheduleRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  def __init__(self, request, client_address, socket_server):
    BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, request, client_address, socket_server)

  def do_GET(self):<commit_msg>Handle null case of distance calculation<commit_after>#!/usr/bin/python

import BaseHTTPServer, sys, urlparse
import mimetypes
from optparse import OptionParser
import sys, os
import pwd
import re
import signal
import simplejson
import time
import datetime
import urllib
import math

import parsedatetime as pdt

from graphserver.core import Graph, Link, State
from graphserver.ext.gtfs import GTFSLoadable
from graphserver.engine import TripPlanEngine
import transitfeed


LOGFILE = '/var/log/openrp.log'
PIDFILE = '/var/run/openrp.pid'


def calc_latlng_distance(src_lat, src_lng, dest_lat, dest_lng):
  # fixme: use a less ridiculous calculation
  # this one from: http://www.zipcodeworld.com/samples/distance.cs.html
  if src_lat == dest_lat and src_lng == dest_lng:
    return 0

  theta = src_lng - dest_lng
  dist = math.sin(math.radians(src_lat)) * math.sin(math.radians(dest_lat)) + math.cos(math.radians(src_lat)) * math.cos(math.radians(dest_lat)) * math.cos(math.radians(theta))
  dist = math.acos(dist)
  dist = math.degrees(dist)
  dist = dist * 60 * 1.1515 * 1.609344 * 1000
  return dist


class ResultEncoder(simplejson.JSONEncoder):
  def default(self, obj):
    try:
      iterable = iter(obj)
    except TypeError:
      pass
    else:
      return list(iterable)
    return simplejson.JSONEncoder.default(self, obj)

class ScheduleRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
  def __init__(self, request, client_address, socket_server):
    BaseHTTPServer.BaseHTTPRequestHandler.__init__(self, request, client_address, socket_server)

  def do_GET(self):
{'fraction_non_alphanumeric': 0.09444985394352483, 'fraction_numerical': 0.012009087958455048, 'mean_word_length': 4.826086956521739, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3765097', 'n_tokens_mistral': 1039, 'n_tokens_neox': 1002, 'n_words': 252}