Skip to content

Commit

Permalink
type:modify struct
Browse files Browse the repository at this point in the history
  • Loading branch information
yonwoo9 committed Jun 6, 2024
1 parent ac0f2eb commit d5f9868
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 101 deletions.
55 changes: 28 additions & 27 deletions analog.go
Original file line number Diff line number Diff line change
@@ -1,69 +1,70 @@
package comtrade

type ComtradeAnalogChan struct {
An uint32 //模拟通道索引号 an
ChId string //通道标识 ch_id
Ph string //通道相别标识 ph
Ccbm string //被监视的电路元件 ccbm
Uu string //通道单位 uu
A float32 //通道增益系数 a
B float32 //通道偏移量 b
Skew float32 //通道时滞 skew
Min float32 //通道最小值 min
Max float32 //通道最大值 max
Primary float32 //一次系数 primary
Secondary float32 //二次系数 secondary
PS string //一次二次标识 ps
// AnalogChan 模拟通道
type AnalogChan struct {
An uint32 `json:"an"` //模拟通道索引号
ChId string `json:"ch_id"` //通道标识
Ph string `json:"ph"` //通道相别标识
Ccbm string `json:"ccbm"` //被监视的电路元件
Uu string `json:"uu"` //通道单位
A float32 `json:"a"` //通道增益系数
B float32 `json:"b"` //通道偏移量
Skew float32 `json:"skew"` //通道时滞
Min float32 `json:"min"` //通道最小值
Max float32 `json:"max"` //通道最大值
Primary float32 `json:"primary"` //一次系数
Secondary float32 `json:"secondary"` //二次系数
PS string `json:"ps"` //一次二次标识
}

func (c *ComtradeAnalogChan) GetAn() uint32 {
func (c *AnalogChan) GetAn() uint32 {
return c.An
}

func (c *ComtradeAnalogChan) GetChId() string {
func (c *AnalogChan) GetChId() string {
return c.ChId
}

func (c *ComtradeAnalogChan) GetPh() string {
func (c *AnalogChan) GetPh() string {
return c.Ph
}

func (c *ComtradeAnalogChan) GetCcbm() string {
func (c *AnalogChan) GetCcbm() string {
return c.Ccbm
}

func (c *ComtradeAnalogChan) GetUu() string {
func (c *AnalogChan) GetUu() string {
return c.Uu
}

func (c *ComtradeAnalogChan) GetA() float32 {
func (c *AnalogChan) GetA() float32 {
return c.A
}

func (c *ComtradeAnalogChan) GetB() float32 {
func (c *AnalogChan) GetB() float32 {
return c.B
}

func (c *ComtradeAnalogChan) GetSkew() float32 {
func (c *AnalogChan) GetSkew() float32 {
return c.Skew
}

func (c *ComtradeAnalogChan) GetMin() float32 {
func (c *AnalogChan) GetMin() float32 {
return c.Min
}

func (c *ComtradeAnalogChan) GetMax() float32 {
func (c *AnalogChan) GetMax() float32 {
return c.Max
}

func (c *ComtradeAnalogChan) GetPrimary() float32 {
func (c *AnalogChan) GetPrimary() float32 {
return c.Primary
}

func (c *ComtradeAnalogChan) GetSecondary() float32 {
func (c *AnalogChan) GetSecondary() float32 {
return c.Secondary
}

func (c *ComtradeAnalogChan) GetPS() string {
func (c *AnalogChan) GetPS() string {
return c.PS
}
8 changes: 4 additions & 4 deletions ascii_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ func ParseComtradeCfg(filePath string) (*ComtradeCfg, error) {
if value, err := strconv.ParseUint(string(bytes.TrimSuffix(bytes.TrimSpace(tempList[2]), []byte("D"))), 10, 64); err != nil {
return nil, err
} else {
comtradeCfg.DigtalNum = uint32(value)
comtradeCfg.DigitalNum = uint32(value)
}

// initialize analog and digital channels
comtradeCfg.Analog = make([]ComtradeAnalogChan, comtradeCfg.AnalogNum)
comtradeCfg.Digital = make([]ComtradeDigitalChan, comtradeCfg.DigtalNum)
comtradeCfg.Analog = make([]AnalogChan, comtradeCfg.AnalogNum)
comtradeCfg.Digital = make([]DigitalChan, comtradeCfg.DigitalNum)

// 读取模拟通道 read analog channels
for i := 0; i < int(comtradeCfg.AnalogNum); i++ {
Expand Down Expand Up @@ -130,7 +130,7 @@ func ParseComtradeCfg(filePath string) (*ComtradeCfg, error) {
}

// read digit channels
for i := 0; i < int(comtradeCfg.DigtalNum); i++ {
for i := 0; i < int(comtradeCfg.DigitalNum); i++ {
tempList = bytes.Split(lines[2+int(comtradeCfg.AnalogNum)+i], []byte(","))
if len(tempList) < 3 {
return nil, ErrReadDigitalChannel
Expand Down
8 changes: 4 additions & 4 deletions ascii_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ func init() {
type AsciiData struct {
}

func (a *AsciiData) Parse(filePath string, analogNum, digitalNum, endSamp uint32) (*ComtradeData, error) {
comtradeData := &ComtradeData{}
func (a *AsciiData) Parse(filePath string, analogNum, digitalNum, endSamp uint32) (*Data, error) {
comtradeData := &Data{}
datFile, err := os.Open(filePath)
if err != nil {
return nil, err
Expand All @@ -35,8 +35,8 @@ func (a *AsciiData) Parse(filePath string, analogNum, digitalNum, endSamp uint32
return nil, ErrInvalidFile
}

comtradeData.AnalogData = make([]ComtradeAnalogData, int(endSamp))
comtradeData.DigitalData = make([]ComtradeDigitalData, int(endSamp))
comtradeData.AnalogData = make([]AnalogData, int(endSamp))
comtradeData.DigitalData = make([]DigitalData, int(endSamp))

for i := 0; i < int(endSamp); i++ {
comtradeData.AnalogData[i].Data = make([]int32, analogNum)
Expand Down
4 changes: 2 additions & 2 deletions ascii_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ func TestAsciiData_Parse(t *testing.T) {
}

a := &AsciiData{}
dat, err := a.Parse("testdata/test2.dat", cfg.AnalogNum, cfg.DigtalNum, cfg.EndSamp[len(cfg.EndSamp)-1])
dat, err := a.Parse("testdata/test2.dat", cfg.AnalogNum, cfg.DigitalNum, cfg.EndSamp[len(cfg.EndSamp)-1])
if err != nil {
t.Errorf("Parse() error = %v", err)
return
}
if reflect.TypeOf(dat) != reflect.TypeOf(&ComtradeData{}) {
if reflect.TypeOf(dat) != reflect.TypeOf(&Data{}) {
t.Errorf("Parse() got = %v", dat)
}
t.Log(dat)
Expand Down
4 changes: 2 additions & 2 deletions binary32_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ func init() {
type Binary32Data struct {
}

func (b *Binary32Data) Parse(filePath string, analogNum, digitalNum, endSamp uint32) (*ComtradeData, error) {
return &ComtradeData{}, nil
func (b *Binary32Data) Parse(filePath string, analogNum, digitalNum, endSamp uint32) (*Data, error) {
return &Data{}, nil
}
8 changes: 4 additions & 4 deletions binary_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func init() {
type BinaryData struct {
}

func (b *BinaryData) Parse(filePath string, analogNum, digitalNum, endSamp uint32) (*ComtradeData, error) {
comtradeData := &ComtradeData{}
func (b *BinaryData) Parse(filePath string, analogNum, digitalNum, endSamp uint32) (*Data, error) {
comtradeData := &Data{}

// 打开文件
file, err := os.Open(filePath)
Expand All @@ -45,8 +45,8 @@ func (b *BinaryData) Parse(filePath string, analogNum, digitalNum, endSamp uint3
}
defer file.Close()

comtradeData.AnalogData = make([]ComtradeAnalogData, int(endSamp))
comtradeData.DigitalData = make([]ComtradeDigitalData, int(endSamp))
comtradeData.AnalogData = make([]AnalogData, int(endSamp))
comtradeData.DigitalData = make([]DigitalData, int(endSamp))

for i := 0; i < int(endSamp); i++ {
comtradeData.AnalogData[i].Data = make([]int32, analogNum)
Expand Down
4 changes: 2 additions & 2 deletions binary_data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ func TestBinaryData_Parse(t *testing.T) {
}

b := &BinaryData{}
dat, err := b.Parse("testdata/test1.dat", cfg.AnalogNum, cfg.DigtalNum, cfg.EndSamp[len(cfg.EndSamp)-1])
dat, err := b.Parse("testdata/test1.dat", cfg.AnalogNum, cfg.DigitalNum, cfg.EndSamp[len(cfg.EndSamp)-1])
if err != nil {
t.Errorf("Parse() error = %v", err)
return
}
if reflect.TypeOf(dat) != reflect.TypeOf(&ComtradeData{}) {
if reflect.TypeOf(dat) != reflect.TypeOf(&Data{}) {
t.Errorf("Parse() got = %v", dat)
}
t.Log(dat)
Expand Down
14 changes: 7 additions & 7 deletions comtrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package comtrade

type Comtrade struct {
Conf *ComtradeCfg
Data *ComtradeData
Data *Data
}

func ParseComtrade(configfilePath, datafilePath string) (comtrade *Comtrade, err error) {
func ParseComtrade(configurePath, datafilePath string) (comtrade *Comtrade, err error) {
c := &Comtrade{}
c.Conf, err = c.parseComtradeConfig(configfilePath)
c.Conf, err = c.parseComtradeConfig(configurePath)
if err != nil {
return nil, err
}
Expand All @@ -18,18 +18,18 @@ func ParseComtrade(configfilePath, datafilePath string) (comtrade *Comtrade, err
return c, nil
}

func (c *Comtrade) parseComtradeConfig(configfilePath string) (*ComtradeCfg, error) {
comtradeConfig, err := ParseComtradeCfg(configfilePath)
func (c *Comtrade) parseComtradeConfig(configurePath string) (*ComtradeCfg, error) {
comtradeConfig, err := ParseComtradeCfg(configurePath)
if err != nil {
return nil, err
}
return comtradeConfig, nil
}

func (c *Comtrade) parseComtradeData(datafilePath string) (*ComtradeData, error) {
func (c *Comtrade) parseComtradeData(datafilePath string) (*Data, error) {
creator, ok := Parsers[c.Conf.Ft]
if !ok {
return nil, ErrUnknowTypeOfData
return nil, ErrUnknownTypeOfData
}
parser := creator()
comtradeData, err := parser.Parse(datafilePath, c.Conf.GetAnalogNum(), c.Conf.GetDigtalNum(), c.Conf.GetEndSamp()[len(c.Conf.GetEndSamp())-1])
Expand Down
36 changes: 18 additions & 18 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,21 @@ import (
)

type ComtradeCfg struct {
StationName string //厂站名称 station_name
RecDevID string //记录设备ID rec_dev_id
RevYear uint16 //COMTRADE版本年份 rev_year 1991、1999、2013
Total uint32 //总通道数 total
AnalogNum uint32 //模拟通道数 analog_num
DigtalNum uint32 //数字/状态通道数 digital_num
Analog []ComtradeAnalogChan //模拟通道 analog
Digital []ComtradeDigitalChan //数字/状态通道 digital
Lf float32 //标称频率 lf
Nrates uint16 //采样率个数 nrates
Samp []float32 //采样率 samp
EndSamp []uint32 //最末采样序号 end_samp
FirstDataTime time.Time //第一条数据时间 first_data_time
TriggerTime time.Time //采样触发时间 trigger_time
Ft string //数据文件类型,ASCII、INARY、BINARY32、FLOAT32 ft
StationName string //厂站名称 station_name
RecDevID string //记录设备ID rec_dev_id
RevYear uint16 //COMTRADE版本年份 rev_year 1991、1999、2013
Total uint32 //总通道数 total
AnalogNum uint32 //模拟通道数 analog_num
DigitalNum uint32 //数字/状态通道数 digital_num
Analog []AnalogChan //模拟通道 analog
Digital []DigitalChan //数字/状态通道 digital
Lf float32 //标称频率 lf
Nrates uint16 //采样率个数 nrates
Samp []float32 //采样率 samp
EndSamp []uint32 //最末采样序号 end_samp
FirstDataTime time.Time //第一条数据时间 first_data_time
TriggerTime time.Time //采样触发时间 trigger_time
Ft string //数据文件类型,ASCII、BINARY、BINARY32、FLOAT32 ft

// 2017
TimeMult float32 //时间倍率因子 time_mult
Expand Down Expand Up @@ -50,7 +50,7 @@ func (cc *ComtradeCfg) GetAnalogNum() uint32 {
}

func (cc *ComtradeCfg) GetDigtalNum() uint32 {
return cc.DigtalNum
return cc.DigitalNum
}

func (cc *ComtradeCfg) GetLf() float32 {
Expand Down Expand Up @@ -101,10 +101,10 @@ func (cc *ComtradeCfg) GetLeapsec() uint8 {
return cc.Leapsec
}

func (cc *ComtradeCfg) GetAnalog() []ComtradeAnalogChan {
func (cc *ComtradeCfg) GetAnalog() []AnalogChan {
return cc.Analog
}

func (cc *ComtradeCfg) GetDigital() []ComtradeDigitalChan {
func (cc *ComtradeCfg) GetDigital() []DigitalChan {
return cc.Digital
}
32 changes: 16 additions & 16 deletions data.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
package comtrade

// ComtradeData is the data of a comtrade file.
type ComtradeData struct {
AnalogData []ComtradeAnalogData
DigitalData []ComtradeDigitalData
// Data is the data of a comtrade file.
type Data struct {
AnalogData []AnalogData
DigitalData []DigitalData
}

// ComtradeAnalogData is the analog data of a comtrade file.
type ComtradeAnalogData struct {
N uint32 //模拟通道序号 n
Timestamp uint32 //模拟通道时标 timestamp
Data []int32 //模拟通道数据 data
// AnalogData is the analog data of a comtrade file.
type AnalogData struct {
N uint32 `json:"n"` //模拟通道序号
Timestamp uint32 `json:"timestamp"` //模拟通道时标
Data []int32 `json:"data"` //模拟通道数据
}

// ComtradeDigitalData is the digital data of a comtrade file.
type ComtradeDigitalData struct {
N uint32 //数字通道序号 n
Timestamp uint32 //数字通道时标 timestamp
Data []uint8 //数字通道数据 data
// DigitalData is the digital data of a comtrade file.
type DigitalData struct {
N uint32 `json:"n"` //数字通道序号
Timestamp uint32 `json:"timestamp"` //数字通道时标
Data []uint8 `json:"data"` //数字通道数据
}

func (cd *ComtradeData) GetAnalogData() []ComtradeAnalogData {
func (cd *Data) GetAnalogData() []AnalogData {
return cd.AnalogData
}

func (cd *ComtradeData) GetDigitalData() []ComtradeDigitalData {
func (cd *Data) GetDigitalData() []DigitalData {
return cd.DigitalData
}
23 changes: 12 additions & 11 deletions digital.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
package comtrade

type ComtradeDigitalChan struct {
Dn uint32 //数字/状态通道索引号 dn
ChId string //通道标识 ch_id
Ph string //通道相别标识 ph
Ccbm string //被监视的电路元件 ccbm
Y uint8 //通道状态 y
// DigitalChan 数字通道
type DigitalChan struct {
Dn uint32 `json:"dn"` //数字/状态通道索引号
ChId string `json:"ch_id"` //通道标识
Ph string `json:"ph"` //通道相别标识
Ccbm string `json:"ccbm"` //被监视的电路元件
Y uint8 `json:"y"` //通道状态
}

func (c *ComtradeDigitalChan) GetDn() uint32 {
func (c *DigitalChan) GetDn() uint32 {
return c.Dn
}

func (c *ComtradeDigitalChan) GetChId() string {
func (c *DigitalChan) GetChId() string {
return c.ChId
}

func (c *ComtradeDigitalChan) GetPh() string {
func (c *DigitalChan) GetPh() string {
return c.Ph
}

func (c *ComtradeDigitalChan) GetCcbm() string {
func (c *DigitalChan) GetCcbm() string {
return c.Ccbm
}

func (c *ComtradeDigitalChan) GetY() uint8 {
func (c *DigitalChan) GetY() uint8 {
return c.Y
}
Loading

0 comments on commit d5f9868

Please sign in to comment.