Source code

Download source archive ↓

src/AddDayState.scala

1package cn.piflow.bundle.flux.pretreatment
2
3
4import cn.piflow.bundle.flux.util.FluxUtil_1
5import cn.piflow.conf.bean.PropertyDescriptor
6import cn.piflow.conf.util.{ImageUtil, MapUtil}
7import cn.piflow.conf.{ConfigurableStop, Port}
8import cn.piflow.{JobContext, JobInputStream, JobOutputStream, ProcessContext}
9import org.apache.spark.sql.SparkSession
10
11class AddDayState extends ConfigurableStop{
12  val authorEmail: String = "ygang@cnic.cn"
13  val description: String = "Add the state of the current time based on the id of the day, month, day, hour and day (day or night (defined by sunrise and sunset))"
14  val inportList: List[String] = List(Port.DefaultPort)
15  val outportList: List[String] = List(Port.DefaultPort)
16
17  var longitude: String = _
18  var latitude: String = _
19
20  override def perform(in: JobInputStream, out: JobOutputStream, pec: JobContext): Unit = {
21    val spark = pec.get[SparkSession]()
22
23    val flux = new FluxUtil_1
24    val df = flux.AddDayStateWithDayHour(spark, in.read(),longitude.toDouble, latitude.toDouble)
25
26    out.write(df)
27  }
28
29  override def setProperties(map: Map[String, Any]): Unit = {
30    longitude = MapUtil.get(map,"longitude").asInstanceOf[String]
31    latitude = MapUtil.get(map,"latitude").asInstanceOf[String]
32
33  }
34
35  override def getPropertyDescriptor(): List[PropertyDescriptor] = {
36    var descriptor : List[PropertyDescriptor] = List()
37
38    val longitude = new PropertyDescriptor()
39      .name("longitude")
40      .displayName("longitude")
41      .description("longitude")
42      .defaultValue("128.1")
43      .required(true)
44      .example("128.1")
45    descriptor = longitude :: descriptor
46
47    val latitude = new PropertyDescriptor()
48      .name("latitude")
49      .displayName("latitude")
50      .description("latitude")
51      .defaultValue("42.4")
52      .required(true)
53      .example("42.4")
54    descriptor = latitude :: descriptor
55
56
57    descriptor
58  }
59
60  override def getIcon(): Array[Byte] = {
61    ImageUtil.getImage("png/Flux/flux.png",this.getClass.getName)
62  }
63
64  override def getGroup(): List[String] = {
65    List("Flux_pretreatment")
66  }
67
68  override def initialize(ctx: ProcessContext): Unit = {
69
70  }
71
72}