<commit_before>package edu.sjsu.mithai.graphX

import org.apache.spark.graphx._
import org.apache.spark.graphx.lib.ShortestPaths

object GraphProcessor {

  def min(graph: Graph[(String, Double), PartitionID]): (VertexId, (String, Double)) = {
    return graph.vertices.min()(new Ordering[Tuple2[VertexId, (String, Double)]]() {
      override def compare(x: (VertexId, (String, Double)), y: (VertexId, (String, Double))): Int =
        Ordering[Double].compare(x._2._2, y._2._2)
    })
  }

  def max(graph: Graph[(String, Double), PartitionID]): (VertexId, (String, Double)) = {
    return graph.vertices.max()(new Ordering[Tuple2[VertexId, (String, Double)]]() {
      override def compare(x: (VertexId, (String, Double)), y: (VertexId, (String, Double))): Int =
        Ordering[Double].compare(x._2._2, y._2._2)
    })
  }

  def shortestPath(graph: Graph[(String, Double), PartitionID], entry: String): String = {

    //TODO : List entry points in the graph (Need to add identifiers in graph properties)
    val firstVId = entry.hashCode

    println("Vertex ID --->" + firstVId)
    val vert: Seq[VertexId] = graph.vertices.collect().map(x=>x._1).toSeq
    val result = ShortestPaths.run(graph, vert)
    if (result.vertices != null && result.vertices.count() > 1) {
      val shortPath = result.vertices.filter(
        {
          case (vid, path) => {
            vid == firstVId
          }
        }).first()._2
      //Finds the non zero min value
      var second = shortPath.filterNot(_._2 == 0).min
      println("Shortest Path from vertices " + entry + " is: " + second._1 + " with length: " + second._2)
      return second._1.toString
    }
    return null;
  }

  def average(graph: Graph[(String, Double), PartitionID]): Double = {
    return graph.vertices.map(_._2._2).sum() / graph.vertices.count()
  }

  def graphOperation(f:Graph[(String, Double), PartitionID] => (VertexId, (String, Double)), graph: Graph[(String, Double), PartitionID]): (VertexId, (String, Double)) = {<commit_msg>Changes in Shortest Path for finding path till available slots<commit_after>package edu.sjsu.mithai.graphX

import org.apache.spark.graphx._
import org.apache.spark.graphx.lib.ShortestPaths

object GraphProcessor {

  def min(graph: Graph[(String, Double), PartitionID]): (VertexId, (String, Double)) = {
    return graph.vertices.min()(new Ordering[Tuple2[VertexId, (String, Double)]]() {
      override def compare(x: (VertexId, (String, Double)), y: (VertexId, (String, Double))): Int =
        Ordering[Double].compare(x._2._2, y._2._2)
    })
  }

  def max(graph: Graph[(String, Double), PartitionID]): (VertexId, (String, Double)) = {
    return graph.vertices.max()(new Ordering[Tuple2[VertexId, (String, Double)]]() {
      override def compare(x: (VertexId, (String, Double)), y: (VertexId, (String, Double))): Int =
        Ordering[Double].compare(x._2._2, y._2._2)
    })
  }

  def shortestPath(graph: Graph[(String, Double), PartitionID], entry: String): String = {

    //TODO : List entry points in the graph (Need to add identifiers in graph properties)
    val firstVId = entry.hashCode

    println("Vertex ID --->" + firstVId)
    val vert: Seq[VertexId] = graph.vertices.collect().map(x=>x._1).toSeq
    //VertexIDs of only available slots to park
    val available: Seq[VertexId] = graph.vertices.collect().filter(x => x._2._2.!=(1)).map(x => x._1).toSeq
    println("Available Slots-->" + available)
    val result = ShortestPaths.run(graph, available)

    if (result.vertices != null && result.vertices.count() > 1) {
      val shortPath = result.vertices.filter(
        {
          case (vid, path) => {
            vid == firstVId
          }
        }).first()._2

      println("Shortest Path Map---->" + shortPath.toString())

      //Finds the non zero min value
      var second = shortPath.filterNot(_._2 == 0).min
      println("Shortest Path from vertices " + firstVId + " is: " + second._1 + " with length: " + second._2)
      return second._1.toString
    }
    return null;
  }

  def average(graph: Graph[(String, Double), PartitionID]): Double = {
    return graph.vertices.map(_._2._2).sum() / graph.vertices.count()
  }

  def graphOperation(f:Graph[(String, Double), PartitionID] => (VertexId, (String, Double)), graph: Graph[(String, Double), PartitionID]): (VertexId, (String, Double)) = {
{'fraction_non_alphanumeric': 0.16049666590020695, 'fraction_numerical': 0.010117268337548863, 'mean_word_length': 3.4207317073170733, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4112115', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1378, 'n_words': 343}