Начало

This commit is contained in:
Anatoly Prohacky 2023-04-14 16:01:18 +10:00
commit 666a1a3c12
9 changed files with 35072 additions and 0 deletions

17417
data.json Normal file

File diff suppressed because it is too large Load Diff

10454
data1.json Normal file

File diff suppressed because it is too large Load Diff

6965
data2.json Normal file

File diff suppressed because it is too large Load Diff

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module gitstore.ru/tolikproh/sirius
go 1.20

BIN
main.exe Normal file

Binary file not shown.

29
main.go Normal file
View File

@ -0,0 +1,29 @@
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"gitstore.ru/tolikproh/sirius/model"
)
func main() {
var sirius model.Sirius
siriusJson, err := ioutil.ReadFile("data1.json")
if err != nil {
fmt.Println("No read file")
panic(err)
}
fmt.Println(json.Valid(siriusJson))
err = json.Unmarshal(siriusJson, &sirius)
if err != nil {
fmt.Println("Error unmarshal")
panic(err)
}
sirius.Zone.Get()
fmt.Println(sirius.Zone.Get())
}

184
model/model.go Normal file
View File

@ -0,0 +1,184 @@
package model
// Sirius structure
type Sirius struct {
Device `json:"device"`
Zone `json:"zone"`
ZoneGroup `json:"zone_group"`
Input `json:"input"`
Output `json:"output"`
Reader `json:"reader"`
Channel `json:"channel"`
AccessGroup `json:"access_group"`
}
// Device
type Device struct {
Keys []string `json:"keys"`
Rows []interface{} `json:"rows"`
}
// type DeviceRows struct {
// I1 int64
// I2 int64
// B1 bool
// I3 int64
// I4 int64
// I5 int64
// I6 int64
// I7 int64
// I8 int64
// I9 int64
// IntArr1 []int64
// IntArr2 []int64
// Name string
// }
// Zone
type Zone struct {
Keys []string `json:"keys"`
Rows [][]interface{} `json:"rows"`
}
func (z *Zone) Get() []ZoneRows {
var zr []ZoneRows
for _, z := range z.Rows {
i, b, s := InterToArray(z)
zz := ZoneRows{
Number: i[0],
I1: i[1],
B1: b[0],
I2: i[2],
I3: i[3],
I4: i[4],
B2: b[1],
B3: b[2],
Name: s[0],
}
zr = append(zr, zz)
}
return zr
}
type ZoneRows struct {
Number int64
I1 int64
B1 bool
I2 int64
I3 int64
I4 int64
B2 bool
B3 bool
Name string
}
// ZoneGroup
type ZoneGroup struct {
Keys []string `json:"keys"`
Rows []interface{} `json:"rows"`
}
// type ZoneGroupRows struct {
// Number int64
// I2 int64
// B1 bool
// I3 int64
// I4 int64
// IntArr []int64
// Name string
// }
// Input
type Input struct {
Keys []string `json:"keys"`
Rows []interface{} `json:"rows"`
}
// type InputRows struct {
// Addr int64
// I2 int64
// I3 int64
// I4 int64
// I5 int64
// I6 int64
// I7 int64
// I8 int64
// Name string
// }
// Output
type Output struct {
Keys []string `json:"keys"`
Rows []interface{} `json:"rows"`
}
// type OutputRows struct {
// Addr int64
// I2 int64
// I3 int64
// I4 int64
// I5 int64
// I6 int64
// I7 int64
// I8 int64
// I9 int64
// I10 int64
// I11 int64
// IntArr1 []int64
// IntArr2 []int64
// I12 int64
// I13 int64
// Name string
// }
// Reader
type Reader struct {
Keys []string `json:"keys"`
Rows []interface{} `json:"rows"`
}
// type ReaderRows struct {
// I1 int64
// I2 int64
// I3 int64
// I4 int64
// I5 int64
// I6 int64
// IntArr1 []int64
// IntArr2 []int64
// Name string
// }
// Channel
type Channel struct {
Keys []string `json:"keys"`
Rows []interface{} `json:"rows"`
}
// type ChannelRows struct {
// I1 int64
// I2 int64
// I3 int64
// I4 int64
// I5 int64
// Name string
// }
// AccessGroup
type AccessGroup struct {
Keys []string `json:"keys"`
Rows []interface{} `json:"rows"`
}
// type AccessGroupRows struct {
// I1 int64
// I2 int64
// IntArr1 []AccessGroupIntArray
// Name string
// }
// type AccessGroupIntArray struct {
// I1 int64
// I2 int64
// }

19
model/utils.go Normal file
View File

@ -0,0 +1,19 @@
package model
func InterToArray(inp []interface{}) ([]int64, []bool, []string) {
var i []int64
var b []bool
var s []string
for _, v1 := range inp {
switch v2 := v1.(type) {
case float64:
i = append(i, int64(v2))
case bool:
b = append(b, bool(v2))
case string:
s = append(s, string(v2))
}
}
return i, b, s
}

1
sirius.json Normal file

File diff suppressed because one or more lines are too long