孙悦完毕
This commit is contained in:
parent
6749b4ef03
commit
ca1aeb21e0
|
@ -1,28 +0,0 @@
|
||||||
package org.jeecg.sy
|
|
||||||
|
|
||||||
import org.apache.spark.sql.{DataFrame, SparkSession}
|
|
||||||
|
|
||||||
object Test {
|
|
||||||
def getString(): String = {
|
|
||||||
// 本地模式
|
|
||||||
val spark = SparkSession.builder()
|
|
||||||
.appName("SparkDemo")
|
|
||||||
.master("local")
|
|
||||||
.getOrCreate()
|
|
||||||
// 输出spark的版本信息
|
|
||||||
// 去除所有日志
|
|
||||||
spark.sparkContext.setLogLevel("WARN")
|
|
||||||
println("-----------------------\n\n\n\n\n\n")
|
|
||||||
// 产生是十个随机的数
|
|
||||||
val data = 1 to 10
|
|
||||||
// 生成RDD
|
|
||||||
val distData = spark.sparkContext.parallelize(data)
|
|
||||||
// 求出数字出现的次数
|
|
||||||
val counts = distData.map(n => (n, 1)).reduceByKey(_ + _)
|
|
||||||
// 打印结果
|
|
||||||
counts.collect().foreach(println)
|
|
||||||
println("\n\n\n\n\n\n-----------------------")
|
|
||||||
// 返回一个文字66
|
|
||||||
return "66"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.jeecg.sy;
|
package org.jeecg.sy.java;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
package org.jeecg.sy.java;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
//日期
|
||||||
|
//白天/晚上
|
||||||
|
//高温
|
||||||
|
//低温
|
||||||
|
//AQI
|
||||||
|
//风向
|
||||||
|
//降雨量
|
||||||
|
@Data
|
||||||
|
public class weather_1 {
|
||||||
|
String data;
|
||||||
|
String dayOrNight;
|
||||||
|
String highTemperature;
|
||||||
|
String lowTemperature;
|
||||||
|
String air;
|
||||||
|
String windSpeed;
|
||||||
|
String totalRainfall;
|
||||||
|
|
||||||
|
public String getAir() {
|
||||||
|
return air;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDayOrNight() {
|
||||||
|
return dayOrNight;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHighTemperature() {
|
||||||
|
return highTemperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLowTemperature() {
|
||||||
|
return lowTemperature;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTotalRainfall() {
|
||||||
|
return totalRainfall;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWindSpeed() {
|
||||||
|
return windSpeed;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
package org.jeecg.sy;
|
package org.jeecg.sy.java;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package org.jeecg.sy.scala
|
||||||
|
|
||||||
|
import scala.beans.BeanProperty
|
||||||
|
|
||||||
|
class Weather1 {
|
||||||
|
@BeanProperty var data: String = _
|
||||||
|
@BeanProperty var dayOrNight: String = _
|
||||||
|
@BeanProperty var highTemperature: String = _
|
||||||
|
@BeanProperty var lowTemperature: String = _
|
||||||
|
@BeanProperty var air: String = _
|
||||||
|
@BeanProperty var windSpeed: String = _
|
||||||
|
@BeanProperty var totalRainfall: String = _
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package org.jeecg.sy.scala
|
||||||
|
|
||||||
|
import scala.beans.BeanProperty
|
||||||
|
|
||||||
|
class Weather2 {
|
||||||
|
@BeanProperty val data: String = null
|
||||||
|
@BeanProperty val temperature: String = null
|
||||||
|
@BeanProperty val weather: String = null
|
||||||
|
}
|
|
@ -0,0 +1,104 @@
|
||||||
|
package org.jeecg.sy.scala
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.{JSONArray, JSONObject}
|
||||||
|
import org.apache.spark.sql.SparkSession
|
||||||
|
import org.jeecg.sy.java.{getData, weather_1, weather_2}
|
||||||
|
|
||||||
|
import java.text.{ParseException, SimpleDateFormat}
|
||||||
|
import java.util
|
||||||
|
import java.util.{ArrayList, Collections, Comparator, HashMap, List, Map}
|
||||||
|
|
||||||
|
object analysis {
|
||||||
|
// 数据爬取,输入一个List[weather_1],返回处理完的数据
|
||||||
|
def getData(list: List[weather_1]): List[weather_1] = {
|
||||||
|
// 将list 倒序// 将list 倒序
|
||||||
|
for (i <- 0 until list.size / 2) {
|
||||||
|
val temp: weather_1 = list.get(i)
|
||||||
|
list.set(i, list.get(list.size - i - 1))
|
||||||
|
list.set(list.size - i - 1, temp)
|
||||||
|
}
|
||||||
|
return list
|
||||||
|
}
|
||||||
|
|
||||||
|
def analysis2(list: List[weather_1]): List[weather_1] = {
|
||||||
|
// 先将list按照时间排序,旧的在前面,新的在后面
|
||||||
|
val sdf: SimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd")
|
||||||
|
Collections.sort(list, new Comparator[weather_1]() {
|
||||||
|
override def compare(d1: weather_1, d2: weather_1): Int = {
|
||||||
|
try return sdf.parse(d1.getData).compareTo(sdf.parse(d2.getData))
|
||||||
|
catch {
|
||||||
|
case e: ParseException =>
|
||||||
|
throw new IllegalArgumentException(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
list
|
||||||
|
}
|
||||||
|
|
||||||
|
def analysis3(list: List[weather_2]): List[weather_2] = {
|
||||||
|
list
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取列表中的 最高气温和最低气温的变化曲线(两条线)
|
||||||
|
def getTemperature(list: util.List[weather_1]): JSONObject = {
|
||||||
|
val result = new JSONObject
|
||||||
|
// 最高气温
|
||||||
|
val highTemperature = new JSONArray
|
||||||
|
// 最低气温
|
||||||
|
val lowTemperature = new JSONArray
|
||||||
|
for (i <- 0 until list.size) {
|
||||||
|
val temp1 = new JSONObject
|
||||||
|
// 格式为 date + temperature
|
||||||
|
//为data加上年份2024,然后转为日期模式
|
||||||
|
val data = list.get(i).getData
|
||||||
|
temp1.put("date", data)
|
||||||
|
temp1.put("temperature", list.get(i).getHighTemperature.replaceAll("℃", ""))
|
||||||
|
highTemperature.add(temp1)
|
||||||
|
val temp2 = new JSONObject
|
||||||
|
temp2.put("date", data)
|
||||||
|
temp2.put("temperature", list.get(i).getLowTemperature.replaceAll("℃", ""))
|
||||||
|
lowTemperature.add(temp2)
|
||||||
|
}
|
||||||
|
// 最高气温
|
||||||
|
result.put("highTemperature", highTemperature)
|
||||||
|
// 最低气温
|
||||||
|
result.put("lowTemperature", lowTemperature)
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取列表中 风力+风向这对字符串的出现次数(并排序)
|
||||||
|
def getWind(list: util.List[weather_1]): JSONObject = {
|
||||||
|
val result = new JSONObject
|
||||||
|
// 风力+风向
|
||||||
|
val wind = new util.HashMap[String, Integer]
|
||||||
|
for (i <- 0 until list.size) {
|
||||||
|
val windSpeed = list.get(i).getWindSpeed
|
||||||
|
if (wind.containsKey(windSpeed)) wind.put(windSpeed, wind.get(windSpeed) + 1)
|
||||||
|
else wind.put(windSpeed, 1)
|
||||||
|
}
|
||||||
|
// 对wind进行排序
|
||||||
|
val list1 = new util.ArrayList[util.Map.Entry[String, Integer]](wind.entrySet)
|
||||||
|
list1.sort(util.Map.Entry.comparingByValue)
|
||||||
|
// 塞入JSONArray
|
||||||
|
val winds = new JSONArray
|
||||||
|
val counts = new JSONArray
|
||||||
|
result.put("wind", winds)
|
||||||
|
result.put("count", counts)
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
|
// 天气类型出现次数饼图
|
||||||
|
def getTemperatureMap(list: util.List[weather_1]): JSONArray = {
|
||||||
|
val temperatureMapArray = new JSONArray
|
||||||
|
val wind = new util.HashMap[String, Integer]
|
||||||
|
for (i <- 0 until list.size) {
|
||||||
|
val windSpeed = list.get(i).getDayOrNight.split("/")(0)
|
||||||
|
if (wind.containsKey(windSpeed)) wind.put(windSpeed, wind.get(windSpeed) + 1)
|
||||||
|
else wind.put(windSpeed, 1)
|
||||||
|
}
|
||||||
|
// 对wind进行排序
|
||||||
|
val list1 = new util.ArrayList[util.Map.Entry[String, Integer]](wind.entrySet)
|
||||||
|
list1.sort(util.Map.Entry.comparingByValue)
|
||||||
|
temperatureMapArray
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,21 +0,0 @@
|
||||||
package org.jeecg.sy;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
//日期
|
|
||||||
//白天/晚上
|
|
||||||
//高温
|
|
||||||
//低温
|
|
||||||
//AQI
|
|
||||||
//风向
|
|
||||||
//降雨量
|
|
||||||
@Data
|
|
||||||
public class weather_1 {
|
|
||||||
String data;
|
|
||||||
String dayOrNight;
|
|
||||||
String highTemperature;
|
|
||||||
String lowTemperature;
|
|
||||||
String air;
|
|
||||||
String windSpeed;
|
|
||||||
String totalRainfall;
|
|
||||||
}
|
|
Loading…
Reference in New Issue