<commit_before>/*
 * Copyright (C) 2011-2017 scalable minds UG (haftungsbeschränkt) & Co. KG. <http://scm.io>
 */
package com.scalableminds.braingames.datastore.tracings.volume

import com.scalableminds.braingames.binary.dataformats.BucketProvider
import com.scalableminds.braingames.binary.models.BucketPosition
import com.scalableminds.braingames.binary.models.datasource._
import com.scalableminds.braingames.binary.models.requests.DataReadInstruction
import com.scalableminds.braingames.binary.storage.DataCubeCache
import com.scalableminds.braingames.binary.storage.kvstore.VersionedKeyValueStore
import com.scalableminds.util.geometry.BoundingBox
import com.scalableminds.util.tools.{Fox, FoxImplicits}
import play.api.libs.json.Json

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.FiniteDuration

class VolumeTracingBucketProvider(layer: VolumeTracingLayer)
  extends BucketProvider
    with VolumeTracingBucketHelper
    with FoxImplicits {

  val volumeDataStore: VersionedKeyValueStore = layer.volumeDataStore

  override def load(readInstruction: DataReadInstruction, cache: DataCubeCache, timeout: FiniteDuration): Fox[Array[Byte]] = {
    loadBucket(layer, readInstruction.bucket)
  }

  override def bucketStream(resolution: Int): Iterator[(BucketPosition, Array[Byte])] = {
    bucketStream(layer, resolution)
  }
}

case class VolumeTracingLayer(
                               name: String,
                               boundingBox: BoundingBox,
                               elementClass: ElementClass.Value,
                               largestSegmentId: Long,
                               resolutions: List[Int] = List(1),
                               // can be removed, after all tracing stuff has been moved to datastore
                               mappings: Set[String] = Set.empty,
                               override val category: Category.Value = Category.segmentation
                             )(implicit val volumeDataStore: VersionedKeyValueStore) extends SegmentationLayer {

  val dataFormat: DataFormat.Value = DataFormat.tracing

  def lengthOfUnderlyingCubes(resolution: Int): Int = DataLayer.bucketLength

  val nextSegmentationId: Long = largestSegmentId + 1

  val bucketProvider: BucketProvider = new VolumeTracingBucketProvider(this)
}

object VolumeTracingLayer {

  val defaultElementClass = ElementClass.uint32

  val defaultLargestSegmentId = 1

  implicit def volumeTracingLayerFormat(implicit volumeDataStore: VersionedKeyValueStore) = Json.format[VolumeTracingLayer]
}<commit_msg>Fix boundingBox.intersects and verify largestSegmentId<commit_after>/*
 * Copyright (C) 2011-2017 scalable minds UG (haftungsbeschränkt) & Co. KG. <http://scm.io>
 */
package com.scalableminds.braingames.datastore.tracings.volume

import com.scalableminds.braingames.binary.dataformats.BucketProvider
import com.scalableminds.braingames.binary.models.BucketPosition
import com.scalableminds.braingames.binary.models.datasource._
import com.scalableminds.braingames.binary.models.requests.DataReadInstruction
import com.scalableminds.braingames.binary.storage.DataCubeCache
import com.scalableminds.braingames.binary.storage.kvstore.VersionedKeyValueStore
import com.scalableminds.util.geometry.BoundingBox
import com.scalableminds.util.tools.{Fox, FoxImplicits}
import play.api.libs.json.Json

import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.FiniteDuration

class VolumeTracingBucketProvider(layer: VolumeTracingLayer)
  extends BucketProvider
    with VolumeTracingBucketHelper
    with FoxImplicits {

  val volumeDataStore: VersionedKeyValueStore = layer.volumeDataStore

  override def load(readInstruction: DataReadInstruction, cache: DataCubeCache, timeout: FiniteDuration): Fox[Array[Byte]] = {
    loadBucket(layer, readInstruction.bucket)
  }

  override def bucketStream(resolution: Int): Iterator[(BucketPosition, Array[Byte])] = {
    bucketStream(layer, resolution)
  }
}

case class VolumeTracingLayer(
                               name: String,
                               boundingBox: BoundingBox,
                               elementClass: ElementClass.Value,
                               largestSegmentId: Long,
                               resolutions: List[Int] = List(1),
                               // can be removed, after all tracing stuff has been moved to datastore
                               mappings: Set[String] = Set.empty,
                               override val category: Category.Value = Category.segmentation
                             )(implicit val volumeDataStore: VersionedKeyValueStore) extends SegmentationLayer {

  val dataFormat: DataFormat.Value = DataFormat.tracing

  def lengthOfUnderlyingCubes(resolution: Int): Int = DataLayer.bucketLength

  val nextSegmentationId: Long = largestSegmentId + 1

  val bucketProvider: BucketProvider = new VolumeTracingBucketProvider(this)
}

object VolumeTracingLayer {

  val defaultElementClass = ElementClass.uint32

  // TODO: set to 0 eventually
  val defaultLargestSegmentId = 1

  implicit def volumeTracingLayerFormat(implicit volumeDataStore: VersionedKeyValueStore) = Json.format[VolumeTracingLayer]
}
{'fraction_non_alphanumeric': 0.07352380952380952, 'fraction_numerical': 0.005142857142857143, 'mean_word_length': 3.45, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3406736', 'n_tokens_mistral': 1459, 'n_tokens_neox': 1406, 'n_words': 291}