def calculate_traffic(incident):
  """Calculates the traffic level at the time of the incident"""
  resources = incident['traffic']['resourceSets'][0]['resources']
  duration_traffic = sum([r['travelDurationTraffic'] for r in resources])/len(resources)
  duration = sum([r['travelDuration'] for r in resources])/len(resources)

  incident['traffic_level'] = (duration_traffic - duration)/duration
  return incident