init
This commit is contained in:
26
model/peak-valley/peak_valley_quarter_rule.go
Normal file
26
model/peak-valley/peak_valley_quarter_rule.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package peak_valley
|
||||
|
||||
import (
|
||||
"energy-management-system/global"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 季度谷峰规则
|
||||
|
||||
// 开始时间
|
||||
// 结束时间
|
||||
// 谷峰规则ID
|
||||
|
||||
type PeakValleyQuarterRule struct {
|
||||
RuleId uint `gorm:"column:rule_id;primaryKey" json:"rule_id"`
|
||||
StartTime uint `gorm:"column:start_time;comment:开始时间" json:"start_time"`
|
||||
EndTime uint `gorm:"column:end_time;comment:结束时间" json:"end_time"`
|
||||
Created time.Time `gorm:"column:created;autoCreateTime;comment:创建时间" json:"created"`
|
||||
Updated time.Time `gorm:"column:updated;autoUpdateTime;comment:修改时间" json:"updated"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
|
||||
}
|
||||
|
||||
func (r *PeakValleyQuarterRule) TableName() string {
|
||||
return global.AppConf.Db.TablePrefix + "peak_valley_quarter_rules"
|
||||
}
|
||||
29
model/peak-valley/peak_valley_rule.go
Normal file
29
model/peak-valley/peak_valley_rule.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package peak_valley
|
||||
|
||||
import (
|
||||
"energy-management-system/global"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
// 一天的完整谷峰规则
|
||||
// 发电 (光伏)
|
||||
// 用电 (电机、生产)
|
||||
|
||||
//新建规则
|
||||
//
|
||||
//选择时间段 设置电价
|
||||
//(将时间段 转化为十分钟区块 查找到对应十分钟区块 创建该规则的电价)
|
||||
|
||||
type PeakValleyRule struct {
|
||||
RuleId uint `gorm:"column:rule_id;primaryKey" json:"rule_id"`
|
||||
RuleName string `gorm:"column:rule_name;comment:规则名称" json:"rule_name"`
|
||||
Description string `gorm:"column:description;comment:描述" json:"description"`
|
||||
Created time.Time `gorm:"column:created;autoCreateTime;comment:创建时间" json:"created"`
|
||||
Updated time.Time `gorm:"column:updated;autoUpdateTime;comment:修改时间" json:"updated"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
|
||||
}
|
||||
|
||||
func (r *PeakValleyRule) TableName() string {
|
||||
return global.AppConf.Db.TablePrefix + "peak_valley_rules"
|
||||
}
|
||||
58
model/peak-valley/peak_valley_time_block.go
Normal file
58
model/peak-valley/peak_valley_time_block.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package peak_valley
|
||||
|
||||
import (
|
||||
"energy-management-system/global"
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
const MinutesInADay = 24 * 60
|
||||
|
||||
// PeakValleyTimeBlock 峰谷时间区块
|
||||
type PeakValleyTimeBlock struct {
|
||||
BlockIndex uint `gorm:"column:block_index;primaryKey;comment:区块编号" json:"block_index"`
|
||||
StartTime uint `gorm:"column:start_time;comment:开始时间" json:"start_time"`
|
||||
EndTime uint `gorm:"column:end_time;comment:结束时间" json:"end_time"`
|
||||
Created time.Time `gorm:"column:created;autoCreateTime;comment:创建时间" json:"created"`
|
||||
Updated time.Time `gorm:"column:updated;autoUpdateTime;comment:修改时间" json:"updated"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
|
||||
}
|
||||
|
||||
func (r *PeakValleyTimeBlock) TableName() string {
|
||||
return global.AppConf.Db.TablePrefix + "peak_valley_time_blocks"
|
||||
}
|
||||
|
||||
func Init() {
|
||||
// 一天有24小时,即1440分钟
|
||||
totalMinutes := 24 * 60
|
||||
// 时间块的持续时间:10分钟
|
||||
blockDuration := 10
|
||||
|
||||
// 遍历一天中的所有时间块
|
||||
for i := 0; i < totalMinutes; i += blockDuration {
|
||||
startTime := i
|
||||
endTime := i + blockDuration
|
||||
|
||||
fmt.Println("start", startTime)
|
||||
fmt.Println("start", endTime)
|
||||
|
||||
global.Db.Create(&PeakValleyTimeBlock{
|
||||
StartTime: uint(startTime),
|
||||
EndTime: uint(endTime),
|
||||
})
|
||||
|
||||
// 打印开始时间和结束时间,格式为 HH:MM
|
||||
//fmt.Printf("时间块 %d: 开始时间: %02d:%02d, 结束时间: %02d:%02d\n",
|
||||
// i/blockDuration+1,
|
||||
// startTime/60, startTime%60,
|
||||
// endTime/60, endTime%60)
|
||||
|
||||
// 使用整数存储时间块的开始和结束时间(以分钟为单位)
|
||||
//startTime := 0 // 00:00
|
||||
//endTime := 10 // 00:10
|
||||
//
|
||||
//fmt.Printf("开始时间: %02d:%02d\n", startTime/60, startTime%60)
|
||||
//fmt.Printf("结束时间: %02d:%02d\n", endTime/60, endTime%60)
|
||||
}
|
||||
}
|
||||
86
model/peak-valley/peak_valley_time_block_price.go
Normal file
86
model/peak-valley/peak_valley_time_block_price.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package peak_valley
|
||||
|
||||
import (
|
||||
"energy-management-system/global"
|
||||
"energy-management-system/utils"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
const (
|
||||
// POINTED 尖
|
||||
POINTED = iota + 1
|
||||
// PEAK 峰
|
||||
PEAK
|
||||
// FLAT 平
|
||||
FLAT
|
||||
// VALLEY 谷
|
||||
VALLEY
|
||||
// FUKAYA 深谷
|
||||
FUKAYA
|
||||
)
|
||||
|
||||
var PeakValleyTypes = map[int]string{
|
||||
POINTED: "尖",
|
||||
PEAK: "峰",
|
||||
FLAT: "平",
|
||||
VALLEY: "谷",
|
||||
FUKAYA: "深谷",
|
||||
}
|
||||
|
||||
type PeakValleyType struct {
|
||||
Value int `json:"value"`
|
||||
Title string `json:"title"`
|
||||
}
|
||||
|
||||
// PeakValleyTimeBlockPrice 峰谷时间区块价格
|
||||
type PeakValleyTimeBlockPrice struct {
|
||||
Id uint `gorm:"column:id;primaryKey" json:"id"`
|
||||
BlockId uint `gorm:"column:block_id;comment:时间区块编号" json:"block_id"`
|
||||
Price int `gorm:"column:price;comment:价格" json:"price"`
|
||||
CustomName string `gorm:"column:custom_name;comment:自定义名称" json:"custom_name"`
|
||||
PeakValleyRuleId uint `gorm:"column:peak_valley_rule_id;comment:峰谷规则" json:"peak_valley_rule_id"`
|
||||
PeakValleyType uint `gorm:"column:peak_valley_type;default:1;size:10;comment:峰谷类型[1:尖,2:峰,3:平,4:谷,5:深谷]" json:"peak_valley_type"` // 峰谷类型
|
||||
Created time.Time `gorm:"column:created;autoCreateTime;comment:创建时间" json:"created"`
|
||||
Updated time.Time `gorm:"column:updated;autoUpdateTime;comment:修改时间" json:"updated"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"index;comment:删除时间" json:"-"`
|
||||
}
|
||||
|
||||
func (r *PeakValleyTimeBlockPrice) TableName() string {
|
||||
return global.AppConf.Db.TablePrefix + "peak_valley_time_block_prices"
|
||||
}
|
||||
|
||||
type PeakValleyRuleCustomName struct {
|
||||
PeakValleyType uint `json:"peak_valley_type"`
|
||||
Price int `json:"price"`
|
||||
CustomName string `json:"custom_name"`
|
||||
StartTime uint `json:"start_time"`
|
||||
EndTime uint `json:"end_time"`
|
||||
StartTimeStr string `json:"start_time_str"`
|
||||
EndTimeStr string `json:"end_time_str"`
|
||||
}
|
||||
|
||||
type PeakValleyRuleType struct {
|
||||
PeakValleyType uint `json:"peak_valley_type"`
|
||||
Price int `json:"price"`
|
||||
RuleTimeBlocks []RuleTimeBlock `gorm:"-" json:"rule_time_blocks"`
|
||||
}
|
||||
|
||||
type RuleTimeBlock struct {
|
||||
StartTime uint `json:"start_time"`
|
||||
EndTime uint `json:"end_time"`
|
||||
StartTimeStr string `json:"start_time_str"`
|
||||
EndTimeStr string `json:"end_time_str"`
|
||||
CustomName string `json:"custom_name"`
|
||||
TimeBlockIds []int `json:"-"`
|
||||
}
|
||||
|
||||
type ByCustomNameNumber []*PeakValleyRuleCustomName
|
||||
|
||||
func (a ByCustomNameNumber) Len() int { return len(a) }
|
||||
func (a ByCustomNameNumber) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a ByCustomNameNumber) Less(i, j int) bool {
|
||||
numI, _ := utils.ExtractNumber(a[i].CustomName)
|
||||
numJ, _ := utils.ExtractNumber(a[j].CustomName)
|
||||
return numI < numJ // 升序排序
|
||||
}
|
||||
Reference in New Issue
Block a user