| | |
| | | @NotNull(message="调度方案时间不能为空") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private Date scheduleTime; |
| | | |
| | | @Schema(description = "动态数据长度(输入端口,数据长度)") |
| | | private Map<Integer, Integer> dynamicDataLength; |
| | | |
| | | @Schema(description = "动态模型设置参数") |
| | | private Map<String, String> dynamicSettings; |
| | | } |
| | |
| | | resp.setScheduleTime(reqDTO.getScheduleTime()); |
| | | try { |
| | | log.info("调度计算开始: " + System.currentTimeMillis()); |
| | | ScheduleResultVO scheduleResult = scheduleModelHandler.doSchedule(reqDTO.getScheduleCode(), reqDTO.getScheduleTime()); |
| | | ScheduleResultVO scheduleResult = scheduleModelHandler.doSchedule(reqDTO.getScheduleCode(), reqDTO.getScheduleTime(), |
| | | reqDTO.getDynamicDataLength(), reqDTO.getDynamicSettings()); |
| | | resp.setStatusCode(scheduleResult.getResultCode()); |
| | | resp.setResult(scheduleResult.getResult()); |
| | | stScheduleRecordService.create(scheduleResult); |
| | |
| | | |
| | | @GetMapping("/export-excel") |
| | | @Operation(summary = "导出调度方案 Excel") |
| | | @PreAuthorize("@ss.hasPermission('system:tenant:export')") |
| | | @PreAuthorize("@ss.hasPermission('sche:scheme:export')") |
| | | @ApiAccessLog(operateType = EXPORT) |
| | | public void exportTenantExcel(@Valid StScheduleSchemePageReqVO exportReqVO, |
| | | HttpServletResponse response) throws IOException { |
| | |
| | | ExcelUtils.write(response, "调度方案.xls", "数据", StScheduleSchemeEntity.class, |
| | | BeanUtils.toBean(list, StScheduleSchemeEntity.class)); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermission('sche:scheme:update')") |
| | | @PutMapping("/enable") |
| | | @Operation(summary = "启用") |
| | | public CommonResult<Boolean> enable(@RequestBody String[] ids) { |
| | | stScheduleSchemeService.enableByIds(ids); |
| | | return success(true); |
| | | } |
| | | |
| | | @PreAuthorize("@ss.hasPermission('sche:scheme:update')") |
| | | @PutMapping("/disable") |
| | | @Operation(summary = "禁用") |
| | | public CommonResult<Boolean> disable(@RequestBody String[] ids) { |
| | | stScheduleSchemeService.disableByIds(ids); |
| | | return success(true); |
| | | } |
| | | } |
| | |
| | | StScheduleSchemeEntity getByCode(String code); |
| | | |
| | | List<StScheduleSchemeDTO> list(Map<String, Object> params); |
| | | |
| | | void enableByIds(String[] ids); |
| | | |
| | | void disableByIds(String[] ids); |
| | | } |
| | |
| | | package com.iailab.module.model.mcs.sche.service.impl; |
| | | |
| | | import com.baomidou.dynamic.datasource.annotation.DSTransactional; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.iailab.framework.common.pojo.PageResult; |
| | | import com.iailab.framework.common.service.impl.BaseServiceImpl; |
| | |
| | | import com.iailab.module.model.mcs.sche.vo.StScheduleSchemePageReqVO; |
| | | import com.iailab.module.model.mcs.sche.vo.StScheduleSchemeSaveReqVO; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.*; |
| | | |
| | |
| | | entity.setScheduleTime(scheduleTime); |
| | | baseDao.updateById(entity); |
| | | } |
| | | |
| | | @Override |
| | | @DSTransactional(rollbackFor = Exception.class) |
| | | public void enableByIds(String[] ids) { |
| | | if (CollectionUtils.isEmpty(Arrays.asList(ids))) { |
| | | return; |
| | | } |
| | | Arrays.asList(ids).forEach(item -> { |
| | | StScheduleSchemeEntity entity = new StScheduleSchemeEntity(); |
| | | entity.setId(item); |
| | | entity.setStatus(0); |
| | | baseDao.updateById(entity); |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | @DSTransactional(rollbackFor = Exception.class) |
| | | public void disableByIds(String[] ids) { |
| | | if (CollectionUtils.isEmpty(Arrays.asList(ids))) { |
| | | return; |
| | | } |
| | | Arrays.asList(ids).forEach(item -> { |
| | | StScheduleSchemeEntity entity = new StScheduleSchemeEntity(); |
| | | entity.setId(item); |
| | | entity.setStatus(1); |
| | | baseDao.updateById(entity); |
| | | }); |
| | | } |
| | | } |
| | |
| | | @Schema(description = "调度模型") |
| | | private String modelId; |
| | | |
| | | @Schema(description = "调度时间") |
| | | private Date scheduleTime; |
| | | |
| | | @Schema(description = " 状态(0正常 1停用)") |
| | | private Integer status; |
| | | |
| | |
| | | } |
| | | String modelId = predictModel.getId(); |
| | | try { |
| | | List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Predict.name(), modelId, predictTime, itemName); |
| | | List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Predict.name(), modelId, predictTime, itemName, new HashMap<>()); |
| | | String modelPath = predictModel.getModelpath(); |
| | | if (modelPath == null) { |
| | | log.info("模型路径不存在,modelId=" + modelId); |
| | |
| | | package com.iailab.module.model.mdk.sample; |
| | | |
| | | import com.iailab.module.model.mdk.common.exceptions.ModelInvokeException; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItemPort; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleData; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleInfo; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.text.MessageFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 样本构造 |
| | |
| | | @Autowired |
| | | private SampleFactory sampleFactory; |
| | | |
| | | public List<SampleData> constructSample(String typeA, String modelId, Date runTime,String itemName) throws ModelInvokeException { |
| | | public List<SampleData> constructSample(String typeA, String modelId, Date runTime,String itemName, Map<Integer, Integer> dynamicDataLength) throws ModelInvokeException { |
| | | try { |
| | | SampleInfoConstructor sampleInfoConstructor = sampleFactory.createSampleInfo(typeA, modelId); |
| | | SampleInfo sampleInfo = sampleInfoConstructor.prepareSampleInfo(modelId, runTime); |
| | | SampleDataConstructor sampleDataConstructor = sampleFactory.createSampelData(typeA); |
| | | if (!CollectionUtils.isEmpty(dynamicDataLength) && sampleInfo.getColumnInfo() != null) { |
| | | for(ColumnItemPort columnInfo : sampleInfo.getColumnInfo()) { |
| | | if (!dynamicDataLength.containsKey(columnInfo.getPortOrder())) { |
| | | continue; |
| | | } |
| | | columnInfo.setDataLength(dynamicDataLength.get(columnInfo.getPortOrder())); |
| | | columnInfo.getColumnItemList().forEach(columnItem -> { |
| | | columnItem.setDataLength(columnInfo.getDataLength()); |
| | | }); |
| | | } |
| | | } |
| | | SampleDataConstructor sampleDataConstructor = sampleFactory.createSampleData(typeA); |
| | | return sampleDataConstructor.prepareSampleData(sampleInfo); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | return sampleInfoConstructor; |
| | | } |
| | | |
| | | public SampleDataConstructor createSampelData(String typeA) { |
| | | public SampleDataConstructor createSampleData(String typeA) { |
| | | SampleDataConstructor sampleDataConstructor = null; |
| | | if (typeA.compareTo(TypeA.Predict.name()) == 0) { |
| | | sampleDataConstructor = predictSampleDataConstructor; |
| | |
| | | |
| | | import com.iailab.module.data.api.ind.IndItemApi; |
| | | import com.iailab.module.data.api.ind.dto.ApiIndItemDTO; |
| | | import com.iailab.module.data.api.plan.PlanItemApi; |
| | | import com.iailab.module.data.api.plan.dto.ApiPlanItemDTO; |
| | | import com.iailab.module.data.api.point.DataPointApi; |
| | | import com.iailab.module.data.api.point.dto.ApiPointDTO; |
| | | import com.iailab.module.data.enums.DataPointFreqEnum; |
| | | import com.iailab.module.data.enums.TimeGranularityEnum; |
| | | import com.iailab.module.data.enums.TimeGranularitySecEnum; |
| | | import com.iailab.module.model.mcs.pre.service.MmPredictItemService; |
| | | import com.iailab.module.model.mdk.common.enums.ModelParamType; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItem; |
| | | import com.iailab.module.model.mdk.sample.dto.ColumnItemPort; |
| | | import com.iailab.module.model.mdk.sample.dto.SampleInfo; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | * @createTime 2024年09月03日 |
| | | */ |
| | | abstract class SampleInfoConstructor { |
| | | |
| | | @Autowired |
| | | private DataPointApi dataPointApi; |
| | | |
| | | @Autowired |
| | | private PlanItemApi planItemApi; |
| | | |
| | | @Autowired |
| | | private IndItemApi indItemApi; |
| | |
| | | private int portOrder; |
| | | |
| | | /** |
| | | * 预测数据长度 |
| | | * 数据长度 |
| | | */ |
| | | private int dataLength; |
| | | } |
| | |
| | | import com.iailab.module.model.mdk.vo.ScheduleResultVO; |
| | | |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | */ |
| | | public interface ScheduleModelHandler { |
| | | |
| | | ScheduleResultVO doSchedule(String schemeCode, Date scheduleTime) throws ModelInvokeException; |
| | | ScheduleResultVO doSchedule(String schemeCode, Date scheduleTime, Map<Integer, Integer> dynamicDataLength, Map<String, String> dynamicSettings) throws ModelInvokeException; |
| | | } |
| | |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author PanZhibao |
| | |
| | | private SampleConstructor sampleConstructor; |
| | | |
| | | @Override |
| | | public ScheduleResultVO doSchedule(String schemeCode, Date scheduleTime) throws ModelInvokeException { |
| | | public ScheduleResultVO doSchedule(String schemeCode, Date scheduleTime, Map<Integer, Integer> dynamicDataLength, |
| | | Map<String, String> dynamicSettings) throws ModelInvokeException { |
| | | ScheduleResultVO scheduleResult = new ScheduleResultVO(); |
| | | StScheduleSchemeEntity scheduleScheme = stScheduleSchemeService.getByCode(schemeCode); |
| | | StScheduleModelEntity scheduleModel = stScheduleModelService.get(scheduleScheme.getModelId()); |
| | |
| | | try { |
| | | //1.根据模型id构造模型输入样本 |
| | | long now = System.currentTimeMillis(); |
| | | List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Schedule.name(), modelId, scheduleTime,scheduleScheme.getName()); |
| | | List<SampleData> sampleDataList = sampleConstructor.constructSample(TypeA.Schedule.name(), modelId, scheduleTime, |
| | | scheduleScheme.getName(), dynamicDataLength); |
| | | log.info("构造模型输入样本消耗时长:" + (System.currentTimeMillis() - now) / 1000 + "秒"); |
| | | if (CollectionUtils.isEmpty(sampleDataList)) { |
| | | log.info("调度模型构造样本失败,schemeCode=" + schemeCode); |
| | |
| | | } |
| | | |
| | | IAILModel newModelBean = composeNewModelBean(scheduleModel); |
| | | HashMap<String, Object> settings = getScheduleSettingsByModelId(modelId); |
| | | HashMap<String, Object> settings = getScheduleSettingsByModelId(modelId, dynamicSettings); |
| | | if (settings == null) { |
| | | log.error("模型setting不存在,modelId=" + modelId); |
| | | return null; |
| | |
| | | * 根据模型id获取参数map |
| | | * |
| | | * @param modelId |
| | | * @param dynamicSettings |
| | | * @return |
| | | */ |
| | | private HashMap<String, Object> getScheduleSettingsByModelId(String modelId) { |
| | | private HashMap<String, Object> getScheduleSettingsByModelId(String modelId, Map<String, String> dynamicSettings) { |
| | | List<StScheduleModelSettingEntity> list = stScheduleModelSettingService.getByModelId(modelId); |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | return null; |
| | | } |
| | | //如果输入参数中包含setting,则覆盖默认的setting |
| | | if (!CollectionUtils.isEmpty(dynamicSettings)){ |
| | | list.forEach(setting -> { |
| | | if (dynamicSettings.containsKey(setting.getKey())) { |
| | | setting.setValue(dynamicSettings.get(setting.getKey())); |
| | | } |
| | | }); |
| | | } |
| | | HashMap<String, Object> result = new HashMap<>(); |
| | | for (StScheduleModelSettingEntity entry : list) { |
| | | String valueType = entry.getValuetype().trim(); //去除两端空格 |
| | |
| | | jmethodID getMID = env->GetMethodID(hashmapClass, "get", "(Ljava/lang/Object;)Ljava/lang/Object;"); |
| | | jstring keyJString = env->NewStringUTF("pyFile"); |
| | | jobject javaValueObj = env->CallObjectMethod(settings, getMID, keyJString); |
| | | const char* strValue = env->GetStringUTFChars((jstring)javaValueObj, NULL); |
| | | |
| | | jstring javaStringValue = (jstring)javaValueObj; |
| | | const char* strValue = env->GetStringUTFChars(javaStringValue, NULL); |
| | | //*************导入模型****************** |
| | | PyObject* pModule = create_py_module(strValue); |
| | | /*PyObject* pModule = create_py_module("${pyModule}.${pyName}");*/ |
| | | // 释放java占用内存 |
| | | env->ReleaseStringUTFChars(javaStringValue, strValue); |
| | | env->DeleteLocalRef(javaStringValue); |
| | | env->DeleteLocalRef(javaValueObj); |
| | | env->DeleteLocalRef(keyJString); |
| | | env->DeleteLocalRef(hashmapClass); |
| | | if (pModule == NULL) |
| | | { |
| | | cout << "model error" << endl; |