Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. /**
  2. * Created by nacta_000 on 25.06.2015.
  3. */
  4.  
  5.  
  6.  
  7. import org.apache.commons.math3.geometry.euclidean.oned.Interval
  8. import org.apache.spark.SparkContext
  9. import org.apache.spark.SparkContext._
  10. import org.apache.spark.SparkConf
  11. import org.joda.time.{DateTime, Seconds}
  12. import org.apache.lucene.search.spell.LevensteinDistance
  13. import scala.io.Source
  14.  
  15. //import org.scala_tools.time.Imports._
  16.  
  17.  
  18.  
  19.  
  20. object SparkApp {
  21.  
  22. def checkInterval(date1: String, date2: String, interval: Int) : Boolean = {
  23. val dt1 = new DateTime(date1)
  24. val dt2 = new DateTime(date2)
  25. val seconds = Seconds.secondsBetween(dt1, dt2).getSeconds
  26. if (seconds <= interval)
  27. true
  28. else
  29. false
  30. }
  31.  
  32.  
  33. def distance(str1: String, str2:String):Float={
  34. val lDistance = new LevensteinDistance
  35. return lDistance.getDistance(str1, str2)
  36. }
  37.  
  38. def changeRegion(grz: String):String ={
  39. val newGrz = """(?=\d\d$)""".r.replaceFirstIn(grz, "1")
  40. newGrz
  41. }
  42. /*
  43. def compareGrz(grz1: String, grz2: String) : Boolean = {
  44. grz1.count(str=>str == '1')
  45. grz1.map(c=>(c,grz1.indexOf(c)))
  46. //apache.livinstainIndex
  47.  
  48. math.abs(grz1.length - grz2.length) match{
  49. case 0 => compareCharByChar(grz1, grz2)
  50. case 1 =>
  51. if (grz1.length < grz2.length){
  52. val newGrz = changeRegion(grz1)
  53. if (newGrz == grz2)
  54. true
  55. else
  56. false
  57. }
  58. else {
  59. val newGrz = changeRegion(grz2)
  60. if (newGrz == grz1)
  61. true
  62. else
  63. false
  64. }
  65. case _ => false
  66. }
  67. }*/
  68.  
  69. def main(args: Array[String]) {
  70. val interval = 7
  71. val conf = new SparkConf().setAppName("Test App").setMaster("local")
  72. val sc = new SparkContext(conf)
  73. val sqlContext = new org.apache.spark.sql.SQLContext(sc)
  74. //import sqlContext.implicits._
  75.  
  76.  
  77. case class Data(Date: String, Number: String, CameraId: Int, SetId:Int) {
  78. }
  79. val df = sqlContext.read.json("first50.json").map(p => Data(p.getString(2), p.getString(3).trim,p.getString(1).toInt,p.getString(4).toInt))
  80.  
  81. val groupedRdd = df.groupBy(_.SetId);
  82.  
  83. val result = groupedRdd.collect()
  84.  
  85. for(value <- result) {
  86. println(value)
  87. }
  88. //println(df.collect())
  89.  
  90. //println(checkInterval("2015-06-01T00:00:18Z","2015-06-01T00:00:26Z", interval))
  91. /* val lines = sc.textFile("H:\\first50.json")
  92. val lineLengths = lines.map(s => 1)
  93. val totalLength = lineLengths.reduce((a, b) => a + b)
  94. println(totalLength)*/
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement