<commit_before>module Physiqual
  module Exporters
    class RawExporter < Exporter
      def configure(service_provider, data_source)
        @service_provider = service_provider
        @data_source = data_source
        self
      end

      def export_data(user, first_measurement, number_of_days)
        tokens = []
        if @service_provider == GoogleToken.csrf_token
          tokens = user.google_tokens
        elsif @service_provider == FitbitToken.csrf_token
          tokens = user.fitbit_tokens
        end
        return [] unless !tokens.blank? && tokens.first.complete?
        token = tokens.first
        session = Sessions::TokenAuthorizedSession.new(token.token, token.class.base_uri)
        service = DataServices::DataServiceFactory.fabricate!(token.class.csrf_token, session)

        from = first_measurement - Physiqual.hours_before_first_measurement.hours
        to   = first_measurement + (number_of_days - 1).days +
               ((Physiqual.measurements_per_day - 1) * Physiqual.interval).hours

        service.send(@data_source.to_sym, from, to)
      end<commit_msg>codeclimate<commit_after>module Physiqual
  module Exporters
    class RawExporter < Exporter
      def configure(service_provider, data_source)
        @service_provider = service_provider
        @data_source = data_source
        self
      end

      def export_data(user, first_measurement, number_of_days)
        tokens = Token.provider_tokens(@service_provider, user)
        return [] unless !tokens.blank? && tokens.first.complete?
        token = tokens.first
        session = Sessions::TokenAuthorizedSession.new(token.token, token.class.base_uri)
        service = DataServices::DataServiceFactory.fabricate!(token.class.csrf_token, session)

        from = first_measurement - Physiqual.hours_before_first_measurement.hours
        to   = first_measurement + (number_of_days - 1).days +
               ((Physiqual.measurements_per_day - 1) * Physiqual.interval).hours

        service.send(@data_source.to_sym, from, to)
      end
{'fraction_non_alphanumeric': 0.08247925817471938, 'fraction_numerical': 0.0019521717911176184, 'mean_word_length': 2.9883268482490273, 'pattern_counts': {'":': 0, '<': 5, '<?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': '512045', 'n_tokens_mistral': 597, 'n_tokens_neox': 573, 'n_words': 106}