完成年度、月度数据查询、数据下载、蛋糕指数答案回显、分析回显、实训提交、重新实训接口开发
parent
4d7d251c2f
commit
20de6611fd
@ -0,0 +1,175 @@
|
||||
package com.sztzjy.linkCommerce.controller.stu;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.nimbusds.jose.shaded.gson.Gson;
|
||||
import com.sztzjy.linkCommerce.annotation.AnonymousAccess;
|
||||
import com.sztzjy.linkCommerce.entity.*;
|
||||
import com.sztzjy.linkCommerce.entity.dto.MonthlyCakeIndex;
|
||||
import com.sztzjy.linkCommerce.entity.dto.StuIndustryAnalysisDTO;
|
||||
import com.sztzjy.linkCommerce.entity.dto.YearCakeIndexDto;
|
||||
import com.sztzjy.linkCommerce.mapper.HyxqfxAnswerMapper;
|
||||
import com.sztzjy.linkCommerce.mapper.HyxqfxDataMapper;
|
||||
import com.sztzjy.linkCommerce.mapper.HyxqfxStuAnswerMapper;
|
||||
import com.sztzjy.linkCommerce.service.IndustryDemandAnalysisService;
|
||||
import com.sztzjy.linkCommerce.util.ResultEntity;
|
||||
import com.sztzjy.linkCommerce.util.excel.DataListener;
|
||||
import com.sztzjy.linkCommerce.util.excel.DemoDataListener;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author 17803
|
||||
* @date 2025-04-24 13:30
|
||||
*/
|
||||
@Api(tags = "行业需求分析")
|
||||
@RestController
|
||||
@RequestMapping("api/industryAnalysis")
|
||||
public class IndustryDemandAnalysisController {
|
||||
|
||||
|
||||
@Autowired
|
||||
private IndustryDemandAnalysisService service;
|
||||
|
||||
@Autowired
|
||||
private HyxqfxDataMapper hyxqfxDataMapper;
|
||||
|
||||
@Autowired
|
||||
private HyxqfxStuAnswerMapper hyxqfxStuAnswerMapper;
|
||||
|
||||
|
||||
|
||||
|
||||
//数据查询
|
||||
@ApiOperation("行业需求分析提交")
|
||||
@PostMapping("/analysisSubmit")
|
||||
@AnonymousAccess
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public ResultEntity uploadExcel(@RequestBody StuIndustryAnalysisDTO analysisDTO) {
|
||||
|
||||
//查询数据
|
||||
HyxqfxStuAnswerExample example = new HyxqfxStuAnswerExample();
|
||||
example.createCriteria().andUserIdEqualTo(analysisDTO.getUserId());
|
||||
|
||||
List<HyxqfxStuAnswer> hyxqfxStuAnswerList = hyxqfxStuAnswerMapper.selectByExample(example);
|
||||
if (!CollectionUtils.isEmpty(hyxqfxStuAnswerList)) {
|
||||
return new ResultEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
//读取文件内容 批量导入excel中 以文件名区分\
|
||||
|
||||
Map<String, Double> yearMap = new HashMap<>();
|
||||
yearMap.put("2018年",0.28);
|
||||
yearMap.put("2019年",0.25);
|
||||
yearMap.put("2020年",0.24);
|
||||
yearMap.put("2021年",0.22);
|
||||
yearMap.put("2022年",0.21);
|
||||
yearMap.put("2023年",0.22);
|
||||
yearMap.put("2024年",0.20);
|
||||
|
||||
Map<String, Double> monthMap = new HashMap<>();
|
||||
monthMap.put("2024年4月",0.21);
|
||||
monthMap.put("2024年5月",0.20);
|
||||
monthMap.put("2024年6月",0.20);
|
||||
monthMap.put("2024年7月",0.22);
|
||||
monthMap.put("2024年8月",0.33);
|
||||
monthMap.put("2024年9月",0.30);
|
||||
monthMap.put("2024年10月",0.33);
|
||||
|
||||
monthMap.put("2024年11月",0.23);
|
||||
monthMap.put("2024年12月",0.22);
|
||||
monthMap.put("2025年1月",0.22);
|
||||
monthMap.put("2025年2月",0.15);
|
||||
monthMap.put("2025年3月",0.27);
|
||||
|
||||
int count = 0;
|
||||
|
||||
List<YearCakeIndexDto> yearCakeIndexDtoList = analysisDTO.getYearCakeIndexDtoList();
|
||||
|
||||
for (YearCakeIndexDto yearCakeIndexDto : yearCakeIndexDtoList) {
|
||||
Double v = yearMap.get(yearCakeIndexDto.getYear());
|
||||
if (yearCakeIndexDto.getYearAnswer() == null || v != yearCakeIndexDto.getYearAnswer()) {
|
||||
count ++;
|
||||
}
|
||||
}
|
||||
|
||||
//分别将两个字段转为json格式
|
||||
List<MonthlyCakeIndex> monthlyCakeIndexList = analysisDTO.getMonthlyCakeIndexList();
|
||||
|
||||
for (MonthlyCakeIndex yearCakeIndexDto : monthlyCakeIndexList) {
|
||||
Double v = monthMap.get(yearCakeIndexDto.getYear());
|
||||
if (yearCakeIndexDto.getMonthAnswer() == null || v != yearCakeIndexDto.getMonthAnswer()) {
|
||||
count ++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
String jsonString = JSONObject.toJSONString(analysisDTO);
|
||||
HyxqfxStuAnswer hyxqfxStuAnswer = new HyxqfxStuAnswer();
|
||||
hyxqfxStuAnswer.setId(IdUtil.randomUUID());
|
||||
hyxqfxStuAnswer.setUserId(analysisDTO.getUserId());
|
||||
hyxqfxStuAnswer.setAnswer(jsonString);
|
||||
hyxqfxStuAnswer.setErrorNumber(count);
|
||||
|
||||
hyxqfxStuAnswerMapper.insertSelective(hyxqfxStuAnswer);
|
||||
|
||||
//插入主观题
|
||||
SubjectiveQuestions subjectiveQuestions = new SubjectiveQuestions();
|
||||
subjectiveQuestions.setId(IdUtil.randomUUID());
|
||||
subjectiveQuestions.setUserId(analysisDTO.getUserId());
|
||||
subjectiveQuestions.setModule("行业需求分析");
|
||||
subjectiveQuestions.setProject("市场需求挖掘");
|
||||
subjectiveQuestions.setCreateTime(new Date());
|
||||
subjectiveQuestions.setSubjectiveContent(analysisDTO.getContext());
|
||||
subjectiveQuestions.setSubjectiveContent(analysisDTO.getContext());
|
||||
|
||||
return new ResultEntity<>(HttpStatus.OK, "上传成功");
|
||||
|
||||
}
|
||||
|
||||
@ApiOperation("行业需求分析根据用户ID查询")
|
||||
@GetMapping("/selectByUserId")
|
||||
@AnonymousAccess
|
||||
public ResultEntity selectByUserId(@ApiParam("用户ID") String userId) {
|
||||
//读取文件内容 批量导入excel中 以文件名区分\
|
||||
|
||||
HyxqfxStuAnswerExample hyxqfxStuAnswer = new HyxqfxStuAnswerExample();
|
||||
hyxqfxStuAnswer.createCriteria().andUserIdEqualTo(userId);
|
||||
|
||||
List<HyxqfxStuAnswer> hyxqfxStuAnswersList = hyxqfxStuAnswerMapper.selectByExampleWithBLOBs(hyxqfxStuAnswer);
|
||||
if (CollectionUtils.isEmpty(hyxqfxStuAnswersList)) {
|
||||
return new ResultEntity<>(HttpStatus.OK);
|
||||
}else {
|
||||
JSONObject jsonObject = JSONObject.parseObject(hyxqfxStuAnswersList.get(0).getAnswer());
|
||||
return new ResultEntity<>(HttpStatus.OK,jsonObject);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void jiaoYanCodeSize(String code){
|
||||
String[] strings = code.split(",");
|
||||
if (strings.length>=20)
|
||||
{
|
||||
//计分规则
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/8/16 15:26
|
||||
*/
|
||||
@Data
|
||||
public class AnalyzeDataDTO {
|
||||
private String userId;
|
||||
private String tableName;
|
||||
private List<String> fieldList;
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/8/17 14:16
|
||||
*/
|
||||
@Data
|
||||
public class AprioriDTO {
|
||||
@ApiModelProperty("最小支持度阀值")
|
||||
private double support;
|
||||
@ApiModelProperty("最小置信度")
|
||||
private double confidence;
|
||||
@ApiModelProperty("用户ID")
|
||||
private String userId;
|
||||
@ApiModelProperty("数据集")
|
||||
private List<Map<String, Object>> deduplicatedDataList;
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/6/20 8:51
|
||||
*/
|
||||
@Data
|
||||
public class AssociationRulesDTO {
|
||||
@ApiModelProperty("关联")
|
||||
private List<String> correlation;
|
||||
|
||||
@ApiModelProperty("被关联")
|
||||
private List<String> associated;
|
||||
|
||||
@ApiModelProperty("置信度")
|
||||
private double confidenceLevel;
|
||||
|
||||
@ApiModelProperty("规则")
|
||||
private String rule;
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import com.sztzjy.linkCommerce.util.algorithm.KMeans;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/6/14 10:12
|
||||
*/
|
||||
@Data
|
||||
public class ClusterAnalysisDTO {
|
||||
private Map<Integer, List<KMeans.Point>> dataSet;
|
||||
|
||||
private Map<Integer,List<KMeans.Point>> centroid;
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/8/16 16:26
|
||||
*/
|
||||
@Data
|
||||
public class ClusterScatterPlotDTO {
|
||||
@ApiModelProperty("簇数")
|
||||
private Integer k;
|
||||
@ApiModelProperty("最大迭代次数")
|
||||
private Integer t;
|
||||
@ApiModelProperty("用户ID")
|
||||
private String userId;
|
||||
@ApiModelProperty("数据集")
|
||||
private List<Map<String, Object>> deduplicatedDataList;
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/8/19 10:33
|
||||
*/
|
||||
@Data
|
||||
@Api(tags = "描述性统计下载表格数据")
|
||||
public class DSExportDTO extends DescriptiveStatistics{
|
||||
|
||||
@ApiModelProperty("字段名")
|
||||
private String field;
|
||||
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/6/25 14:21
|
||||
*/
|
||||
@Data
|
||||
public class DataPreprocessingDTO {
|
||||
private String userId;
|
||||
|
||||
private String method;
|
||||
|
||||
private List<Map<String,Object>> mapList;
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/6/21 9:51
|
||||
*/
|
||||
@Data
|
||||
public class DescriptiveStatistics {
|
||||
@ApiModelProperty("平均数")
|
||||
private double average;
|
||||
|
||||
@ApiModelProperty("中位数")
|
||||
private double median;
|
||||
|
||||
@ApiModelProperty("众数")
|
||||
private double mode;
|
||||
|
||||
@ApiModelProperty("标准差")
|
||||
private double standardDeviation;
|
||||
|
||||
@ApiModelProperty("方差")
|
||||
private double variance;
|
||||
|
||||
@ApiModelProperty("标准误差")
|
||||
private double standardError;
|
||||
|
||||
@ApiModelProperty("峰度")
|
||||
private double kurtosis;
|
||||
|
||||
@ApiModelProperty("偏度")
|
||||
private double skewness;
|
||||
|
||||
@ApiModelProperty("最大值")
|
||||
private double max;
|
||||
|
||||
@ApiModelProperty("最小值")
|
||||
private double min;
|
||||
|
||||
@ApiModelProperty("求和")
|
||||
private double summation;
|
||||
|
||||
@ApiModelProperty("观测数")
|
||||
private Integer observations;
|
||||
|
||||
@ApiModelProperty("字段名")
|
||||
private String field;
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/6/21 10:00
|
||||
*/
|
||||
@Data
|
||||
public class DescriptiveStatisticsDTO {
|
||||
private String field;
|
||||
|
||||
private DescriptiveStatistics statistics;
|
||||
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/8/19 16:09
|
||||
*/
|
||||
@Data
|
||||
public class EmotionalAnalysisDto {
|
||||
|
||||
private String userId;
|
||||
private String modelType;
|
||||
private String content;
|
||||
@XmlElement(name = "optionalField", required = false)
|
||||
private String id;
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/8/28 9:09
|
||||
*/
|
||||
@Data
|
||||
public class KmeansDTO {
|
||||
|
||||
private ArrayList<ArrayList<ArrayList<Float>>> clusters;
|
||||
|
||||
private Integer iterations;
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/7/23 16:52
|
||||
*/
|
||||
@Data
|
||||
public class LogisticDTO {
|
||||
|
||||
@ApiModelProperty("自变量x")
|
||||
private double[] x;
|
||||
|
||||
@ApiModelProperty("因变量y")
|
||||
private double[] y;
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
private String userId;
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/8/19 9:38
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class LogisticPredictDTO extends RAnalysisDTO {
|
||||
|
||||
private double x;
|
||||
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author 17803
|
||||
* @date 2025-04-24 14:22
|
||||
*/
|
||||
@Data
|
||||
public class MonthlyCakeIndex {
|
||||
|
||||
|
||||
@ApiModelProperty(notes = "月份")
|
||||
private String year;
|
||||
|
||||
@ApiModelProperty(notes = "月度蛋糕指数")
|
||||
private Double monthAnswer;
|
||||
}
|
||||
@ -0,0 +1,48 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/11/26 13:42
|
||||
*/
|
||||
//新版描述性统计分析返回数据格式
|
||||
@Data
|
||||
public class NewDescriptiveStatisticsDTO {
|
||||
@ApiModelProperty("平均数")
|
||||
private double average;
|
||||
|
||||
@ApiModelProperty("中位数")
|
||||
private double median;
|
||||
|
||||
@ApiModelProperty("众数")
|
||||
private double mode;
|
||||
|
||||
@ApiModelProperty("标准差")
|
||||
private double standardDeviation;
|
||||
|
||||
@ApiModelProperty("方差")
|
||||
private double variance;
|
||||
|
||||
@ApiModelProperty("标准误差")
|
||||
private double standardError;
|
||||
|
||||
@ApiModelProperty("峰度")
|
||||
private double kurtosis;
|
||||
|
||||
@ApiModelProperty("偏度")
|
||||
private double skewness;
|
||||
|
||||
@ApiModelProperty("最大值")
|
||||
private double max;
|
||||
|
||||
@ApiModelProperty("最小值")
|
||||
private double min;
|
||||
|
||||
@ApiModelProperty("求和")
|
||||
private double summation;
|
||||
|
||||
@ApiModelProperty("观测数")
|
||||
private Integer observations;
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/8/17 16:30
|
||||
*/
|
||||
@Data
|
||||
public class RAnalysisDTO {
|
||||
@ApiModelProperty("回归系数值")
|
||||
private double intercept;
|
||||
@ApiModelProperty("逻辑回归常数项值")
|
||||
private double slope;
|
||||
}
|
||||
@ -0,0 +1,16 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/8/19 14:55
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class RAnalysisExportDTO extends RAnalysisDTO{
|
||||
@ApiModelProperty("预测值")
|
||||
private double prediction;
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/7/19 13:56
|
||||
*/
|
||||
@Data
|
||||
public class RegressionAnalysisDTO {
|
||||
@ApiModelProperty("自变量x")
|
||||
private double[][] x;
|
||||
|
||||
@ApiModelProperty("因变量y")
|
||||
private double[] y;
|
||||
|
||||
@ApiModelProperty("用户ID")
|
||||
private String userId;
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/6/21 10:57
|
||||
*/
|
||||
@Data
|
||||
public class StatisticsDTO {
|
||||
private Map<String, List<Double>> map;
|
||||
private List<String> statistic;
|
||||
private String userId;
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author 17803
|
||||
* @date 2025-04-24 14:12
|
||||
*/
|
||||
//
|
||||
@Data
|
||||
public class StuIndustryAnalysisDTO {
|
||||
|
||||
@ApiModelProperty(notes = "年度蛋糕指数")
|
||||
private List<YearCakeIndexDto> yearCakeIndexDtoList;
|
||||
|
||||
@ApiModelProperty(notes = "月度蛋糕指数")
|
||||
private List<MonthlyCakeIndex> monthlyCakeIndexList;
|
||||
|
||||
|
||||
@ApiModelProperty(notes = "用户ID")
|
||||
private String userId;
|
||||
|
||||
@ApiModelProperty(notes = "主观题")
|
||||
private String context;
|
||||
|
||||
}
|
||||
@ -0,0 +1,14 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/6/18 16:48
|
||||
*/
|
||||
@Data
|
||||
public class WordFrequencyDTO {
|
||||
private String keyword;
|
||||
|
||||
private Integer frequency;
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
package com.sztzjy.linkCommerce.entity.dto;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author 17803
|
||||
* @date 2025-04-24 14:22
|
||||
*/
|
||||
@Data
|
||||
public class YearCakeIndexDto {
|
||||
|
||||
|
||||
|
||||
@ApiModelProperty(notes = "月份")
|
||||
private String year;
|
||||
|
||||
@ApiModelProperty(notes = "童装童鞋类目年度蛋糕指数")
|
||||
private Double yearAnswer;
|
||||
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
package com.sztzjy.linkCommerce.service;
|
||||
|
||||
/**
|
||||
* @author 17803
|
||||
* @date 2025-04-24 13:35
|
||||
*/
|
||||
public interface IndustryDemandAnalysisService {
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package com.sztzjy.linkCommerce.service;
|
||||
|
||||
import com.sztzjy.linkCommerce.entity.dto.AnalyzeDataDTO;
|
||||
import com.sztzjy.linkCommerce.util.ResultEntity;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tz
|
||||
* @date 2024/6/14 11:05
|
||||
*/
|
||||
public interface StuDigitalMarketingModelService {
|
||||
List<String> dropdownBox(String userId);
|
||||
|
||||
ResultEntity emotionalAnalysis(String userId, String modelType, String content,String id) throws IOException;
|
||||
|
||||
|
||||
ResultEntity descriptiveStatistics(Map<String, List<Double>> map, List<String> statistic, String userId);
|
||||
|
||||
List<String> viewMetrics(String userId, String tableName,String algorithmName);
|
||||
|
||||
ResultEntity viewAnalyzeData(AnalyzeDataDTO analyzeDataDTO);
|
||||
|
||||
ResultEntity dataPreprocessing(String userId, String method, List<Map<String, Object>> mapList);
|
||||
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package com.sztzjy.linkCommerce.service.impl;
|
||||
|
||||
import com.sztzjy.linkCommerce.service.IndustryDemandAnalysisService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author 17803
|
||||
* @date 2025-04-24 13:35
|
||||
*/
|
||||
@Service
|
||||
public class IndustryDemandAnalysisServiceImpl implements IndustryDemandAnalysisService {
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package com.sztzjy.linkCommerce.util;
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
/**
|
||||
* 将驼峰命名法的字符串转换为下划线命名法的字符串。
|
||||
* @param camelCaseStr 驼峰命名的字符串。
|
||||
* @return 下划线命名法的字符串。
|
||||
*/
|
||||
public static String convertCamelCaseToUnderscore(String camelCaseStr) {
|
||||
// 使用Pattern和Matcher处理字符串
|
||||
StringBuilder underscoreStr = new StringBuilder();
|
||||
for (int i = 0; i < camelCaseStr.length(); i++) {
|
||||
char c = camelCaseStr.charAt(i);
|
||||
if (Character.isUpperCase(c) && i > 0) {
|
||||
// 如果当前字符是大写,并且不是第一个字符,则添加下划线
|
||||
underscoreStr.append("_");
|
||||
}
|
||||
// 将字符添加到结果字符串中,如果是大写,则转换为小写
|
||||
underscoreStr.append(Character.toLowerCase(c));
|
||||
}
|
||||
return underscoreStr.toString();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
package com.sztzjy.linkCommerce.util.algorithm;
|
||||
|
||||
public class Data {
|
||||
public double[] features;
|
||||
public double label;
|
||||
|
||||
public Data(double[] features, double label) {
|
||||
this.features = features;
|
||||
this.label = label;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,182 @@
|
||||
package com.sztzjy.linkCommerce.util.algorithm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
public class KMeans {
|
||||
|
||||
private int k; // 簇数
|
||||
private int maxIterations; // 最大迭代次数
|
||||
private List<Point> centroids; // 质心
|
||||
private List<Point> points; // 数据集
|
||||
|
||||
|
||||
public KMeans(int k, int maxIterations, List<Point> points) {
|
||||
this.k = k;
|
||||
this.maxIterations = maxIterations;
|
||||
this.points = points;
|
||||
this.centroids = initializeCentroids();
|
||||
}
|
||||
|
||||
public List<Point> getCentroids() {
|
||||
return centroids;
|
||||
}
|
||||
|
||||
|
||||
// 初始化质心
|
||||
private List<Point> initializeCentroids() {
|
||||
List<Point> centroids = new ArrayList<>();
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < k; i++) {
|
||||
int randomIndex = random.nextInt(points.size());
|
||||
centroids.add(points.get(randomIndex));
|
||||
}
|
||||
return centroids;
|
||||
}
|
||||
|
||||
// 计算点到质心的距离
|
||||
private double distance(Point point1, Point point2) {
|
||||
return Math.sqrt(Math.pow(point1.getX() - point2.getX(), 2) + Math.pow(point1.getY() - point2.getY(), 2));
|
||||
}
|
||||
|
||||
// 找到每个点所属的最近质心
|
||||
private int closestCentroid(Point point) {
|
||||
double minDistance = Double.MAX_VALUE;
|
||||
int closestCentroidIndex = -1;
|
||||
for (int i = 0; i < centroids.size(); i++) {
|
||||
double dist = distance(point, centroids.get(i));
|
||||
if (dist < minDistance) {
|
||||
minDistance = dist;
|
||||
closestCentroidIndex = i;
|
||||
}
|
||||
}
|
||||
return closestCentroidIndex;
|
||||
}
|
||||
|
||||
// 更新质心位置为每个簇的平均值
|
||||
private void updateCentroids(List<List<Point>> clusters) {
|
||||
for (int i = 0; i < k; i++) {
|
||||
double sumX = 0;
|
||||
double sumY = 0;
|
||||
List<Point> cluster = clusters.get(i);
|
||||
int clusterSize = cluster.size();
|
||||
for (Point point : cluster) {
|
||||
sumX += point.getX();
|
||||
sumY += point.getY();
|
||||
}
|
||||
if (clusterSize > 0) {
|
||||
centroids.get(i).setX(sumX / clusterSize);
|
||||
centroids.get(i).setY(sumY / clusterSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// K-means聚类算法
|
||||
public List<List<Point>> cluster() {
|
||||
List<List<Point>> clusters=null;
|
||||
for (int iter = 0; iter < maxIterations; iter++) {
|
||||
clusters = new ArrayList<>(k);
|
||||
for (int i = 0; i < k; i++) {
|
||||
clusters.add(new ArrayList<>());
|
||||
}
|
||||
|
||||
// 分配每个点到最近的质心
|
||||
for (Point point : points) {
|
||||
int closestIndex = closestCentroid(point);
|
||||
clusters.get(closestIndex).add(point);
|
||||
}
|
||||
|
||||
// 更新质心位置
|
||||
updateCentroids(clusters);
|
||||
}
|
||||
|
||||
// 返回每个簇的点集合
|
||||
return clusters;
|
||||
}
|
||||
|
||||
// 示例中的数据点类
|
||||
public static class Point {
|
||||
private double x;
|
||||
private double y;
|
||||
|
||||
public Point(double x, double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public double getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public double getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setX(double x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public void setY(double y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "(" + x + ", " + y + ")";
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// List<KMeans.Point> irisData = readIrisData("D:\\home\\linkCommerce\\Iris.txt");
|
||||
// int k = 3; // 假设聚为3类
|
||||
// int maxIterations = 100;
|
||||
// KMeans kMeans = new KMeans(k, maxIterations, irisData);
|
||||
// List<List<KMeans.Point>> clusters = kMeans.cluster();
|
||||
//
|
||||
// // 打印每个簇的结果
|
||||
// for (int i = 0; i < clusters.size(); i++) {
|
||||
// System.out.println("Cluster " + i + ": " + clusters.get(i));
|
||||
// }
|
||||
//
|
||||
// // 获取每个簇的中心点坐标
|
||||
// List<Point> centroids = kMeans.getCentroids();
|
||||
// for (int i = 0; i < centroids.size(); i++) {
|
||||
// System.out.println("Centroid for cluster " + i + ": " + centroids.get(i));
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
public static List<String> convertToDelimitedStringList(List<Map<String, Object>> nestedList) {
|
||||
List<String> flatList = new ArrayList<>();
|
||||
for (Map<String, Object> innerMap : nestedList) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Object value : innerMap.values()) {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append(value);
|
||||
}
|
||||
flatList.add(sb.toString());
|
||||
}
|
||||
return flatList;
|
||||
}
|
||||
|
||||
|
||||
public static List<Point> readIrisData(List<String> data) {
|
||||
List<Point> points = new ArrayList<>();
|
||||
for (String line : data) {
|
||||
String[] values = line.split(",");
|
||||
|
||||
double x = Double.parseDouble(values[0]);
|
||||
double y = Double.parseDouble(values[1]);
|
||||
|
||||
|
||||
points.add(new Point(x, y));
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,96 @@
|
||||
package com.sztzjy.linkCommerce.util.algorithm;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
public class LinearRegression {
|
||||
private double intercept;
|
||||
private double[] slopes;
|
||||
|
||||
// 线性回归的训练方法
|
||||
public void fit(double[][] x, double[] y) {
|
||||
int n = y.length;
|
||||
int m = x[0].length;
|
||||
double[] sumX = new double[m];
|
||||
double sumY = 0.0;
|
||||
double[] sumXY = new double[m];
|
||||
double[] sumX2 = new double[m];
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
for (int j = 0; j < m; j++) {
|
||||
sumX[j] += x[i][j];
|
||||
sumXY[j] += x[i][j] * y[i];
|
||||
sumX2[j] += x[i][j] * x[i][j];
|
||||
}
|
||||
sumY += y[i];
|
||||
}
|
||||
|
||||
double[] xMean = new double[m];
|
||||
for (int j = 0; j < m; j++) {
|
||||
xMean[j] = sumX[j] / n;
|
||||
}
|
||||
double yMean = sumY / n;
|
||||
|
||||
DecimalFormat df = new DecimalFormat("#.00");
|
||||
|
||||
|
||||
this.slopes = new double[m];
|
||||
for (int j = 0; j < m; j++) {
|
||||
this.slopes[j] = Double.parseDouble(df.format((sumXY[j] - n * xMean[j] * yMean) / (sumX2[j] - n * xMean[j] * xMean[j])));
|
||||
}
|
||||
|
||||
this.intercept = Double.parseDouble(df.format(yMean - dotProduct(this.slopes, xMean)));
|
||||
}
|
||||
|
||||
// 辅助方法:计算向量的点积
|
||||
private double dotProduct(double[] a, double[] b) {
|
||||
double result = 0.0;
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
result += a[i] * b[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// 预测方法
|
||||
public double predict(double[] x,double intercept,double[] slopes) {
|
||||
if (x.length != slopes.length) {
|
||||
throw new IllegalArgumentException("输入的x维度与模型不匹配");
|
||||
}
|
||||
return intercept + dotProduct(slopes, x);
|
||||
}
|
||||
|
||||
// 获取截距
|
||||
public double getIntercept() {
|
||||
return this.intercept;
|
||||
}
|
||||
|
||||
// 获取斜率
|
||||
public double[] getSlopes() {
|
||||
return this.slopes;
|
||||
}
|
||||
|
||||
// public static void main(String[] args) {
|
||||
// // 示例数据
|
||||
// double[][] x = {{1, 19}, {1, 21}, {2, 20}, {2, 23}, {2, 31}};
|
||||
// double[] y = {15, 15, 16, 16, 17};
|
||||
//
|
||||
// // 创建线性回归模型
|
||||
// LinearRegression lr = new LinearRegression();
|
||||
// lr.fit(x, y);
|
||||
//
|
||||
// DecimalFormat df = new DecimalFormat("#.0");
|
||||
//
|
||||
// List<String> list=new ArrayList<>();
|
||||
// for (int i = 0; i < lr.getSlopes().length; i++) {
|
||||
// String format = df.format(lr.getSlopes()[i]);
|
||||
// list.add(format);
|
||||
// }
|
||||
// // 输出模型参数
|
||||
// System.out.println("常数项值: " + df.format(lr.getIntercept()));
|
||||
// System.out.println("第一个特征系数值: " + list.get(0));
|
||||
//
|
||||
// // 预测新数据
|
||||
// double[] newX = {2, 88};
|
||||
// double predictedY = lr.predict(newX);
|
||||
// System.out.println("输入x: " + java.util.Arrays.toString(newX) + "预测y=" + df.format(predictedY));
|
||||
// }
|
||||
}
|
||||
@ -0,0 +1,57 @@
|
||||
package com.sztzjy.linkCommerce.util.algorithm;
|
||||
|
||||
public class LogisticRegression {
|
||||
|
||||
private double[] x;
|
||||
|
||||
|
||||
private double[] y;
|
||||
|
||||
public LogisticRegression(double[] x, double[] y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
// 计算线性回归参数
|
||||
public double[] fit() {
|
||||
if (x.length != y.length || x.length == 0) {
|
||||
throw new IllegalArgumentException("Invalid input data");
|
||||
}
|
||||
|
||||
int n = x.length;
|
||||
double sumX = 0;
|
||||
double sumY = 0;
|
||||
double sumXY = 0;
|
||||
double sumXX = 0;
|
||||
|
||||
// 计算各项和
|
||||
for (int i = 0; i < n; i++) {
|
||||
sumX += x[i];
|
||||
sumY += y[i];
|
||||
sumXY += x[i] * y[i];
|
||||
sumXX += x[i] * x[i];
|
||||
}
|
||||
|
||||
// 计算斜率和截距
|
||||
double slope = (n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX);
|
||||
double intercept = (sumY - slope * sumX) / n;
|
||||
|
||||
return new double[] { intercept, slope };
|
||||
}
|
||||
|
||||
public double[][] getCoordinatesOnLine() {
|
||||
double[] parameters = fit();
|
||||
double intercept = parameters[0];
|
||||
double slope = parameters[1];
|
||||
|
||||
double[][] coordinates = new double[x.length][2];
|
||||
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
coordinates[i][0] = x[i];
|
||||
coordinates[i][1] = slope * x[i] + intercept;
|
||||
}
|
||||
|
||||
return coordinates;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,23 @@
|
||||
package com.sztzjy.linkCommerce.util.algorithm;
|
||||
|
||||
import cn.hutool.core.io.resource.ClassPathResource;
|
||||
import com.hankcs.hanlp.corpus.io.IIOAdapter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.Files;
|
||||
|
||||
public class ResourceFileIoAdapter implements IIOAdapter {
|
||||
@Override
|
||||
public InputStream open(String path) throws IOException {
|
||||
ClassPathResource resource = new ClassPathResource(path);
|
||||
return Files.newInputStream(resource.getFile().toPath());
|
||||
}
|
||||
|
||||
@Override
|
||||
public OutputStream create(String path) throws IOException {
|
||||
ClassPathResource resource = new ClassPathResource(path);
|
||||
return Files.newOutputStream(resource.getFile().toPath());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
package com.sztzjy.linkCommerce.util.algorithm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TrainDataSet {
|
||||
|
||||
/**
|
||||
* 特征集合
|
||||
**/
|
||||
public List<double[]> features = new ArrayList<>();
|
||||
/**
|
||||
* 标签集合
|
||||
**/
|
||||
public List<Double> labels = new ArrayList<>();
|
||||
/**
|
||||
* 特征向量维度
|
||||
**/
|
||||
public int featureDim;
|
||||
|
||||
public int size() {
|
||||
return labels.size();
|
||||
}
|
||||
|
||||
public double[] getFeature(int index) {
|
||||
return features.get(index);
|
||||
}
|
||||
|
||||
public double getLabel(int index) {
|
||||
return labels.get(index);
|
||||
}
|
||||
|
||||
public void addData(double[] feature, double label) {
|
||||
if (features.isEmpty()) {
|
||||
featureDim = feature.length;
|
||||
} else {
|
||||
if (featureDim != feature.length) {
|
||||
throwDimensionMismatchException(feature.length);
|
||||
}
|
||||
}
|
||||
features.add(feature);
|
||||
labels.add(label);
|
||||
}
|
||||
|
||||
public void throwDimensionMismatchException(int errorLen) {
|
||||
throw new RuntimeException("DimensionMismatchError: 你应该传入维度为 " + featureDim + " 的特征向量 , 但你传入了维度为 " + errorLen + " 的特征向量");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue