<commit_before>import { Injectable } from '@angular/core';
import { File, FileEntry } from '@ionic-native/file';
import { Trip } from './trip';
import { ObjectManager } from './object_manager';
import { Storage } from './storage';
import { Locations } from './locations';
import * as moment from 'moment';

@Injectable()
export class Trips extends ObjectManager {
  protected table = 'trip';
  protected columns = [
    'origin_type',
    'destination_type',
    'start_time',
    'end_time',
    'distance',
    'transit',
    'submitted',
    'desired_accuracy',
    'app_version',
    'image_url'
  ];

  constructor(protected locations: Locations, protected storage: Storage, protected file: File) {
    super();
  }

  protected fromRow(row) {
    return new Trip(
      row.id,
      row.origin_type,
      row.destination_type,
      moment(row.start_time),
      moment(row.end_time),
      row.distance,
      row.transit === 1,
      row.submitted === 1,
      row.desired_accuracy,
      row.app_version,
      row.image_url
    )
  }

  protected toRow(trip: Trip) {
    return [
      trip.origin,
      trip.destination,
      trip.startTime.valueOf(),
      trip.endTime.valueOf(),
      trip.distance,
      + trip.transit,
      + trip.submitted,
      trip.desiredAccuracy,
      trip.appVersion,
      trip.imageUrl
    ];
  }

  protected imagePath(trip) {
    return `images/trip-${trip.id}.jpg`;
  }

  public delete(trip: Trip) {
    let locationDelete = this.locations.batchDelete(`trip_id = ?`, [trip.id]),
      imageDelete = (trip.imageUrl) ?
        this.deleteImage(trip) : Promise.resolve();
    return Promise.all([locationDelete, imageDelete, super.delete(trip)]);
  }

  public deleteImage(trip) {
    return this.file.removeFile(
      this.file.dataDirectory, this.imagePath(trip));
  }

  public saveImage(trip, blob) {
    return this.file.createDir(this.file.dataDirectory, 'images', false)
      .catch((err) => { if (err.code !== 12) throw err })
      .then<FileEntry>(() => this.file.writeFile(
        this.file.dataDirectory, this.imagePath(trip), blob, {
          replace: true<commit_msg>Location deletes are now handled by the database.<commit_after>import { Injectable } from '@angular/core';
import { File, FileEntry } from '@ionic-native/file';
import { Trip } from './trip';
import { ObjectManager } from './object_manager';
import { Storage } from './storage';
import { Locations } from './locations';
import * as moment from 'moment';

@Injectable()
export class Trips extends ObjectManager {
  protected table = 'trip';
  protected columns = [
    'origin_type',
    'destination_type',
    'start_time',
    'end_time',
    'distance',
    'transit',
    'submitted',
    'desired_accuracy',
    'app_version',
    'image_url'
  ];

  constructor(protected locations: Locations, protected storage: Storage, protected file: File) {
    super();
  }

  protected fromRow(row) {
    return new Trip(
      row.id,
      row.origin_type,
      row.destination_type,
      moment(row.start_time),
      moment(row.end_time),
      row.distance,
      row.transit === 1,
      row.submitted === 1,
      row.desired_accuracy,
      row.app_version,
      row.image_url
    )
  }

  protected toRow(trip: Trip) {
    return [
      trip.origin,
      trip.destination,
      trip.startTime.valueOf(),
      trip.endTime.valueOf(),
      trip.distance,
      + trip.transit,
      + trip.submitted,
      trip.desiredAccuracy,
      trip.appVersion,
      trip.imageUrl
    ];
  }

  protected imagePath(trip) {
    return `images/trip-${trip.id}.jpg`;
  }

  public delete(trip: Trip) {
    let imageDelete = (trip.imageUrl) ?
        this.deleteImage(trip) : Promise.resolve();
    return Promise.all([imageDelete, super.delete(trip)]);
  }

  public deleteImage(trip) {
    return this.file.removeFile(
      this.file.dataDirectory, this.imagePath(trip));
  }

  public saveImage(trip, blob) {
    return this.file.createDir(this.file.dataDirectory, 'images', false)
      .catch((err) => { if (err.code !== 12) throw err })
      .then<FileEntry>(() => this.file.writeFile(
        this.file.dataDirectory, this.imagePath(trip), blob, {
          replace: true
{'fraction_non_alphanumeric': 0.13814384049370995, 'fraction_numerical': 0.0018988844054118206, 'mean_word_length': 2.8838709677419354, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '1498599', 'n_tokens_mistral': 1376, 'n_tokens_neox': 1314, 'n_words': 278}