<commit_before>package com.flipkart.foxtrot.core.cardinality;
/**
 * Copyright 2014 Flipkart Internet Pvt. Ltd.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import com.flipkart.foxtrot.core.querystore.impl.HazelcastConnection;
import com.flipkart.foxtrot.core.table.TableMetadataManager;
import io.dropwizard.lifecycle.Managed;
import net.javacrumbs.shedlock.core.DefaultLockingTaskExecutor;
import net.javacrumbs.shedlock.core.LockConfiguration;
import net.javacrumbs.shedlock.core.LockingTaskExecutor;
import net.javacrumbs.shedlock.provider.hazelcast.HazelcastLockProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.*;
import java.util.Calendar;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/***
 Created by nitish.goyal on 13/08/18
 ***/
public class CardinalityCalculationManager implements Managed {

    private static final Logger LOGGER = LoggerFactory.getLogger(CardinalityCalculationManager.class.getSimpleName());
    private static final int MAX_TIME_TO_RUN_TASK_IN_HOURS = 2;

    private final TableMetadataManager tableMetadataManager;
    private final CardinalityConfig cardinalityConfig;
    private final HazelcastConnection hazelcastConnection;
    private final ScheduledExecutorService scheduledExecutorService;

    public CardinalityCalculationManager(TableMetadataManager tableMetadataManager, CardinalityConfig cardinalityConfig,
                                         HazelcastConnection hazelcastConnection,
                                         ScheduledExecutorService scheduledExecutorService) {
        this.tableMetadataManager = tableMetadataManager;
        this.cardinalityConfig = cardinalityConfig;
        this.hazelcastConnection = hazelcastConnection;
        this.scheduledExecutorService = scheduledExecutorService;
    }

    @Override
    public void start() throws Exception {
        LOGGER.info("Starting Cardinality Manager");
        if (cardinalityConfig.isActive()) {
            LOGGER.info("Scheduling cardinality calculation job");
            LocalDateTime localNow = LocalDateTime.now();
            Calendar now = Calendar.getInstance();
            ZoneId currentZone = ZoneId.of(now.getTimeZone().getID());
            ZonedDateTime zonedNow = ZonedDateTime.of(localNow, currentZone);
            ZonedDateTime zonedNext5 = zonedNow.withHour(cardinalityConfig.getInitialDelay()).withMinute(0).withSecond(0);
            if (zonedNow.compareTo(zonedNext5) > 0)
                zonedNext5 = zonedNext5.plusDays(1);

            Duration duration = Duration.between(zonedNow, zonedNext5);
            long initialDelay = duration.getSeconds();<commit_msg>Foxtrot Minor Change<commit_after>package com.flipkart.foxtrot.core.cardinality;
/**
 * Copyright 2014 Flipkart Internet Pvt. Ltd.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import com.flipkart.foxtrot.core.querystore.impl.HazelcastConnection;
import com.flipkart.foxtrot.core.table.TableMetadataManager;
import io.dropwizard.lifecycle.Managed;
import net.javacrumbs.shedlock.core.DefaultLockingTaskExecutor;
import net.javacrumbs.shedlock.core.LockConfiguration;
import net.javacrumbs.shedlock.core.LockingTaskExecutor;
import net.javacrumbs.shedlock.provider.hazelcast.HazelcastLockProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.*;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/***
 Created by nitish.goyal on 13/08/18
 ***/
public class CardinalityCalculationManager implements Managed {

    private static final Logger LOGGER = LoggerFactory.getLogger(CardinalityCalculationManager.class.getSimpleName());
    private static final int MAX_TIME_TO_RUN_TASK_IN_HOURS = 2;

    private final TableMetadataManager tableMetadataManager;
    private final CardinalityConfig cardinalityConfig;
    private final HazelcastConnection hazelcastConnection;
    private final ScheduledExecutorService scheduledExecutorService;
    private static final String TIME_ZONE = "Asia/Kolkata";

    public CardinalityCalculationManager(TableMetadataManager tableMetadataManager, CardinalityConfig cardinalityConfig,
                                         HazelcastConnection hazelcastConnection, ScheduledExecutorService scheduledExecutorService) {
        this.tableMetadataManager = tableMetadataManager;
        this.cardinalityConfig = cardinalityConfig;
        this.hazelcastConnection = hazelcastConnection;
        this.scheduledExecutorService = scheduledExecutorService;
    }

    @Override
    public void start() throws Exception {
        LOGGER.info("Starting Cardinality Manager");
        if(cardinalityConfig.isActive()) {
            LOGGER.info("Scheduling cardinality calculation job");
            LocalDateTime localNow = LocalDateTime.now();
            ZoneId currentZone = ZoneId.of(TIME_ZONE);
            ZonedDateTime zonedNow = ZonedDateTime.of(localNow, currentZone);
            ZonedDateTime zonedNext5 = zonedNow.withHour(cardinalityConfig.getInitialDelay()).withMinute(0).withSecond(0);
            if(zonedNow.compareTo(zonedNext5) > 0)
                zonedNext5 = zonedNext5.plusDays(1);

            Duration duration = Duration.between(zonedNow, zonedNext5);
            long initialDelay = duration.getSeconds();
{'fraction_non_alphanumeric': 0.07633228840125392, 'fraction_numerical': 0.008150470219435737, 'mean_word_length': 4.020456333595594, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '23064', 'n_tokens_mistral': 1759, 'n_tokens_neox': 1674, 'n_words': 426}