<commit_before>import { Component, OnInit } from '@angular/core';
import { MD_CARD_DIRECTIVES } from '@angular2-material/card';
import { ROUTER_DIRECTIVES } from '@angular/router';
import { GroupService } from '../services/group.service';
import { Group } from '../domain/group';
import { MD_PROGRESS_CIRCLE_DIRECTIVES } from '@angular2-material/progress-circle';
import { MD_ICON_DIRECTIVES } from '@angular2-material/icon';
import { NotificationService } from '../services/notification.service';
import { MemberService } from '../services/member.service';
import { Member } from '../domain/member';
import { LocationService } from '../services/location.service';

@Component({
    moduleId: module.id,
    selector: 'app-groups',
    templateUrl: 'groups.component.html',
    styleUrls: ['groups.component.css'],
    directives: [
        MD_CARD_DIRECTIVES,
        ROUTER_DIRECTIVES,
        MD_PROGRESS_CIRCLE_DIRECTIVES,
        MD_ICON_DIRECTIVES
    ]
})
export class GroupsComponent implements OnInit {
    groups: Group[];
    isLoading: boolean;
    constructor(
        private groupService: GroupService,
        private notificationService: NotificationService,
        private memberService: MemberService,
        private locationService: LocationService
    ) { }
    ngOnInit() {
        this.isLoading = true;
        this.groupService.list().then(groups => {
            this.groups = groups.sort(function comparator(a, b) { return b.createdTs - a.createdTs });
            if (this.groups.length > 0) {
                this.memberService.list(this.groups[0].id).then(this.drawMap.bind(this), this.handleMembersFailure.bind(this));
            } else {
                this.isLoading = false;
            }
        }, () => {
            this.handleGroupsFailure();
            this.isLoading = false;
        });
    }
    handleGroupsFailure() {
        this.notificationService.notify('Error: Could not retrieve groups');
    }
    handleMembersFailure() {
        this.notificationService.notify('Error: Could not retrieve group members');
    }
    drawMap(members: Member[]) {
        let avg = { lat: 0, lng: 0 },
            count = 0,
            randomLocation = this.locationService.getRandomKnownLocation(),
            map = new google.maps.Map(document.querySelector('#map'), {
                disableDoubleClickZoom: true,
                draggable: false,
                mapTypeControlOptions: {
                    mapTypeIds: []
                },
                panControl: false,
                rotateControl: false,
                scaleControl: false,
                scrollwheel: false,
                streetViewControl: false,
                zoomControl: false
            }),
            defaultZoom = 11;

        /* calculate the average */
        members.forEach(function iterator(member) {
            avg.lat += member.lat;
            avg.lng += member.lng;
            count++;
        });
        if (count > 0) {
            avg.lat /= count;
            avg.lng /= count;
            let avgLatLng = new google.maps.LatLng(avg.lat, avg.lng);
            new google.maps.Marker({
                position: avgLatLng,
                map: map
            });
            map.setCenter(avgLatLng);
            map.setZoom(defaultZoom);
        } else {
            map.setCenter(new google.maps.LatLng(randomLocation.lat, randomLocation.lng));
            map.setZoom(randomLocation.zoom);
        }
        this.isLoading = false;
    }
}<commit_msg>fix bug where groups never loaded<commit_after>import { Component, OnInit } from '@angular/core';
import { MD_CARD_DIRECTIVES } from '@angular2-material/card';
import { ROUTER_DIRECTIVES } from '@angular/router';
import { GroupService } from '../services/group.service';
import { Group } from '../domain/group';
import { MD_PROGRESS_CIRCLE_DIRECTIVES } from '@angular2-material/progress-circle';
import { MD_ICON_DIRECTIVES } from '@angular2-material/icon';
import { NotificationService } from '../services/notification.service';
import { MemberService } from '../services/member.service';
import { Member } from '../domain/member';
import { LocationService } from '../services/location.service';

@Component({
    moduleId: module.id,
    selector: 'app-groups',
    templateUrl: 'groups.component.html',
    styleUrls: ['groups.component.css'],
    directives: [
        MD_CARD_DIRECTIVES,
        ROUTER_DIRECTIVES,
        MD_PROGRESS_CIRCLE_DIRECTIVES,
        MD_ICON_DIRECTIVES
    ]
})
export class GroupsComponent implements OnInit {
    groups: Group[];
    isLoading: boolean;
    constructor(
        private groupService: GroupService,
        private notificationService: NotificationService,
        private memberService: MemberService,
        private locationService: LocationService
    ) { }
    ngOnInit() {
        this.isLoading = true;
        this.groupService.list().then(groups => {
            this.groups = groups.sort(function comparator(a, b) { return b.createdTs - a.createdTs });
            if (this.groups.length > 0) {
                this.memberService.list(this.groups[0].id).then((members) => { this.isLoading = false; this.drawMap(members); }, this.handleMembersFailure.bind(this));
            } else {
                this.isLoading = false;
            }
        }, () => {
            this.handleGroupsFailure();
            this.isLoading = false;
        });
    }
    handleGroupsFailure() {
        this.notificationService.notify('Error: Could not retrieve groups');
    }
    handleMembersFailure() {
        this.notificationService.notify('Error: Could not retrieve group members');
    }
    drawMap(members: Member[]) {
        this.isLoading = false;
        let avg = { lat: 0, lng: 0 },
            count = 0,
            randomLocation = this.locationService.getRandomKnownLocation(),
            map = new google.maps.Map(document.querySelector('#map'), {
                disableDoubleClickZoom: true,
                draggable: false,
                mapTypeControlOptions: {
                    mapTypeIds: []
                },
                panControl: false,
                rotateControl: false,
                scaleControl: false,
                scrollwheel: false,
                streetViewControl: false,
                zoomControl: false
            }),
            defaultZoom = 11;

        /* calculate the average */
        members.forEach(function iterator(member) {
            avg.lat += member.lat;
            avg.lng += member.lng;
            count++;
        });
        if (count > 0) {
            avg.lat /= count;
            avg.lng /= count;
            let avgLatLng = new google.maps.LatLng(avg.lat, avg.lng);
            new google.maps.Marker({
                position: avgLatLng,
                map: map
            });
            map.setCenter(avgLatLng);
            map.setZoom(defaultZoom);
        } else {
            map.setCenter(new google.maps.LatLng(randomLocation.lat, randomLocation.lng));
            map.setZoom(randomLocation.zoom);
        }
    }
}
{'fraction_non_alphanumeric': 0.11542808703023454, 'fraction_numerical': 0.0031082226617688614, 'mean_word_length': 2.0764884832681445, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, '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': '7644071', 'n_tokens_mistral': 1952, 'n_tokens_neox': 1884, 'n_words': 384}