Source code

Download source archive ↓

upstream/piflow-bundle/src/main/scala/cn/piflow/bundle/flux/pretreatment/AddDayState.scala

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