<commit_before>import { Map, List } from 'immutable';
import * as _ from 'lodash';
import { getPromotions, filterPromotions } from '../utils/marketingUtils';

const productPropertiesMap = Map({
  prod_id: ['code'],
  prod_name: ['name'],
  prod_brand: ['brand', 'name'],
  prod_category: ['mainCategoryName'],
  prod_univers: ['mainCategoryRooms', '0'],
  prod_price: ['price', 'selling', 'gross'],
  prod_avail_online: ['vendible'],
  prod_avail_store: ['isClickCollectProduct'],
  prod_gamma: ['gamma'],
  prod_sconto: ['price', 'selling', 'discount']
});

const buildCommonLayer = (product) => {
  const commonPropertiesLayer = productPropertiesMap.reduce((acc, property, key) => {
    const productProperty = product.hasIn(property) ? product.getIn(property) : 'null';
    return acc.set(key, List().push(productProperty));
  }, Map({}));

  const normalizedCommonPropertiesLayer = normalizeProperties(commonPropertiesLayer);
  return normalizedCommonPropertiesLayer;
};

const normalizeProperties = (layer) => {
  let obj = layer;
  obj = obj.set('prod_sconto', normalizeSconto(obj.get('prod_sconto')));
  obj = obj.set('prod_avail_online', normalizeAvail(obj.get('prod_avail_online')));
  obj = obj.set('prod_avail_store', normalizeAvail(obj.get('prod_avail_store')));
  return obj;
};

const normalizeSconto = (value = Map({})) => {
  const sconto = value.get(0);
  return List().push(sconto !== 'null' ? Math.round(sconto * 10) : sconto);
};

const normalizeAvail = (field = List()) => List().push(field.get(0) ? '1' : '0');<commit_msg>fix default value if product doesn't have property<commit_after>import { Map, List } from 'immutable';
import * as _ from 'lodash';
import { getPromotions, filterPromotions } from '../utils/marketingUtils';

const productPropertiesMap = Map({
  prod_id: ['code'],
  prod_name: ['name'],
  prod_brand: ['brand', 'name'],
  prod_category: ['mainCategoryName'],
  prod_univers: ['mainCategoryRooms', '0'],
  prod_price: ['price', 'selling', 'gross'],
  prod_avail_online: ['vendible'],
  prod_avail_store: ['isClickCollectProduct'],
  prod_gamma: ['gamma'],
  prod_sconto: ['price', 'selling', 'discount']
});

const buildCommonLayer = (product) => {
  const commonPropertiesLayer = productPropertiesMap.reduce((acc, property, key) => {
    const productProperty = product.hasIn(property) ? product.getIn(property) : '';
    return acc.set(key, List().push(productProperty));
  }, Map({}));

  const normalizedCommonPropertiesLayer = normalizeProperties(commonPropertiesLayer);
  return normalizedCommonPropertiesLayer;
};

const normalizeProperties = (layer) => {
  let obj = layer;
  obj = obj.set('prod_sconto', normalizeSconto(obj.get('prod_sconto')));
  obj = obj.set('prod_avail_online', normalizeAvail(obj.get('prod_avail_online')));
  obj = obj.set('prod_avail_store', normalizeAvail(obj.get('prod_avail_store')));
  return obj;
};

const normalizeSconto = (value = Map({})) => {
  const sconto = value.get(0);
  return List().push(sconto !== 'null' ? Math.round(sconto * 10) : sconto);
};

const normalizeAvail = (field = List()) => List().push(field.get(0) ? '1' : '0');
{'fraction_non_alphanumeric': 0.17526433835309196, 'fraction_numerical': 0.004485741749439282, 'mean_word_length': 5.96875, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '5913727', 'n_tokens_mistral': 1038, 'n_tokens_neox': 1014, 'n_words': 209}