<commit_before>package org.vtsukur.spring.rest.market.util;

import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.datatype.jsr310.JSR310Module;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
import org.springframework.stereotype.Component;
import org.vtsukur.spring.rest.market.domain.core.ad.Ad;
import org.vtsukur.spring.rest.market.domain.core.user.User;
import org.vtsukur.spring.rest.market.infrastructure.SecurityUtils;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDateTime;
import java.util.Random;

/**
 * @author volodymyr.tsukur
 */
@Component
public class ApplicationConfiguration {

    private static final Integer[] MOBILE_OPERATOR_CODES = new Integer[] {
            39,
            50,
            63,
            66,
            67,
            68,
            93,
            95,
            96,
            97,
            98,
            99
    };

    private static final String[] KYIV_DISTRICTS = new String[] {
            "Голосеево",
            "Дарница",
            "Деснянский",
            "Днепровский",
            "Оболонь",
            "Печерск",
            "Подол",
            "Святошино",
            "Соломенский",
            "Шевченковский"
    };

    private static final String[] LVIV_DISTRICTS = new String[] {
            "Шевченківський",
            "Личаківський",
            "Сихівський",
            "Франківський",
            "Залізничний",
            "Личаківський"
    };

    private static final String[] COMMENTS = new String[] {
            "",
            "всю суму",
            "ну дуже треба",
            "можна частинами",
            "маленький, можу під'їхати"
    };
    public static final int PUBLISHING_TIME_MAX_DIFF = 4;

    @Autowired
    private CrudRepository<User, Long> userRepository;

    @Autowired
    private CrudRepository<Ad, Long> adRepository;

    private boolean stableUsersOnly;

    public void load() {
        int amount = 100;
        LocalDateTime now = LocalDateTime.now();
        final LocalDateTime publishedAt = now.minusMinutes(PUBLISHING_TIME_MAX_DIFF * amount);

        SecurityUtils.run("system", "system", new String[]{"ROLE_ADMIN"}, () -> {
            setupAdmin(publishedAt.minusMinutes(10));
            setupStableUser(publishedAt);

            if (!stableUsersOnly) {
                LocalDateTime at = publishedAt;
                for (int i = 0; i < amount; ++i) {
                    User user = nextUser();
                    userRepository.save(user);

                    Ad ad = nextAd(user, at);
                    adRepository.save(ad);

                    at = ad.getPublishedAt();
                }
            }
        });
    }

    private void setupAdmin(LocalDateTime publishedAt) {<commit_msg>Adding stable user after major block.<commit_after>package org.vtsukur.spring.rest.market.util;

import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.datatype.jsr310.JSR310Module;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.rest.core.config.RepositoryRestConfiguration;
import org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration;
import org.springframework.stereotype.Component;
import org.vtsukur.spring.rest.market.domain.core.ad.Ad;
import org.vtsukur.spring.rest.market.domain.core.user.User;
import org.vtsukur.spring.rest.market.infrastructure.SecurityUtils;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.LocalDateTime;
import java.util.Random;

/**
 * @author volodymyr.tsukur
 */
@Component
public class ApplicationConfiguration {

    private static final Integer[] MOBILE_OPERATOR_CODES = new Integer[] {
            39,
            50,
            63,
            66,
            67,
            68,
            93,
            95,
            96,
            97,
            98,
            99
    };

    private static final String[] KYIV_DISTRICTS = new String[] {
            "Голосеево",
            "Дарница",
            "Деснянский",
            "Днепровский",
            "Оболонь",
            "Печерск",
            "Подол",
            "Святошино",
            "Соломенский",
            "Шевченковский"
    };

    private static final String[] LVIV_DISTRICTS = new String[] {
            "Шевченківський",
            "Личаківський",
            "Сихівський",
            "Франківський",
            "Залізничний",
            "Личаківський"
    };

    private static final String[] COMMENTS = new String[] {
            "",
            "всю суму",
            "ну дуже треба",
            "можна частинами",
            "маленький, можу під'їхати"
    };
    public static final int PUBLISHING_TIME_MAX_DIFF = 4;

    @Autowired
    private CrudRepository<User, Long> userRepository;

    @Autowired
    private CrudRepository<Ad, Long> adRepository;

    private boolean stableUsersOnly;

    public void load() {
        int amount = 100;
        LocalDateTime now = LocalDateTime.now();
        final LocalDateTime publishedAt = now.minusMinutes(PUBLISHING_TIME_MAX_DIFF * amount);

        SecurityUtils.run("system", "system", new String[]{"ROLE_ADMIN"}, () -> {
            if (!stableUsersOnly) {
                LocalDateTime at = publishedAt;
                for (int i = 0; i < amount; ++i) {
                    User user = nextUser();
                    userRepository.save(user);

                    Ad ad = nextAd(user, at);
                    adRepository.save(ad);

                    at = ad.getPublishedAt();
                }
            }

            setupAdmin(publishedAt.minusMinutes(10));
            setupStableUser(publishedAt);
        });
    }

    private void setupAdmin(LocalDateTime publishedAt) {
{'fraction_non_alphanumeric': 0.09984375, 'fraction_numerical': 0.0115625, 'mean_word_length': 2.1270151441133365, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '3143844', 'n_tokens_mistral': 1895, 'n_tokens_neox': 1891, 'n_words': 353}