<commit_before>const camelCase = require('lodash/camelCase')

function normalizeEvent (event) {
  return Object.keys(event).reduce(function (normalizedEvent, key) {
    normalizedEvent[normalizeFieldName(key)] = event[key]
    return normalizedEvent
  }, {})
}

module.exports = normalizeEvent

function normalizeFieldName (fieldName) {
  return camelCase(fieldName.replace(/^(.*)\(.*\)$/, function (fullString, match) {
    return match
  })).trim()
}<commit_msg>Adding event transformation logic to server<commit_after>const camelCase = require('lodash/camelCase')

function normalizeEvent (event) {
  return Object.keys(event)
    .reduce(function (normalizedEvent, key) {
      normalizedEvent[normalizeFieldName(key)] = event[key]
      return normalizedEvent
    }, {})
    .map(transformEvent)
}

module.exports = normalizeEvent

function normalizeFieldName (fieldName) {
  return camelCase(fieldName.replace(/^(.*)\(.*\)$/, function (fullString, match) {
    return match
  })).trim()
}

function transformEvent (event) {
  const transformedEvent = {}
  // need to ensure this doesnt blow up when transforming a piece that doesnt exist

  transformedEvent.id = event.id ? event.id : '' + Math.random() + ''
  transformedEvent.name = event.eventName.trim()
  transformedEvent.startTime = event.startTime.trim()
  transformedEvent.endTime = event.endTime.trim()
  transformedEvent.dateOfEvent = event.dateOfEvent.trim()
  transformedEvent.location = event.location.trim()
  transformedEvent.description = event.eventDescription.trim()
  transformedEvent.shortDescription = transformedEvent.description.substring(0, 70) + '...'
  transformedEvent.latitude = Number(event.locationLatitude.trim())
  transformedEvent.longitude = Number(event.locationLongitude.trim())
  transformedEvent.coordinates = [transformedEvent.latitude, transformedEvent.longitude]
  transformedEvent.hasCoordinates = (transformedEvent.latitude && transformedEvent.longitude && !Number.isNaN(transformedEvent.latitude) && !Number.isNaN(transformedEvent.longitude))
  transformedEvent.intendedAges = event.intendedAges.trim()
  transformedEvent.themeCampName = event.themeCampName.trim()

  return transformedEvent
}
{'fraction_non_alphanumeric': 0.12266301869585043, 'fraction_numerical': 0.0013679890560875513, 'mean_word_length': 5.415204678362573, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '730564', 'n_tokens_mistral': 630, 'n_tokens_neox': 604, 'n_words': 117}