<commit_before>'use strict';

/*
 * The general structure of this code is that all the timeline information for
 * a particular day is retrieved from the Timeline factory and put into the scope.
 * For best performance, all data should be loaded into the in-memory timeline,
 * and in addition to writing to storage, the data should be written to memory.
 * All UI elements should only use $scope variables.
 */

angular.module('emission.main.diary.infscrolllist',['ui-leaflet',
                                      'ionic-datepicker',
                                      'emission.main.common.services',
                                      'emission.incident.posttrip.manual',
                                      'emission.tripconfirm.services',
                                      'emission.services',
                                      'ng-walkthrough', 'nzTour', 'emission.plugin.kvstore',
                                      'emission.main.diary.infscrollfilters',
                                      'emission.stats.clientstats',
                                      'emission.plugin.logger'])

.controller("InfiniteDiaryListCtrl", function($window, $scope, $rootScope, $ionicPlatform, $state,
                                    $ionicScrollDelegate, $ionicPopup, ClientStats,
                                    $ionicLoading,
                                    $ionicActionSheet,
                                    ionicDatePicker,
                                    leafletData, Timeline, CommonGraph, DiaryHelper,
                                    InfScrollFilters,
    Config, PostTripManualMarker, ConfirmHelper, nzTour, KVStore, Logger, UnifiedDataLoader, $ionicPopover, $ionicModal, $translate) {

  // TODO: load only a subset of entries instead of everything

  console.log("controller InfiniteDiaryListCtrl called");
  // Add option

  const placeLimiter = new Bottleneck({ maxConcurrent: 2, minTime: 500 });

  $scope.userInputDetails = [];
  ConfirmHelper.INPUTS.forEach(function(item, index) {
    const currInput = angular.copy(ConfirmHelper.inputDetails[item]);
    currInput.name = item;
    $scope.userInputDetails.push(currInput);
  });

  $scope.data = {};
  // reset all filters
  $scope.filterInputs = [
    InfScrollFilters.TO_LABEL,
    InfScrollFilters.UNLABELED
  ];
  $scope.filterInputs.forEach((f) => {
    f.state = false;
  });
  $scope.filterInputs[0].state = true;
  $scope.allTrips = false;
  const ONE_WEEK = 7 * 24 * 60 * 60; // seconds

  $scope.infScrollControl = {threshold: 75, scrollLock: true, fromBottom: -1, callback: undefined};

  $scope.readDataFromServer = function() {
    $scope.infScrollControl.scrollLock = true;
    $scope.infScrollControl.fromBottom = $ionicScrollDelegate.getScrollView().__contentHeight-$ionicScrollDelegate.getScrollPosition().top;
    console.log("calling readDataFromServer with "+
        JSON.stringify($scope.infScrollControl));
    const currEnd = $scope.infScrollControl.currentEnd;
    if (!angular.isDefined(currEnd)) {
        console.log("trying to read data too early, early return");
        $scope.$broadcast('scroll.infiniteScrollComplete')
        return;
    }
    Timeline.readAllConfirmedTrips(currEnd, ONE_WEEK).then((ctList) => {
        Logger.log("Received batch of size "+ctList.length);
        ctList.forEach($scope.populateBasicClasses);
        ctList.forEach((trip, tIndex) => {
            // console.log("Expectation: "+JSON.stringify(trip.expectation));
            // console.log("Inferred labels from server: "+JSON.stringify(trip.inferred_labels));
            trip.userInput = {};
            ConfirmHelper.INPUTS.forEach(function(item, index) {
                $scope.populateManualInputs(trip, ctList[tIndex+1], item, $scope.data.manualResultMap[item]);
            });
            trip.finalInference = {};
            $scope.inferFinalLabels(trip);
            $scope.updateVerifiability(trip);
        });
        ctList.forEach(function(trip, index) {<commit_msg>Fill place names in bottom -> upwards order<commit_after>'use strict';

/*
 * The general structure of this code is that all the timeline information for
 * a particular day is retrieved from the Timeline factory and put into the scope.
 * For best performance, all data should be loaded into the in-memory timeline,
 * and in addition to writing to storage, the data should be written to memory.
 * All UI elements should only use $scope variables.
 */

angular.module('emission.main.diary.infscrolllist',['ui-leaflet',
                                      'ionic-datepicker',
                                      'emission.main.common.services',
                                      'emission.incident.posttrip.manual',
                                      'emission.tripconfirm.services',
                                      'emission.services',
                                      'ng-walkthrough', 'nzTour', 'emission.plugin.kvstore',
                                      'emission.main.diary.infscrollfilters',
                                      'emission.stats.clientstats',
                                      'emission.plugin.logger'])

.controller("InfiniteDiaryListCtrl", function($window, $scope, $rootScope, $ionicPlatform, $state,
                                    $ionicScrollDelegate, $ionicPopup, ClientStats,
                                    $ionicLoading,
                                    $ionicActionSheet,
                                    ionicDatePicker,
                                    leafletData, Timeline, CommonGraph, DiaryHelper,
                                    InfScrollFilters,
    Config, PostTripManualMarker, ConfirmHelper, nzTour, KVStore, Logger, UnifiedDataLoader, $ionicPopover, $ionicModal, $translate) {

  // TODO: load only a subset of entries instead of everything

  console.log("controller InfiniteDiaryListCtrl called");
  // Add option

  const placeLimiter = new Bottleneck({ maxConcurrent: 2, minTime: 500 });

  $scope.userInputDetails = [];
  ConfirmHelper.INPUTS.forEach(function(item, index) {
    const currInput = angular.copy(ConfirmHelper.inputDetails[item]);
    currInput.name = item;
    $scope.userInputDetails.push(currInput);
  });

  $scope.data = {};
  // reset all filters
  $scope.filterInputs = [
    InfScrollFilters.TO_LABEL,
    InfScrollFilters.UNLABELED
  ];
  $scope.filterInputs.forEach((f) => {
    f.state = false;
  });
  $scope.filterInputs[0].state = true;
  $scope.allTrips = false;
  const ONE_WEEK = 7 * 24 * 60 * 60; // seconds

  $scope.infScrollControl = {threshold: 75, scrollLock: true, fromBottom: -1, callback: undefined};

  $scope.readDataFromServer = function() {
    $scope.infScrollControl.scrollLock = true;
    $scope.infScrollControl.fromBottom = $ionicScrollDelegate.getScrollView().__contentHeight-$ionicScrollDelegate.getScrollPosition().top;
    console.log("calling readDataFromServer with "+
        JSON.stringify($scope.infScrollControl));
    const currEnd = $scope.infScrollControl.currentEnd;
    if (!angular.isDefined(currEnd)) {
        console.log("trying to read data too early, early return");
        $scope.$broadcast('scroll.infiniteScrollComplete')
        return;
    }
    Timeline.readAllConfirmedTrips(currEnd, ONE_WEEK).then((ctList) => {
        Logger.log("Received batch of size "+ctList.length);
        ctList.forEach($scope.populateBasicClasses);
        ctList.forEach((trip, tIndex) => {
            // console.log("Expectation: "+JSON.stringify(trip.expectation));
            // console.log("Inferred labels from server: "+JSON.stringify(trip.inferred_labels));
            trip.userInput = {};
            ConfirmHelper.INPUTS.forEach(function(item, index) {
                $scope.populateManualInputs(trip, ctList[tIndex+1], item, $scope.data.manualResultMap[item]);
            });
            trip.finalInference = {};
            $scope.inferFinalLabels(trip);
            $scope.updateVerifiability(trip);
        });
        // Fill places on a reversed copy of the list so we fill from the bottom up
        ctList.slice().reverse().forEach(function(trip, index) {
{'fraction_non_alphanumeric': 0.10827399950896145, 'fraction_numerical': 0.003928308372207218, 'mean_word_length': 2.256195043964828, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2748066', 'n_tokens_mistral': 2239, 'n_tokens_neox': 2090, 'n_words': 458}