<commit_before>var Moves = require('moves');
var dates = require('moves-date');
var moves;

var defaultPort = 3000;
var defaultUrl = 'http://localhost:' + defaultPort + '/';
var MAX_DAYS = 50;

var adapter = {};

var eventType = 'moves-summary';
var c8 = correl8(eventType);

adapter.sensorName = 'googlecalendar-event';

var summaryIndex = 'moves-summary';
var summaryType = 'moves-summary';
var moveIndex = 'moves-move';
var moveType = 'moves-move';
var placeIndex = 'moves-place';
var placeType = 'moves-place';

adapter.types = [
  {
    name: 'moves-summary',
    fields: {
      timestamp: 'date',
      summary: {
        activity: 'string',
        group: 'string',
        duration: 'float',
        distance: 'float',
        steps: 'integer',
        calories: 'integer'
      },
      caloriesIdle: 'integer',
      lastUpdate: 'date'
    }
  },
  {
    name: 'moves-move',
    fields: {
      type: 'string',
      startTime: 'date',
      endTime: 'date',
      activities: {
        activity: 'string',
        group: 'string',
        manual: 'boolean',
        startTime: 'date',
        endTime: 'date',
        duration: 'float',
        distance: 'float',
        steps: 'integer',
        calories: 'integer',
        trackPoints: {
          lat: 'float',
          lon: 'float',
          position: 'geo_point',
          time: 'date'
        }
      },
      'lastUpdate': 'date'
    }
  },
  {
    name: 'moves-place',
    fields: {
      type: 'string',
      startTime: 'date',
      endTime: 'date',
      duration: 'float',
      activities: {
        activity: 'string',
        group: 'string',
        manual: 'boolean',
        startTime: 'date',
        endTime: 'date',
        duration: 'float',
        distance: 'float',
        steps: 'integer',
        calories: 'integer',
        trackPoints: {
          lat: 'float',
          lon: 'float',
          position: 'geo_point',
          time: 'date'
        }
      },
      place: {
        id: 'integer',
        type: 'string',
        foursquareId: 'string',
        foursquareCategoryIds: 'string',
        // position: 'geo_point',
        location: {
          lat: 'float',
          lon: 'float',
          position: 'geo_point'
        }
      },
      'lastUpdate': 'date'
    }
  }
];

adapter.promptProps = {
  properties: {
    client_id: {
      description: 'Enter your Moves client ID'.magenta
    },
    client_secret: {
      description: 'Enter your Moves client secret'.magenta
    },
    redirect_uri: {
      description: 'Enter your redirect URL (' + defaultUrl+ ')'.magenta,
      default: defaultUrl
    },
  }
};

adapter.storeConfig = function(c8, result) {
  var app = express();
  app.all('/', function (req, res) {
    if (req.query && req.query.code) {
      moves = new Moves(result);
      moves.token(req.query.code, function(error, response, body) {
        if (error) {
          console.trace(error);
          res.json(error);
          return;
        }
        var rb = JSON.parse(response.body);
        if (rb) {
          return c8.config(rb).then(function(){
            console.log('Configuration stored.');
          }).catch(function(error) {
            console.trace(error);
          });
        }
        else {
          console.error('Authorization failed');
          console.trace(res);
        }
      });
    }
    else {
      res.send('Waiting for code in query string...');
    }
  });
  var server = app.listen(defaultPort, function () {
    var host = server.address().address;
    var port = server.address().port;
    // console.log('Temporary Moves auth server listening at http://%s:%s', host, port);
  });
}

adapter.importData = function(c8, conf, opts) {
  moves = new Moves(conf);
  c8.type(summaryType).search({
    _source: ['timestamp'],<commit_msg>finalized modularization<commit_after>var Moves = require('moves');
var dates = require('moves-date');
var express = require('express');
var moves;

var defaultPort = 3000;
var defaultUrl = 'http://localhost:' + defaultPort + '/';
var MAX_DAYS = 50;

var adapter = {};

adapter.sensorName = 'moves';

var summaryIndex = 'moves-summary';
var summaryType = 'moves-summary';
var moveIndex = 'moves-move';
var moveType = 'moves-move';
var placeIndex = 'moves-place';
var placeType = 'moves-place';

adapter.types = [
  {
    name: 'moves-summary',
    fields: {
      timestamp: 'date',
      summary: {
        activity: 'string',
        group: 'string',
        duration: 'float',
        distance: 'float',
        steps: 'integer',
        calories: 'integer'
      },
      caloriesIdle: 'integer',
      lastUpdate: 'date'
    }
  },
  {
    name: 'moves-move',
    fields: {
      type: 'string',
      startTime: 'date',
      endTime: 'date',
      activities: {
        activity: 'string',
        group: 'string',
        manual: 'boolean',
        startTime: 'date',
        endTime: 'date',
        duration: 'float',
        distance: 'float',
        steps: 'integer',
        calories: 'integer',
        trackPoints: {
          lat: 'float',
          lon: 'float',
          position: 'geo_point',
          time: 'date'
        }
      },
      'lastUpdate': 'date'
    }
  },
  {
    name: 'moves-place',
    fields: {
      type: 'string',
      startTime: 'date',
      endTime: 'date',
      duration: 'float',
      activities: {
        activity: 'string',
        group: 'string',
        manual: 'boolean',
        startTime: 'date',
        endTime: 'date',
        duration: 'float',
        distance: 'float',
        steps: 'integer',
        calories: 'integer',
        trackPoints: {
          lat: 'float',
          lon: 'float',
          position: 'geo_point',
          time: 'date'
        }
      },
      place: {
        id: 'integer',
        type: 'string',
        foursquareId: 'string',
        foursquareCategoryIds: 'string',
        // position: 'geo_point',
        location: {
          lat: 'float',
          lon: 'float',
          position: 'geo_point'
        }
      },
      'lastUpdate': 'date'
    }
  }
];

adapter.promptProps = {
  properties: {
    client_id: {
      description: 'Enter your Moves client ID'.magenta
    },
    client_secret: {
      description: 'Enter your Moves client secret'.magenta
    },
    redirect_uri: {
      description: 'Enter your redirect URL'.magenta,
      default: defaultUrl
    },
  }
};

adapter.storeConfig = function(c8, result) {
  var conf = result;
  var app = express();
  var server = app.listen(defaultPort, function () {
    var host = server.address().address;
    var port = server.address().port;
    // console.log('Temporary Moves auth server listening at http://%s:%s', host, port);
  });
  moves = new Moves(result);
  var auth_url = moves.authorize({
    scope: ['activity', 'location']
  });
  console.log('Authorize the app by opening the followin url in your browser:\n ' + auth_url);
  app.all('/', function (req, res) {
    if (req.query && req.query.code) {
      // moves = new Moves(result);
      moves.token(req.query.code, function(error, response, body) {
        if (error) {
          console.trace(error);
          res.json(error);
          return;
        }
        var rb = JSON.parse(response.body);
        if (rb) {
          Object.assign(conf, rb);
          server.close();
          return c8.config(conf).then(function(){
            res.send('Access token saved.');
            console.log('Configuration stored.');
            c8.release();
            process.exit();
          }).catch(function(error) {
            console.trace(error);
          });
        }
        else {
          console.error('Authorization failed');
          console.trace(res);
        }
      });
    }
    else {
      res.send('Waiting for code in query string...');
    }
  });
}

adapter.importData = function(c8, conf, opts) {
  moves = new Moves(conf);
  c8.type(summaryType).search({
    _source: ['timestamp'],
{'fraction_non_alphanumeric': 0.15096709369505149, 'fraction_numerical': 0.0028887214267771916, 'mean_word_length': 1.9969890854347008, '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': '6460365', 'n_tokens_mistral': 2421, 'n_tokens_neox': 2434, 'n_words': 565}