<commit_before># == Schema Information
#
# Table name: withings_accounts
#
#  id                 :integer          not null, primary key
#  userid             :string(255)
#  created_at         :datetime         not null
#  updated_at         :datetime         not null
#  oauth_token        :string(255)
#  oauth_verifier     :string(255)
#  user_id            :integer
#  oauth_token_secret :string(255)
#

class WithingsAccount < DataProvider
  attr_accessible :userid, :oauth_token, :oauth_token_secret

  validates_presence_of :userid, :oauth_token, :oauth_token_secret

  def get_user_data
    if synced_at
      sync_measurement_groups WithingsAccount.authenticated_user(id).send(:measurement_groups, { start_at: synced_at })
    else
      sync_measurement_groups WithingsAccount.authenticated_user(id).send(:measurement_groups)
    end

    update_attribute :synced_at, Time.now
  end

  def sync_measurement_groups(measurement_groups)
    binding.pry
    measurement_groups.each do |measurement|
      return if user.weights.where("meta @> 'grpid=>#{measurement.grpid.to_s}'").first
      user.weights.create(
        value: Unit.new(measurement.weight, :kilograms).to(:pounds),<commit_msg>Removed erroneously committed line<commit_after># == Schema Information
#
# Table name: withings_accounts
#
#  id                 :integer          not null, primary key
#  userid             :string(255)
#  created_at         :datetime         not null
#  updated_at         :datetime         not null
#  oauth_token        :string(255)
#  oauth_verifier     :string(255)
#  user_id            :integer
#  oauth_token_secret :string(255)
#

class WithingsAccount < DataProvider
  attr_accessible :userid, :oauth_token, :oauth_token_secret

  validates_presence_of :userid, :oauth_token, :oauth_token_secret

  def get_user_data
    if synced_at
      sync_measurement_groups WithingsAccount.authenticated_user(id).send(:measurement_groups, { start_at: synced_at })
    else
      sync_measurement_groups WithingsAccount.authenticated_user(id).send(:measurement_groups)
    end

    update_attribute :synced_at, Time.now
  end

  def sync_measurement_groups(measurement_groups)
    measurement_groups.each do |measurement|
      return if user.weights.where("meta @> 'grpid=>#{measurement.grpid.to_s}'").first
      user.weights.create(
        value: Unit.new(measurement.weight, :kilograms).to(:pounds),
{'fraction_non_alphanumeric': 0.08856548856548857, 'fraction_numerical': 0.00997920997920998, 'mean_word_length': 3.4065934065934065, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '5692316', 'n_tokens_mistral': 785, 'n_tokens_neox': 754, 'n_words': 143}