<commit_before>package nl.wiegman.home.service;

import nl.wiegman.home.model.Klimaat;
import nl.wiegman.home.model.Meterstand;
import nl.wiegman.home.realtime.UpdateEvent;
import nl.wiegman.home.repository.KlimaatRepo;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.inject.Inject;
import java.math.BigDecimal;
import java.util.*;

/**
 * Receives updates from klimaat sensors, stores the values and provides them.
 */
@Component
public class KlimaatService {

    private static final Logger LOG = LoggerFactory.getLogger(KlimaatService.class);

    private final List<Klimaat> receivedInLastQuarter = new ArrayList<>();

    @Inject
    private KlimaatRepo klimaatRepository;

    @Autowired
    private ApplicationEventPublisher eventPublisher;

    @Scheduled(cron = "0 0/15 * * * ?") // Every 15 minutes
    public void save() {
        LOG.debug("Running " + this.getClass().getSimpleName() + ".save()");

        Date now = new Date();

        List<BigDecimal> validTemperaturesFromLastQuarter = getValidTemperaturesFromLastQuarter();

        receivedInLastQuarter.clear();

        if (validTemperaturesFromLastQuarter.size() >= 2) {
            BigDecimal totalTemperature = BigDecimal.ZERO;

            for (BigDecimal validTemperatuur : validTemperaturesFromLastQuarter) {
                totalTemperature = totalTemperature.add(validTemperatuur);
            }
            BigDecimal averageTemperatuur = totalTemperature.divide(BigDecimal.valueOf(validTemperaturesFromLastQuarter.size()));

            DateUtils.setMilliseconds(now, 0);
            DateUtils.setSeconds(now, 0);

            Klimaat klimaatToSave = new Klimaat();
            klimaatToSave.setDatumtijd(now.getTime());
            klimaatToSave.setTemperatuur(averageTemperatuur);

            Klimaat savedKlimaat = klimaatRepository.save(klimaatToSave);

            eventPublisher.publishEvent(new UpdateEvent(savedKlimaat));
        }
    }

    public Klimaat getMeestRecente() {
        LOG.info("getMeestRecente()");
        return klimaatRepository.getMeestRecente();
    }
<commit_msg>Fix roundingmode bug<commit_after>package nl.wiegman.home.service;

import nl.wiegman.home.model.Klimaat;
import nl.wiegman.home.model.Meterstand;
import nl.wiegman.home.realtime.UpdateEvent;
import nl.wiegman.home.repository.KlimaatRepo;
import org.apache.commons.lang3.time.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.inject.Inject;
import java.math.BigDecimal;
import java.util.*;

/**
 * Receives updates from klimaat sensors, stores the values and provides them.
 */
@Component
public class KlimaatService {

    private static final Logger LOG = LoggerFactory.getLogger(KlimaatService.class);

    private final List<Klimaat> receivedInLastQuarter = new ArrayList<>();

    @Inject
    private KlimaatRepo klimaatRepository;

    @Autowired
    private ApplicationEventPublisher eventPublisher;

    @Scheduled(cron = "0 0/15 * * * ?") // Every 15 minutes
    public void save() {
        LOG.debug("Running " + this.getClass().getSimpleName() + ".save()");

        Date now = new Date();

        List<BigDecimal> validTemperaturesFromLastQuarter = getValidTemperaturesFromLastQuarter();

        receivedInLastQuarter.clear();

        if (validTemperaturesFromLastQuarter.size() >= 2) {
            BigDecimal totalTemperature = BigDecimal.ZERO;

            for (BigDecimal validTemperatuur : validTemperaturesFromLastQuarter) {
                totalTemperature = totalTemperature.add(validTemperatuur);
            }
            BigDecimal averageTemperatuur = totalTemperature.divide(BigDecimal.valueOf(validTemperaturesFromLastQuarter.size(), BigDecimal.ROUND_CEILING));

            DateUtils.setMilliseconds(now, 0);
            DateUtils.setSeconds(now, 0);

            Klimaat klimaatToSave = new Klimaat();
            klimaatToSave.setDatumtijd(now.getTime());
            klimaatToSave.setTemperatuur(averageTemperatuur);

            Klimaat savedKlimaat = klimaatRepository.save(klimaatToSave);

            eventPublisher.publishEvent(new UpdateEvent(savedKlimaat));
        }
    }

    public Klimaat getMeestRecente() {
        LOG.info("getMeestRecente()");
        return klimaatRepository.getMeestRecente();
    }

{'fraction_non_alphanumeric': 0.09664653197250572, 'fraction_numerical': 0.0049989585503020205, 'mean_word_length': 3.7217305801376597, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '4150923', 'n_tokens_mistral': 1439, 'n_tokens_neox': 1441, 'n_words': 245}