Documentation
¶
Index ¶
- type AddedGroupColumnsInfo
- type AddedGroupInfo
- type AddedGroupInfos
- type AddedItemsInfo
- type CheckItemsInfo
- type Cols
- type Config
- type DeadZone
- type DeletedGroupColumnNamesInfo
- type DeletedItemsInfo
- type Gdb
- func (gdb *Gdb) AddGroupColumns(info AddedGroupColumnsInfo) (Cols, error)
- func (gdb *Gdb) AddGroups(groupInfos ...AddedGroupInfo) (Rows, error)
- func (gdb *Gdb) AddItems(itemInfo AddedItemsInfo) (Rows, error)
- func (gdb *Gdb) BatchWrite(infos ...ItemValue) (Rows, error)
- func (gdb *Gdb) BatchWriteHistoricalData(infos ...HistoricalItemValue) error
- func (gdb *Gdb) CheckItems(groupName string, itemNames ...string) error
- func (gdb *Gdb) CleanGroupItems(groupNames ...string) (Rows, error)
- func (gdb *Gdb) DeleteGroupColumns(info DeletedGroupColumnNamesInfo) (Cols, error)
- func (gdb *Gdb) DeleteGroups(groupInfos GroupNamesInfo) (Rows, error)
- func (gdb *Gdb) DeleteItems(itemInfo DeletedItemsInfo) (Rows, error)
- func (gdb *Gdb) GetGroupProperty(groupName, condition string) (GroupPropertyInfo, error)
- func (gdb *Gdb) GetGroups() (GroupNamesInfo, error)
- func (gdb *Gdb) GetHistoricalData(groupNames, itemNames []string, ...) (cmap.ConcurrentMap, error)
- func (gdb *Gdb) GetHistoricalDataWithCondition(groupNames, itemNames []string, startTime []int, endTime []int, ...) (cmap.ConcurrentMap, error)
- func (gdb *Gdb) GetHistoricalDataWithStamp(groupNames, itemNames []string, timeStamps ...[]int) (cmap.ConcurrentMap, error)
- func (gdb *Gdb) GetItems(itemInfo ItemsInfo) (GdbItems, error)
- func (gdb *Gdb) GetRawHistoricalData(groupNames []string, itemNames ...string) (cmap.ConcurrentMap, error)
- func (gdb *Gdb) GetRealTimeData(groupNames []string, itemNames ...string) (cmap.ConcurrentMap, error)
- func (gdb *Gdb) UpdateGroupColumnNames(info UpdatedGroupColumnNamesInfo) (Cols, error)
- func (gdb *Gdb) UpdateGroupNames(groupInfos ...UpdatedGroupNameInfo) (Rows, error)
- func (gdb *Gdb) UpdateItems(itemInfo UpdatedItemsInfo) (Rows, error)
- type GdbConfigs
- type GdbItems
- type GroupNamesInfo
- type GroupPropertyInfo
- type HistoricalItemValue
- type HttpsConfigs
- type ItemValue
- type ItemsInfo
- type LogConfigs
- type ResponseData
- type Rows
- type UpdatedGroupColumnNamesInfo
- type UpdatedGroupNameInfo
- type UpdatedGroupNamesInfo
- type UpdatedItemsInfo
Examples ¶
- Gdb.AddGroupColumns
- Gdb.AddGroups
- Gdb.AddItems
- Gdb.BatchWrite
- Gdb.BatchWriteHistoricalData
- Gdb.CheckItems
- Gdb.CleanGroupItems
- Gdb.DeleteGroupColumns
- Gdb.DeleteGroups
- Gdb.DeleteItems
- Gdb.GetGroupProperty
- Gdb.GetGroups
- Gdb.GetHistoricalData
- Gdb.GetHistoricalDataWithCondition
- Gdb.GetHistoricalDataWithStamp
- Gdb.GetItems
- Gdb.GetRawHistoricalData
- Gdb.GetRealTimeData
- Gdb.UpdateGroupColumnNames
- Gdb.UpdateGroupNames
- Gdb.UpdateItems
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AddedGroupColumnsInfo ¶ added in v1.0.3
type AddedGroupInfo ¶ added in v1.0.3
type AddedGroupInfos ¶ added in v1.0.3
type AddedGroupInfos struct {
GroupInfos []AddedGroupInfo `json:"groupInfos" binding:"required"`
}
type AddedItemsInfo ¶ added in v1.0.3
type CheckItemsInfo ¶ added in v1.0.3
type Config ¶ added in v1.0.3
type Config struct { GdbConfigs `json:"gdbConfigs"` LogConfigs `json:"logConfigs"` }
type DeletedGroupColumnNamesInfo ¶ added in v1.0.3
type DeletedItemsInfo ¶ added in v1.0.3
type Gdb ¶
type Gdb struct { DbPath string // path of leveldb ItemDbPath string // path of item of leveldb // contains filtered or unexported fields }
Gdb define the struct of gdb
func (*Gdb) AddGroupColumns ¶ added in v1.0.1
func (gdb *Gdb) AddGroupColumns(info AddedGroupColumnsInfo) (Cols, error)
AddGroupColumns add columns to group, all columns type are text
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") if _, err := gdb.AddGroupColumns(AddedGroupColumnsInfo{ GroupName: "2DCS", ColumnNames: []string{"Column3", "Column4"}, DefaultValues: []string{"", ""}, }); err != nil { log.Fatal(err) } else { if r, err := gdb.GetGroupProperty("2DCS", "1=1"); err != nil { log.Fatal(err) } else { fmt.Println("add group columns:", r.ItemColumnNames) } }
Output:
func (*Gdb) AddGroups ¶ added in v1.0.1
func (gdb *Gdb) AddGroups(groupInfos ...AddedGroupInfo) (Rows, error)
AddGroups add group to gdb
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") // you can not add itemName column if _, err := gdb.AddGroups(AddedGroupInfo{ GroupName: "1DCS", ColumnNames: []string{"description"}, }); err != nil { log.Fatal(err) }
Output:
func (*Gdb) AddItems ¶
func (gdb *Gdb) AddItems(itemInfo AddedItemsInfo) (Rows, error)
AddItems to gdb,you can not add existed items
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") // By default group has columns itemName , description and dataType if _, err := gdb.AddItems(AddedItemsInfo{ GroupName: "1DCS", ItemValues: []map[string]string{{"itemName": "x", "description": "x", "dataType": "float64"}, {"itemName": "y", "description": "y", "dataType": "float64"}, {"itemName": "z", "description": "z", "dataType": "float64"}, {"itemName": "item1", "description": "item1", "dataType": "float64"}, {"itemName": "item2", "description": "item2", "dataType": "float64"}}, }); err != nil { log.Fatal(err) }
Output:
func (*Gdb) BatchWrite ¶
BatchWrite write realTimeData, all items to be written should be existed in gdb. otherWise will fail to writing.
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") if _, err := gdb.BatchWrite([]ItemValue{{ItemName: "x", Value: 1.0, GroupName: "1DCS"}, {ItemName: "y", Value: 2.0, GroupName: "1DCS"}}...); err != nil { log.Fatal(err) }
Output:
func (*Gdb) BatchWriteHistoricalData ¶ added in v1.0.3
func (gdb *Gdb) BatchWriteHistoricalData(infos ...HistoricalItemValue) error
BatchWriteHistoricalData write historicalData, all items to be written should be existed in gdb. and the timeStamp should be unix timeStamp
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") var xData, yData []interface{} var ts []int now := time.Now() fmt.Println("now: ", now.Format("2006-01-02 15:04:05")) r := rand.New(rand.NewSource(99)) for i := 0; i < 3600; i++ { x := float64(r.Intn(3600)) * math.Pi y := 2 * x t := now.Add(time.Second*time.Duration(i)).Unix() + 8*3600 xData = append(xData, x) yData = append(yData, y) ts = append(ts, int(t)) } if err := gdb.BatchWriteHistoricalData([]HistoricalItemValue{{ItemName: "x", Values: xData, TimeStamps: ts, GroupName: "1DCS"}, {ItemName: "y", Values: yData, TimeStamps: ts, GroupName: "1DCS"}}...); err != nil { log.Fatal(err) }
Output:
func (*Gdb) CheckItems ¶ added in v1.0.3
CheckItems check whether the given items existed in the given group
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") if err := gdb.CheckItems("1DCS", "x", "x1"); err != nil { fmt.Println(err) }
Output:
func (*Gdb) CleanGroupItems ¶ added in v1.0.3
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") if _, err := gdb.CleanGroupItems("1DCS"); err != nil { log.Fatal(err) }
Output:
func (*Gdb) DeleteGroupColumns ¶ added in v1.0.1
func (gdb *Gdb) DeleteGroupColumns(info DeletedGroupColumnNamesInfo) (Cols, error)
DeleteGroupColumns delete columns from group
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") if _, err := gdb.DeleteGroupColumns(DeletedGroupColumnNamesInfo{ GroupName: "2DCS", ColumnNames: []string{"Column3"}, }); err != nil { log.Fatal(err) } else { if r, err := gdb.GetGroupProperty("2DCS", "1=1"); err != nil { log.Fatal(err) } else { fmt.Println("delete group columns:", r.ItemColumnNames) } }
Output:
func (*Gdb) DeleteGroups ¶ added in v1.0.1
func (gdb *Gdb) DeleteGroups(groupInfos GroupNamesInfo) (Rows, error)
DeleteGroups delete group from gdb
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") if _, err := gdb.DeleteGroups(GroupNamesInfo{GroupNames: []string{"1DCS"}}); err != nil { log.Fatal(err) }
Output:
func (*Gdb) DeleteItems ¶
func (gdb *Gdb) DeleteItems(itemInfo DeletedItemsInfo) (Rows, error)
DeleteItems delete items from given group according to condition, condition is where clause in sqlite
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") if _, err := gdb.DeleteItems(DeletedItemsInfo{ GroupName: "1DCS", Condition: "itemName like '%item%'", }); err != nil { log.Fatal(err) }
Output:
func (*Gdb) GetGroupProperty ¶ added in v1.0.1
func (gdb *Gdb) GetGroupProperty(groupName, condition string) (GroupPropertyInfo, error)
GetGroupProperty get the column name and item count of the given groupName and condition condition is the where clause of sqlite
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") if r, err := gdb.GetGroupProperty("1DCS", "1=1"); err != nil { log.Fatal(err) } else { fmt.Println("get group property: ", r.ItemColumnNames, r.ItemCount) }
Output:
func (*Gdb) GetGroups ¶ added in v1.0.1
func (gdb *Gdb) GetGroups() (GroupNamesInfo, error)
GetGroups get group name
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") if r, err := gdb.GetGroups(); err != nil { log.Fatal(err) } else { fmt.Println("update group name: ", r.GroupNames) }
Output:
func (*Gdb) GetHistoricalData ¶
func (gdb *Gdb) GetHistoricalData(groupNames, itemNames []string, startTimeStamps, endTimeStamps, intervals []int) (cmap.ConcurrentMap, error)
GetHistoricalData get historical data, timeStamp should be unix timeStamp, and units of interval is seconds.All items should be existed in gdb, otherWise will fail to getting data
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") now := time.Now() stX := int(now.Add(time.Minute*5).Unix() + 8*3600) etX := int(now.Add(time.Minute*25).Unix() + 8*3600) stY := int(now.Add(time.Minute*35).Unix() + 8*3600) etY := int(now.Add(time.Minute*55).Unix() + 8*3600) // Obtain the historical data of x and y in startTime stX, endTime etX, with an interval of 2s, // and startTime as stY, endTime as etY, and an interval of 10s. if r, err := gdb.GetHistoricalData([]string{"1DCS", "1DCS"}, []string{"x", "y"}, []int{stX, stY}, []int{etX, etY}, []int{2, 10}); err != nil { log.Fatal(err) } else { d, _ := json.Marshal(r) _ = ioutil.WriteFile("./hX.txt", d, 0644) }
Output:
func (*Gdb) GetHistoricalDataWithCondition ¶
func (gdb *Gdb) GetHistoricalDataWithCondition(groupNames, itemNames []string, startTime []int, endTime []int, intervals []int, filterCondition string, zones ...DeadZone) (cmap.ConcurrentMap, error)
GetHistoricalDataWithCondition filter condition must be correct js expression,itemName should be startedWith by item. eg: item["itemName1"]>10 && item["itemName2"] > 30 .... It should be noted that the entire judgment is based on the itemName with less historical value in the condition. If the longest itemName is used as the benchmark, we cannot make an accurate judgment on the AND logic in it. Just imagine the history of Item1 It is [3,4,5], and item2 is [10,11]. If item1 is used as the benchmark, we cannot determine how much other elements of item2 should be expanded, because the condition may have complicated logic about item1 and item2 And or logic, no matter what the number is expanded, there may be a judgment error. DeadZone is used to define the maximum number of continuous data allowed by itemName.eg,the deadZoneCount of item x is 2, that is all data in x whose number of continuous > 2 will be filtered
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") now := time.Now() stX := int(now.Add(time.Minute*5).Unix() + 8*3600) etX := int(now.Add(time.Minute*25).Unix() + 8*3600) stY := int(now.Add(time.Minute*35).Unix() + 8*3600) etY := int(now.Add(time.Minute*55).Unix() + 8*3600) // Obtain the historical data of x and y in startTime stX, endTime etX, with an interval of 2s, // and startTime as stY, endTime as etY, and an interval of 10s under the given condition and deadZone if r, err := gdb.GetHistoricalDataWithCondition([]string{"1DCS", "1DCS"}, []string{"x", "y"}, []int{stX, stY}, []int{etX, etY}, []int{2, 10}, `item["x"] > 0 && item["y"] > 1000`, []DeadZone{}...); err != nil { log.Fatal(err) } else { d, _ := json.Marshal(r) _ = ioutil.WriteFile("./f.txt", d, 0644) }
Output:
func (*Gdb) GetHistoricalDataWithStamp ¶
func (gdb *Gdb) GetHistoricalDataWithStamp(groupNames, itemNames []string, timeStamps ...[]int) (cmap.ConcurrentMap, error)
GetHistoricalDataWithStamp get history data according to the given time stamps
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") now := time.Now() stX := int(now.Add(time.Minute*5).Unix() + 8*3600) etX := int(now.Add(time.Minute*25).Unix() + 8*3600) stY := int(now.Add(time.Minute*35).Unix() + 8*3600) etY := int(now.Add(time.Minute*55).Unix() + 8*3600) // Obtain the historical data of x with timeStamp stX, etX, y with timeStamp stY, etY if r, err := gdb.GetHistoricalDataWithStamp([]string{"1DCS", "1DCS"}, []string{"x", "y"}, [][]int{{stX, etX}, {stY, etY}}...); err != nil { log.Fatal(err) } else { d, _ := json.Marshal(r) fmt.Println(string(d)) }
Output:
func (*Gdb) GetItems ¶ added in v1.0.1
GetItems get items from gdb according to the given columnName, condition,startRow and rowCount. columnName is the columnName you want to get, and condition is where clause, startRow and rowCount is used to page query, if startRow is -1, that is get all items without pagination
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") if r, err := gdb.GetItems(ItemsInfo{ GroupName: "1DCS", Condition: "1=1", ColumnNames: "*", StartRow: -1, RowCount: 0, }); err != nil { log.Fatal(err) } else { fmt.Println(r.ItemValues) }
Output:
func (*Gdb) GetRawHistoricalData ¶ added in v1.0.2
func (gdb *Gdb) GetRawHistoricalData(groupNames []string, itemNames ...string) (cmap.ConcurrentMap, error)
GetRawHistoricalData get raw(that is all historical data, it should only be used for debugging. All items should be existed in gdb, otherWise will fail to getting data
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") if r, err := gdb.GetRawHistoricalData([]string{"1DCS"}, "x"); err != nil { log.Fatal(err) } else { d, _ := json.Marshal(r) _ = ioutil.WriteFile("./rawX.txt", d, 0644) }
Output:
func (*Gdb) GetRealTimeData ¶
func (gdb *Gdb) GetRealTimeData(groupNames []string, itemNames ...string) (cmap.ConcurrentMap, error)
GetRealTimeData get realTime data,that is the latest updated value of item.All items should be existed in gdb, otherWise will fail to getting data
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") if r, err := gdb.GetRealTimeData([]string{"1DCS", "1DCS"}, "x", "y"); err != nil { log.Fatal(err) } else { d, _ := json.Marshal(r) fmt.Println(string(d)) }
Output:
func (*Gdb) UpdateGroupColumnNames ¶ added in v1.0.1
func (gdb *Gdb) UpdateGroupColumnNames(info UpdatedGroupColumnNamesInfo) (Cols, error)
UpdateGroupColumnNames update column names of group
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") if _, err := gdb.UpdateGroupColumnNames(UpdatedGroupColumnNamesInfo{ GroupName: "2DCS", OldColumnNames: []string{"Column1", "Column2"}, NewColumnNames: []string{"Column11", "Column22"}, }); err != nil { log.Fatal(err) } else { if r, err := gdb.GetGroupProperty("2DCS", "1=1"); err != nil { log.Fatal(err) } else { fmt.Println("update group column name:", r.ItemColumnNames) } }
Output:
func (*Gdb) UpdateGroupNames ¶ added in v1.0.1
func (gdb *Gdb) UpdateGroupNames(groupInfos ...UpdatedGroupNameInfo) (Rows, error)
UpdateGroupNames update groupNames
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") if _, err := gdb.UpdateGroupNames(UpdatedGroupNameInfo{ OldGroupName: "1DCS", NewGroupName: "2DCS", }); err != nil { log.Fatal(err) } else { if r, err := gdb.GetGroups(); err != nil { log.Fatal(err) } else { fmt.Println("update group name: ", r.GroupNames) } }
Output:
func (*Gdb) UpdateItems ¶
func (gdb *Gdb) UpdateItems(itemInfo UpdatedItemsInfo) (Rows, error)
UpdateItems update items in gdb according to given condition and clause.condition is where clause in sqlite and clause is set clause in sqlite
Example ¶
gdb, _ := NewGdb("./leveldb", "./itemDb") if _, err := gdb.UpdateItems(UpdatedItemsInfo{ GroupName: "1DCS", Clause: "description='x1'", Condition: "itemName='x'", }); err != nil { log.Fatal(err) }
Output:
type GdbConfigs ¶ added in v1.0.3
type GroupNamesInfo ¶ added in v1.0.3
type GroupNamesInfo struct {
GroupNames []string `json:"groupNames"`
}
type GroupPropertyInfo ¶ added in v1.0.3
type HistoricalItemValue ¶ added in v1.0.3
type HttpsConfigs ¶ added in v1.0.3
type LogConfigs ¶ added in v1.0.3
type ResponseData ¶
type ResponseData struct { Code int `json:"code"` Message string `json:"message"` Data interface{} `json:"data"` }
ResponseData common
type UpdatedGroupColumnNamesInfo ¶ added in v1.0.3
type UpdatedGroupNameInfo ¶ added in v1.0.3
type UpdatedGroupNamesInfo ¶ added in v1.0.3
type UpdatedGroupNamesInfo struct {
Infos []UpdatedGroupNameInfo `json:"infos" binding:"required"`
}