<commit_before>package com.dak.duty.service;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.text.SimpleDateFormat;

import javax.transaction.Transactional;

import lombok.NonNull;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dak.duty.model.Duty;
import com.dak.duty.model.Event;
import com.dak.duty.model.EventType;
import com.dak.duty.model.Person;
import com.dak.duty.model.enums.EventTypeInterval;
import com.dak.duty.model.enums.IntervalWeekly;
import com.dak.duty.repository.DutyRepository;
import com.dak.duty.repository.EventRepository;
import com.dak.duty.repository.EventTypeRepository;
import com.dak.duty.repository.PersonRepository;

import org.apache.commons.math3.random.RandomDataGenerator;
import org.fluttercode.datafactory.impl.DataFactory;

@Service
@Transactional
public class InitialisationService {

   private static final Logger logger = LoggerFactory.getLogger(InitialisationService.class);
   private static final DateFormat format = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH);
   
   @Autowired
   EventTypeRepository eventTypeRepos;
   
   @Autowired
   DutyRepository dutyRepos;
   
   @Autowired
   PersonRepository personRepos;
   
   @Autowired
   EventRepository eventRepos;
   
   protected void clearAllData(){
      eventRepos.deleteAll();
      eventRepos.flush();
      
      personRepos.deleteAll();
      personRepos.flush();
      
      eventTypeRepos.deleteAll();
      eventTypeRepos.flush();
      
      dutyRepos.deleteAll();
      dutyRepos.flush();
   }
   
   public void populateDefaultData(){
      clearAllData();
      
      final List<Duty> defaultDuties = getDefaultDuties();
      dutyRepos.save(defaultDuties);
      
      final List<EventType> defaultEventTypes = getDefaultEventTypes(defaultDuties);
      eventTypeRepos.save(defaultEventTypes);
      
      final List<Person> defaultPeople = getDefaultPeople(defaultDuties); 
      personRepos.save(defaultPeople);
      
      final List<Event> defaultEvents = getDefaultEvents(defaultEventTypes);
      eventRepos.save(defaultEvents);
      
   }
   
   protected List<Event> getDefaultEvents(final List<EventType> eventTypes){
      final List<Event> events = new ArrayList<Event>(eventTypes.size());
      
      for(EventType et : eventTypes){
         final Event e = new Event();
        
         e.setName(et.getName());
         try{
            if(e.getName().contains("Sunday")){
               e.setDateEvent(format.parse("05/24/2015")); // sunday
            } else {
               e.setDateEvent(format.parse("05/27/2015")); // wednesday
            }
         } catch (ParseException pe){ }
         e.setEventType(et);
        
         events.add(e);
      }
      
      return events;
   }
   
   @SuppressWarnings("deprecation")
   protected List<Person> getDefaultPeople(final List<Duty> duties){
      final List<Person> people = new ArrayList<Person>();
      DataFactory df = new DataFactory();
      RandomDataGenerator randomData = new RandomDataGenerator();
      
      final List<Duty> scrambledDuties = new ArrayList<Duty>(duties);
      for(int i = 0; i < 100; i++){
         Person p = new Person();
         p.setActive(true);
         p.setEmailAddress(df.getEmailAddress());
         p.setNameFirst(df.getFirstName());
         p.setNameLast(df.getLastName());
         
         Collections.shuffle(scrambledDuties);
         final int numDuties = randomData.nextInt(2, scrambledDuties.size()-1);
         for(int x = 0; x < numDuties; x++){
            p.addDutyAndPreference(scrambledDuties.get(x), randomData.nextInt(1, 9));
         }
         
         people.add(p);
      }
      
      return people;
   }
   
   protected List<Duty> getDefaultDuties(){
      final List<Duty> duties = new ArrayList<Duty>();
      
      Duty duty = null;
      int count = 1;
      
      duty = new Duty();
      duty.setName("Song Leading");
      duty.setDescription(duty.getName());
      duty.setSortOrder(count++);
      duties.add(duty);

      duty = new Duty();
      duty.setName("Opening Prayer");
      duty.setDescription(duty.getName());
      duty.setSortOrder(count++);
      duties.add(duty);

      duty = new Duty();
      duty.setName("Closing Prayer");
      duty.setDescription(duty.getName());
      duty.setSortOrder(count++);
      duties.add(duty);

      duty = new Duty();
      duty.setName("Annoucements");
      duty.setDescription(duty.getName());
      duty.setSortOrder(count++);<commit_msg>fix typo in Annoucements<commit_after>package com.dak.duty.service;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.text.SimpleDateFormat;

import javax.transaction.Transactional;

import lombok.NonNull;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dak.duty.model.Duty;
import com.dak.duty.model.Event;
import com.dak.duty.model.EventType;
import com.dak.duty.model.Person;
import com.dak.duty.model.enums.EventTypeInterval;
import com.dak.duty.model.enums.IntervalWeekly;
import com.dak.duty.repository.DutyRepository;
import com.dak.duty.repository.EventRepository;
import com.dak.duty.repository.EventTypeRepository;
import com.dak.duty.repository.PersonRepository;

import org.apache.commons.math3.random.RandomDataGenerator;
import org.fluttercode.datafactory.impl.DataFactory;

@Service
@Transactional
public class InitialisationService {

   private static final Logger logger = LoggerFactory.getLogger(InitialisationService.class);
   private static final DateFormat format = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH);
   
   @Autowired
   EventTypeRepository eventTypeRepos;
   
   @Autowired
   DutyRepository dutyRepos;
   
   @Autowired
   PersonRepository personRepos;
   
   @Autowired
   EventRepository eventRepos;
   
   protected void clearAllData(){
      eventRepos.deleteAll();
      eventRepos.flush();
      
      personRepos.deleteAll();
      personRepos.flush();
      
      eventTypeRepos.deleteAll();
      eventTypeRepos.flush();
      
      dutyRepos.deleteAll();
      dutyRepos.flush();
   }
   
   public void populateDefaultData(){
      clearAllData();
      
      final List<Duty> defaultDuties = getDefaultDuties();
      dutyRepos.save(defaultDuties);
      
      final List<EventType> defaultEventTypes = getDefaultEventTypes(defaultDuties);
      eventTypeRepos.save(defaultEventTypes);
      
      final List<Person> defaultPeople = getDefaultPeople(defaultDuties); 
      personRepos.save(defaultPeople);
      
      final List<Event> defaultEvents = getDefaultEvents(defaultEventTypes);
      eventRepos.save(defaultEvents);
      
   }
   
   protected List<Event> getDefaultEvents(final List<EventType> eventTypes){
      final List<Event> events = new ArrayList<Event>(eventTypes.size());
      
      for(EventType et : eventTypes){
         final Event e = new Event();
        
         e.setName(et.getName());
         try{
            if(e.getName().contains("Sunday")){
               e.setDateEvent(format.parse("05/24/2015")); // sunday
            } else {
               e.setDateEvent(format.parse("05/27/2015")); // wednesday
            }
         } catch (ParseException pe){ }
         e.setEventType(et);
        
         events.add(e);
      }
      
      return events;
   }
   
   @SuppressWarnings("deprecation")
   protected List<Person> getDefaultPeople(final List<Duty> duties){
      final List<Person> people = new ArrayList<Person>();
      DataFactory df = new DataFactory();
      RandomDataGenerator randomData = new RandomDataGenerator();
      
      final List<Duty> scrambledDuties = new ArrayList<Duty>(duties);
      for(int i = 0; i < 100; i++){
         Person p = new Person();
         p.setActive(true);
         p.setEmailAddress(df.getEmailAddress());
         p.setNameFirst(df.getFirstName());
         p.setNameLast(df.getLastName());
         
         Collections.shuffle(scrambledDuties);
         final int numDuties = randomData.nextInt(2, scrambledDuties.size()-1);
         for(int x = 0; x < numDuties; x++){
            p.addDutyAndPreference(scrambledDuties.get(x), randomData.nextInt(1, 9));
         }
         
         people.add(p);
      }
      
      return people;
   }
   
   protected List<Duty> getDefaultDuties(){
      final List<Duty> duties = new ArrayList<Duty>();
      
      Duty duty = null;
      int count = 1;
      
      duty = new Duty();
      duty.setName("Song Leading");
      duty.setDescription(duty.getName());
      duty.setSortOrder(count++);
      duties.add(duty);

      duty = new Duty();
      duty.setName("Opening Prayer");
      duty.setDescription(duty.getName());
      duty.setSortOrder(count++);
      duties.add(duty);

      duty = new Duty();
      duty.setName("Closing Prayer");
      duty.setDescription(duty.getName());
      duty.setSortOrder(count++);
      duties.add(duty);

      duty = new Duty();
      duty.setName("Announcements");
      duty.setDescription(duty.getName());
      duty.setSortOrder(count++);
{'fraction_non_alphanumeric': 0.11569204880100968, 'fraction_numerical': 0.006100126209507783, 'mean_word_length': 2.922854785478548, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 37, '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': '935979', 'n_tokens_mistral': 2927, 'n_tokens_neox': 2816, 'n_words': 504}