<commit_before>import {Component, Input, OnInit, ViewChild, ViewEncapsulation} from '@angular/core';
import {DateTimeAdapter, OwlDateTimeComponent} from 'ng-pick-datetime';
import {fromEvent, merge, Observable, Subscription} from "rxjs";
import {filter} from "rxjs/operators";
import {OsmLangService} from "../../../../services/osm-lang.service";
import {ResultSelectionStore} from "../../services/result-selection.store";

@Component({
  selector: 'osm-result-selection-time-frame',
  templateUrl: './time-frame.component.html',
  styleUrls: ['./time-frame.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class TimeFrameComponent implements OnInit {

  @Input() showAggregation: boolean = false;
  @Input() showComparativeTimeFrame: boolean = false;
  @ViewChild('dateTimeFrom') dateTimeFrom: OwlDateTimeComponent<Date>;
  @ViewChild('dateTimeTo') dateTimeTo: OwlDateTimeComponent<Date>;
  @ViewChild('comparativeDateTimeFrom') comparativeDateTimeFrom: OwlDateTimeComponent<Date>;
  @ViewChild('comparativeDateTimeTo') comparativeDateTimeTo: OwlDateTimeComponent<Date>;

  calendarClick$: Observable<MouseEvent>;
  calendarEnter$: Observable<KeyboardEvent>;
  calendarEventSubscription: Subscription;

  selectableTimeFramesInSeconds: number[] = [-1, 3600, 43200, 86400, 259200, 604800, 1209600, 2419200];
  timeFrameInSeconds: number = -1;

  selectableAggregationIntervalsInSeconds: number[] = [-1, 60, 1440, 10080];
  aggregationIntervalInSeconds: number = -1;

  selectedDates: Date[];
  selectedComparativeDates: Date[];
  max = new Date();

  comparativeSelectionActive: boolean = false;

  CalendarType: typeof CalendarType = CalendarType;

  constructor(private resultSelectionStore: ResultSelectionStore, private dateTimeAdapter: DateTimeAdapter<any>, private osmLangService: OsmLangService) {
    if (osmLangService.getOsmLang() == 'en') {
      dateTimeAdapter.setLocale('en-GB');
    } else {
      dateTimeAdapter.setLocale(osmLangService.getOsmLang());
    }
  }

  ngOnInit() {
    let defaultFrom = new Date();
    let defaultTo = new Date();
    defaultFrom.setDate(defaultTo.getDate() - 3);

    this.selectedDates = [defaultFrom, defaultTo];

    this.resultSelectionStore.setResultSelectionCommandTimeFrame(this.selectedDates);

    this.timeFrameInSeconds = this.selectableTimeFramesInSeconds[4];
  }

  selectTimeFrame(): void {
    if (this.timeFrameInSeconds != this.selectableTimeFramesInSeconds[0]) {
      let from = new Date();
      let to = new Date();
      from.setSeconds(to.getSeconds() - this.timeFrameInSeconds);
      this.selectedDates = [from, to];

      if (this.comparativeSelectionActive) {
        let comparativeTo = new Date(from);
        let comparativeFrom = new Date(from);

        comparativeTo.setSeconds(comparativeTo.getSeconds() - 1);
        comparativeFrom.setSeconds(comparativeTo.getSeconds() - this.timeFrameInSeconds);
        this.selectedComparativeDates = [comparativeFrom, comparativeTo];
      }
    } else if (this.comparativeSelectionActive) {
      let from = this.selectedDates[0];
      let to = this.selectedDates[1];

      let comparativeTo = new Date(from);
      let comparativeFrom = new Date(from);<commit_msg>set from time according to the to time<commit_after>import {Component, Input, OnInit, ViewChild, ViewEncapsulation} from '@angular/core';
import {DateTimeAdapter, OwlDateTimeComponent} from 'ng-pick-datetime';
import {fromEvent, merge, Observable, Subscription} from "rxjs";
import {filter} from "rxjs/operators";
import {OsmLangService} from "../../../../services/osm-lang.service";
import {ResultSelectionStore} from "../../services/result-selection.store";

@Component({
  selector: 'osm-result-selection-time-frame',
  templateUrl: './time-frame.component.html',
  styleUrls: ['./time-frame.component.scss'],
  encapsulation: ViewEncapsulation.None
})
export class TimeFrameComponent implements OnInit {

  @Input() showAggregation: boolean = false;
  @Input() showComparativeTimeFrame: boolean = false;
  @ViewChild('dateTimeFrom') dateTimeFrom: OwlDateTimeComponent<Date>;
  @ViewChild('dateTimeTo') dateTimeTo: OwlDateTimeComponent<Date>;
  @ViewChild('comparativeDateTimeFrom') comparativeDateTimeFrom: OwlDateTimeComponent<Date>;
  @ViewChild('comparativeDateTimeTo') comparativeDateTimeTo: OwlDateTimeComponent<Date>;

  calendarClick$: Observable<MouseEvent>;
  calendarEnter$: Observable<KeyboardEvent>;
  calendarEventSubscription: Subscription;

  selectableTimeFramesInSeconds: number[] = [-1, 3600, 43200, 86400, 259200, 604800, 1209600, 2419200];
  timeFrameInSeconds: number = -1;

  selectableAggregationIntervalsInSeconds: number[] = [-1, 60, 1440, 10080];
  aggregationIntervalInSeconds: number = -1;

  selectedDates: Date[];
  selectedComparativeDates: Date[];
  max = new Date();

  comparativeSelectionActive: boolean = false;

  CalendarType: typeof CalendarType = CalendarType;

  constructor(private resultSelectionStore: ResultSelectionStore, private dateTimeAdapter: DateTimeAdapter<any>, private osmLangService: OsmLangService) {
    if (osmLangService.getOsmLang() == 'en') {
      dateTimeAdapter.setLocale('en-GB');
    } else {
      dateTimeAdapter.setLocale(osmLangService.getOsmLang());
    }
  }

  ngOnInit() {
    let defaultFrom = new Date();
    let defaultTo = new Date();
    defaultFrom.setDate(defaultTo.getDate() - 3);

    this.selectedDates = [defaultFrom, defaultTo];

    this.resultSelectionStore.setResultSelectionCommandTimeFrame(this.selectedDates);

    this.timeFrameInSeconds = this.selectableTimeFramesInSeconds[4];
  }

  selectTimeFrame(): void {
    if (this.timeFrameInSeconds != this.selectableTimeFramesInSeconds[0]) {
      let to = new Date();
      let from = new Date(to.getTime() - this.timeFrameInSeconds * 1000);
      this.selectedDates = [from, to];

      if (this.comparativeSelectionActive) {
        let comparativeTo = new Date(from);
        let comparativeFrom = new Date(from);

        comparativeTo.setSeconds(comparativeTo.getSeconds() - 1);
        comparativeFrom.setSeconds(comparativeTo.getSeconds() - this.timeFrameInSeconds);
        this.selectedComparativeDates = [comparativeFrom, comparativeTo];
      }
    } else if (this.comparativeSelectionActive) {
      let from = this.selectedDates[0];
      let to = this.selectedDates[1];

      let comparativeTo = new Date(from);
      let comparativeFrom = new Date(from);
{'fraction_non_alphanumeric': 0.12064134495641345, 'fraction_numerical': 0.019613947696139476, 'mean_word_length': 4.905330882352941, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '6724701', 'n_tokens_mistral': 1971, 'n_tokens_neox': 1858, 'n_words': 390}