mirror of
https://github.com/MickMake/GoSungrow.git
synced 2025-03-26 17:41:42 +01:00
v1.2.4
This commit is contained in:
parent
9c30f56f93
commit
3930b5259b
1140
.idea/workspace.xml
generated
1140
.idea/workspace.xml
generated
File diff suppressed because it is too large
Load Diff
20
README.md
20
README.md
@ -98,6 +98,26 @@ Produce basic storage report
|
||||
./bin/GoSungrow api get queryMutiPointDataList '{"ps_key":"1129147_14_1_1,1129147_14_1_1,1129147_14_1_1,1129147_14_1_1,1129147_14_1_1,1129147_14_1_1,1129147_14_1_1,1129147_14_1_1,1129147_14_1_1,1129147_11_0_0","points":"p13150,p13126,p13142,p13143,p13019,p13141,p13121,p13003,p13149,p83106","minute_interval":"5","start_time_stamp":"20220215000000","end_time_stamp":"20220215235900", "ps_id":"1129147"}'
|
||||
```
|
||||
|
||||
Show all data points used in a report template.
|
||||
```
|
||||
./bin/GoSungrow data get template-points 8040
|
||||
┏━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━┓
|
||||
┃ PointId ┃ Description ┃ Unit ┃
|
||||
┣━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━┫
|
||||
┃ p13008 │ Phase A Current │ A ┃
|
||||
┃ p13162 │ Max. Charging Current (BMS) │ A ┃
|
||||
┃ p18063 │ Phase B Backup Current │ A ┃
|
||||
┃ p13009 │ Phase B Current │ A ┃
|
||||
┃ p18062 │ Phase A Backup Current │ A ┃
|
||||
┃ p13163 │ Max. Discharging Current (BMS) │ A ┃
|
||||
┃ p13106 │ MPPT2 Current │ A ┃
|
||||
┃ p13139 │ Battery Current │ A ┃
|
||||
┃ p18064 │ Phase C Backup Current │ A ┃
|
||||
┃ p13002 │ MPPT1 Current │ A ┃
|
||||
┃ p13010 │ Phase C Current │ A ┃
|
||||
┗━━━━━━━━━┷━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┷━━━━━━┛
|
||||
```
|
||||
|
||||
Get the household storage report
|
||||
```
|
||||
./bin/GoSungrow api get getHouseholdStoragePsReport '{"date_id":"2022","date_type":"4","ps_id":"1129147"}'
|
||||
|
170
cmd/cmd_data.go
170
cmd/cmd_data.go
@ -16,27 +16,29 @@ func AttachCmdData(cmd *cobra.Command) *cobra.Command {
|
||||
DisableFlagParsing: false,
|
||||
DisableFlagsInUseLine: false,
|
||||
PreRunE: Cmd.ProcessArgs,
|
||||
Run: cmdDataFunc,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return cmd.Help()
|
||||
},
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
}
|
||||
cmd.AddCommand(cmdData)
|
||||
cmdData.Example = PrintExamples(cmdData, "get <endpoint>", "put <endpoint>")
|
||||
|
||||
|
||||
// ********************************************************************************
|
||||
var cmdDataList = &cobra.Command{
|
||||
Use: "ls",
|
||||
Aliases: []string{"list"},
|
||||
Short: fmt.Sprintf("List iSolarCloud high-level data commands."),
|
||||
Long: fmt.Sprintf("List iSolarCloud high-level data commands."),
|
||||
DisableFlagParsing: false,
|
||||
DisableFlagsInUseLine: false,
|
||||
// PreRunE: Cmd.SunGrowArgs,
|
||||
Run: cmdDataListFunc,
|
||||
Args: cobra.RangeArgs(0, 1),
|
||||
}
|
||||
cmdData.AddCommand(cmdDataList)
|
||||
cmdDataList.Example = PrintExamples(cmdDataList, "", "areas", "endpoints", "<area name>")
|
||||
// // ********************************************************************************
|
||||
// var cmdDataList = &cobra.Command{
|
||||
// Use: "ls",
|
||||
// Aliases: []string{"list"},
|
||||
// Short: fmt.Sprintf("List iSolarCloud high-level data commands."),
|
||||
// Long: fmt.Sprintf("List iSolarCloud high-level data commands."),
|
||||
// DisableFlagParsing: false,
|
||||
// DisableFlagsInUseLine: false,
|
||||
// // PreRunE: Cmd.SunGrowArgs,
|
||||
// Run: cmdDataListFunc,
|
||||
// Args: cobra.RangeArgs(0, 1),
|
||||
// }
|
||||
// cmdData.AddCommand(cmdDataList)
|
||||
// cmdDataList.Example = PrintExamples(cmdDataList, "", "areas", "endpoints", "<area name>")
|
||||
|
||||
// ********************************************************************************
|
||||
var cmdDataLogin = &cobra.Command{
|
||||
@ -53,6 +55,7 @@ func AttachCmdData(cmd *cobra.Command) *cobra.Command {
|
||||
cmdData.AddCommand(cmdDataLogin)
|
||||
cmdDataLogin.Example = PrintExamples(cmdDataLogin, "")
|
||||
|
||||
|
||||
// ********************************************************************************
|
||||
var cmdDataGet = &cobra.Command{
|
||||
Use: "get",
|
||||
@ -62,11 +65,17 @@ func AttachCmdData(cmd *cobra.Command) *cobra.Command {
|
||||
DisableFlagParsing: false,
|
||||
DisableFlagsInUseLine: false,
|
||||
PreRunE: Cmd.SunGrowArgs,
|
||||
Run: cmdDataGetFunc,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return cmd.Help()
|
||||
},
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
}
|
||||
cmdData.AddCommand(cmdDataGet)
|
||||
cmdDataGet.Example = PrintExamples(cmdDataGet, "[area.]<endpoint>")
|
||||
AttachCmdDataStats(cmdDataGet)
|
||||
AttachCmdDataTemplate(cmdDataGet)
|
||||
AttachCmdDataTemplatePoints(cmdDataGet)
|
||||
AttachCmdDataPoints(cmdDataGet)
|
||||
|
||||
// ********************************************************************************
|
||||
var cmdDataRaw = &cobra.Command{
|
||||
@ -77,11 +86,16 @@ func AttachCmdData(cmd *cobra.Command) *cobra.Command {
|
||||
DisableFlagParsing: false,
|
||||
DisableFlagsInUseLine: false,
|
||||
PreRunE: Cmd.SunGrowArgs,
|
||||
Run: cmdDataRawFunc,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return cmd.Help()
|
||||
},
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
}
|
||||
cmdData.AddCommand(cmdDataRaw)
|
||||
cmdDataRaw.Example = PrintExamples(cmdDataRaw, "[area.]<endpoint>")
|
||||
AttachCmdDataStats(cmdDataRaw)
|
||||
AttachCmdDataTemplate(cmdDataRaw)
|
||||
AttachCmdDataPoints(cmdDataRaw)
|
||||
|
||||
// ********************************************************************************
|
||||
var cmdDataSave = &cobra.Command{
|
||||
@ -92,11 +106,16 @@ func AttachCmdData(cmd *cobra.Command) *cobra.Command {
|
||||
DisableFlagParsing: false,
|
||||
DisableFlagsInUseLine: false,
|
||||
PreRunE: Cmd.SunGrowArgs,
|
||||
Run: cmdDataSaveFunc,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return cmd.Help()
|
||||
},
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
}
|
||||
cmdData.AddCommand(cmdDataSave)
|
||||
cmdDataSave.Example = PrintExamples(cmdDataSave, "[area.]<endpoint>")
|
||||
AttachCmdDataStats(cmdDataSave)
|
||||
AttachCmdDataTemplate(cmdDataSave)
|
||||
AttachCmdDataPoints(cmdDataSave)
|
||||
|
||||
// ********************************************************************************
|
||||
var cmdDataGraph = &cobra.Command{
|
||||
@ -107,11 +126,16 @@ func AttachCmdData(cmd *cobra.Command) *cobra.Command {
|
||||
DisableFlagParsing: false,
|
||||
DisableFlagsInUseLine: false,
|
||||
PreRunE: Cmd.SunGrowArgs,
|
||||
Run: cmdDataGraphFunc,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return cmd.Help()
|
||||
},
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
}
|
||||
cmdData.AddCommand(cmdDataGraph)
|
||||
cmdDataGraph.Example = PrintExamples(cmdDataGraph, "[area.]<endpoint> ''")
|
||||
AttachCmdDataStats(cmdDataGraph)
|
||||
AttachCmdDataTemplate(cmdDataGraph)
|
||||
AttachCmdDataPoints(cmdDataGraph)
|
||||
|
||||
// ********************************************************************************
|
||||
var cmdDataPut = &cobra.Command{
|
||||
@ -132,49 +156,49 @@ func AttachCmdData(cmd *cobra.Command) *cobra.Command {
|
||||
}
|
||||
|
||||
|
||||
func cmdDataFunc(cmd *cobra.Command, _ []string) {
|
||||
Cmd.Error = cmd.Help()
|
||||
}
|
||||
|
||||
func cmdDataListFunc(_ *cobra.Command, _ []string) {
|
||||
Cmd.SunGrow.ListHighLevel()
|
||||
}
|
||||
|
||||
func cmdDataGetFunc(_ *cobra.Command, args []string) {
|
||||
for range Only.Once {
|
||||
Cmd.SunGrow.OutputType.SetHuman()
|
||||
|
||||
args = fillArray(3, args)
|
||||
Cmd.Error = Cmd.SunGrow.GetHighLevel(args[0], args[1:]...)
|
||||
}
|
||||
}
|
||||
|
||||
func cmdDataRawFunc(_ *cobra.Command, args []string) {
|
||||
for range Only.Once {
|
||||
Cmd.SunGrow.OutputType.SetRaw()
|
||||
|
||||
args = fillArray(3, args)
|
||||
Cmd.Error = Cmd.SunGrow.GetHighLevel(args[0], args[1:]...)
|
||||
}
|
||||
}
|
||||
|
||||
func cmdDataSaveFunc(_ *cobra.Command, args []string) {
|
||||
for range Only.Once {
|
||||
Cmd.SunGrow.OutputType.SetFile()
|
||||
|
||||
args = fillArray(3, args)
|
||||
Cmd.Error = Cmd.SunGrow.GetHighLevel(args[0], args[1:]...)
|
||||
}
|
||||
}
|
||||
|
||||
func cmdDataGraphFunc(_ *cobra.Command, args []string) {
|
||||
for range Only.Once {
|
||||
Cmd.SunGrow.OutputType.SetGraph()
|
||||
|
||||
args = fillArray(4, args)
|
||||
Cmd.Error = Cmd.SunGrow.GetHighLevel(args[0], args[1:]...)
|
||||
}
|
||||
}
|
||||
// func cmdDataFunc(cmd *cobra.Command, _ []string) {
|
||||
// Cmd.Error = cmd.Help()
|
||||
// }
|
||||
//
|
||||
// func cmdDataListFunc(_ *cobra.Command, _ []string) {
|
||||
// Cmd.SunGrow.ListHighLevel()
|
||||
// }
|
||||
//
|
||||
// func cmdDataGetFunc(_ *cobra.Command, args []string) {
|
||||
// for range Only.Once {
|
||||
// Cmd.SunGrow.OutputType.SetHuman()
|
||||
//
|
||||
// args = fillArray(3, args)
|
||||
// Cmd.Error = Cmd.SunGrow.GetHighLevel(args[0], args[1:]...)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func cmdDataRawFunc(_ *cobra.Command, args []string) {
|
||||
// for range Only.Once {
|
||||
// Cmd.SunGrow.OutputType.SetRaw()
|
||||
//
|
||||
// args = fillArray(3, args)
|
||||
// Cmd.Error = Cmd.SunGrow.GetHighLevel(args[0], args[1:]...)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func cmdDataSaveFunc(_ *cobra.Command, args []string) {
|
||||
// for range Only.Once {
|
||||
// Cmd.SunGrow.OutputType.SetFile()
|
||||
//
|
||||
// args = fillArray(3, args)
|
||||
// Cmd.Error = Cmd.SunGrow.GetHighLevel(args[0], args[1:]...)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func cmdDataGraphFunc(_ *cobra.Command, args []string) {
|
||||
// for range Only.Once {
|
||||
// Cmd.SunGrow.OutputType.SetGraph()
|
||||
//
|
||||
// args = fillArray(4, args)
|
||||
// Cmd.Error = Cmd.SunGrow.GetHighLevel(args[0], args[1:]...)
|
||||
// }
|
||||
// }
|
||||
|
||||
func cmdDataPutFunc(_ *cobra.Command, args []string) {
|
||||
for range Only.Once {
|
||||
@ -184,3 +208,25 @@ func cmdDataPutFunc(_ *cobra.Command, args []string) {
|
||||
// Cmd.Error = SunGrow.PutHighLevel(args[0], args[1])
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func SwitchOutput(cmd *cobra.Command) error {
|
||||
var err error
|
||||
for range Only.Once {
|
||||
foo := cmd.Parent()
|
||||
switch foo.Use {
|
||||
case "get":
|
||||
Cmd.SunGrow.OutputType.SetHuman()
|
||||
case "raw":
|
||||
Cmd.SunGrow.OutputType.SetRaw()
|
||||
case "save":
|
||||
Cmd.SunGrow.OutputType.SetFile()
|
||||
case "graph":
|
||||
Cmd.SunGrow.OutputType.SetGraph()
|
||||
default:
|
||||
Cmd.SunGrow.OutputType.SetHuman()
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
@ -1,30 +1,95 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"GoSungrow/Only"
|
||||
"GoSungrow/iSolarCloud/api"
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
||||
// ********************************************************************************
|
||||
var cmdDataStats = &cobra.Command{
|
||||
Use: "stats",
|
||||
// Aliases: []string{""},
|
||||
Short: fmt.Sprintf("Get live data from iSolarCloud"),
|
||||
Long: fmt.Sprintf("Get live data from iSolarCloud"),
|
||||
DisableFlagParsing: false,
|
||||
DisableFlagsInUseLine: false,
|
||||
PreRunE: Cmd.SunGrowArgs,
|
||||
Run: cmdDataStatsFunc,
|
||||
Args: cobra.MinimumNArgs(1),
|
||||
}
|
||||
|
||||
func cmdDataStatsFunc(_ *cobra.Command, args []string) {
|
||||
for range Only.Once {
|
||||
Cmd.SunGrow.OutputType.SetFile()
|
||||
|
||||
Cmd.Error = Cmd.SunGrow.GetCurrentStats()
|
||||
func AttachCmdDataTemplatePoints(cmd *cobra.Command) *cobra.Command {
|
||||
// ********************************************************************************
|
||||
var cmdDataTemplatePoints = &cobra.Command{
|
||||
Use: "template-points <template_id>",
|
||||
Aliases: []string{""},
|
||||
Short: fmt.Sprintf("List data points used in report template."),
|
||||
Long: fmt.Sprintf("List data points used in report template."),
|
||||
DisableFlagParsing: false,
|
||||
DisableFlagsInUseLine: false,
|
||||
PreRunE: Cmd.SunGrowArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
_ = SwitchOutput(cmd)
|
||||
return Cmd.SunGrow.GetTemplatePoints(args[0])
|
||||
},
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
cmd.AddCommand(cmdDataTemplatePoints)
|
||||
cmdDataTemplatePoints.Example = PrintExamples(cmdDataTemplatePoints, "8042", "8040")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func AttachCmdDataTemplate(cmd *cobra.Command) *cobra.Command {
|
||||
// ********************************************************************************
|
||||
var cmdDataGetTemplate = &cobra.Command{
|
||||
Use: "template <template_id> <date> [filter]",
|
||||
Short: fmt.Sprintf("Get data from report template."),
|
||||
Long: fmt.Sprintf("Get data from report template."),
|
||||
DisableFlagParsing: false,
|
||||
DisableFlagsInUseLine: false,
|
||||
PreRunE: Cmd.SunGrowArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
_ = SwitchOutput(cmd)
|
||||
return Cmd.SunGrow.GetTemplateData(args[0], args[1], args[2])
|
||||
},
|
||||
Args: cobra.MinimumNArgs(2),
|
||||
}
|
||||
cmd.AddCommand(cmdDataGetTemplate)
|
||||
cmdDataGetTemplate.Example = PrintExamples(cmdDataGetTemplate, "8042 20220212", "8042 20220212 '{\"search_string\":\"p83106\",\"min_left_axis\":-6000,\"max_left_axis\":12000}'")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func AttachCmdDataStats(cmd *cobra.Command) *cobra.Command {
|
||||
// ********************************************************************************
|
||||
var cmdDataStats = &cobra.Command{
|
||||
Use: "stats",
|
||||
Aliases: []string{""},
|
||||
Short: fmt.Sprintf("Get current inverter stats, (last 5 minutes)."),
|
||||
Long: fmt.Sprintf("Get current inverter stats, (last 5 minutes)."),
|
||||
DisableFlagParsing: false,
|
||||
DisableFlagsInUseLine: false,
|
||||
PreRunE: Cmd.SunGrowArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
_ = SwitchOutput(cmd)
|
||||
return Cmd.SunGrow.GetCurrentStats()
|
||||
},
|
||||
Args: cobra.ExactArgs(0),
|
||||
}
|
||||
cmd.AddCommand(cmdDataStats)
|
||||
cmdDataStats.Example = PrintExamples(cmdDataStats, "")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
func AttachCmdDataPoints(cmd *cobra.Command) *cobra.Command {
|
||||
// ********************************************************************************
|
||||
var cmdDataStats = &cobra.Command{
|
||||
Use: "points <date> <device_id.point_id> ...",
|
||||
Aliases: []string{""},
|
||||
Short: fmt.Sprintf("Get points data for a specific date."),
|
||||
Long: fmt.Sprintf("Get points data for a specific date."),
|
||||
DisableFlagParsing: false,
|
||||
DisableFlagsInUseLine: false,
|
||||
PreRunE: Cmd.SunGrowArgs,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
_ = SwitchOutput(cmd)
|
||||
return Cmd.SunGrow.GetPointData(args[0], api.CreatePoints(args[1:]))
|
||||
},
|
||||
Args: cobra.MinimumNArgs(2),
|
||||
}
|
||||
cmd.AddCommand(cmdDataStats)
|
||||
cmdDataStats.Example = PrintExamples(cmdDataStats, "20220202 1129147.p13019 1129147.p83106")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 35 KiB |
@ -4,6 +4,7 @@ import (
|
||||
"GoSungrow/Only"
|
||||
"GoSungrow/iSolarCloud/api"
|
||||
"GoSungrow/iSolarCloud/api/apiReflect"
|
||||
"GoSungrow/iSolarCloud/api/output"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
@ -199,6 +200,10 @@ func (e *ResultData) GetPsId() int64 {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (e *EndPoint) GetPsId() int64 {
|
||||
return e.Response.ResultData.GetPsId()
|
||||
}
|
||||
|
||||
func (e *ResultData) GetData() [][]string {
|
||||
var ret [][]string
|
||||
for range Only.Once {
|
||||
@ -232,3 +237,60 @@ func (e *ResultData) GetData() [][]string {
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (e *EndPoint) GetDataTable() output.Table {
|
||||
var table output.Table
|
||||
for range Only.Once {
|
||||
table = output.NewTable()
|
||||
e.Error = table.SetTitle("")
|
||||
if e.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
_ = table.SetHeader(
|
||||
"Date",
|
||||
"Point Id",
|
||||
"Point Name",
|
||||
"Value",
|
||||
"Unit",
|
||||
)
|
||||
|
||||
now := time.Now().Round(5 * time.Minute).Format(api.DtLayoutZeroSeconds)
|
||||
|
||||
for _, p := range e.Response.ResultData.PageList {
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Co2 Reduce", p.Co2Reduce.Value, p.Co2Reduce.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Co2 Reduce Total", p.Co2ReduceTotal.Value, p.Co2ReduceTotal.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Curr Power", p.CurrPower.Value, p.CurrPower.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Daily Irradiation", p.DailyIrradiation.Value, p.DailyIrradiation.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Equivalent Hour", p.EquivalentHour.Value, p.EquivalentHour.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Es Discharge Energy", p.EsDisenergy.Value, p.EsDisenergy.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Es Energy", p.EsEnergy.Value, p.EsEnergy.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Es Power", p.EsPower.Value, p.EsPower.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Es Total Discharge Energy", p.EsTotalDisenergy.Value, p.EsTotalDisenergy.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Es Total Energy", p.EsTotalEnergy.Value, p.EsTotalEnergy.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Installed Power Map", p.InstalledPowerMap.Value, p.InstalledPowerMap.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Pv Energy", p.PvEnergy.Value, p.PvEnergy.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Pv Power", p.PvPower.Value, p.PvPower.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Radiation", p.Radiation.Value, p.Radiation.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Today Energy", p.TodayEnergy.Value, p.TodayEnergy.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Today Income", p.TodayIncome.Value, p.TodayIncome.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Total Capacity", p.TotalCapcity.Value, p.TotalCapcity.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Total Energy", p.TotalEnergy.Value, p.TotalEnergy.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Total Income", p.TotalIncome.Value, p.TotalIncome.Unit)
|
||||
_ = table.AddRow(now, fmt.Sprintf("%d.%d", p.PsID, 0), "Use Energy", p.UseEnergy.Value, p.UseEnergy.Unit)
|
||||
}
|
||||
|
||||
table.InitGraph(output.GraphRequest {
|
||||
Title: "",
|
||||
TimeColumn: output.SetInteger(1),
|
||||
ValueColumn: output.SetInteger(3),
|
||||
UnitsColumn: output.SetInteger(4),
|
||||
SearchColumn: output.SetInteger(2),
|
||||
SearchString: output.SetString(""),
|
||||
MinLeftAxis: output.SetFloat(0),
|
||||
MaxLeftAxis: output.SetFloat(0),
|
||||
})
|
||||
|
||||
}
|
||||
return table
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ package queryDeviceList
|
||||
|
||||
import (
|
||||
"GoSungrow/Only"
|
||||
"GoSungrow/iSolarCloud/api"
|
||||
"GoSungrow/iSolarCloud/api/apiReflect"
|
||||
"GoSungrow/iSolarCloud/api/output"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
@ -206,45 +208,48 @@ func (e *ResultData) GetDataByName(name string) PointData {
|
||||
return ret
|
||||
}
|
||||
|
||||
// func (e *ResultData) GetDataTable(name string, points api.TemplatePoints) api.Table {
|
||||
// var table api.Table
|
||||
// for range Only.Once {
|
||||
// // points := e.GetDataByName(name)
|
||||
// _ = table.SetHeader([]string{
|
||||
// "Date",
|
||||
// "PointGroupName",
|
||||
// "PointName",
|
||||
// "Value",
|
||||
// "Unit",
|
||||
// })
|
||||
//
|
||||
// for _, d := range e.PageList {
|
||||
// for _, p := range d.PointData {
|
||||
// gp := points.GetPoint(deviceName, pointId)
|
||||
// _ = table.AddRow(
|
||||
// // tim.Key.PrintFull(),
|
||||
// api.NewDateTime(p.TimeStamp),
|
||||
// fmt.Sprintf("%s.%d", d.DeviceName, p.PointID),
|
||||
// p.PointGroupName,
|
||||
// p.PointName,
|
||||
// p.Unit,
|
||||
// p.Value,
|
||||
// gp.Description,
|
||||
// gp.Unit,
|
||||
// )
|
||||
//
|
||||
// // _ = table.AddRow([]string{
|
||||
// // t.Format(api.DtLayout),
|
||||
// // p.PointGroupName,
|
||||
// // fmt.Sprintf("%s.%d", d.DeviceName, p.PointID),
|
||||
// // p.PointName,
|
||||
// // p.Value,
|
||||
// // p.Unit,
|
||||
// // })
|
||||
// }
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// return table
|
||||
// }
|
||||
func (e *EndPoint) GetDataTable() output.Table {
|
||||
var table output.Table
|
||||
for range Only.Once {
|
||||
table = output.NewTable()
|
||||
e.Error = table.SetTitle("")
|
||||
if e.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
_ = table.SetHeader(
|
||||
"Date",
|
||||
"Point Id",
|
||||
"PointGroupName",
|
||||
"PointName",
|
||||
"Value",
|
||||
"Unit",
|
||||
)
|
||||
|
||||
for _, d := range e.Response.ResultData.PageList {
|
||||
for _, p := range d.PointData {
|
||||
_ = table.AddRow(
|
||||
api.NewDateTime(p.TimeStamp).PrintFull(),
|
||||
fmt.Sprintf("%s.%d", d.PsKey, p.PointID),
|
||||
p.PointGroupName,
|
||||
p.PointName,
|
||||
p.Value,
|
||||
p.Unit,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
table.InitGraph(output.GraphRequest {
|
||||
Title: "",
|
||||
TimeColumn: output.SetInteger(1),
|
||||
ValueColumn: output.SetInteger(5),
|
||||
UnitsColumn: output.SetInteger(6),
|
||||
SearchColumn: output.SetInteger(2),
|
||||
SearchString: output.SetString(""),
|
||||
MinLeftAxis: output.SetFloat(0),
|
||||
MaxLeftAxis: output.SetFloat(0),
|
||||
})
|
||||
|
||||
}
|
||||
return table
|
||||
}
|
||||
|
@ -171,15 +171,9 @@ func (e *EndPoint) GetDataTable(points api.TemplatePoints) output.Table {
|
||||
break
|
||||
}
|
||||
|
||||
fn := e.SetFilenamePrefix("%s-", api.NewDateTime(e.Request.StartTimeStamp).String())
|
||||
e.Error = table.SetFilePrefix(fn)
|
||||
if e.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
e.Error = table.SetHeader(
|
||||
"Date/Time",
|
||||
"PointId Name",
|
||||
"Point Id",
|
||||
"Point Name",
|
||||
"Value",
|
||||
"Units",
|
||||
@ -190,6 +184,10 @@ func (e *EndPoint) GetDataTable(points api.TemplatePoints) output.Table {
|
||||
|
||||
t := api.NewDateTime(e.Request.RequestData.StartTimeStamp)
|
||||
e.SetFilenamePrefix(t.String())
|
||||
e.Error = table.SetFilePrefix(t.String())
|
||||
if e.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
for deviceName, deviceRef := range e.Response.ResultData.Devices {
|
||||
for pointId, pointRef := range deviceRef.Points {
|
||||
@ -208,6 +206,18 @@ func (e *EndPoint) GetDataTable(points api.TemplatePoints) output.Table {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
table.InitGraph(output.GraphRequest {
|
||||
Title: "",
|
||||
TimeColumn: output.SetInteger(1),
|
||||
ValueColumn: output.SetInteger(4),
|
||||
UnitsColumn: output.SetInteger(5),
|
||||
SearchColumn: output.SetInteger(2),
|
||||
SearchString: output.SetString(""),
|
||||
MinLeftAxis: output.SetFloat(0),
|
||||
MaxLeftAxis: output.SetFloat(0),
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
return table
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/wcharczuk/go-chart/v2"
|
||||
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||
"go.pennock.tech/tabular"
|
||||
"os"
|
||||
"strconv"
|
||||
@ -15,17 +16,92 @@ import (
|
||||
|
||||
type GraphRequest struct {
|
||||
Title string `json:"title"`
|
||||
TimeColumn int `json:"time_column"`
|
||||
ValueColumn int `json:"value_column"`
|
||||
SearchColumn int `json:"search_column"`
|
||||
SearchString string `json:"search_string"`
|
||||
FileName string `json:"file_name"`
|
||||
MaxLeftAxis float64 `json:"max_left_axis"`
|
||||
MinLeftAxis float64 `json:"min_left_axis"`
|
||||
|
||||
TimeColumn *int `json:"time_column"`
|
||||
ValueColumn *int `json:"value_column"`
|
||||
UnitsColumn *int `json:"units_column"`
|
||||
SearchColumn *int `json:"search_column"`
|
||||
SearchString *string `json:"search_string"`
|
||||
|
||||
MinLeftAxis *float64 `json:"min_left_axis"`
|
||||
MaxLeftAxis *float64 `json:"max_left_axis"`
|
||||
|
||||
Error error `json:"-"`
|
||||
}
|
||||
|
||||
func JsonToGraphRequest(j string) GraphRequest {
|
||||
func SetInteger(v int) *int {
|
||||
return &v
|
||||
}
|
||||
func SetString(v string) *string {
|
||||
return &v
|
||||
}
|
||||
func SetFloat(v float64) *float64 {
|
||||
return &v
|
||||
}
|
||||
|
||||
// type Integer int
|
||||
// func (c *Integer) Set(f int) (*Integer, bool) {
|
||||
// var changed bool
|
||||
// for range Only.Once {
|
||||
// ff := Integer(f)
|
||||
// if c == nil {
|
||||
// c = &ff
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// if*c == ff {
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// changed = true
|
||||
// }
|
||||
// return c, changed
|
||||
// }
|
||||
//
|
||||
// type Float float64
|
||||
// func (c *Float) Set(f float64) (*Float, bool) {
|
||||
// var changed bool
|
||||
// for range Only.Once {
|
||||
// ff := Float(f)
|
||||
// if c == nil {
|
||||
// c = &ff
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// if*c == ff {
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// changed = true
|
||||
// }
|
||||
// return c, changed
|
||||
// }
|
||||
//
|
||||
// type String string
|
||||
// func (c *String) Set(s string) (*String, bool) {
|
||||
// var changed bool
|
||||
// for range Only.Once {
|
||||
// ss := String(s)
|
||||
// if c == nil {
|
||||
// c = &ss
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// if*c == ss {
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// if ss == "" {
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// changed = true
|
||||
// }
|
||||
// return c, changed
|
||||
// }
|
||||
|
||||
|
||||
func JsonToGraphRequest(j Json) GraphRequest {
|
||||
var ret GraphRequest
|
||||
for range Only.Once {
|
||||
ret.Error = json.Unmarshal([]byte(j), &ret)
|
||||
@ -37,31 +113,104 @@ func JsonToGraphRequest(j string) GraphRequest {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (t *Table) WriteGraphFile(req GraphRequest) error {
|
||||
// func (t Table) Graph(name string, timeColumn int, valueColumn int, searchString string, searchColumn int, fileName string) error {
|
||||
for range Only.Once {
|
||||
foo := New(req.Title)
|
||||
func (t *Table) InitGraph(req GraphRequest) {
|
||||
if t.graph == nil {
|
||||
t.graph = New(req.Title)
|
||||
}
|
||||
|
||||
t.Error = foo.SetFilename(t.filePrefix + ".png")
|
||||
t.graph.req = req
|
||||
}
|
||||
|
||||
func (t *Table) SetGraph(req GraphRequest) error {
|
||||
for range Only.Once {
|
||||
if t.graph == nil {
|
||||
t.graph = New(req.Title)
|
||||
}
|
||||
|
||||
t.Error = t.graph.SetFilename(t.filePrefix + ".png")
|
||||
if t.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
t.graph.SetRangeY(req.MinLeftAxis, req.MaxLeftAxis)
|
||||
if t.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
changed := t.graph.SetGraphSearch(req)
|
||||
if !changed {
|
||||
break
|
||||
}
|
||||
if t.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
t.Error = t.ProcessGraphData()
|
||||
if t.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return t.Error
|
||||
}
|
||||
|
||||
func (t *Table) SetGraphFromJson(j Json) error {
|
||||
for range Only.Once {
|
||||
gr := JsonToGraphRequest(j)
|
||||
if gr.Error != nil {
|
||||
t.Error = gr.Error
|
||||
break
|
||||
}
|
||||
|
||||
t.Error = t.SetGraph(gr)
|
||||
if t.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return t.Error
|
||||
}
|
||||
|
||||
|
||||
func (t *Table) GetSearchColumn() SearchStrings {
|
||||
return t.graph.otherSearch
|
||||
}
|
||||
|
||||
func (t *Table) ProcessGraphData() error {
|
||||
for range Only.Once {
|
||||
req := t.graph.req
|
||||
|
||||
var units string
|
||||
var times []time.Time
|
||||
var values []float64
|
||||
for row := 0; row < t.table.NRows(); row++ {
|
||||
// Get the search column
|
||||
var cell *tabular.Cell
|
||||
cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: req.SearchColumn})
|
||||
cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.SearchColumn})
|
||||
if t.Error != nil {
|
||||
continue
|
||||
}
|
||||
if !strings.Contains(cell.String(), req.SearchString) {
|
||||
if !strings.Contains(cell.String(), *req.SearchString) {
|
||||
continue
|
||||
}
|
||||
|
||||
if req.Title == "" {
|
||||
_ = t.SetTitle(cell.String())
|
||||
}
|
||||
|
||||
cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: req.TimeColumn})
|
||||
//
|
||||
if units == "" {
|
||||
if *req.UnitsColumn > 0 {
|
||||
cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.UnitsColumn})
|
||||
if t.Error != nil {
|
||||
continue
|
||||
}
|
||||
units = cell.String()
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.TimeColumn})
|
||||
if t.Error != nil {
|
||||
continue
|
||||
}
|
||||
@ -72,8 +221,8 @@ func (t *Table) WriteGraphFile(req GraphRequest) error {
|
||||
}
|
||||
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})
|
||||
if t.Error != nil {
|
||||
continue
|
||||
}
|
||||
@ -85,22 +234,12 @@ func (t *Table) WriteGraphFile(req GraphRequest) error {
|
||||
values = append(values, val)
|
||||
}
|
||||
|
||||
t.Error = foo.SetX("Date", times...)
|
||||
t.Error = t.graph.SetX("Date", times...)
|
||||
if t.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
t.Error = foo.SetY("kWh", values...)
|
||||
if t.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
foo.SetRangeY(req.MinLeftAxis, req.MaxLeftAxis)
|
||||
if t.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
t.Error = foo.Generate()
|
||||
t.Error = t.graph.SetY(units, values...)
|
||||
if t.Error != nil {
|
||||
break
|
||||
}
|
||||
@ -109,12 +248,50 @@ func (t *Table) WriteGraphFile(req GraphRequest) error {
|
||||
return t.Error
|
||||
}
|
||||
|
||||
type SearchStrings map[string]int
|
||||
func (t *Table) FindSearchStrings() error {
|
||||
for range Only.Once {
|
||||
t.graph.otherSearch = make(SearchStrings)
|
||||
|
||||
for row := 0; row < t.table.NRows(); row++ {
|
||||
// Get the search column
|
||||
var cell *tabular.Cell
|
||||
cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *t.graph.req.SearchColumn})
|
||||
if t.Error != nil {
|
||||
continue
|
||||
}
|
||||
if _, ok := t.graph.otherSearch[cell.String()]; ok {
|
||||
t.graph.otherSearch[cell.String()] += 1
|
||||
} else {
|
||||
t.graph.otherSearch[cell.String()] = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return t.Error
|
||||
}
|
||||
|
||||
func (t *Table) SearchStrings() SearchStrings {
|
||||
return t.graph.otherSearch
|
||||
}
|
||||
|
||||
func (t *Table) CreateGraph() error {
|
||||
return t.graph.Generate()
|
||||
}
|
||||
|
||||
func (t *Table) CreateGraphAll() error {
|
||||
return t.graph.Generate()
|
||||
}
|
||||
|
||||
|
||||
type Chart struct {
|
||||
Error error `json:"-"`
|
||||
|
||||
otherSearch SearchStrings
|
||||
req GraphRequest
|
||||
filename string
|
||||
timeSeries chart.TimeSeries
|
||||
timeSeries1 chart.TimeSeries
|
||||
timeSeries2 chart.TimeSeries
|
||||
graph chart.Chart
|
||||
}
|
||||
|
||||
@ -159,12 +336,17 @@ func New(title string) *Chart {
|
||||
var c Chart
|
||||
|
||||
for range Only.Once {
|
||||
if title == "" {
|
||||
c.Error = errors.New("empty title")
|
||||
break
|
||||
c.timeSeries1 = chart.TimeSeries {
|
||||
Name: "",
|
||||
Style: chart.Style{},
|
||||
YAxis: chart.YAxisPrimary,
|
||||
XValues: []time.Time{},
|
||||
YValues: []float64{},
|
||||
}
|
||||
|
||||
c.timeSeries = chart.TimeSeries {
|
||||
c.timeSeries2 = chart.TimeSeries{
|
||||
Name: "",
|
||||
Style: chart.Style{},
|
||||
YAxis: chart.YAxisSecondary,
|
||||
XValues: []time.Time{},
|
||||
YValues: []float64{},
|
||||
}
|
||||
@ -182,7 +364,7 @@ func New(title string) *Chart {
|
||||
YAxis: chart.YAxis{},
|
||||
YAxisSecondary: chart.YAxis{},
|
||||
Font: nil,
|
||||
Series: []chart.Series{c.timeSeries},
|
||||
Series: []chart.Series{c.timeSeries1}, // , c.timeSeries2},
|
||||
Elements: nil,
|
||||
Log: nil,
|
||||
}
|
||||
@ -206,22 +388,73 @@ func (c *Chart) SetFilename(fn string) error {
|
||||
return c.Error
|
||||
}
|
||||
|
||||
func (c *Chart) SetRangeY(min float64, max float64) {
|
||||
c.graph.YAxis.Range = &chart.ContinuousRange {
|
||||
Min: min,
|
||||
Max: max,
|
||||
Domain: 0,
|
||||
Descending: false,
|
||||
func (c *Chart) SetTitle(fn string) error {
|
||||
c.graph.Title = fn
|
||||
c.req.Title = fn
|
||||
return c.Error
|
||||
}
|
||||
|
||||
func (c *Chart) SetRangeY(min *float64, max *float64) bool {
|
||||
var changed bool
|
||||
for range Only.Once {
|
||||
if min == nil {
|
||||
min = c.req.MinLeftAxis
|
||||
}
|
||||
|
||||
if max == nil {
|
||||
max = c.req.MaxLeftAxis
|
||||
}
|
||||
|
||||
c.graph.YAxis.Range = &chart.ContinuousRange {
|
||||
Min: *c.req.MinLeftAxis,
|
||||
Max: *c.req.MaxLeftAxis,
|
||||
Domain: 0,
|
||||
Descending: false,
|
||||
}
|
||||
|
||||
changed = true
|
||||
}
|
||||
// c.graph.YAxis.Range.SetMin(min)
|
||||
// c.graph.YAxis.Range.SetMax(max)
|
||||
|
||||
return changed
|
||||
}
|
||||
|
||||
func (c *Chart) SetGraphSearch(req GraphRequest) bool {
|
||||
var changed bool
|
||||
for range Only.Once {
|
||||
if req.SearchString != nil {
|
||||
c.req.SearchString = req.SearchString
|
||||
changed = true
|
||||
}
|
||||
|
||||
if req.TimeColumn != nil {
|
||||
c.req.TimeColumn = req.TimeColumn
|
||||
changed = true
|
||||
}
|
||||
|
||||
if req.ValueColumn != nil {
|
||||
c.req.ValueColumn = req.ValueColumn
|
||||
changed = true
|
||||
}
|
||||
|
||||
if req.UnitsColumn != nil {
|
||||
c.req.UnitsColumn = req.UnitsColumn
|
||||
changed = true
|
||||
}
|
||||
|
||||
if req.SearchColumn != nil {
|
||||
c.req.SearchColumn = req.SearchColumn
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
|
||||
return changed
|
||||
}
|
||||
|
||||
func (c *Chart) SetX(name string, values ...time.Time) error {
|
||||
|
||||
for range Only.Once {
|
||||
if len(values) == 0 {
|
||||
c.Error = errors.New("empty X values")
|
||||
c.Error = errors.New("no X values")
|
||||
break
|
||||
}
|
||||
|
||||
@ -238,14 +471,33 @@ func (c *Chart) SetX(name string, values ...time.Time) error {
|
||||
},
|
||||
TickStyle: chart.Style{},
|
||||
Ticks: nil,
|
||||
TickPosition: 0,
|
||||
TickPosition: chart.TickPositionUnderTick,
|
||||
GridLines: nil,
|
||||
GridMajorStyle: chart.Style{},
|
||||
GridMinorStyle: chart.Style{},
|
||||
}
|
||||
|
||||
c.timeSeries.XValues = append(c.timeSeries.XValues, values...)
|
||||
c.graph.Series = []chart.Series{ c.timeSeries }
|
||||
// c.graph.XAxis.ValueFormatter = func(v interface{}) string {
|
||||
// typed := v.(float64)
|
||||
// typedDate := chart.TimeFromFloat64(typed)
|
||||
// return typedDate.Format(DateTimeLayout)
|
||||
// // t := v.(time.Time)
|
||||
// // return t.Format(DateTimeLayout)
|
||||
// }
|
||||
|
||||
// c.graph.XAxis.TickPosition = chart.TickPositionUnderTick
|
||||
// c.graph.XAxis.GridLines = []chart.GridLine {
|
||||
// {IsMinor: true, Style: chart.Style{}, Value: 600},
|
||||
// }
|
||||
// c.graph.XAxis.Range = &chart.ContinuousRange {
|
||||
// Min: 0,
|
||||
// Max: 0,
|
||||
// Domain: 0,
|
||||
// Descending: false,
|
||||
// }
|
||||
|
||||
c.timeSeries1.XValues = append(c.timeSeries1.XValues, values...)
|
||||
// c.timeSeries2.XValues = append(c.timeSeries2.XValues, values...)
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
@ -254,33 +506,84 @@ func (c *Chart) SetY(name string, values ...float64) error {
|
||||
|
||||
for range Only.Once {
|
||||
if len(values) == 0 {
|
||||
c.Error = errors.New("empty Y values")
|
||||
c.Error = errors.New("no Y values")
|
||||
break
|
||||
}
|
||||
|
||||
c.graph.YAxis = chart.YAxis{
|
||||
Name: name,
|
||||
NameStyle: chart.Style{},
|
||||
Style: chart.Style{},
|
||||
Zero: chart.GridLine{},
|
||||
AxisType: 0,
|
||||
Ascending: false,
|
||||
ValueFormatter: nil,
|
||||
Range: &chart.ContinuousRange {
|
||||
Min: 0,
|
||||
Max: 0,
|
||||
Domain: 0,
|
||||
Descending: false,
|
||||
},
|
||||
TickStyle: chart.Style{},
|
||||
Ticks: nil,
|
||||
GridLines: nil,
|
||||
GridMajorStyle: chart.Style{},
|
||||
GridMinorStyle: chart.Style{},
|
||||
// c.graph.YAxis = chart.YAxis {
|
||||
// Name: name,
|
||||
// NameStyle: chart.Style{},
|
||||
// Style: chart.Style{},
|
||||
// Zero: chart.GridLine{},
|
||||
// AxisType: 0,
|
||||
// Ascending: false,
|
||||
// ValueFormatter: nil,
|
||||
// Range: &chart.ContinuousRange {
|
||||
// Min: 0,
|
||||
// Max: 0,
|
||||
// Domain: 0,
|
||||
// Descending: false,
|
||||
// },
|
||||
// TickStyle: chart.Style{},
|
||||
// Ticks: nil,
|
||||
// GridLines: nil,
|
||||
// GridMajorStyle: chart.Style{},
|
||||
// GridMinorStyle: chart.Style{},
|
||||
// }
|
||||
|
||||
c.graph.YAxis.Name = name
|
||||
|
||||
c.timeSeries1.YValues = append(c.timeSeries1.YValues, values...)
|
||||
// c.graph.Series = []chart.Series{ c.timeSeries }
|
||||
// c.graph.YAxis.Range = &chart.ContinuousRange {
|
||||
// Min: 0,
|
||||
// Max: 0,
|
||||
// Domain: 0,
|
||||
// Descending: false,
|
||||
// }
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
|
||||
func (c *Chart) SetY2(name string, values ...float64) error {
|
||||
|
||||
for range Only.Once {
|
||||
if len(values) == 0 {
|
||||
c.Error = errors.New("no Y values")
|
||||
break
|
||||
}
|
||||
|
||||
c.timeSeries.YValues = append(c.timeSeries.YValues, values...)
|
||||
c.graph.Series = []chart.Series{ c.timeSeries }
|
||||
// c.graph.YAxis = chart.YAxis {
|
||||
// Name: name,
|
||||
// NameStyle: chart.Style{},
|
||||
// Style: chart.Style{},
|
||||
// Zero: chart.GridLine{},
|
||||
// AxisType: 0,
|
||||
// Ascending: false,
|
||||
// ValueFormatter: nil,
|
||||
// Range: &chart.ContinuousRange {
|
||||
// Min: 0,
|
||||
// Max: 0,
|
||||
// Domain: 0,
|
||||
// Descending: false,
|
||||
// },
|
||||
// TickStyle: chart.Style{},
|
||||
// Ticks: nil,
|
||||
// GridLines: nil,
|
||||
// GridMajorStyle: chart.Style{},
|
||||
// GridMinorStyle: chart.Style{},
|
||||
// }
|
||||
|
||||
c.graph.YAxis.Name = name
|
||||
|
||||
c.timeSeries1.YValues = append(c.timeSeries1.YValues, values...)
|
||||
// c.graph.Series = []chart.Series{ c.timeSeries }
|
||||
// c.graph.YAxis.Range = &chart.ContinuousRange {
|
||||
// Min: 0,
|
||||
// Max: 0,
|
||||
// Domain: 0,
|
||||
// Descending: false,
|
||||
// }
|
||||
}
|
||||
return c.Error
|
||||
}
|
||||
@ -293,7 +596,23 @@ func (c *Chart) Generate() error {
|
||||
break
|
||||
}
|
||||
|
||||
f, _ := os.Create(c.filename)
|
||||
c.timeSeries1.Style = chart.Style {
|
||||
StrokeColor: drawing.ColorBlue,
|
||||
FillColor: drawing.ColorBlue.WithAlpha(64),
|
||||
}
|
||||
|
||||
c.graph.Series = []chart.Series {
|
||||
c.timeSeries1,
|
||||
// c.timeSeries2,
|
||||
}
|
||||
|
||||
c.graph.Title = c.req.Title
|
||||
|
||||
var f *os.File
|
||||
f, c.Error = os.Create(c.filename)
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
//goland:noinspection GoUnhandledErrorResult,GoDeferInLoop
|
||||
defer f.Close()
|
||||
|
@ -13,7 +13,7 @@ type Table struct {
|
||||
filePrefix string
|
||||
title string
|
||||
table datatable.RenderTable
|
||||
// graph *graph.Chart
|
||||
graph *Chart
|
||||
Error error
|
||||
}
|
||||
|
||||
|
@ -112,20 +112,26 @@ func (sg *SunGrow) GetByStruct(endpoint string, request interface{}, cache time.
|
||||
func (sg *SunGrow) GetHighLevel(name string, args ...string) error {
|
||||
for range Only.Once {
|
||||
name = strings.ToLower(name)
|
||||
if name == "stats" {
|
||||
sg.Error = sg.GetCurrentStats()
|
||||
break
|
||||
}
|
||||
|
||||
if name == "template" {
|
||||
args = fillArray(3, args)
|
||||
if args[0] == "" {
|
||||
sg.Error = errors.New("need a date")
|
||||
break
|
||||
}
|
||||
sg.Error = sg.GetTemplateData(args[0], args[1], args[2])
|
||||
break
|
||||
}
|
||||
// if name == "stats" {
|
||||
// sg.Error = sg.GetCurrentStats()
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// if name == "template" {
|
||||
// args = fillArray(3, args)
|
||||
// if args[0] == "" {
|
||||
// sg.Error = errors.New("need a date")
|
||||
// break
|
||||
// }
|
||||
// sg.Error = sg.GetTemplateData(args[0], args[1], args[2])
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// if name == "template-points" {
|
||||
// args = fillArray(1, args)
|
||||
// sg.Error = sg.GetTemplatePoints(args[0])
|
||||
// break
|
||||
// }
|
||||
|
||||
if name == "points" {
|
||||
args = fillArray(2, args)
|
||||
@ -143,22 +149,22 @@ func (sg *SunGrow) GetHighLevel(name string, args ...string) error {
|
||||
return sg.Error
|
||||
}
|
||||
|
||||
func (sg *SunGrow) ListHighLevel() {
|
||||
fmt.Println("stats - Get current inverter stats, (last 5 minutes).")
|
||||
fmt.Println("\tdata get stats")
|
||||
fmt.Println("")
|
||||
|
||||
fmt.Println("template [date] [template_id] - Get data from template.")
|
||||
fmt.Println("\tdata get template - Get data using default template 8042 for today.")
|
||||
fmt.Println("\tdata get template 2022 8040 - Get year data for template 8040 for the year 2022.")
|
||||
fmt.Println("\tdata get template 202202 8040 - Get month data for template 8040 for the month 202202.")
|
||||
fmt.Println("\tdata get template 20220202 8040 - Get day data for template 8040 for the day 20220202.")
|
||||
fmt.Println("\tdata get template 2022 - Get year data for default template 8042 for the year 2022.")
|
||||
fmt.Println("")
|
||||
|
||||
fmt.Println("points <date> <device_id.point_id> ... - Get data from points list.")
|
||||
fmt.Println("")
|
||||
}
|
||||
// func (sg *SunGrow) ListHighLevel() {
|
||||
// fmt.Println("stats - Get current inverter stats, (last 5 minutes).")
|
||||
// fmt.Println("\tdata get stats")
|
||||
// fmt.Println("")
|
||||
//
|
||||
// fmt.Println("template [date] [template_id] - Get data from template.")
|
||||
// fmt.Println("\tdata get template - Get data using default template 8042 for today.")
|
||||
// fmt.Println("\tdata get template 2022 8040 - Get year data for template 8040 for the year 2022.")
|
||||
// fmt.Println("\tdata get template 202202 8040 - Get month data for template 8040 for the month 202202.")
|
||||
// fmt.Println("\tdata get template 20220202 8040 - Get day data for template 8040 for the day 20220202.")
|
||||
// fmt.Println("\tdata get template 2022 - Get year data for default template 8042 for the year 2022.")
|
||||
// fmt.Println("")
|
||||
//
|
||||
// fmt.Println("points <date> <device_id.point_id> ... - Get data from points list.")
|
||||
// fmt.Println("")
|
||||
// }
|
||||
|
||||
func (sg *SunGrow) AllCritical() error {
|
||||
var ep api.EndPoint
|
||||
@ -250,28 +256,18 @@ func (sg *SunGrow) AllCritical() error {
|
||||
func (sg *SunGrow) GetCurrentStats() error {
|
||||
var ep api.EndPoint
|
||||
for range Only.Once {
|
||||
// ep = sg.GetByStruct("AppService.getPsList", nil, DefaultCacheTimeout)
|
||||
// // ep = sg.GetByJson("AppService.getPsList", "")
|
||||
// if ep.IsError() {
|
||||
// break
|
||||
// }
|
||||
// _getPsList := getPsList.AssertResultData(ep)
|
||||
// psId := _getPsList.GetPsId()
|
||||
psId := sg.GetPsId()
|
||||
ep = sg.GetByStruct("AppService.getPsList", nil, DefaultCacheTimeout)
|
||||
if ep.IsError() {
|
||||
break
|
||||
}
|
||||
_getPsList := getPsList.Assert(ep)
|
||||
psId := _getPsList.GetPsId()
|
||||
table := _getPsList.GetDataTable()
|
||||
sg.Error = sg.Output(_getPsList, table, "")
|
||||
if sg.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
if sg.OutputType.IsHuman() {
|
||||
_queryDeviceList := getPsList.AssertResultData(ep)
|
||||
points := _queryDeviceList.GetData()
|
||||
for _, r := range points {
|
||||
for _, c := range r {
|
||||
fmt.Printf("\"%s\",", c)
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
}
|
||||
|
||||
// ep = sg.GetByJson("AppService.queryDeviceList", fmt.Sprintf(`{"ps_id":"%d"}`, psId))
|
||||
ep = sg.GetByStruct(
|
||||
@ -279,18 +275,25 @@ func (sg *SunGrow) GetCurrentStats() error {
|
||||
queryDeviceList.RequestData{PsId: strconv.FormatInt(psId, 10)},
|
||||
DefaultCacheTimeout,
|
||||
)
|
||||
if ep.IsError() {
|
||||
if sg.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
if sg.OutputType.IsHuman() {
|
||||
_queryDeviceList := queryDeviceList.AssertResultData(ep)
|
||||
points := _queryDeviceList.GetDataByName("SH10RT")
|
||||
fmt.Printf("%v", points)
|
||||
ep2 := queryDeviceList.Assert(ep)
|
||||
table = ep2.GetDataTable()
|
||||
sg.Error = sg.Output(ep2, table, "")
|
||||
if sg.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
// if sg.OutputType.IsHuman() {
|
||||
// _queryDeviceList := queryDeviceList.AssertResultData(ep)
|
||||
// points := _queryDeviceList.GetDataByName("SH10RT")
|
||||
// // @TODO - Improve output of this!
|
||||
// fmt.Printf("%v", points)
|
||||
// }
|
||||
}
|
||||
|
||||
sg.Error = ep.GetError()
|
||||
return sg.Error
|
||||
}
|
||||
|
||||
@ -319,6 +322,16 @@ func (sg *SunGrow) GetPointData(date string, pointNames api.TemplatePoints) erro
|
||||
},
|
||||
DefaultCacheTimeout,
|
||||
)
|
||||
if sg.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
ep2 := queryMutiPointDataList.Assert(ep)
|
||||
table := ep2.GetDataTable(pointNames)
|
||||
sg.Error = sg.Output(ep2, table, "")
|
||||
if sg.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
//
|
||||
// csv := api.NewCsv()
|
||||
@ -331,14 +344,6 @@ func (sg *SunGrow) GetPointData(date string, pointNames api.TemplatePoints) erro
|
||||
// })
|
||||
//
|
||||
// data := queryMutiPointDataList.AssertResultData(ep)
|
||||
|
||||
ep2 := queryMutiPointDataList.Assert(ep)
|
||||
table := ep2.GetDataTable(pointNames)
|
||||
sg.Error = sg.Output(ep2, table, "")
|
||||
if sg.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
// for deviceName, deviceRef := range data.Devices {
|
||||
// for pointId, pointRef := range deviceRef.Points {
|
||||
// for _, tim := range pointRef.Times {
|
||||
@ -400,20 +405,15 @@ func (sg *SunGrow) Output(endpoint api.EndPoint, table output.Table, graphFilter
|
||||
fmt.Println(endpoint.GetJsonData(false))
|
||||
|
||||
case sg.OutputType.IsGraph():
|
||||
gr := output.JsonToGraphRequest(graphFilter)
|
||||
if gr.Error != nil {
|
||||
sg.Error = gr.Error
|
||||
sg.Error = table.SetGraphFromJson(output.Json(graphFilter))
|
||||
if sg.Error != nil {
|
||||
break
|
||||
}
|
||||
sg.Error = table.WriteGraphFile(gr)
|
||||
// api.GraphRequest {
|
||||
// Title: "Testing 1. 2. 3.",
|
||||
// TimeColumn: 1,
|
||||
// ValueColumn: 4,
|
||||
// SearchColumn: 3,
|
||||
// SearchString: "p83106",
|
||||
// FileName: "foo.png",
|
||||
// }
|
||||
sg.Error = table.CreateGraph()
|
||||
if sg.Error != nil {
|
||||
break
|
||||
}
|
||||
//
|
||||
|
||||
default:
|
||||
}
|
||||
@ -447,10 +447,9 @@ func (sg *SunGrow) GetPsId() int64 {
|
||||
func fillArray(count int, args []string) []string {
|
||||
var ret []string
|
||||
for range Only.Once {
|
||||
//
|
||||
// if len(args) == 0 {
|
||||
// break
|
||||
// }
|
||||
if count < len(args) {
|
||||
count = len(args)
|
||||
}
|
||||
ret = make([]string, count)
|
||||
for i, e := range args {
|
||||
ret[i] = e
|
||||
|
@ -5,78 +5,12 @@ import (
|
||||
"GoSungrow/iSolarCloud/AppService/queryMutiPointDataList"
|
||||
"GoSungrow/iSolarCloud/WebAppService/queryUserCurveTemplateData"
|
||||
"GoSungrow/iSolarCloud/api"
|
||||
"GoSungrow/iSolarCloud/api/output"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
// type TemplatePoint struct {
|
||||
// Description string
|
||||
// PsKey string
|
||||
// PointId string
|
||||
// Unit string
|
||||
// }
|
||||
// type TemplatePoints []TemplatePoint
|
||||
//
|
||||
//
|
||||
// func (t *TemplatePoints) PrintKeys() string {
|
||||
// var ret string
|
||||
// for _, p := range *t {
|
||||
// ret += fmt.Sprintf("%s,", p.PsKey)
|
||||
// }
|
||||
// ret = strings.TrimSuffix(ret, ",")
|
||||
// return ret
|
||||
// }
|
||||
//
|
||||
// func (t *TemplatePoints) PrintPoints() string {
|
||||
// var ret string
|
||||
// for _, p := range *t {
|
||||
// ret += fmt.Sprintf("%s,", p.PointId)
|
||||
// }
|
||||
// ret = strings.TrimSuffix(ret, ",")
|
||||
// return ret
|
||||
// }
|
||||
//
|
||||
// func (t *TemplatePoints) GetPoint(pskey string, point string) TemplatePoint {
|
||||
// var ret TemplatePoint
|
||||
// for _, k := range *t {
|
||||
// if k.PsKey != pskey {
|
||||
// continue
|
||||
// }
|
||||
// if k.PointId != point {
|
||||
// continue
|
||||
// }
|
||||
// ret = k
|
||||
// break
|
||||
// }
|
||||
// return ret
|
||||
// }
|
||||
//
|
||||
// func CreatePoints(points []string) TemplatePoints {
|
||||
// var ret TemplatePoints
|
||||
// for range Only.Once {
|
||||
// // Feed in a string array and generate points data.
|
||||
// // strings can be either "pskey/point_id", "pskey.point_id", "pskey:point_id",
|
||||
// for _, p := range points {
|
||||
// pa := strings.Split(p, ".")
|
||||
// if len(pa) == 2 {
|
||||
// ret = append(ret, TemplatePoint{
|
||||
// Description: "",
|
||||
// PsKey: pa[0],
|
||||
// PointId: pa[1],
|
||||
// Unit: "",
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return ret
|
||||
// }
|
||||
//
|
||||
// func SetPointName(pskey string, point string) string {
|
||||
// point = strings.TrimPrefix(point, "p")
|
||||
// return pskey + ".p" + point
|
||||
// }
|
||||
|
||||
func (sg *SunGrow) GetPointNamesFromTemplate(template string) api.TemplatePoints {
|
||||
var ret api.TemplatePoints
|
||||
|
||||
@ -111,7 +45,7 @@ func (sg *SunGrow) GetPointNamesFromTemplate(template string) api.TemplatePoints
|
||||
return ret
|
||||
}
|
||||
|
||||
func (sg *SunGrow) GetTemplateData(date string, template string, filter string) error {
|
||||
func (sg *SunGrow) GetTemplateData(template string, date string, filter string) error {
|
||||
for range Only.Once {
|
||||
if template == "" {
|
||||
template = "8042"
|
||||
@ -151,71 +85,58 @@ func (sg *SunGrow) GetTemplateData(date string, template string, filter string)
|
||||
// data := queryMutiPointDataList.AssertResultData(ep)
|
||||
data := queryMutiPointDataList.Assert(ep)
|
||||
table := data.GetDataTable(pointNames)
|
||||
sg.Error = sg.Output(ep, table, filter)
|
||||
if table.Error != nil {
|
||||
sg.Error = table.Error
|
||||
break
|
||||
}
|
||||
|
||||
fn := data.SetFilenamePrefix("%s-%s", when.String(), template)
|
||||
sg.Error = table.SetFilePrefix(fn)
|
||||
if sg.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
//
|
||||
// csv := api.NewCsv()
|
||||
// csv = csv.SetHeader(
|
||||
// "Date/Time",
|
||||
// "PointId Name",
|
||||
// "Point Name",
|
||||
// "Value",
|
||||
// "Units",
|
||||
// )
|
||||
//
|
||||
// for deviceName, deviceRef := range data.Devices {
|
||||
// for pointId, pointRef := range deviceRef.Points {
|
||||
// for _, tim := range pointRef.Times {
|
||||
// gp := pointNames.GetPoint(deviceName, pointId)
|
||||
// csv = csv.AddRow(
|
||||
// tim.Key.PrintFull(),
|
||||
// fmt.Sprintf("%s.%s", deviceName, pointId),
|
||||
// gp.Description,
|
||||
// tim.Value,
|
||||
// gp.Unit,
|
||||
// )
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// switch {
|
||||
// case sg.OutputType.IsNone():
|
||||
//
|
||||
// case sg.OutputType.IsHuman():
|
||||
// table.Print()
|
||||
//
|
||||
// case sg.OutputType.IsGraph():
|
||||
// gr := output.JsonToGraphRequest(filter)
|
||||
// if gr.Error != nil {
|
||||
// sg.Error = gr.Error
|
||||
// break
|
||||
// }
|
||||
// sg.Error = table.WriteGraphFile(gr)
|
||||
// // api.GraphRequest {
|
||||
// // Title: "Testing 1. 2. 3.",
|
||||
// // TimeColumn: 1,
|
||||
// // ValueColumn: 4,
|
||||
// // SearchColumn: 3,
|
||||
// // SearchString: "p83106",
|
||||
// // FileName: "foo.png",
|
||||
// // }
|
||||
//
|
||||
// case sg.OutputType.IsFile():
|
||||
// a := queryMutiPointDataList.Assert(ep)
|
||||
// a.SetFilenamePrefix("%s-%s", when, template)
|
||||
// sg.Error = table.WriteCsvFile()
|
||||
//
|
||||
// case sg.OutputType.IsRaw():
|
||||
// fmt.Println(ep.GetJsonData(true))
|
||||
//
|
||||
// case sg.OutputType.IsJson():
|
||||
// fmt.Println(ep.GetJsonData(false))
|
||||
//
|
||||
// default:
|
||||
// }
|
||||
sg.Error = sg.Output(ep, table, filter)
|
||||
if sg.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return sg.Error
|
||||
}
|
||||
|
||||
func (sg *SunGrow) GetTemplatePoints(template string) error {
|
||||
for range Only.Once {
|
||||
if template == "" {
|
||||
template = "8042"
|
||||
}
|
||||
|
||||
table := output.NewTable()
|
||||
sg.Error = table.SetHeader(
|
||||
"PointId",
|
||||
"Description",
|
||||
"Unit",
|
||||
)
|
||||
if sg.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
ss := sg.GetPointNamesFromTemplate(template)
|
||||
for _, s := range ss {
|
||||
sg.Error = table.AddRow(
|
||||
s.PointId,
|
||||
s.Description,
|
||||
s.Unit,
|
||||
)
|
||||
if sg.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
if sg.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
table.Print()
|
||||
}
|
||||
|
||||
return sg.Error
|
||||
|
Loading…
x
Reference in New Issue
Block a user