Skip to content

Commit

Permalink
v2.3.6 - Rename GoStruct
Browse files Browse the repository at this point in the history
  • Loading branch information
MickMake committed Nov 4, 2022
1 parent c02eacf commit 260fd19
Show file tree
Hide file tree
Showing 44 changed files with 1,707 additions and 1,300 deletions.
115 changes: 115 additions & 0 deletions iSolarCloud/api/GoStruct/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package GoStruct

// These are tags that can be added to a Go structure that GoStruct uses to process the structure.


const (
// NameGoStruct - Name of field within structure that allows for assigning tags to the parent.
// Add like this:
// type ResultData []struct {
// GoStruct GoStruct.GoStruct `json:"GoStruct" DataTable:"true" DataTableSortOn:"UnitConvertId"`
NameGoStruct = "GoStruct"

// PointId - Point id in the form p\d+ or \d+ or free-form text.
PointId = "PointId"

// PointParentId - Associated parent of point.
PointParentId = "PointParentId"

// PointUpdateFreq - Point update frequency - Total, Yearly, Monthly, Day.
PointUpdateFreq = "PointUpdateFreq"
UpdateFreqInstant = "instant"
UpdateFreq5Mins = "5mins"
UpdateFreqBoot = "boot"
UpdateFreqDay = "daily"
UpdateFreqMonth = "monthly"
UpdateFreqYear = "yearly"
UpdateFreqTotal = "total"

// PointValueType - Value type of point: energy, date, battery, temperature.
PointValueType = "PointValueType"

// PointIgnore - Ignore this point.
PointIgnore = "PointIgnore"

// PointIgnoreIfNil - Ignore this point if a child is nil or empty.
PointIgnoreIfNil = "PointIgnoreIfNil"

// PointIgnoreIfNilFromChild - Ignore this point if a child is nil or empty.
PointIgnoreIfNilFromChild = "PointIgnoreIfNilFromChild"

// PointAliasTo - Alias this point to another point.
PointAliasTo = "PointAliasTo"

// PointAliasFrom - Alias this point from another point.
PointAliasFrom = "PointAliasFrom"

// PointUnit - Units: Wh, kWh, C, h.
PointUnit = "PointUnit"

// PointUnitFrom - Get PointUnit from another field structure.
PointUnitFrom = "PointUnitFrom"

// PointUnitFromParent - Get PointUnit from another parent field structure.
PointUnitFromParent = "PointUnitFromParent"

// PointGroupName - Point group name.
PointGroupName = "PointGroupName"

// PointGroupNameFrom - Get PointGroupName from another field structure.
PointGroupNameFrom = "PointGroupNameFrom"

// PointName - Human-readable name of point.
PointName = "PointName"

// PointNameFromChild - Searches child for field value to use for naming when hitting a slice, (as opposed to using an index).
PointNameFromChild = "PointNameFromChild"

// PointNameFromParent - Searches child for field value to use for naming when hitting a slice, (as opposed to using an index).
PointNameFromParent = "PointNameFromParent"

// PointNameDateFormat - Date format when using PointNameFrom, (if the field is a time.Time type).
PointNameDateFormat = "PointNameDateFormat"

// PointNameAppend - Append PointNameFrom instead of replace.
PointNameAppend = "PointNameAppend"

// PointArrayFlatten - Flatten an array into a string. EG: ["one", "two", "three"]
PointArrayFlatten = "PointArrayFlatten"

// PointSplitOn - Split a point into an array separating by defined string.
PointSplitOn = "PointSplitOn"

// PointSplitOnType - What valueTypes will be used for a split.
PointSplitOnType = "PointSplitOnType"

// PointIgnoreZero - Ignore arrays with zero size, (default true).
PointIgnoreZero = "PointIgnoreZero"

// PointTimestampFrom - Pull timestamp from another field structure.
PointTimestampFrom = "PointTimestampFrom"

// IsDataTable - This entity is a data table - Will only traverse down one child.
IsDataTable = "DataTable"

// DataTableId - Table id, (defaults to Json tag).
DataTableId = "DataTableId"

// DataTableName - Table Name, (defaults to DataTableId).
DataTableName = "DataTableName"

// DataTableTitle - Table Title, (defaults to DataTableId in name format).
DataTableTitle = "DataTableTitle"

// DataTableMerge - Merge rows together - useful for when we use, for EG: []valueTypes.Float
DataTableMerge = "DataTableMerge"

// DataTableShowIndex - Show index on table.
DataTableShowIndex = "DataTableShowIndex"

// DataTableSortOn - Sort table using this Field.
DataTableSortOn = "DataTableSortOn"

)

type GoStruct bool
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Package apiReflect - Snaffooed from https://github.com/fatih/structs
package apiReflect
// Package GoStruct - Snaffooed from https://github.com/fatih/structs
package GoStruct

import (
"errors"
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ import (
"fmt"
"github.com/wcharczuk/go-chart/v2"
"github.com/wcharczuk/go-chart/v2/drawing"
"go.pennock.tech/tabular"
"os"
"strconv"
"strings"
"time"
)

// "go.pennock.tech/tabular"
// tabular "github.com/agrison/go-tablib"

type GraphRequest struct {
Title string `json:"title"`

TimeColumn *int `json:"time_column"`
ValueColumn *int `json:"value_column"`
UnitsColumn *int `json:"units_column"`
NameColumn *int `json:"name_column"`
SearchColumn *int `json:"search_column"`
TimeColumn *string `json:"time_column"`
ValueColumn *string `json:"value_column"`
UnitsColumn *string `json:"units_column"`
NameColumn *string `json:"name_column"`
SearchColumn *string `json:"search_column"`
SearchString *string `json:"search_string"`

MinLeftAxis *float64 `json:"min_left_axis"`
Expand Down Expand Up @@ -130,67 +130,72 @@ func (t *Table) GetSearchColumn() SearchStrings {

func (t *Table) ProcessGraphData() error {
for range Only.Once {
fmt.Println("This is currently broken!")
break
req := t.graph.req

t.graph.searchName = ""
var units string
var times []time.Time
var values []float64
for row := 0; row < t.table.NRows(); row++ {
for row := 0; row < t.RowLength(); row++ {
// Get the search column
var cell *tabular.Cell
cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.SearchColumn})
var cell interface{}
// cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.SearchColumn})
cell, t.Error = t.GetCell(row, *req.SearchColumn)
if t.Error != nil {
continue
}
if !strings.Contains(cell.String(), *req.SearchString) {
continue
}
// if !strings.Contains(cell.String(), *req.SearchString) {
// continue
// }

if req.Title == "" {
t.SetTitle(cell.String())
t.SetTitle(cell.(string))
}

if t.graph.searchName == "" {
if *req.NameColumn > 0 {
cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.NameColumn})
if req.NameColumn != nil {
// cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.NameColumn})
cell, t.Error = t.GetCell(row, *req.NameColumn)
if t.Error != nil {
continue
}
t.graph.searchName = cell.String()
t.graph.searchName = cell.(string)
}
}

// Get units
if units == "" {
if *req.UnitsColumn > 0 {
cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.UnitsColumn})
if req.UnitsColumn != nil {
// cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.UnitsColumn})
cell, t.Error = t.GetCell(row, *req.UnitsColumn)
if t.Error != nil {
continue
}
units = cell.String()
units = cell.(string)
}
}

//
cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.TimeColumn})
// cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.TimeColumn})
cell, t.Error = t.GetCell(row, *req.TimeColumn)
if t.Error != nil {
continue
}
var tim time.Time
tim, t.Error = time.ParseInLocation(DateTimeSearchLayout, cell.String(), time.Local) // @TODO - May have to revisit this!
tim, t.Error = time.ParseInLocation(DateTimeSearchLayout, cell.(string), time.Local) // @TODO - May have to revisit this!
if t.Error != nil {
continue
}
times = append(times, tim)

//
cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.ValueColumn})
// cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.ValueColumn})
cell, t.Error = t.GetCell(row, *req.ValueColumn)
if t.Error != nil {
continue
}
var val float64
val, t.Error = strconv.ParseFloat(cell.String(), 64)
val, t.Error = strconv.ParseFloat(cell.(string), 64)
if t.Error != nil {
val = 0
}
Expand Down Expand Up @@ -219,19 +224,22 @@ func (t *Table) ProcessGraphData() error {
type SearchStrings map[string]int
func (t *Table) FindSearchStrings() error {
for range Only.Once {
fmt.Println("This is currently broken!")
break
t.graph.otherSearch = make(SearchStrings)

for row := 0; row < t.table.NRows(); row++ {
for row := 0; row < t.RowLength(); row++ {
// Get the search column
var cell *tabular.Cell
cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *t.graph.req.SearchColumn})
var cell interface{}
// cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *t.graph.req.SearchColumn})
cell, t.Error = t.GetCell(row, *t.graph.req.SearchColumn)
if t.Error != nil {
continue
}
if _, ok := t.graph.otherSearch[cell.String()]; ok {
t.graph.otherSearch[cell.String()] += 1
if _, ok := t.graph.otherSearch[cell.(string)]; ok {
t.graph.otherSearch[cell.(string)] += 1
} else {
t.graph.otherSearch[cell.String()] = 0
t.graph.otherSearch[cell.(string)] = 0
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package output

import (
"GoSungrow/Only"
"GoSungrow/iSolarCloud/api/apiReflect"
"GoSungrow/iSolarCloud/api/GoStruct/reflection"
"encoding/json"
"fmt"
)
Expand Down Expand Up @@ -50,7 +50,7 @@ func GetAsString(r interface{}) string {
break
}

a, e := apiReflect.GetStructName(r)
a, e := reflection.GetStructName(r)
ret += fmt.Sprintf(`"%s.%s": %s`, a, e, j)
}
return ret
Expand All @@ -65,7 +65,7 @@ func GetRequestString(r interface{}) string {
break
}

a, e := apiReflect.GetStructName(r)
a, e := reflection.GetStructName(r)
ret += fmt.Sprintf(`"%s.%s": %s`, a, e, j)
}
return ret
Expand Down
File renamed without changes.

0 comments on commit 260fd19

Please sign in to comment.