def atcInsert(self, row, update_time): updateTime = update_time date_time = updateTime _date = updateTime[0:10] call_sign = row[0] atc_id = row[1] if (row[16] != ''): user_rating = int(row[16]) else: user_rating = '' if (user_rating == 0): user_rating = 'Ground Controller' elif (user_rating == 1): user_rating = 'Tower Controller' elif (user_rating == 2): user_rating = 'TMA Controller' elif (user_rating == 3): user_rating = 'Enroute Controller' elif (user_rating == 4): user_rating = 'Senior Controller' client_type = "ATC" freq = row[4] lat = row[5] lon = row[6] serv = row[15] facility_type = row[18] if (facility_type == 0): facility_type = 'Other' elif (facility_type == 1): facility_type = 'Observer' elif (facility_type == 2): facility_type = 'Clearance Delivery' elif (facility_type == 3): facility_type = 'Ground' elif (facility_type == 4): facility_type = 'Tower' elif (facility_type == 5): facility_type = 'Approach/Departure' elif (facility_type == 6): facility_type = 'Center' if (row[19] != ''): visual_range = int(row[19]) else: visual_range = '' logon = row[37] timelogon = logon[0:4] + "-" + logon[4:6] + "-" + logon[6:8] + " " + logon[8:10] + ":" + logon[10:12] + ":" + logon[12:14] + "+0000" date = updateTime totaltime = datetime.datetime.utcnow() - datetime.datetime.strptime(timelogon, "%Y-%m-%d %H:%M:%S") totaltime = sr(totaltime) if (Personal.objects.filter(cid=atc_id).exists() == False): newPersonal = Personal(cid = atc_id, realname = real_name, atc_rating = user_rating) newPersonal.save() else: personal = Personal.objects.get(cid=atc_id) if (personal.atc_rating != user_rating): personal.atc_rating = user_rating if (ActiveControllers.objects.filter(cid=atc_id, callsign=call_sign, datetime=date_time).exists == False): newActiveATC = ActiveControllers(datetime=date_time, callsign=call_sign, cid=atc_id, clienttype=client_type, frequency=freq, latitude=lat, longitude=lon, server=serv, facilitytype=facility_type, visualrange=visual_range, time_logon=timelogon) #delete old active controller oldActiveATC = ActiveControllers.objects.filter(cid=atc_id, callsign = call_sign).exclude(datetime = updateTime) oldActiveATC.delete() if (Controllers.objects.filter(date=_date, callsign= call_sign, cid = atc_id).exists() == False): totaltime = datetime.datetime.utcnow() - time_logon newController(date=_date, callsign = call_sign, cid = atc_id, facilitytype = facility_type, TotalTime = totaltime) else: controller = Controllers.objects.get(date=date, callsign= call_sign, cid=atc_id) controller.TotalTime = controller.TotalTime + (updateTime - controller.lastUpdate) controller.lastUpdate = updateTime controller.save()
altairport = row[28] flight_remarks= row[29] flight_route = row[30] Route_String = ";" + str(lat) + "," + str(lon) + ";" flightStatus = "" logon = row[37] timelogon = logon[0:4] + "-" + logon[4:6] + "-" + logon[6:8] + " " + logon[8:10] + ":" + logon[10:12] + ":" + logon[12:14] + "+0000" #Deal with Personal Table ######################### ######################### if (Personal.objects.filter(cid=pilotId).exists() == False): newPersonal = Personal(cid = pilotId, realname = real_name, pilot_rating = user_rating) newPersonal.save() else: personal = Personal.objects.get(cid=pilotId) if (personal.pilot_rating != user_rating): personal.pilot_rating = user_rating #Deal with Flights Table ######################### ######################### if (Flights.objects.filter(date = flight_date, callsign = call_sign, cid = pilotId).exists() == False): try: origAirport = Airports.objects.get(icao=depairport) origLat = origAirport.lat origLon = origAirport.lon dist = getNmFromLatLon(lat, lon, origLat, origLon)