<commit_before>import Ember from 'ember';
import DS from 'ember-data';
import _ from 'npm:lodash';

var Feed = DS.Model.extend({
  onestop_id: Ember.computed.alias('id'),
  operators: DS.hasMany('operator', { async: true }),
  url: DS.attr('string'),
  feed_format: DS.attr('string'),
  license_name: DS.attr('string'),
  license_url: DS.attr('string'),
  license_use_without_attribution: DS.attr('string'),
  license_create_derived_product: DS.attr('string'),
  license_redistribute: DS.attr('string'),
  license_attribution_text: DS.attr('string'),
  last_sha1: DS.attr('string'),
  last_fetched_at: DS.attr('string'),
  last_imported_at: DS.attr('string'),
  created_at: DS.attr('date'),
  updated_at: DS.attr('date'),
  operators_in_feed: DS.attr(),
  geometry: DS.attr(),
  tags: DS.attr(),
  import_level_of_active_feed_version: DS.attr(),
	isAtLeastImportLevelZero: Ember.computed.gte('import_level_of_active_feed_version', 0),
	isAtLeastImportLevelOne: Ember.computed.gte('import_level_of_active_feed_version', 1),
	isAtLeastImportLevelTwo: Ember.computed.gte('import_level_of_active_feed_version', 2),
	isAtLeastImportLevelFour: Ember.computed.gte('import_level_of_active_feed_version', 4),
  addOperator: function(operator) {
    this.get('operators').createRecord({
      id: operator.onestop_id,
      name: operator.name,
      short_name: operator.short_name,
      country: operator.country,
      state: operator.state,
      metro: operator.metro,
      website: operator.website,
      timezone: operator.timezone,
      geometry: operator.geometry,
      tags: operator.tags
    });
  },
  toChange: function() {
    var feedJson = {};
    // Map Ember data attributes to Feed Schema
    feedJson.onestopId = this.id;
    feedJson.geometry = this.get('geometry');
    feedJson.name = this.get('name');
    feedJson.tags = this.get('tags');
    feedJson.url = this.get('url');
    feedJson.feedFormat = this.get('feed_format');
    feedJson.licenseName = this.get('license_name');
    feedJson.licenseUrl = this.get('license_url');
    feedJson.licenseUseWithoutAttribution = this.get('license_use_without_attribution');
    feedJson.licenseAttributionText = this.get('license_attribution_text');
    feedJson.licenseCreateDerivedProduct = this.get('license_create_derived_product');
    feedJson.licenseRedistribute = this.get('license_redistribute');
    // Lookup table of operator onestop_id to gtfs agency_id
    // ex. gtfs_agency_id['o-9q9-caltrain'] = 'ca-us-caltrain';
    var gtfs_agency_ids = {};
    this.get('operators_in_feed').forEach(function(oif) {
      gtfs_agency_ids[oif.operator_onestop_id] = oif.gtfs_agency_id
    });
    // filter operators by include_in_changeset
    feedJson.includesOperators = this
      .get('operators')
      .filterBy('include_in_changeset', true)
      .map(function(operator) {
        return {
          gtfsAgencyId: gtfs_agency_ids[operator.get('onestop_id')],
          operatorOnestopId: operator.get('onestop_id')
        }
      });
    // remove any attributes with null values, undefined values, or empty strings
    feedJson = _.omit(feedJson, function(value) {
      return value === null || value === '' || value === undefined;
    });
    return feedJson;
  }
});


export default Feed;
<commit_msg>Feed: only include changed attributes<commit_after>import Ember from 'ember';
import DS from 'ember-data';
import _ from 'npm:lodash';

var Feed = DS.Model.extend({
  onestop_id: Ember.computed.alias('id'),
  operators: DS.hasMany('operator', { async: true }),
  url: DS.attr('string'),
  feed_format: DS.attr('string'),
  license_name: DS.attr('string'),
  license_url: DS.attr('string'),
  license_use_without_attribution: DS.attr('string'),
  license_create_derived_product: DS.attr('string'),
  license_redistribute: DS.attr('string'),
  license_attribution_text: DS.attr('string'),
  last_sha1: DS.attr('string'),
  last_fetched_at: DS.attr('string'),
  last_imported_at: DS.attr('string'),
  created_at: DS.attr('date'),
  updated_at: DS.attr('date'),
  operators_in_feed: DS.attr(),
  geometry: DS.attr(),
  tags: DS.attr(),
  import_level_of_active_feed_version: DS.attr(),
	isAtLeastImportLevelZero: Ember.computed.gte('import_level_of_active_feed_version', 0),
	isAtLeastImportLevelOne: Ember.computed.gte('import_level_of_active_feed_version', 1),
	isAtLeastImportLevelTwo: Ember.computed.gte('import_level_of_active_feed_version', 2),
	isAtLeastImportLevelFour: Ember.computed.gte('import_level_of_active_feed_version', 4),
  addOperator: function(operator) {
    this.get('operators').createRecord({
      id: operator.onestop_id,
      name: operator.name,
      short_name: operator.short_name,
      country: operator.country,
      state: operator.state,
      metro: operator.metro,
      website: operator.website,
      timezone: operator.timezone,
      geometry: operator.geometry,
      tags: operator.tags
    });
  },
  toChange: function() {
    var change = {};
    change.onestopId = this.id;
    // Map Ember data attributes to Feed Schema
    var changed_attributes = this.changedAttributes();
    var changed_key_map = {
      geometry: 'geometry',
      name: 'name',
      tags: 'tags',
      url: 'url',
      feed_format: 'feedFormat',
      license_name: 'licenseName',
      license_url: 'licenseUrl',
      license_use_without_attribution: 'licenseUseWithoutAttribution',
      license_attribution_text: 'licenseAttributionText',
      license_create_derived_product: 'licenseCreateDerivedProduct',
      license_redistribute: 'licenseRedistribute'
    }
    for (var changed_key in changed_attributes) {
      var old_value = changed_attributes[changed_key][0];
      var new_value = changed_attributes[changed_key][1];
      var new_key = changed_key_map[changed_key];
      if (new_key) {
        change[new_key] = new_value;
      } else {
        console.log('No handler for:', changed_key)
      }
    };
    // Lookup table of operator onestop_id to gtfs agency_id
    // ex. gtfs_agency_id['o-9q9-caltrain'] = 'ca-us-caltrain';
    var gtfs_agency_ids = {};
    (this.get('operators_in_feed') || []).forEach(function(oif) {
      gtfs_agency_ids[oif.operator_onestop_id] = oif.gtfs_agency_id
    });
    // Filter operators by include_in_changeset
    change.includesOperators = this
      .get('operators')
      .filterBy('include_in_changeset', true)
      .map(function(operator) {
        return {
          gtfsAgencyId: gtfs_agency_ids[operator.get('onestop_id')],
          operatorOnestopId: operator.get('onestop_id')
        }
      });
    // remove any attributes with null values, undefined values, or empty strings
    feedJson = _.omit(feedJson, function(value) {
      return value === null || value === '' || value === undefined;
    });
    return feedJson;
  }
});


export default Feed;

{'fraction_non_alphanumeric': 0.13224107665301346, 'fraction_numerical': 0.0023405500292568754, 'mean_word_length': 4.094634873323398, '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': '1020807', 'n_tokens_mistral': 2279, 'n_tokens_neox': 2230, 'n_words': 393}