<commit_before>angular.module('board.data', [])

  .constant('Config', {
    baseUrl: 'http://building.hackersandfounders.nl/api/v1/'
    //baseUrl: 'http://building.10.0.7.158.xip.io/api/v1/'
  })

  .factory('Data', function($http, $q, Config) {

    function getPresenceList() {
      return $http.get(Config.baseUrl + 'presence').then(function(r) {
        return r.data.people;
      });
    }

    function calculateBoardState(people) {
      // filter out unknown people
      people = _.filter(people, function(p) {
        return p.room !== null && p.tags.length > 0; });
      
      // calculate per-person's presence state
      var states = _(people)
        .map(
          function(p) {
            var unsureFlag = false;

            // get most recent tag
            var tag = _(p.tags).sortBy('updated_at').last();
            var ts = moment(tag.updated_at);
            var delta = moment().diff(ts, 'seconds');

            if (delta > 3600*12) {
              unsureFlag = true;
            }
            var checkinState = tag.status == 'present' ? 'in' : 'out';

            return {
              person: p,
              room: p.room,
              date: moment(tag.updated_at).unix(),
              state: checkinState,
              unsure: unsureFlag,
              time: ts.format("HH:mm")
            };
          })
        .sortBy('date')
        .reverse()
        .value();

      var rooms = _(states)
        .groupBy('room')
        .mapValues(function(v) {
          var inCount = _(v).filter({state:'in'}).value().length;
          return {
            total: v.length,
            'in': inCount,
            state: inCount > 0 ? 'inhabited' : 'deserted'
          };
        })
        .value();
      
      var recent = _(states).reject('unsure').slice(0,12).value();
      var unsure = _(states).filter('unsure').map('person').slice(0,8).value();
      
      return {
        people: {
          'in': _.filter(states, {state: 'in'}).length,
          'out': _.filter(states, {state: 'out'}).length
        },
        rooms: rooms,
        recent: recent,
        unsure: unsure
      };
    }
    
    return {
      getPresenceList: getPresenceList,
      getBoardState: function() {
        return getPresenceList().then(function(people) {
          return calculateBoardState(people);
          return {
            people: {
              'in': 45,
              out: 43,
            },
            rooms: {
              "1.1": {
                'in': 3,
                'total': 10,
                state: 'inhabited'	
              }
            },
            recent: [
              {type: 'in',
               name: '<NAME>',
               time: '9:14'},
              {type: 'out',
               name: '<NAME>',
               time: '9:34'}
            ],
            unsure: [
              {type: 'in',
               name: '<NAME>',
               time: '9:14'},
              {type: 'out',
               name: '<NAME>',
               time: '9:34'}
            ]
          };
        });
      },
      getTagInfo: function(tag) {
        return $http.get(Config.baseUrl + 'tags/' + tag).then(function(r) {<commit_msg>Remove stub data<commit_after>angular.module('board.data', [])

  .constant('Config', {
    baseUrl: 'http://building.hackersandfounders.nl/api/v1/'
    //baseUrl: 'http://building.10.0.7.158.xip.io/api/v1/'
  })

  .factory('Data', function($http, Config) {

    function getPresenceList() {
      return $http.get(Config.baseUrl + 'presence').then(function(r) {
        return r.data.people;
      });
    }

    function calculateBoardState(people) {
      // filter out unknown people
      people = _.filter(people, function(p) {
        return p.room !== null && p.tags.length > 0; });
      
      // calculate per-person's presence state
      var states = _(people)
        .map(
          function(p) {
            var unsureFlag = false;

            // get most recent tag
            var tag = _(p.tags).sortBy('updated_at').last();
            var ts = moment(tag.updated_at);
            var delta = moment().diff(ts, 'seconds');

            if (delta > 3600*12) {
              unsureFlag = true;
            }
            var checkinState = tag.status == 'present' ? 'in' : 'out';

            return {
              person: p,
              room: p.room,
              date: moment(tag.updated_at).unix(),
              state: checkinState,
              unsure: unsureFlag,
              time: ts.format("HH:mm")
            };
          })
        .sortBy('date')
        .reverse()
        .value();

      var rooms = _(states)
        .groupBy('room')
        .mapValues(function(v) {
          var inCount = _(v).filter({state:'in'}).value().length;
          return {
            total: v.length,
            'in': inCount,
            state: inCount > 0 ? 'inhabited' : 'deserted'
          };
        })
        .value();
      
      var recent = _(states).reject('unsure').slice(0,12).value();
      var unsure = _(states).filter('unsure').map('person').slice(0,8).value();
      
      return {
        people: {
          'in': _.filter(states, {state: 'in'}).length,
          'out': _.filter(states, {state: 'out'}).length
        },
        rooms: rooms,
        recent: recent,
        unsure: unsure
      };
    }
    
    return {
      getPresenceList: getPresenceList,
      getBoardState: function() {
        return getPresenceList().then(function(people) {
          return calculateBoardState(people);
        });
      },
      getTagInfo: function(tag) {
        return $http.get(Config.baseUrl + 'tags/' + tag).then(function(r) {
{'fraction_non_alphanumeric': 0.15456633103691927, 'fraction_numerical': 0.011482070305599718, 'mean_word_length': 1.485513608428446, 'pattern_counts': {'":': 1, '<': 7, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6050447', 'n_tokens_mistral': 1712, 'n_tokens_neox': 1655, 'n_words': 321}