<commit_before>import Rebase from 're-base';
import GeoFire from 'geofire';
import Q from 'q';

import { firebase } from './config';

var ENDPOINT_URI = firebase.ENDPOINT_URI;

import helpers from './helpers';

var base = Rebase.createClass(ENDPOINT_URI);

var platesRef = new Firebase(`${ENDPOINT_URI}/plates`);
var geoFireRef = new Firebase(`${ENDPOINT_URI}/geofire`);
var usersRef = new Firebase(`${ENDPOINT_URI}/users`);
var imageDataRef = new Firebase(`${ENDPOINT_URI}/image-data`);

var geoFire = new GeoFire(geoFireRef);

var firebase_api = {
  getDistance(location1, location2) {
    // returns kms
    return GeoFire.distance(location1, location2);
  },
  getReBase() {
    return base;
  },
  addUser(user) {
    var {id, first_name, last_name } = user;
    var profile_image = user.picture.data.url;

    base.post(`users/${id}`, {
      data: {first_name, last_name, profile_image},
      then() {
        console.log(`User ${first_name} ${last_name} Updated`);
      }
    });
  },
  addImageData(image_id, image_url, user_id, restaurant_id, plate_id) {
    var deferred = Q.defer();
    var date = new Date().toString();
    var feeling = 'meh';

    base.post(`image-data/${image_id}`, {
      data: {date, feeling, user_id, image_url, restaurant_id, plate_id},
      then() {
        deferred.resolve('image data updated');
      }
    });

    return deferred.promise;
  },
  getUserByImageId(imageId) {
    var deferred = Q.defer();

    base.fetch(`image-data/${imageId}`, {
      context: this,
      then(imageData) {
        if(!imageData) {
          return deferred.reject(new Error(`no image data for ${imageId}`));
        }
        base.fetch(`users/${imageData.user_id}`, {
          context: this,
          then(user) {
            deferred.resolve(user);
          }<commit_msg>[Bugfix] dont remove user adventures on logout<commit_after>import Rebase from 're-base';
import GeoFire from 'geofire';
import Q from 'q';

import { firebase } from './config';

var ENDPOINT_URI = firebase.ENDPOINT_URI;

import helpers from './helpers';

var base = Rebase.createClass(ENDPOINT_URI);

var platesRef = new Firebase(`${ENDPOINT_URI}/plates`);
var geoFireRef = new Firebase(`${ENDPOINT_URI}/geofire`);
var usersRef = new Firebase(`${ENDPOINT_URI}/users`);
var imageDataRef = new Firebase(`${ENDPOINT_URI}/image-data`);

var geoFire = new GeoFire(geoFireRef);

var firebase_api = {
  getDistance(location1, location2) {
    // returns kms
    return GeoFire.distance(location1, location2);
  },
  getReBase() {
    return base;
  },
  addUser(user) {
    var {id, first_name, last_name } = user;
    var userRef = usersRef.child(id);
    var profile_image = user.picture.data.url;

    userRef.child('first_name').set(first_name);
    userRef.child('last_name').set(last_name);
    userRef.child('profile_image').set(profile_image);
  },
  addImageData(image_id, image_url, user_id, restaurant_id, plate_id) {
    var deferred = Q.defer();
    var date = new Date().toString();
    var feeling = 'meh';

    base.post(`image-data/${image_id}`, {
      data: {date, feeling, user_id, image_url, restaurant_id, plate_id},
      then() {
        deferred.resolve('image data updated');
      }
    });

    return deferred.promise;
  },
  getUserByImageId(imageId) {
    var deferred = Q.defer();

    base.fetch(`image-data/${imageId}`, {
      context: this,
      then(imageData) {
        if(!imageData) {
          return deferred.reject(new Error(`no image data for ${imageId}`));
        }
        base.fetch(`users/${imageData.user_id}`, {
          context: this,
          then(user) {
            deferred.resolve(user);
          }
{'fraction_non_alphanumeric': 0.14773347897323866, 'fraction_numerical': 0.002184598580010923, 'mean_word_length': 3.2792056074766354, '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': '3482710', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1207, 'n_words': 256}