コード例 #1
0
def save_location_points_for(request, id):
    points = json.loads(request.GET["data"])

    # validation
    valid = True
    for point in points:
        hour, minute, second = point["hour"].strip(), point["minute"].strip(), point["second"].strip()

        if not hour.isalnum() or int(hour) < 0 or int(hour) > 23:
            valid = False
            break
        if not minute.isalnum() or int(minute) < 0 or int(minute) > 59:
            valid = False
            break
        if not second.replace(".", "").isalnum() or float(second) < 0 or float(second) >= 60:
            valid = False
            break
    if not valid:
        result = {"result": "wrong"}
        return HttpResponse(json.dumps(result))

    for point in points:
        hour, minute, second = point["hour"].strip(), point["minute"].strip(), point["second"].strip()
        latitude, longitude = point["latitude"].strip(), point["longitude"].strip()
        queries.add_location_point(id, hour, minute, second, latitude, longitude)

    result = {"result": "OK"}
    return HttpResponse(json.dumps(result))
コード例 #2
0
def save_location_points_for(request, id):
    points = json.loads(request.GET['data'])

    #validation
    valid = True
    for point in points:
        hour, minute, second = point['hour'].strip(), point['minute'].strip(), point['second'].strip()

        if not hour.isalnum() or int(hour) < 0 or int(hour) > 23:
            valid = False
            break
        if not minute.isalnum() or int(minute) < 0 or int(minute) > 59:
            valid = False
            break
        if not second.replace('.','').isalnum() or float(second) < 0 or float(second) >= 60:
            valid = False
            break
    if not valid:
        result = {'result' : 'wrong' }
        return HttpResponse(json.dumps(result))

    for point in points:
        hour, minute, second = point['hour'].strip(), point['minute'].strip(), point['second'].strip()
        latitude, longitude = point['latitude'].strip(), point['longitude'].strip()
        queries.add_location_point(id, hour, minute, second, latitude, longitude)

    result = {'result' : 'OK' }
    return HttpResponse(json.dumps(result))
コード例 #3
0
ファイル: views.py プロジェクト: snowwlex/interactive_map
def handle_file(content):
    content.replace('\r','') #will handle both: windows and linux-formatted files
    counter = 0
    for line in content.split('\n'):
        if not line.startswith('$'):
            continue
        line = re.sub(r"\s", "", line)
        id, time, latitude, p, longitude, j = line[1:].split(',')

        if (p != 'S' and p != 'N') or (j != 'E' and j != 'W'):
            continue

        h,m,s = time[0:2], time[2:4], time[4:]
        latitude_degree, latitude_minute = int(latitude[0:2]), float(latitude[2:])
        longitude_degree, longitude_minute = int(longitude[0:2]), float(longitude[2:])

        real_latitude = float(latitude_degree) + float(latitude_minute/60)
        real_longitude = float(longitude_degree) + float(longitude_minute/60)

        if p == 'S':
            real_latitude *= -1
        if j == 'W':
            real_longitude *= -1

        #TODO add duplicates rules
        result = queries.add_location_point(id, h, m, s, real_latitude, real_longitude)
        if not result:
            continue
        counter += 1
    return counter