孙悦完毕
This commit is contained in:
parent
ca1aeb21e0
commit
6af21ee8e4
|
@ -22,6 +22,11 @@
|
||||||
<artifactId>spark-sql_2.13</artifactId>
|
<artifactId>spark-sql_2.13</artifactId>
|
||||||
<version>3.2.0</version>
|
<version>3.2.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.spark</groupId>
|
||||||
|
<artifactId>spark-mllib_2.13</artifactId>
|
||||||
|
<version>3.2.0</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- SYSTEM 系统管理模块 -->
|
<!-- SYSTEM 系统管理模块 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
package org.jeecg.sy;
|
package org.jeecg.sy.java;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import org.apache.spark.sql.Dataset;
|
|
||||||
import org.apache.spark.sql.Row;
|
|
||||||
import org.jeecg.common.api.vo.Result;
|
import org.jeecg.common.api.vo.Result;
|
||||||
|
import org.jeecg.sy.scala.WeatherPrediction$;
|
||||||
|
import org.jeecg.sy.temp.analysis$;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@ -16,9 +16,6 @@ import java.text.ParseException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static org.jeecg.sy.getData.getDatas;
|
|
||||||
import static org.jeecg.sy.getData.getDatas2;
|
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/sy")
|
@RequestMapping("/sy")
|
||||||
public class Controller {
|
public class Controller {
|
||||||
|
@ -29,16 +26,7 @@ public class Controller {
|
||||||
|
|
||||||
@RequestMapping("/get")
|
@RequestMapping("/get")
|
||||||
public Result test1() throws MalformedURLException {
|
public Result test1() throws MalformedURLException {
|
||||||
List<weather_1> list = getDatas("");
|
return Result.ok(analysis$.MODULE$.analysis2(getData.getDatas("")));
|
||||||
// 将list 倒序
|
|
||||||
for (int i = 0; i < list.size() / 2; i++) {
|
|
||||||
weather_1 temp = list.get(i);
|
|
||||||
list.set(i, list.get(list.size() - i - 1));
|
|
||||||
list.set(list.size() - i - 1, temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
String df = Test$.MODULE$.getString();
|
|
||||||
return Result.ok(list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//分析数据
|
//分析数据
|
||||||
|
@ -49,35 +37,7 @@ public class Controller {
|
||||||
if (redisTemplate.hasKey(key)) {
|
if (redisTemplate.hasKey(key)) {
|
||||||
return Result.ok(redisTemplate.opsForValue().get(key));
|
return Result.ok(redisTemplate.opsForValue().get(key));
|
||||||
}
|
}
|
||||||
// 获取一年的数据
|
List<weather_1> list = analysis$.MODULE$.analysis2(getWeathers());
|
||||||
String time[] = new String[12];
|
|
||||||
time[0] = "202304";
|
|
||||||
time[1] = "202305";
|
|
||||||
time[2] = "202306";
|
|
||||||
time[3] = "202307";
|
|
||||||
time[4] = "202308";
|
|
||||||
time[5] = "202309";
|
|
||||||
time[6] = "202310";
|
|
||||||
time[7] = "202311";
|
|
||||||
time[8] = "202312";
|
|
||||||
time[9] = "202401";
|
|
||||||
time[10] = "202402";
|
|
||||||
time[11] = "202403";
|
|
||||||
List<weather_1> list = new ArrayList<>();
|
|
||||||
for (int i = 11; i >= 0; i--) {
|
|
||||||
list.addAll(getDatas(time[i]));
|
|
||||||
}
|
|
||||||
// 先将list按照时间排序,旧的在前面,新的在后面
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
||||||
Collections.sort(list, new Comparator<weather_1>() {
|
|
||||||
public int compare(weather_1 d1, weather_1 d2) {
|
|
||||||
try {
|
|
||||||
return sdf.parse(d1.getData()).compareTo(sdf.parse(d2.getData()));
|
|
||||||
} catch (ParseException e) {
|
|
||||||
throw new IllegalArgumentException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// 三个结果
|
// 三个结果
|
||||||
JSONObject result = new JSONObject();
|
JSONObject result = new JSONObject();
|
||||||
result.put("temperature", getTemperature(list));
|
result.put("temperature", getTemperature(list));
|
||||||
|
@ -92,13 +52,26 @@ public class Controller {
|
||||||
// 预测未来一周的天气情况和最高温度
|
// 预测未来一周的天气情况和最高温度
|
||||||
@RequestMapping("/fe")
|
@RequestMapping("/fe")
|
||||||
public Result test3() throws MalformedURLException {
|
public Result test3() throws MalformedURLException {
|
||||||
List<weather_2> list = getDatas2();
|
List<weather_2> list = analysis$.MODULE$.analysis3(getData.getDatas2());
|
||||||
// 三个结果
|
// 三个结果
|
||||||
JSONObject result = new JSONObject();
|
JSONObject result = new JSONObject();
|
||||||
result.put("data", list);
|
result.put("data", list);
|
||||||
return Result.ok(result);
|
return Result.ok(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static List<weather_1> getWeathers() throws MalformedURLException {
|
||||||
|
// 获取一年的数据
|
||||||
|
String times = "202204,202205,202206,202207,202208,202209,202210,202211,202212,202301,202302,202303,202304,202305,202306,202307,202308,202309,202310,202311,202312,202401,202402,202403,";
|
||||||
|
List<weather_1> list = new ArrayList<>();
|
||||||
|
String time[] = times.split(",");
|
||||||
|
for (int i = time.length - 1; i >= 0; i--) {
|
||||||
|
list.addAll(getData.getDatas(time[i]));
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// 获取列表中的 最高气温和最低气温的变化曲线(两条线)
|
// 获取列表中的 最高气温和最低气温的变化曲线(两条线)
|
||||||
public static JSONObject getTemperature(List<weather_1> list) {
|
public static JSONObject getTemperature(List<weather_1> list) {
|
||||||
JSONObject result = new JSONObject();
|
JSONObject result = new JSONObject();
|
|
@ -0,0 +1,57 @@
|
||||||
|
package org.jeecg.sy.scala
|
||||||
|
|
||||||
|
import org.apache.spark.sql.SparkSession
|
||||||
|
import org.apache.spark.sql.functions._
|
||||||
|
import org.apache.spark.ml.feature.VectorAssembler
|
||||||
|
import org.apache.spark.ml.regression.LinearRegression
|
||||||
|
import org.apache.spark.ml.Pipeline
|
||||||
|
import org.apache.spark.sql.Encoders
|
||||||
|
import org.jeecg.sy.java.weather_1
|
||||||
|
|
||||||
|
import java.util
|
||||||
|
|
||||||
|
object WeatherPrediction {
|
||||||
|
|
||||||
|
def forecast(): Unit = {
|
||||||
|
val list = new util.ArrayList[Weather1]()
|
||||||
|
val spark = SparkSession.builder()
|
||||||
|
.appName("Weather Temperature Prediction")
|
||||||
|
.master("local[*]") // 适用于本地开发和测试
|
||||||
|
.getOrCreate()
|
||||||
|
|
||||||
|
import spark.implicits._
|
||||||
|
|
||||||
|
// 将List转换为DataFrame
|
||||||
|
val weatherData = null
|
||||||
|
|
||||||
|
// 定义特征向量
|
||||||
|
val assembler = new VectorAssembler()
|
||||||
|
.setInputCols(Array("lowTemperature", "windSpeed")) // 根据你的数据选择合适的特征
|
||||||
|
.setOutputCol("features")
|
||||||
|
|
||||||
|
// 创建线性回归模型
|
||||||
|
val lr = new LinearRegression()
|
||||||
|
.setLabelCol("highTemperature")
|
||||||
|
.setFeaturesCol("features")
|
||||||
|
.setMaxIter(10)
|
||||||
|
.setRegParam(0.3)
|
||||||
|
.setElasticNetParam(0.8)
|
||||||
|
|
||||||
|
// 创建Pipeline
|
||||||
|
val pipeline = new Pipeline()
|
||||||
|
.setStages(Array(assembler, lr))
|
||||||
|
|
||||||
|
// 训练模型
|
||||||
|
val model = pipeline.fit(weatherData)
|
||||||
|
|
||||||
|
// 使用模型进行预测
|
||||||
|
val predictions = model.transform(weatherData)
|
||||||
|
|
||||||
|
// 显示预测结果
|
||||||
|
predictions.select("data", "highTemperature", "features", "prediction").show()
|
||||||
|
|
||||||
|
// 停止SparkSession
|
||||||
|
spark.stop()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package org.jeecg.sy.temp
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.{JSONArray, JSONObject}
|
||||||
|
import org.jeecg.sy.java.{weather_1, weather_2}
|
||||||
|
|
||||||
|
import java.text.{ParseException, SimpleDateFormat}
|
||||||
|
import java.util
|
||||||
|
import java.util.{Collections, Comparator, List}
|
||||||
|
|
||||||
|
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按照时间排序,旧的在前面,新的在后面
|
||||||
|
// 先将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
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -170,7 +170,7 @@ spring:
|
||||||
#driver-class-name: com.mysql.cj.jdbc.Driver
|
#driver-class-name: com.mysql.cj.jdbc.Driver
|
||||||
#redis 配置
|
#redis 配置
|
||||||
redis:
|
redis:
|
||||||
database: 3
|
database: 13
|
||||||
host: 82.157.76.162
|
host: 82.157.76.162
|
||||||
port: 6379
|
port: 6379
|
||||||
password: aB3cDeF9
|
password: aB3cDeF9
|
||||||
|
@ -239,7 +239,7 @@ jeecg:
|
||||||
#大屏报表参数设置
|
#大屏报表参数设置
|
||||||
jmreport:
|
jmreport:
|
||||||
#多租户模式,默认值为空(created:按照创建人隔离、tenant:按照租户隔离) (v1.6.2+ 新增)
|
#多租户模式,默认值为空(created:按照创建人隔离、tenant:按照租户隔离) (v1.6.2+ 新增)
|
||||||
saasMode:
|
saasMode:
|
||||||
# 平台上线安全配置(v1.6.2+ 新增)
|
# 平台上线安全配置(v1.6.2+ 新增)
|
||||||
firewall:
|
firewall:
|
||||||
# 数据源安全 (开启后,不允许使用平台数据源、SQL解析加签并且不允许查询数据库)
|
# 数据源安全 (开启后,不允许使用平台数据源、SQL解析加签并且不允许查询数据库)
|
||||||
|
|
Loading…
Reference in New Issue