<commit_before>/*
 * Copyright 2016 OrgSync.
 *
 * 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
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.
 */

package com.orgsync.oskr.events.streams

import java.time.Duration

import com.orgsync.oskr.events.messages.{Message, Part, Parts}
import com.orgsync.oskr.events.streams.grouping.PartGroupingWindows
import org.apache.flink.api.java.utils.ParameterTool
import org.apache.flink.api.scala._
import org.apache.flink.streaming.api.scala.DataStream
import org.apache.flink.streaming.api.windowing.time.Time
import org.apache.flink.streaming.api.windowing.windows.TimeWindow
import org.apache.flink.util.Collector

class GroupStream(parameters: ParameterTool) {
  private val groupingGap = Duration.parse(parameters.get("groupingGap", "PT5M"))

  private val allowedLateness = Time.milliseconds(
    Duration.parse(parameters.get("allowedLateness", "PT1H")).toMillis
  )

  private val reducePartsWindow = (
    key: (String, Option[String]),
    w: TimeWindow,
    parts: Iterable[Part],
    out: Collector[Message]
  ) => Parts.toMessage(parts).foreach(out.collect)

  def getStream(partStream: DataStream[Part]): DataStream[Message] = {
    partStream
      .keyBy(p => (p.recipient.id, p.groupingKey))
      .window(new PartGroupingWindows(groupingGap))
      .allowedLateness(allowedLateness)<commit_msg>Use configuration<commit_after>/*
 * Copyright 2016 OrgSync.
 *
 * 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
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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.
 */

package com.orgsync.oskr.events.streams

import java.time.Duration

import com.orgsync.oskr.events.messages.{Message, Part, Parts}
import com.orgsync.oskr.events.streams.grouping.PartGroupingWindows
import org.apache.flink.api.scala._
import org.apache.flink.configuration.Configuration
import org.apache.flink.streaming.api.scala.DataStream
import org.apache.flink.streaming.api.windowing.time.Time
import org.apache.flink.streaming.api.windowing.windows.TimeWindow
import org.apache.flink.util.Collector

class GroupStream(parameters: Configuration) {
  private val groupingGap = Duration.parse(parameters.getString("groupingGap", "PT5M"))

  private val allowedLateness = Time.milliseconds(
    Duration.parse(parameters.getString("allowedLateness", "PT1H")).toMillis
  )

  private val reducePartsWindow = (
    key: (String, Option[String]),
    w: TimeWindow,
    parts: Iterable[Part],
    out: Collector[Message]
  ) => Parts.toMessage(parts).foreach(out.collect)

  def getStream(partStream: DataStream[Part]): DataStream[Message] = {
    partStream
      .keyBy(p => (p.recipient.id, p.groupingKey))
      .window(new PartGroupingWindows(groupingGap))
      .allowedLateness(allowedLateness)
{'fraction_non_alphanumeric': 0.10398899587345255, 'fraction_numerical': 0.005502063273727648, 'mean_word_length': 4.559633027522936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3632891', 'n_tokens_mistral': 1094, 'n_tokens_neox': 1058, 'n_words': 284}