mirror of
https://github.com/MickMake/GoSungrow.git
synced 2025-04-01 00:18:23 +02:00
v3.0.0-alpha - graphing fixes
This commit is contained in:
parent
efcc3b1513
commit
73160f9456
1226
.idea/workspace.xml
generated
1226
.idea/workspace.xml
generated
File diff suppressed because it is too large
Load Diff
@ -128,21 +128,21 @@ func (c *CmdInfo) AttachCommand(cmd *cobra.Command) *cobra.Command {
|
||||
cmdInfoCsv.Example = cmdHelp.PrintExamples(cmdInfoCsv, "[area.]<endpoint>")
|
||||
c.AttachCmdInfo(cmdInfoCsv)
|
||||
|
||||
// ********************************************************************************
|
||||
var cmdInfoPut = &cobra.Command{
|
||||
Use: "put",
|
||||
Aliases: []string{"set", "write"},
|
||||
Annotations: map[string]string{"group": "Info"},
|
||||
Short: fmt.Sprintf("Set info on iSolarCloud"),
|
||||
Long: fmt.Sprintf("Set info on iSolarCloud"),
|
||||
DisableFlagParsing: false,
|
||||
DisableFlagsInUseLine: false,
|
||||
PreRunE: cmds.SunGrowArgs,
|
||||
Run: cmds.CmdInfoPut,
|
||||
Args: cobra.ExactArgs(2),
|
||||
}
|
||||
c.SelfCmd.AddCommand(cmdInfoPut)
|
||||
cmdInfoPut.Example = cmdHelp.PrintExamples(cmdInfoPut, "[area.]<endpoint> <value>")
|
||||
// // ********************************************************************************
|
||||
// var cmdInfoPut = &cobra.Command{
|
||||
// Use: "put",
|
||||
// Aliases: []string{"set", "write"},
|
||||
// Annotations: map[string]string{"group": "Info"},
|
||||
// Short: fmt.Sprintf("Set info on iSolarCloud"),
|
||||
// Long: fmt.Sprintf("Set info on iSolarCloud"),
|
||||
// DisableFlagParsing: false,
|
||||
// DisableFlagsInUseLine: false,
|
||||
// PreRunE: cmds.SunGrowArgs,
|
||||
// Run: cmds.CmdInfoPut,
|
||||
// Args: cobra.ExactArgs(2),
|
||||
// }
|
||||
// c.SelfCmd.AddCommand(cmdInfoPut)
|
||||
// cmdInfoPut.Example = cmdHelp.PrintExamples(cmdInfoPut, "[area.]<endpoint> <value>")
|
||||
}
|
||||
return c.SelfCmd
|
||||
}
|
||||
@ -172,14 +172,14 @@ func (c *CmdInfo) AttachCmdInfo(cmd *cobra.Command) *cobra.Command {
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (ca *Cmds) CmdInfoPut(_ *cobra.Command, _ []string) {
|
||||
for range Only.Once {
|
||||
fmt.Println("Not yet implemented.")
|
||||
// ca.Api.SunGrow.OutputType.SetFile()
|
||||
// args = cmdConfig.FillArray(2, args)
|
||||
// c.Error = SunGrow.PutHighLevel(args[0], args[1])
|
||||
}
|
||||
}
|
||||
// func (ca *Cmds) CmdInfoPut(_ *cobra.Command, _ []string) {
|
||||
// for range Only.Once {
|
||||
// fmt.Println("Not yet implemented.")
|
||||
// // ca.Api.SunGrow.OutputType.SetFile()
|
||||
// // args = cmdConfig.FillArray(2, args)
|
||||
// // c.Error = SunGrow.PutHighLevel(args[0], args[1])
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
func (c *CmdInfo) AttachCmdInfoMqtt(cmd *cobra.Command) *cobra.Command {
|
||||
|
@ -31,7 +31,7 @@ type ResultData struct {
|
||||
AlarmCount valueTypes.Count `json:"alarm_count"`
|
||||
DevFaultStatus valueTypes.Integer `json:"dev_fault_status"`
|
||||
DevStatus valueTypes.Integer `json:"dev_status"`
|
||||
DevUpdateTime valueTypes.DateTime `json:"dev_update_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
DevUpdateTime valueTypes.DateTime `json:"dev_update_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
FaultCount valueTypes.Count `json:"fault_count"`
|
||||
InstallerAlarmCount valueTypes.Count `json:"installer_alarm_count"`
|
||||
InstallerDevFaultStatus valueTypes.Integer `json:"installer_dev_fault_status"`
|
||||
@ -61,7 +61,7 @@ type ResultData struct {
|
||||
P81202 interface{} `json:"p81202"`
|
||||
P81203 interface{} `json:"p81203"`
|
||||
PsKey valueTypes.PsKey `json:"ps_key"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
UpdateUser valueTypes.Integer `json:"update_user"`
|
||||
UUID valueTypes.Integer `json:"uuid"`
|
||||
} `json:"device_point_data" DataTable:"true"`
|
||||
|
@ -26,13 +26,13 @@ func (rd RequestData) Help() string {
|
||||
|
||||
type ResultData struct {
|
||||
Echartunit valueTypes.String `json:"echartunit" PointId:"echart_unit"`
|
||||
EndTime valueTypes.DateTime `json:"endTime" PointId:"end_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
EndTime valueTypes.DateTime `json:"endTime" PointId:"end_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
EnergyMap struct {
|
||||
ValStr valueTypes.String `json:"valStr" PointId:"val_str"`
|
||||
} `json:"energyMap" PointId:"energy_map"`
|
||||
Energyunit valueTypes.String `json:"energyunit" PointId:"energy_unit"`
|
||||
PowerMap struct {
|
||||
Dates []valueTypes.DateTime `json:"dates" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
Dates []valueTypes.DateTime `json:"dates" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
Units valueTypes.String `json:"units"`
|
||||
ValStr valueTypes.String `json:"valStr" PointId:"val_str"`
|
||||
} `json:"powerMap" PointId:"power_map"`
|
||||
|
@ -33,8 +33,8 @@ type ResultData struct {
|
||||
ChannelId valueTypes.Integer `json:"chnnl_id" PointId:"channel_id"`
|
||||
ChannelName valueTypes.String `json:"chnnl_name" PointId:"channel_name"`
|
||||
ChannelDesc interface{} `json:"chnnl_desc" PointId:"channel_description"`
|
||||
CreateTime valueTypes.DateTime `json:"create_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UpdateDate valueTypes.DateTime `json:"update_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
CreateTime valueTypes.DateTime `json:"create_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
UpdateDate valueTypes.DateTime `json:"update_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
DataFlag valueTypes.Integer `json:"data_flag"`
|
||||
DataFlagDetail valueTypes.Integer `json:"data_flag_detail"`
|
||||
IsAuto valueTypes.Bool `json:"is_auto"`
|
||||
|
@ -52,7 +52,7 @@ type Device struct {
|
||||
DevFaultStatus valueTypes.Integer `json:"dev_fault_status"`
|
||||
DevStatus valueTypes.Bool `json:"dev_status"`
|
||||
DeviceArea valueTypes.String `json:"device_area"`
|
||||
DeviceFactoryDate valueTypes.DateTime `json:"device_factory_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
DeviceFactoryDate valueTypes.DateTime `json:"device_factory_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
DeviceId valueTypes.Integer `json:"device_id"`
|
||||
DeviceModel valueTypes.String `json:"device_model"`
|
||||
DeviceModelCode valueTypes.String `json:"device_model_code"`
|
||||
|
@ -55,7 +55,7 @@ func (e *ResultData) UnmarshalJSON(data []byte) error {
|
||||
type DataPoint struct {
|
||||
GoStruct.GoStruct `json:"-" PointIdReplace:"true" PointIdFrom:"TimeStamp" PointNameDateFormat:"20060102-150405" PointTimestampFrom:"TimeStamp"`
|
||||
|
||||
TimeStamp valueTypes.DateTime `json:"time_stamp" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
TimeStamp valueTypes.DateTime `json:"time_stamp" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
Points map[string]valueTypes.UnitValue `json:"points"`
|
||||
// P13148 valueTypes.Integer `json:"p13148"`
|
||||
IsPlatformDefaultUnit valueTypes.Bool `json:"is_platform_default_unit"`
|
||||
|
@ -35,25 +35,25 @@ type ResultData struct {
|
||||
CountyAllowanceMoney interface{} `json:"county_allowance_money"`
|
||||
DefaultCharge valueTypes.Float `json:"default_charge"`
|
||||
ElectricChargeId valueTypes.Integer `json:"electric_charge_id"`
|
||||
EndTime valueTypes.DateTime `json:"end_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
EndTime valueTypes.DateTime `json:"end_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
IncomeStyle interface{} `json:"income_style"`
|
||||
IntervalTimeCharge interface{} `json:"interval_time_charge"`
|
||||
NationAllowanceMoney interface{} `json:"nation_allowance_money"`
|
||||
ParamIncomeUnit valueTypes.Integer `json:"param_income_unit"`
|
||||
ProvinceAllowanceMoney interface{} `json:"province_allowance_money"`
|
||||
PsId valueTypes.PsId `json:"ps_id"`
|
||||
StartTime valueTypes.DateTime `json:"start_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
StartTime valueTypes.DateTime `json:"start_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
UseSharpPeekValleyFlat interface{} `json:"use_sharp_peek_valley_flat"`
|
||||
ValidFlag valueTypes.Bool `json:"valid_flag"`
|
||||
} `json:"powerElectricalChargeMap" PointId:"power_electrical_charge_map"`
|
||||
PowerIntervalTimesChargeMap interface{} `json:"powerIntevalTimesChargeMap" PointId:"power_interval_times_charge_map"`
|
||||
PowerSelfUseTimesChargeMap struct {
|
||||
DefaultCharge valueTypes.Float `json:"default_charge"`
|
||||
EndTime valueTypes.DateTime `json:"end_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
EndTime valueTypes.DateTime `json:"end_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
IntervalTimeCharge valueTypes.String `json:"interval_time_charge"`
|
||||
OnlineElectricityPercent valueTypes.Float `json:"online_electricity_percent" PointUnit:"%"`
|
||||
PsId valueTypes.PsId `json:"ps_id"`
|
||||
StartTime valueTypes.DateTime `json:"start_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
StartTime valueTypes.DateTime `json:"start_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
UseElectricityDiscount valueTypes.Float `json:"use_electricity_discount" PointUnit:"%"`
|
||||
} `json:"powerSelfUseTimesChargeMap" PointId:"power_selfuse_times_charge_map"`
|
||||
PsId valueTypes.PsId `json:"ps_id"`
|
||||
|
@ -32,9 +32,9 @@ type ResultData struct {
|
||||
GoStruct GoStruct.GoStruct `json:"-" PointIdReplace:"true" PointIdFrom:"TaskId" PointNameDateFormat:"20060102-150405" PointTimestampFrom:"CreateTime"`
|
||||
|
||||
TaskId valueTypes.Integer `json:"task_id"`
|
||||
CreateTime valueTypes.DateTime `json:"create_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
OverTime valueTypes.DateTime `json:"over_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
CreateTime valueTypes.DateTime `json:"create_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
OverTime valueTypes.DateTime `json:"over_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
ExpireSecond valueTypes.Integer `json:"expire_second"`
|
||||
TaskName valueTypes.String `json:"task_name"`
|
||||
CommandStatus valueTypes.Integer `json:"command_status"`
|
||||
|
@ -39,9 +39,9 @@ type ResultData struct {
|
||||
OperateUserId valueTypes.Integer `json:"operate_user_id"`
|
||||
CommandStatus valueTypes.Integer `json:"command_status"`
|
||||
CommandType valueTypes.Integer `json:"command_type"`
|
||||
CreateTime valueTypes.DateTime `json:"create_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
OverTime valueTypes.DateTime `json:"over_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
CreateTime valueTypes.DateTime `json:"create_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
OverTime valueTypes.DateTime `json:"over_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
SetCancelNum valueTypes.Count `json:"set_cancel_num"`
|
||||
SetFailNum valueTypes.Count `json:"set_fail_num"`
|
||||
SetFinishNum valueTypes.Count `json:"set_finish_num"`
|
||||
|
@ -33,7 +33,7 @@ type ResultData struct {
|
||||
DesignCapacity valueTypes.Float `json:"design_capacity"`
|
||||
Email valueTypes.String `json:"email"`
|
||||
EnergyScheme interface{} `json:"energy_scheme"`
|
||||
ExpectInstallDate valueTypes.DateTime `json:"expect_install_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
ExpectInstallDate valueTypes.DateTime `json:"expect_install_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
FaultSendType interface{} `json:"fault_send_type"`
|
||||
GcjLatitude valueTypes.Float `json:"gcj_latitude"`
|
||||
GcjLongitude valueTypes.Float `json:"gcj_longitude"`
|
||||
@ -46,7 +46,7 @@ type ResultData struct {
|
||||
ParamIncome valueTypes.Float `json:"param_income"`
|
||||
Prov interface{} `json:"prov"`
|
||||
ProvCode interface{} `json:"prov_code"`
|
||||
PsBuildDate valueTypes.DateTime `json:"ps_build_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
PsBuildDate valueTypes.DateTime `json:"ps_build_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
PsCountryId valueTypes.Integer `json:"ps_country_id"`
|
||||
PsDesc interface{} `json:"ps_desc"`
|
||||
PsHolder valueTypes.String `json:"ps_holder"`
|
||||
|
@ -55,14 +55,14 @@ type ResultData struct {
|
||||
DivisionCode valueTypes.String `json:"division_code"`
|
||||
Email valueTypes.String `json:"email"`
|
||||
EnergyScheme interface{} `json:"energy_scheme"`
|
||||
ExpectInstallDate valueTypes.DateTime `json:"expect_install_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
ExpectInstallDate valueTypes.DateTime `json:"expect_install_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
GcjLatitude valueTypes.Float `json:"gcj_latitude"`
|
||||
GcjLongitude valueTypes.Float `json:"gcj_longitude"`
|
||||
GprsLatitude valueTypes.Float `json:"gprs_latitude"`
|
||||
GprsLongitude valueTypes.Float `json:"gprs_longitude"`
|
||||
GridLevel interface{} `json:"grid_level"`
|
||||
InstallDate valueTypes.DateTime `json:"install_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
InstallDateZone valueTypes.DateTime `json:"install_date_zone" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
InstallDate valueTypes.DateTime `json:"install_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
InstallDateZone valueTypes.DateTime `json:"install_date_zone" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
InverterCount valueTypes.Integer `json:"inverter_count"`
|
||||
InvestmentType valueTypes.Integer `json:"investment_type"`
|
||||
InvestmentTypeDesc valueTypes.String `json:"investment_type_desc"`
|
||||
@ -92,7 +92,7 @@ type ResultData struct {
|
||||
ParamIncomeUnitName valueTypes.String `json:"param_income_unit_name"`
|
||||
ProvinceCode valueTypes.String `json:"province_code"`
|
||||
ProvinceName valueTypes.String `json:"province_name"`
|
||||
PsBuildDate valueTypes.DateTime `json:"ps_build_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
PsBuildDate valueTypes.DateTime `json:"ps_build_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
PsCountryId valueTypes.Integer `json:"ps_country_id"`
|
||||
PsCreateUserId valueTypes.Integer `json:"ps_create_user_id"`
|
||||
PsCurrentTimeZone valueTypes.String `json:"ps_current_time_zone"`
|
||||
@ -108,8 +108,8 @@ type ResultData struct {
|
||||
PsTypeDesc valueTypes.String `json:"ps_type_desc"`
|
||||
PsTypeName valueTypes.String `json:"ps_type_name"`
|
||||
PsUserId valueTypes.Integer `json:"ps_user_id"`
|
||||
RecordCreateTime valueTypes.DateTime `json:"recore_create_time" PointId:"record_create_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
SafeStartDate valueTypes.DateTime `json:"safe_start_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
RecordCreateTime valueTypes.DateTime `json:"recore_create_time" PointId:"record_create_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
SafeStartDate valueTypes.DateTime `json:"safe_start_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
SetUserOrg valueTypes.Integer `json:"set_user_org"`
|
||||
ShareType valueTypes.Integer `json:"share_type"`
|
||||
ShareUserType interface{} `json:"share_user_type"`
|
||||
|
@ -39,7 +39,7 @@ type ResultData struct {
|
||||
DesignCapacity valueTypes.Float `json:"design_capacity" PointUnit:"W"`
|
||||
Email valueTypes.String `json:"email"`
|
||||
EnergyScheme Common.Unknown `json:"energy_scheme"`
|
||||
ExpectInstallDate valueTypes.DateTime `json:"expect_install_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
ExpectInstallDate valueTypes.DateTime `json:"expect_install_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
FaultSendType Common.Unknown `json:"fault_send_type"`
|
||||
GcjLatitude valueTypes.Float `json:"gcj_latitude"`
|
||||
GcjLongitude valueTypes.Float `json:"gcj_longitude"`
|
||||
@ -52,7 +52,7 @@ type ResultData struct {
|
||||
ParamIncome valueTypes.Float `json:"param_income"`
|
||||
Prov Common.Unknown `json:"prov"`
|
||||
ProvCode Common.Unknown `json:"prov_code"`
|
||||
PsBuildDate valueTypes.DateTime `json:"ps_build_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
PsBuildDate valueTypes.DateTime `json:"ps_build_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
PsCountryId valueTypes.Integer `json:"ps_country_id"`
|
||||
PsDesc Common.Unknown `json:"ps_desc"`
|
||||
PsHolder valueTypes.String `json:"ps_holder"`
|
||||
@ -60,7 +60,7 @@ type ResultData struct {
|
||||
PsLocation valueTypes.String `json:"ps_location"`
|
||||
PsName valueTypes.String `json:"ps_name"`
|
||||
PsType valueTypes.Integer `json:"ps_type"`
|
||||
RecordCreateTime valueTypes.DateTime `json:"recore_create_time" PointId:"record_create_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
RecordCreateTime valueTypes.DateTime `json:"recore_create_time" PointId:"record_create_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
ReportType Common.Unknown `json:"report_type"`
|
||||
ShippingAddress valueTypes.String `json:"shipping_address"`
|
||||
ShippingZipCode valueTypes.String `json:"shipping_zip_code"`
|
||||
@ -85,10 +85,10 @@ type ResultData struct {
|
||||
CodeType valueTypes.Integer `json:"code_type"`
|
||||
DefaultCharge valueTypes.Float `json:"default_charge"`
|
||||
ElectricChargeId valueTypes.Integer `json:"electric_charge_id"`
|
||||
EndTime valueTypes.DateTime `json:"end_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
EndTime valueTypes.DateTime `json:"end_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
IntervalTimeCharge Common.Unknown `json:"interval_time_charge"`
|
||||
ParamIncomeUnitName valueTypes.String `json:"param_income_unit_name"`
|
||||
StartTime valueTypes.DateTime `json:"start_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
StartTime valueTypes.DateTime `json:"start_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
} `json:"powerChargeDataMap" PointId:"power_charge_data_map"`
|
||||
|
||||
SysTimeZones []struct {
|
||||
|
@ -29,12 +29,12 @@ type ResultData struct {
|
||||
ActualEnergy []valueTypes.Float `json:"actual_energy" PointId:"actual_energy" PointName:"Actual Energy" PointUnitFrom:"ActualEnergyUnit" PointArrayFlatten:"true"`
|
||||
PlanEnergy []valueTypes.Float `json:"plan_energy" PointUnitFrom:"PlanEnergyUnit" PointArrayFlatten:"true"`
|
||||
|
||||
BuildDate valueTypes.DateTime `json:"build_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
DataLastUpdateTime valueTypes.DateTime `json:"data_last_update_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
ExpectInstallDate valueTypes.DateTime `json:"expect_install_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
InstallDate valueTypes.DateTime `json:"install_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
RecordCreateTime valueTypes.DateTime `json:"recore_create_time" PointId:"record_create_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
SafeStartDate valueTypes.DateTime `json:"safe_start_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
BuildDate valueTypes.DateTime `json:"build_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
DataLastUpdateTime valueTypes.DateTime `json:"data_last_update_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
ExpectInstallDate valueTypes.DateTime `json:"expect_install_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
InstallDate valueTypes.DateTime `json:"install_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
RecordCreateTime valueTypes.DateTime `json:"recore_create_time" PointId:"record_create_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
SafeStartDate valueTypes.DateTime `json:"safe_start_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
ActualEnergyUnit valueTypes.String `json:"actual_energy_unit" PointId:"actual_energy_unit" PointIgnore:"true"`
|
||||
AlarmCount valueTypes.Count `json:"alarm_count"`
|
||||
AreaId interface{} `json:"area_id"`
|
||||
@ -218,7 +218,7 @@ type ResultData struct {
|
||||
StorageInverterData []struct {
|
||||
GoStruct GoStruct.GoStruct `json:"-" PointIdReplace:"true" PointIdFrom:"PsKey" PointDeviceFrom:"PsKey"`
|
||||
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
PsKey valueTypes.PsKey `json:"ps_key"`
|
||||
CommunicationDevSn valueTypes.String `json:"communication_dev_sn"`
|
||||
DevFaultStatus valueTypes.Integer `json:"dev_fault_status"`
|
||||
|
@ -52,9 +52,9 @@ type ResultData struct {
|
||||
// AreaId valueTypes.String `json:"area_id"`
|
||||
// AreaType valueTypes.Integer `json:"area_type"`
|
||||
// ArrearsStatus valueTypes.Integer `json:"arrears_status"`
|
||||
// BuildDate valueTypes.DateTime `json:"build_date" PointUpdateFreq:"UpdateFreqBoot" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
// ExpectInstallDate valueTypes.DateTime `json:"expect_install_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
// InstallDate valueTypes.DateTime `json:"install_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
// BuildDate valueTypes.DateTime `json:"build_date" PointUpdateFreq:"UpdateFreqBoot" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
// ExpectInstallDate valueTypes.DateTime `json:"expect_install_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
// InstallDate valueTypes.DateTime `json:"install_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
// BuildStatus valueTypes.Integer `json:"build_status" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
// Co2Reduce valueTypes.UnitValue `json:"co2_reduce"`
|
||||
// Co2ReduceTotal valueTypes.UnitValue `json:"co2_reduce_total" PointUpdateFreq:"UpdateFreqTotal"`
|
||||
@ -93,8 +93,8 @@ type ResultData struct {
|
||||
// OwnerFaultCount valueTypes.Count `json:"owner_fault_count"`
|
||||
// OwnerPsFaultStatus valueTypes.Integer `json:"owner_ps_fault_status"`
|
||||
// Producer valueTypes.String `json:"producer"`
|
||||
// RecordCreateTime valueTypes.DateTime `json:"recore_create_time" PointId:"record_create_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
// SafeStartDate valueTypes.DateTime `json:"safe_start_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
// RecordCreateTime valueTypes.DateTime `json:"recore_create_time" PointId:"record_create_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
// SafeStartDate valueTypes.DateTime `json:"safe_start_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
// ShareType valueTypes.Integer `json:"share_type"`
|
||||
// ShippingAddress valueTypes.String `json:"shipping_address"`
|
||||
// ShippingZipCode valueTypes.String `json:"shipping_zip_code"`
|
||||
|
@ -38,7 +38,7 @@ type ResultData struct {
|
||||
DesignCapacity valueTypes.Float `json:"design_capacity" PointUnit:"W"`
|
||||
GprsLatitude valueTypes.Float `json:"gprs_latitude"`
|
||||
GprsLongitude valueTypes.Float `json:"gprs_longitude"`
|
||||
InstallDate valueTypes.DateTime `json:"install_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
InstallDate valueTypes.DateTime `json:"install_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
InstallerPsFaultStatus valueTypes.Integer `json:"installer_ps_fault_status"`
|
||||
Latitude valueTypes.Float `json:"latitude"`
|
||||
Location valueTypes.String `json:"location"`
|
||||
|
@ -58,7 +58,7 @@ type ResultData struct {
|
||||
}
|
||||
|
||||
type TotalData struct {
|
||||
MinDateId valueTypes.DateTime `json:"min_date_id" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
MinDateId valueTypes.DateTime `json:"min_date_id" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
|
||||
Co2Reduce valueTypes.Float `json:"co2_reduce" PointUnitFrom:"Co2ReduceOriginalUnit"`
|
||||
Co2ReduceMap valueTypes.UnitValue `json:"co2_reduce_map"`
|
||||
|
@ -29,7 +29,7 @@ type ResultData struct {
|
||||
BloodType valueTypes.String `json:"blood_type"`
|
||||
CountryId valueTypes.Integer `json:"country_id"`
|
||||
CountryName valueTypes.String `json:"country_name"`
|
||||
CreateDate valueTypes.DateTime `json:"create_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
CreateDate valueTypes.DateTime `json:"create_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
CreateUserId valueTypes.Integer `json:"create_user_id"`
|
||||
DiseaseHis valueTypes.String `json:"disease_his"`
|
||||
Email valueTypes.String `json:"email"`
|
||||
|
@ -28,7 +28,7 @@ type ResultData struct {
|
||||
WeatherList []struct {
|
||||
GoStruct GoStruct.GoStruct `json:"-" PointIdReplace:"true" PointIdFrom:"DateTime" PointNameDateFormat:"20060102" PointTimestampFrom:"DateTime"`
|
||||
|
||||
DateTime valueTypes.DateTime `json:"date_time" PointNameDateFormat:"2006/01/02"`
|
||||
DateTime valueTypes.DateTime `json:"date_time" PointNameDateFormat:"2006-01-02"`
|
||||
PsId valueTypes.PsId `json:"ps_id"`
|
||||
|
||||
Chill valueTypes.Float `json:"chill"`
|
||||
|
@ -39,7 +39,7 @@ type DataList struct {
|
||||
DateId valueTypes.DateTime `json:"date_id" PointTimestampFrom:"UpdateTime" PointNameDateFormat:"20060102"`
|
||||
PsId valueTypes.PsId `json:"ps_id" PointTimestampFrom:"UpdateTime"`
|
||||
TimeStamp valueTypes.Generic `json:"time_stamp" PointTimestampFrom:"UpdateTime"` // Sad that this alternates between string and valueTypes.Integer.
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointTimestampFrom:"UpdateTime" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointTimestampFrom:"UpdateTime" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
DeviceName interface{} `json:"device_name" PointTimestampFrom:"UpdateTime"`
|
||||
UUID interface{} `json:"uuid" PointTimestampFrom:"UpdateTime"`
|
||||
Co2Reduce valueTypes.Float `json:"co2_reduce" PointTimestampFrom:"UpdateTime"`
|
||||
|
@ -29,23 +29,23 @@ type ResultData struct {
|
||||
ReportEmailConfigInfoList []struct {
|
||||
Email valueTypes.String `json:"email"`
|
||||
ReportList []struct {
|
||||
CreateTime valueTypes.DateTime `json:"create_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
CreateTime valueTypes.DateTime `json:"create_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
CreateUserId valueTypes.Integer `json:"create_user_id"`
|
||||
EmailAddTime valueTypes.DateTime `json:"email_add_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
EmailAddTime valueTypes.DateTime `json:"email_add_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
Id valueTypes.Integer `json:"id"`
|
||||
IsAllowEmailSend valueTypes.Bool `json:"is_allow_email_send"`
|
||||
IsBank valueTypes.Bool `json:"is_bank"`
|
||||
IsCanRenewSendConfirmEmail valueTypes.Bool `json:"is_can_renew_send_confirm_email"`
|
||||
IsNewWeb valueTypes.Bool `json:"is_new_web"`
|
||||
OrderId valueTypes.Integer `json:"order_id"`
|
||||
ReSendConfirmEmailTime valueTypes.DateTime `json:"re_send_confirm_email_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
ReSendConfirmEmailTime valueTypes.DateTime `json:"re_send_confirm_email_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
ReportId valueTypes.Integer `json:"report_id"`
|
||||
ReportName valueTypes.String `json:"report_name"`
|
||||
SendEmail valueTypes.String `json:"send_email"`
|
||||
Status valueTypes.Bool `json:"status"`
|
||||
TimeDimension valueTypes.Integer `json:"time_dimension"`
|
||||
Type valueTypes.Integer `json:"type"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
UserId valueTypes.Integer `json:"user_id"`
|
||||
} `json:"report_list" DataTable:"true"`
|
||||
} `json:"report_email_config_info_list"`
|
||||
|
@ -28,10 +28,10 @@ type ResultData []struct {
|
||||
GoStructParent GoStruct.GoStructParent `json:"-" DataTable:"true" DataTableSortOn:"CreateTime" PointIdReplace:"false"`
|
||||
|
||||
MsgId valueTypes.Integer `json:"msg_id"`
|
||||
CreateTime valueTypes.DateTime `json:"create_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
PublishTime valueTypes.DateTime `json:"publish_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
StartTime valueTypes.DateTime `json:"start_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
EndTime valueTypes.DateTime `json:"end_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
CreateTime valueTypes.DateTime `json:"create_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
PublishTime valueTypes.DateTime `json:"publish_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
StartTime valueTypes.DateTime `json:"start_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
EndTime valueTypes.DateTime `json:"end_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
Ispublish valueTypes.Bool `json:"ispublish" PointId:"is_publish"`
|
||||
UserName valueTypes.String `json:"user_name"`
|
||||
UserId valueTypes.Integer `json:"user_id"`
|
||||
|
@ -31,7 +31,7 @@ type ResultData struct {
|
||||
type Template struct {
|
||||
TemplateId valueTypes.Integer `json:"template_id"`
|
||||
TemplateName valueTypes.String `json:"template_name"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
}
|
||||
|
||||
func (e *ResultData) IsValid() error {
|
||||
|
@ -65,15 +65,15 @@ type ResultData struct {
|
||||
Isdst valueTypes.Bool `json:"isdst"`
|
||||
Jobs interface{} `json:"jobs"`
|
||||
Language string `json:"language"`
|
||||
LoginFirstDate valueTypes.DateTime `json:"loginFirstDate" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
LoginFirstDate2 valueTypes.DateTime `json:"loginFristDate" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
LoginLastDate valueTypes.DateTime `json:"loginLastDate" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
LoginFirstDate valueTypes.DateTime `json:"loginFirstDate" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
LoginFirstDate2 valueTypes.DateTime `json:"loginFristDate" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
LoginLastDate valueTypes.DateTime `json:"loginLastDate" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
LoginLastIP string `json:"loginLastIp"`
|
||||
LoginTimes valueTypes.Integer `json:"loginTimes"`
|
||||
Logo interface{} `json:"logo"`
|
||||
LogoHTTPSURL interface{} `json:"logo_https_url"`
|
||||
MapType string `json:"map_type"`
|
||||
MinDate valueTypes.DateTime `json:"min_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
MinDate valueTypes.DateTime `json:"min_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
MobileTel interface{} `json:"mobile_tel"`
|
||||
OrgId string `json:"org_id"`
|
||||
OrgName string `json:"org_name"`
|
||||
|
@ -27,7 +27,7 @@ func (rd RequestData) Help() string {
|
||||
type ResultData struct {
|
||||
CurrentPage valueTypes.Integer `json:"currentPage" PointIgnore:"true"`
|
||||
PageDataList []struct {
|
||||
CreateTime valueTypes.DateTime `json:"create_time" PointIgnore:"true" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
CreateTime valueTypes.DateTime `json:"create_time" PointIgnore:"true" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
DeviceType valueTypes.Integer `json:"device_type"`
|
||||
Id valueTypes.Integer `json:"id"`
|
||||
Period valueTypes.Integer `json:"period"` // 0, 1, 2, 3, 4
|
||||
|
@ -30,7 +30,7 @@ type ResultData struct {
|
||||
AreaForecastList []struct {
|
||||
GoStruct GoStruct.GoStruct `json:"-" PointIdReplace:"true" PointIdFrom:"DateTime" PointNameDateFormat:"20060102" PointTimestampFrom:"DateTime"`
|
||||
|
||||
DateTime valueTypes.DateTime `json:"date_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
DateTime valueTypes.DateTime `json:"date_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
|
||||
City valueTypes.String `json:"city"`
|
||||
Chill valueTypes.Float `json:"chill"`
|
||||
|
@ -148,7 +148,7 @@ type PointStruct struct {
|
||||
GoStruct GoStruct.GoStruct `json:"-" PointIdFrom:"PointId" PointIdReplace:"true" PointTimestampFrom:"TimeStamp" PointDeviceFromParent:"PsKey"`
|
||||
// GoStruct GoStruct.GoStruct `json:"-" PointDeviceFromParent:"PsKey"`
|
||||
|
||||
TimeStamp valueTypes.DateTime `json:"time_stamp" PointUpdateFreq:"UpdateFreq5Mins" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
TimeStamp valueTypes.DateTime `json:"time_stamp" PointUpdateFreq:"UpdateFreq5Mins" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
PointId valueTypes.PointId `json:"point_id" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
PointGroupName valueTypes.String `json:"point_group_name" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
PointName valueTypes.String `json:"point_name" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
@ -160,7 +160,7 @@ type PointStruct struct {
|
||||
CodeId valueTypes.Integer `json:"code_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
CodeIdOrderId valueTypes.String `json:"code_id_order_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
CodeName valueTypes.String `json:"code_name" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
DevPointLastUpdateTime valueTypes.DateTime `json:"dev_point_last_update_time" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreq5Mins" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
DevPointLastUpdateTime valueTypes.DateTime `json:"dev_point_last_update_time" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreq5Mins" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
IsPlatformDefaultUnit valueTypes.Bool `json:"is_platform_default_unit" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
IsShow valueTypes.Bool `json:"is_show" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
OrderId valueTypes.Integer `json:"order_id" PointGroupNameFrom:"PointGroupName" PointTimestampFrom:"TimeStamp" PointUpdateFreq:"UpdateFreqBoot"`
|
||||
|
@ -46,7 +46,7 @@ type ResultData struct {
|
||||
DevFaultStatus valueTypes.Integer `json:"dev_fault_status"`
|
||||
DevStatus valueTypes.Bool `json:"dev_status"`
|
||||
DeviceArea valueTypes.String `json:"device_area"`
|
||||
DeviceFactoryDate valueTypes.DateTime `json:"device_factory_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
DeviceFactoryDate valueTypes.DateTime `json:"device_factory_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
DeviceId valueTypes.Integer `json:"device_id"`
|
||||
DeviceModel valueTypes.String `json:"device_model"`
|
||||
DeviceModelCode valueTypes.String `json:"device_model_code"`
|
||||
|
@ -58,7 +58,7 @@ func (e *ResultData) UnmarshalJSON(data []byte) error {
|
||||
type DataPoint struct {
|
||||
GoStruct.GoStructParent `json:"-" PointIdReplace:"true" PointIdFrom:"TimeStamp" PointNameDateFormat:"20060102-150405" PointTimestampFrom:"TimeStamp"`
|
||||
|
||||
TimeStamp valueTypes.DateTime `json:"time_stamp" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
TimeStamp valueTypes.DateTime `json:"time_stamp" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
Points map[string]valueTypes.UnitValue `json:"points"`
|
||||
IsPlatformDefaultUnit valueTypes.Bool `json:"is_platform_default_unit"`
|
||||
}
|
||||
|
@ -30,10 +30,10 @@ type ResultData struct {
|
||||
FileName valueTypes.String `json:"file_name"`
|
||||
FileSize valueTypes.Integer `json:"file_size"`
|
||||
FileType valueTypes.Integer `json:"file_type"`
|
||||
UploadTime valueTypes.DateTime `json:"upload_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UploadTime valueTypes.DateTime `json:"upload_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
URL valueTypes.String `json:"url"`
|
||||
Operation valueTypes.Integer `json:"operation"`
|
||||
OperationTime valueTypes.DateTime `json:"operation_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
OperationTime valueTypes.DateTime `json:"operation_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
OperatorId valueTypes.String `json:"operator_id"`
|
||||
OperatorName valueTypes.String `json:"operator_name"`
|
||||
System valueTypes.String `json:"system"`
|
||||
|
@ -42,7 +42,7 @@ type Value struct {
|
||||
GoStructParent GoStruct.GoStructParent `json:"-" PointIdFrom:"PsKey.Timestamp" PointIdReplace:"true"`
|
||||
// GoStruct GoStruct.GoStruct `json:"-" PointIdFrom:"PsKey" PointIdReplace:"false" PointDeviceFrom:"PsKey"`
|
||||
|
||||
Timestamp valueTypes.DateTime `json:"timestamp" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
Timestamp valueTypes.DateTime `json:"timestamp" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
PsKey valueTypes.PsKey `json:"ps_key"`
|
||||
Points map[string]valueTypes.Generic `json:"points" PointDeviceFrom:"PsKey"`
|
||||
}
|
||||
@ -301,5 +301,18 @@ func (e *EndPoint) GetData() api.DataMap {
|
||||
entries := api.NewDataMap()
|
||||
// entries.StructToDataMap(*e, e.Request.PsId.String(), GoStruct.NewEndPointPath(e.Request.PsId.String()))
|
||||
entries.StructToDataMap(*e, e.Request.PsId.String(), GoStruct.EndPointPath{})
|
||||
|
||||
// table.InitGraph(output.GraphRequest {
|
||||
// Title: "",
|
||||
// TimeColumn: output.SetString("Date/Time"),
|
||||
// SearchColumn: output.SetString("Point Id"),
|
||||
// NameColumn: output.SetString("Point Name"),
|
||||
// ValueColumn: output.SetString("Value"),
|
||||
// UnitsColumn: output.SetString("Units"),
|
||||
// SearchString: output.SetString(""),
|
||||
// MinLeftAxis: output.SetFloat(0),
|
||||
// MaxLeftAxis: output.SetFloat(0),
|
||||
// })
|
||||
|
||||
return entries
|
||||
}
|
||||
|
@ -56,14 +56,14 @@ type ResultData struct {
|
||||
DivisionCode valueTypes.String `json:"division_code"`
|
||||
Email valueTypes.String `json:"email"`
|
||||
EnergyScheme interface{} `json:"energy_scheme"`
|
||||
ExpectInstallDate valueTypes.DateTime `json:"expect_install_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
ExpectInstallDate valueTypes.DateTime `json:"expect_install_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
GcjLatitude valueTypes.Float `json:"gcj_latitude"`
|
||||
GcjLongitude valueTypes.Float `json:"gcj_longitude"`
|
||||
GprsLatitude valueTypes.Float `json:"gprs_latitude"`
|
||||
GprsLongitude valueTypes.Float `json:"gprs_longitude"`
|
||||
GridLevel interface{} `json:"grid_level"`
|
||||
InstallDate valueTypes.DateTime `json:"install_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
InstallDateZone valueTypes.DateTime `json:"install_date_zone" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
InstallDate valueTypes.DateTime `json:"install_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
InstallDateZone valueTypes.DateTime `json:"install_date_zone" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
InverterCount valueTypes.Integer `json:"inverter_count"`
|
||||
InvestmentType valueTypes.Integer `json:"investment_type"`
|
||||
InvestmentTypeDesc valueTypes.String `json:"investment_type_desc"`
|
||||
@ -93,7 +93,7 @@ type ResultData struct {
|
||||
ParamIncomeUnitName valueTypes.String `json:"param_income_unit_name"`
|
||||
ProvinceCode valueTypes.String `json:"province_code"`
|
||||
ProvinceName valueTypes.String `json:"province_name"`
|
||||
PsBuildDate valueTypes.DateTime `json:"ps_build_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
PsBuildDate valueTypes.DateTime `json:"ps_build_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
PsCountryId valueTypes.Integer `json:"ps_country_id"`
|
||||
PsCreateUserId valueTypes.Integer `json:"ps_create_user_id"`
|
||||
PsCurrentTimeZone valueTypes.String `json:"ps_current_time_zone"`
|
||||
@ -109,8 +109,8 @@ type ResultData struct {
|
||||
PsTypeDesc valueTypes.String `json:"ps_type_desc"`
|
||||
PsTypeName valueTypes.String `json:"ps_type_name"`
|
||||
PsUserId valueTypes.Integer `json:"ps_user_id"`
|
||||
RecordCreateTime valueTypes.DateTime `json:"recore_create_time" PointId:"record_create_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
SafeStartDate valueTypes.DateTime `json:"safe_start_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
RecordCreateTime valueTypes.DateTime `json:"recore_create_time" PointId:"record_create_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
SafeStartDate valueTypes.DateTime `json:"safe_start_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
SetUserOrg valueTypes.Integer `json:"set_user_org"`
|
||||
ShareType valueTypes.Integer `json:"share_type"`
|
||||
ShareUserType interface{} `json:"share_user_type"`
|
||||
|
@ -33,8 +33,8 @@ type ResultData struct {
|
||||
ActualList []struct {
|
||||
GoStruct GoStruct.GoStruct `json:"-" PointIdReplace:"true" PointIdFrom:"DateId" PointNameDateFormat:"20060102" PointTimestampFrom:"UpdateTime"`
|
||||
|
||||
DateId valueTypes.DateTime `json:"date_id" PointNameDateFormat:"2006/01/02" PointTimestampFrom:"UpdateTime"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
DateId valueTypes.DateTime `json:"date_id" PointNameDateFormat:"2006-01-02" PointTimestampFrom:"UpdateTime"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
|
||||
NetPowerProfit valueTypes.Float `json:"net_power_profit" PointTimestampFrom:"UpdateTime"`
|
||||
SubsidyProfit interface{} `json:"subsidy_profit" PointTimestampFrom:"UpdateTime"`
|
||||
|
@ -45,7 +45,7 @@ type DataList struct {
|
||||
DateId valueTypes.DateTime `json:"date_id" PointTimestampFrom:"UpdateTime" PointNameDateFormat:"20060102"`
|
||||
PsId valueTypes.PsId `json:"ps_id" PointTimestampFrom:"UpdateTime"`
|
||||
TimeStamp valueTypes.Generic `json:"time_stamp" PointTimestampFrom:"UpdateTime"` // Sad that this alternates between string and valueTypes.Integer.
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointTimestampFrom:"UpdateTime" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointTimestampFrom:"UpdateTime" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
DeviceName interface{} `json:"device_name" PointTimestampFrom:"UpdateTime"`
|
||||
UUID interface{} `json:"uuid" PointTimestampFrom:"UpdateTime"`
|
||||
Co2Reduce valueTypes.Float `json:"co2_reduce" PointTimestampFrom:"UpdateTime"`
|
||||
|
@ -33,7 +33,7 @@ type ResultData []struct {
|
||||
ArrearsStatus valueTypes.Integer `json:"arrears_status"`
|
||||
DesignCapacity valueTypes.Float `json:"design_capacity" PointUnitFrom:"DesignCapacityUnit"`
|
||||
DesignCapacityUnit valueTypes.String `json:"design_capacity_unit" PointIgnore:"true"`
|
||||
InstallDate valueTypes.DateTime `json:"install_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
InstallDate valueTypes.DateTime `json:"install_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
PsCode valueTypes.String `json:"ps_code"`
|
||||
PsCountryId valueTypes.Integer `json:"ps_country_id"`
|
||||
PsLocation valueTypes.String `json:"ps_location"`
|
||||
|
@ -36,7 +36,7 @@ type ResultData []struct {
|
||||
PsStatus valueTypes.Integer `json:"ps_status"`
|
||||
PsType valueTypes.Integer `json:"ps_type"`
|
||||
State valueTypes.Bool `json:"state"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
PsFaultStatus valueTypes.Integer `json:"ps_fault_status"`
|
||||
|
||||
ArrearsStatus valueTypes.Integer `json:"arrears_status"`
|
||||
@ -45,7 +45,7 @@ type ResultData []struct {
|
||||
Value valueTypes.Float `json:"value" PointUnitFrom:"Unit"`
|
||||
} `json:"design_capacity"`
|
||||
DesignCapacityOriginal valueTypes.Float `json:"design_capacity_original"`
|
||||
DeviceStatusUpdateTime valueTypes.DateTime `json:"device_status_update_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
DeviceStatusUpdateTime valueTypes.DateTime `json:"device_status_update_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
EquivalentHour valueTypes.Integer `json:"equivalent_hour"`
|
||||
GcjLatitude valueTypes.Float `json:"gcj_latitude"`
|
||||
GcjLongitude valueTypes.Float `json:"gcj_longitude"`
|
||||
|
@ -28,7 +28,7 @@ func (rd RequestData) Help() string {
|
||||
type ResultData []struct {
|
||||
GoStructParent GoStruct.GoStructParent `json:"GoStruct" DataTable:"true" DataTableSortOn:"CreateTime"`
|
||||
|
||||
CreateTime valueTypes.DateTime `json:"create_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
CreateTime valueTypes.DateTime `json:"create_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
Cycle valueTypes.Integer `json:"cycle"`
|
||||
ID valueTypes.Integer `json:"id"`
|
||||
MonthDate valueTypes.String `json:"month_date"`
|
||||
@ -36,7 +36,7 @@ type ResultData []struct {
|
||||
ReportName valueTypes.String `json:"report_name"`
|
||||
ReportType valueTypes.Integer `json:"report_type"`
|
||||
Status valueTypes.Bool `json:"status"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
}
|
||||
|
||||
func (e *ResultData) IsValid() error {
|
||||
|
@ -37,11 +37,11 @@ func (rd RequestData) Help() string {
|
||||
|
||||
// ResultData (struct) -> PointsData(struct) -> Devices(map[string]DeviceData) -> Points(map[string]Point)
|
||||
type ResultData struct {
|
||||
CreateTime valueTypes.DateTime `json:"create_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
OpenTime valueTypes.DateTime `json:"open_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
StartTime valueTypes.DateTime `json:"start_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
EndTime valueTypes.DateTime `json:"end_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
CreateTime valueTypes.DateTime `json:"create_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
OpenTime valueTypes.DateTime `json:"open_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
UpdateTime valueTypes.DateTime `json:"update_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
StartTime valueTypes.DateTime `json:"start_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
EndTime valueTypes.DateTime `json:"end_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
DateType valueTypes.Integer `json:"date_type"`
|
||||
Cycle valueTypes.Integer `json:"cycle"`
|
||||
TemplateId valueTypes.Integer `json:"template_id"`
|
||||
|
@ -40,7 +40,7 @@ type ResultData struct {
|
||||
Remark valueTypes.String `json:"remark"`
|
||||
SysId valueTypes.String `json:"sys_id"`
|
||||
SysType valueTypes.String `json:"sys_type"`
|
||||
UpdateDate valueTypes.DateTime `json:"updatedate" PointId:"update_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UpdateDate valueTypes.DateTime `json:"updatedate" PointId:"update_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
UpdateUserCode valueTypes.Bool `json:"updateusercode" PointId:"update_user_code"`
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ func (rd RequestData) Help() string {
|
||||
type ResultData []struct {
|
||||
GoStructParent GoStruct.GoStructParent `json:"-" DataTable:"true" DataTableSortOn:"DeploymentTime"`
|
||||
|
||||
DeploymentTime valueTypes.DateTime `json:"deploymentTime" PointId:"deployment_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
DeploymentTime valueTypes.DateTime `json:"deploymentTime" PointId:"deployment_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
Id valueTypes.String `json:"id"`
|
||||
Name valueTypes.String `json:"name"`
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ type ResultData struct {
|
||||
Phone valueTypes.String `json:"phone"`
|
||||
Protocol valueTypes.String `json:"protocol"`
|
||||
Remark valueTypes.String `json:"remark"`
|
||||
UpdateDate valueTypes.DateTime `json:"updatedate" PointId:"update_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UpdateDate valueTypes.DateTime `json:"updatedate" PointId:"update_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
UpdateUserCode valueTypes.Bool `json:"updateusercode" PointId:"update_user_code"`
|
||||
} `json:"powerDeviceModel"`
|
||||
SysTypeList []struct {
|
||||
@ -101,7 +101,7 @@ type ResultData struct {
|
||||
SysId valueTypes.String `json:"sys_id"`
|
||||
SysName valueTypes.String `json:"sys_name"`
|
||||
IsRemoteUpgrade valueTypes.Bool `json:"is_remote_upgrade"`
|
||||
UpdateDate valueTypes.DateTime `json:"update_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UpdateDate valueTypes.DateTime `json:"update_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
ValidFlag valueTypes.Bool `json:"valid_flag"`
|
||||
} `json:"deviceTypeList" PointId:"device_type_list" DataTable:"true" DataTableSortOn:"TypeId"`
|
||||
}
|
||||
|
@ -37,12 +37,12 @@ type ResultData struct {
|
||||
TechCode valueTypes.String `json:"tech_code"`
|
||||
TechContent valueTypes.String `json:"tech_content"`
|
||||
TechContentTransId valueTypes.Integer `json:"tech_content_trans_id"`
|
||||
TechCreateTime valueTypes.DateTime `json:"tech_createtime" PointId:"tech_create_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
TechCreateTime valueTypes.DateTime `json:"tech_createtime" PointId:"tech_create_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
TechCreator valueTypes.String `json:"tech_creator"`
|
||||
TechDescription interface{} `json:"tech_description"`
|
||||
TechId valueTypes.Integer `json:"tech_id"`
|
||||
TechModifier interface{} `json:"tech_modifier"`
|
||||
TechModifyTime valueTypes.DateTime `json:"tech_modifytime" PointId:"tech_modify_time" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
TechModifyTime valueTypes.DateTime `json:"tech_modifytime" PointId:"tech_modify_time" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
TechName valueTypes.String `json:"tech_name"`
|
||||
TypeId valueTypes.Integer `json:"type_id"`
|
||||
TypeName valueTypes.String `json:"type_name"`
|
||||
|
@ -27,7 +27,7 @@ func (rd RequestData) Help() string {
|
||||
|
||||
type ResultData struct {
|
||||
PowerDeviceTypeMap struct {
|
||||
UpdateDate valueTypes.DateTime `json:"update_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UpdateDate valueTypes.DateTime `json:"update_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
SysId valueTypes.String `json:"sys_id"`
|
||||
SysName valueTypes.String `json:"sys_name"`
|
||||
TypeCode valueTypes.Integer `json:"type_code"`
|
||||
|
@ -56,7 +56,7 @@ type ResultData []struct {
|
||||
RegisteredAddress valueTypes.String `json:"registered_address"`
|
||||
RegisteredArea valueTypes.String `json:"registered_area"`
|
||||
RegisteredCapital valueTypes.Integer `json:"registered_capital"`
|
||||
RegisteredDate valueTypes.DateTime `json:"registered_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
RegisteredDate valueTypes.DateTime `json:"registered_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
ServiceEmail valueTypes.String `json:"service_emaill" PointId:"service_email"`
|
||||
TaxCertificate valueTypes.String `json:"tax_certificate"`
|
||||
TelNo valueTypes.String `json:"tel_no"`
|
||||
|
@ -39,7 +39,7 @@ type ResultData struct {
|
||||
PsGUID valueTypes.String `json:"psGuid" PointId:"ps_guid"`
|
||||
SnCode interface{} `json:"snCode" PointId:"sn_code"`
|
||||
SyncDate interface{} `json:"syncDate" PointId:"sync_date"`
|
||||
UpdateDate valueTypes.DateTime `json:"updateDate" PointId:"update_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UpdateDate valueTypes.DateTime `json:"updateDate" PointId:"update_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
UpdateUserCode interface{} `json:"updateUserCode" PointId:"update_user_code"`
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ func (rd RequestData) Help() string {
|
||||
type ResultData []struct {
|
||||
GoStructParent GoStruct.GoStructParent `json:"GoStruct" PointIdReplace:"true" DataTable:"true" DataTableSortOn:"UpdateDate"`
|
||||
|
||||
UpdateDate valueTypes.DateTime `json:"update_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
UpdateDate valueTypes.DateTime `json:"update_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
SysId valueTypes.String `json:"sys_id"`
|
||||
SysName valueTypes.String `json:"sys_name"`
|
||||
TypeId valueTypes.Integer `json:"type_id"`
|
||||
|
@ -82,7 +82,7 @@ type ResultData struct {
|
||||
AccessType Common.Unknown `json:"access_type"`
|
||||
AreaType Common.Unknown `json:"area_type"`
|
||||
AreaId Common.Unknown `json:"areaid" PointId:"area_id"`
|
||||
BuildDate valueTypes.DateTime `json:"build_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
BuildDate valueTypes.DateTime `json:"build_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
BuildStatus valueTypes.Integer `json:"buildstatus" PointId:"build_status"`
|
||||
CapitalType valueTypes.Integer `json:"capitaltype" PointId:"capital_type"`
|
||||
City Common.Unknown `json:"city"`
|
||||
@ -91,13 +91,13 @@ type ResultData struct {
|
||||
DistrictFlag valueTypes.Integer `json:"district_flag"`
|
||||
DivisionCode Common.Unknown `json:"division_code"`
|
||||
Email valueTypes.String `json:"email"`
|
||||
ExpectInstallDate valueTypes.DateTime `json:"expect_install_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
ExpectInstallDate valueTypes.DateTime `json:"expect_install_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
FaultSendType Common.Unknown `json:"fault_send_type"`
|
||||
GcjLatitude valueTypes.Float `json:"gcj_latitude"`
|
||||
GcjLongitude valueTypes.Float `json:"gcj_longitude"`
|
||||
GprsLatitude valueTypes.Float `json:"gprs_latitude"`
|
||||
GprsLongitude valueTypes.Float `json:"gprs_longitude"`
|
||||
InstallDate valueTypes.DateTime `json:"installdate" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
InstallDate valueTypes.DateTime `json:"installdate" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
InvestmentType valueTypes.Integer `json:"investment_type"`
|
||||
Latitude valueTypes.Float `json:"latitude"`
|
||||
Longitude valueTypes.Float `json:"longitude"`
|
||||
@ -119,7 +119,7 @@ type ResultData struct {
|
||||
Producer Common.Unknown `json:"producer"`
|
||||
Prov Common.Unknown `json:"prov"`
|
||||
ProvCode Common.Unknown `json:"prov_code"`
|
||||
PsBuildDate valueTypes.DateTime `json:"ps_build_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
PsBuildDate valueTypes.DateTime `json:"ps_build_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
PsCountryId valueTypes.Integer `json:"ps_country_id"`
|
||||
PsCode valueTypes.String `json:"pscode" PointId:"ps_code"`
|
||||
PsDesc Common.Unknown `json:"psdesc" PointId:"ps_desc"`
|
||||
@ -130,7 +130,7 @@ type ResultData struct {
|
||||
PsNameEnus Common.Unknown `json:"psnameenus" PointId:"ps_name_enus"`
|
||||
PsOrgId Common.Unknown `json:"psorgid" PointId:"ps_org_id"`
|
||||
PsOrgName Common.Unknown `json:"psorgname" PointId:"ps_org_name"`
|
||||
SafeStartDate valueTypes.DateTime `json:"safe_start_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
SafeStartDate valueTypes.DateTime `json:"safe_start_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
SchedulingType valueTypes.Integer `json:"schedulingtype" PointId:"scheduling_type"`
|
||||
Shortname valueTypes.String `json:"shortname"`
|
||||
Sn valueTypes.String `json:"sn"`
|
||||
@ -154,7 +154,7 @@ type ResultData struct {
|
||||
ChannelDesc Common.Unknown `json:"chnnl_desc" PointId:"channel_description"`
|
||||
ChannelId valueTypes.Integer `json:"chnnl_id" PointId:"channel_id"`
|
||||
ChannelName valueTypes.String `json:"chnnl_name" PointId:"channel_name"`
|
||||
CrtDate valueTypes.DateTime `json:"crt_date" PointId:"create_date" PointNameDateFormat:"2006/01/02 15:04:05"`
|
||||
CrtDate valueTypes.DateTime `json:"crt_date" PointId:"create_date" PointNameDateFormat:"2006-01-02 15:04:05"`
|
||||
CrtUserName Common.Unknown `json:"crt_user_name" PointId:"create_username"`
|
||||
DataFlag valueTypes.Integer `json:"data_flag"`
|
||||
FlagServer Common.Unknown `json:"flag_server"`
|
||||
|
@ -100,3 +100,253 @@ package GoStruct
|
||||
//
|
||||
// return &ret
|
||||
// }
|
||||
|
||||
// -------------------------------------------------------------------------------- //
|
||||
// From structmap.go
|
||||
//
|
||||
//
|
||||
// func (sm *StructMap) GetTables() StructTables {
|
||||
// var ret StructTables
|
||||
//
|
||||
// for range Only.Once {
|
||||
// st := sm.GetResultTableData()
|
||||
// ret = append(ret, st)
|
||||
//
|
||||
// names := sm.GetTableNames()
|
||||
// for _, name := range names {
|
||||
// st = sm.GetTableData(name)
|
||||
// if !st.IsValid {
|
||||
// continue
|
||||
// }
|
||||
// ret = append(ret, st)
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// return ret
|
||||
// }
|
||||
//
|
||||
// func (sm *StructMap) GetTableData(name string) *StructTable {
|
||||
// var ret StructTable
|
||||
//
|
||||
// for range Only.Once {
|
||||
// if current, ok := sm.TableMap[name]; ok {
|
||||
// sm.Error = ret.Process(name, current)
|
||||
// _, _ = ret.CreateTable()
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// sm.PrintDebug("GetTableData(%s) - UNKNOWN path:%s type:%s\n", name, ret.Current.FieldPath, ret.Current.Kind)
|
||||
// }
|
||||
//
|
||||
// // for range Only.Once {
|
||||
// // var ok bool
|
||||
// // if ret.Current, ok = sm.TableMap[name]; !ok {
|
||||
// // break
|
||||
// // }
|
||||
// //
|
||||
// // ret.Name = ret.Current.Name()
|
||||
// // ret.IsValid = true
|
||||
// //
|
||||
// // if ret.Current.DataStructure.DataTableIndex {
|
||||
// // ret.ShowIndex = ret.Current.DataStructure.DataTableIndex
|
||||
// // }
|
||||
// //
|
||||
// // ret.IndexTitle = "Index"
|
||||
// // if ret.Current.DataStructure.DataTableIndexTitle != "" {
|
||||
// // ret.IndexTitle = ret.Current.DataStructure.DataTableIndexTitle
|
||||
// // }
|
||||
// //
|
||||
// //
|
||||
// // ret.Rows, ret.Cols = ret.Current.CountChildren()
|
||||
// // var isPivot bool
|
||||
// // if ret.Current.DataStructure.DataTablePivot {
|
||||
// // isPivot = true
|
||||
// // }
|
||||
// // if ret.Cols <= 1 {
|
||||
// // isPivot = true
|
||||
// // }
|
||||
// //
|
||||
// // // if rows == 0 {
|
||||
// // // // var refs ReflectArray
|
||||
// // // for row, Child := range ret.Current.Value.Range(true) {
|
||||
// // // fmt.Printf("GetTableData() row[%d]: %s - %s == %s\n", row, Child, Child.ValueKey(), Child.StringValue)
|
||||
// // //
|
||||
// // // // var refRow ReflectArrayRow
|
||||
// // // // refRow = append(refRow, ChildStruct)
|
||||
// // // //
|
||||
// // // // if len(refRow) > 0 {
|
||||
// // // // refs = refs.AddRow(refRow...)
|
||||
// // // // continue
|
||||
// // // // }
|
||||
// // //
|
||||
// // // // Single column.
|
||||
// // // ret.ShowIndex = true
|
||||
// // // // refs = refs.AddRow(Child)
|
||||
// // // }
|
||||
// // // break
|
||||
// // // }
|
||||
// //
|
||||
// // sm.PrintDebug("GetTableData(%s) - path:%s type:%s rows:%d cols:%d\n", name, ret.Current.FieldPath, ret.Current.Kind, ret.Rows, ret.Cols)
|
||||
// // if ret.Current.IsPointIgnore() {
|
||||
// // break
|
||||
// // }
|
||||
// //
|
||||
// // var refs ReflectArray
|
||||
// // for row, Child := range ret.Current.ChildReflect {
|
||||
// // sm.PrintDebug("GetTableData() row[%d]: %s\n", row, Child)
|
||||
// // if Child.IsPointIgnore() {
|
||||
// // continue
|
||||
// // }
|
||||
// //
|
||||
// // var refRow ReflectArrayRow
|
||||
// //
|
||||
// // for col, ChildStruct := range Child.ChildReflect {
|
||||
// // sm.PrintDebug("GetTableData() cell[%d][%d]: %s\n", row, col, Child)
|
||||
// // if ChildStruct.IsPointIgnore() {
|
||||
// // continue
|
||||
// // }
|
||||
// //
|
||||
// // // Make sure we have a valid sort column name.
|
||||
// // if ret.Current.DataStructure.DataTableSortOn == ChildStruct.FieldName {
|
||||
// // ret.SortOn = ChildStruct.DataStructure.PointName
|
||||
// // }
|
||||
// //
|
||||
// // if ChildStruct.IsKnown() {
|
||||
// // refRow = append(refRow, ChildStruct)
|
||||
// // continue
|
||||
// // }
|
||||
// // refRow = append(refRow, ChildStruct)
|
||||
// // }
|
||||
// //
|
||||
// // if len(refRow) > 0 {
|
||||
// // if ret.ActualCols < len(refRow) {
|
||||
// // ret.ActualCols = len(refRow)
|
||||
// // }
|
||||
// // refs = refs.AddRow(refRow...)
|
||||
// // continue
|
||||
// // }
|
||||
// //
|
||||
// // // Single column.
|
||||
// // ret.ShowIndex = true
|
||||
// // if Child.IsPointIgnore() {
|
||||
// // continue
|
||||
// // }
|
||||
// // if ret.ActualCols < len(refRow) {
|
||||
// // ret.ActualCols = len(refRow)
|
||||
// // }
|
||||
// // refs = refs.AddRow(Child)
|
||||
// // }
|
||||
// //
|
||||
// // if refs == nil {
|
||||
// // break
|
||||
// // }
|
||||
// //
|
||||
// // if !isPivot {
|
||||
// // ret.Reflects = refs
|
||||
// // // ret.AddHeader(ret.Reflects[0]...)
|
||||
// // break
|
||||
// // }
|
||||
// //
|
||||
// // // Handle table pivots here.
|
||||
// // for row := 0; row < len(refs[0]); row++ {
|
||||
// // var refRow ReflectArrayRow
|
||||
// // for col := 0; col < len(refs); col++ {
|
||||
// // refRow = append(refRow, refs[col][row])
|
||||
// // }
|
||||
// // if len(refRow) > 0 {
|
||||
// // ret.Reflects = ret.Reflects.AddRow(refRow...)
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
//
|
||||
// return &ret
|
||||
// }
|
||||
//
|
||||
// func (sm *StructMap) GetResultTableData() StructTable {
|
||||
// var ret StructTable
|
||||
//
|
||||
// fmt.Printf("NOT IMPLEMENTED YET.\n")
|
||||
// // for range Only.Once {
|
||||
// // var sorted []string
|
||||
// // // @TODO - Add in other column sorting options here.
|
||||
// // for name := range sm.Map {
|
||||
// // sorted = append(sorted, name)
|
||||
// // }
|
||||
// //
|
||||
// // ret.Name = "Results"
|
||||
// // ret.IsValid = true
|
||||
// //
|
||||
// // for _, name := range sorted {
|
||||
// // Current := sm.Map[name]
|
||||
// //
|
||||
// // rows, cols := Current.CountChildren()
|
||||
// // // fmt.Printf("GetTableData(%s) - path:%s type:%s rows:%d cols:%d\n", name, ret.Current.FieldPath, ret.Current.Kind, rows, cols)
|
||||
// // sm.PrintDebug("GetResultTableData(%s) - path:%s type:%s rows:%d cols:%d\n", name, Current.FieldPath, Current.Kind, rows, cols)
|
||||
// // if Current.IsPointIgnore() {
|
||||
// // break
|
||||
// // }
|
||||
// //
|
||||
// // // if len(refs) > 0 {
|
||||
// // // ret.AddRow(refs...)
|
||||
// // // }
|
||||
// //
|
||||
// // // for row, Child := range Current.ChildReflect {
|
||||
// // // fmt.Printf("[%s]%s - Known:%t Current:%d / Child:%d\n", Child.FieldPath, ret.Current.Kind,
|
||||
// // // Child.IsKnown(),
|
||||
// // // len(ret.Current.ChildReflect),
|
||||
// // // len(Child.ChildReflect))
|
||||
// // // if sm.Debug {
|
||||
// // // _, _ = fmt.Fprintf(os.Stderr, "GetResultTableData() row[%d]: %s\n", row, Child)
|
||||
// // // }
|
||||
// // // if Child.IsPointIgnore() {
|
||||
// // // continue
|
||||
// // // }
|
||||
// // //
|
||||
// // // var refs []*Reflect
|
||||
// // //
|
||||
// // // for col, ChildStruct := range Child.ChildReflect {
|
||||
// // // // fmt.Printf("[%s]%s - Known:%t Current:%d / Child:%d / ChildStruct:%d\n", ChildStruct.FieldPath, ret.Current.Kind,
|
||||
// // // // ChildStruct.IsKnown(),
|
||||
// // // // len(ret.Current.ChildReflect),
|
||||
// // // // len(Child.ChildReflect),
|
||||
// // // // len(ChildStruct.ChildReflect))
|
||||
// // // if sm.Debug {
|
||||
// // // _, _ = fmt.Fprintf(os.Stderr, "GetResultTableData() cell[%d][%d]: %s\n", row, col, Child)
|
||||
// // // }
|
||||
// // // if ChildStruct.IsPointIgnore() {
|
||||
// // // continue
|
||||
// // // }
|
||||
// // //
|
||||
// // // // Make sure we have a valid sort column name.
|
||||
// // // if Current.DataStructure.DataTableSortOn != "" {
|
||||
// // // if Current.DataStructure.DataTableSortOn == ChildStruct.FieldName {
|
||||
// // // ret.SortOn = ChildStruct.DataStructure.PointName
|
||||
// // // }
|
||||
// // // }
|
||||
// // //
|
||||
// // // if ChildStruct.IsKnown() {
|
||||
// // // refs = append(refs, ChildStruct)
|
||||
// // // continue
|
||||
// // // }
|
||||
// // // refs = append(refs, ChildStruct)
|
||||
// // // }
|
||||
// // //
|
||||
// // // if len(refs) > 0 {
|
||||
// // // ret.AddRow(refs...)
|
||||
// // // }
|
||||
// // }
|
||||
// // }
|
||||
//
|
||||
// return ret
|
||||
// }
|
||||
//
|
||||
// func (sm *StructMap) GetTableNames() []string {
|
||||
// var ret []string
|
||||
// for name := range sm.TableMap {
|
||||
// ret = append(ret, name)
|
||||
// }
|
||||
// return ret
|
||||
// }
|
||||
//
|
||||
|
||||
|
@ -1,35 +1,36 @@
|
||||
package output
|
||||
|
||||
import (
|
||||
"github.com/MickMake/GoUnify/Only"
|
||||
"GoSungrow/iSolarCloud/api/GoStruct/valueTypes"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/MickMake/GoUnify/Only"
|
||||
"github.com/wcharczuk/go-chart/v2"
|
||||
"github.com/wcharczuk/go-chart/v2/drawing"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
// "go.pennock.tech/tabular"
|
||||
// tabular "github.com/agrison/go-tablib"
|
||||
|
||||
|
||||
type GraphRequest struct {
|
||||
Title string `json:"title"`
|
||||
|
||||
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"`
|
||||
TimeColumn *string `json:"time_column"`
|
||||
DataColumn *string `json:"value_column"`
|
||||
UnitsColumn *string `json:"units_column"`
|
||||
NameColumn *string `json:"name_column"`
|
||||
DataUnit *string `json:"unit"`
|
||||
DataMin *float64 `json:"min"`
|
||||
DataMax *float64 `json:"max"`
|
||||
Width *int `json:"width"`
|
||||
Height *int `json:"height"`
|
||||
|
||||
MinLeftAxis *float64 `json:"min_left_axis"`
|
||||
MaxLeftAxis *float64 `json:"max_left_axis"`
|
||||
|
||||
Width *int `json:"width"`
|
||||
Height *int `json:"height"`
|
||||
// DataColumn *string `json:"data_column"`
|
||||
// SearchString *string `json:"search_string"`
|
||||
|
||||
Error error `json:"-"`
|
||||
}
|
||||
@ -62,7 +63,8 @@ func JsonToGraphRequest(j Json) GraphRequest {
|
||||
|
||||
func (t *Table) InitGraph(req GraphRequest) {
|
||||
if t.graph == nil {
|
||||
t.graph = New(req.Title)
|
||||
t.graph = New()
|
||||
_ = t.graph.SetTitle(req.Title)
|
||||
}
|
||||
|
||||
t.graph.req = req
|
||||
@ -71,7 +73,14 @@ func (t *Table) InitGraph(req GraphRequest) {
|
||||
func (t *Table) SetGraph(req GraphRequest) error {
|
||||
for range Only.Once {
|
||||
if t.graph == nil {
|
||||
t.graph = New(req.Title)
|
||||
t.graph = New()
|
||||
}
|
||||
|
||||
t.graph.req = req
|
||||
|
||||
_ = t.graph.SetTitle(req.Title)
|
||||
if t.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
t.graph.SetWidth(req.Width)
|
||||
@ -84,7 +93,7 @@ func (t *Table) SetGraph(req GraphRequest) error {
|
||||
break
|
||||
}
|
||||
|
||||
changed := t.graph.SetGraphSearch(req)
|
||||
changed := t.graph.SetColumns(req)
|
||||
if !changed {
|
||||
break
|
||||
}
|
||||
@ -92,7 +101,7 @@ func (t *Table) SetGraph(req GraphRequest) error {
|
||||
break
|
||||
}
|
||||
|
||||
t.graph.SetRangeY(req.MinLeftAxis, req.MaxLeftAxis)
|
||||
t.graph.SetRangeY(req.DataMin, req.DataMax)
|
||||
if t.Error != nil {
|
||||
break
|
||||
}
|
||||
@ -124,156 +133,179 @@ func (t *Table) SetGraphFromJson(j Json) error {
|
||||
}
|
||||
|
||||
|
||||
func (t *Table) GetSearchColumn() SearchStrings {
|
||||
return t.graph.otherSearch
|
||||
}
|
||||
// func (t *Table) GetSearchColumn() SearchStrings {
|
||||
// return t.graph.otherSearch
|
||||
// }
|
||||
|
||||
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.RowLength(); row++ {
|
||||
// Get the search column
|
||||
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 req.Title == "" {
|
||||
t.SetTitle(cell.(string))
|
||||
}
|
||||
|
||||
if t.graph.searchName == "" {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
// Get units
|
||||
if units == "" {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
// 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!
|
||||
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.GetCell(row, *req.ValueColumn)
|
||||
if t.Error != nil {
|
||||
continue
|
||||
}
|
||||
var val float64
|
||||
val, t.Error = strconv.ParseFloat(cell.(string), 64)
|
||||
if t.Error != nil {
|
||||
val = 0
|
||||
}
|
||||
values = append(values, val)
|
||||
}
|
||||
|
||||
t.Error = t.graph.SetFilename(fmt.Sprintf("%s-%s.png", t.filePrefix, strings.ReplaceAll(t.graph.searchName, " ", "")))
|
||||
if t.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
t.Error = t.graph.SetX("Date", times...)
|
||||
if t.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
t.Error = t.graph.SetY(units, values...)
|
||||
if t.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
t.Error = t.graph.ProcessGraphData(t)
|
||||
return t.Error
|
||||
|
||||
// for range Only.Once {
|
||||
// req := t.graph.req
|
||||
//
|
||||
// t.graph.searchName = ""
|
||||
// var units string
|
||||
// var times []time.Time
|
||||
// var values []float64
|
||||
//
|
||||
// if t.graph.req.DataUnit != nil {
|
||||
// units = *t.graph.req.DataUnit
|
||||
// }
|
||||
//
|
||||
// for row := 0; row < t.RowLength(); row++ {
|
||||
// var cell interface{}
|
||||
//
|
||||
// // Get the search column
|
||||
// // cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.SearchColumn})
|
||||
// // cell, t.Error = t.GetCell(row, *req.DataColumn)
|
||||
// // if t.Error != nil {
|
||||
// // continue
|
||||
// // }
|
||||
// // if !strings.Contains(cell.String(), *req.SearchString) {
|
||||
// // continue
|
||||
// // }
|
||||
//
|
||||
//
|
||||
// if req.Title == "" {
|
||||
// req.Title = cell.(string)
|
||||
// t.SetTitle(cell.(string))
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // if t.graph.searchName == "" {
|
||||
// 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)
|
||||
// }
|
||||
// // }
|
||||
//
|
||||
//
|
||||
// // Get units
|
||||
// if units == "" {
|
||||
// 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)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// // 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!
|
||||
// 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.GetCell(row, *req.DataColumn)
|
||||
// if t.Error != nil {
|
||||
// continue
|
||||
// }
|
||||
// var val float64
|
||||
// val, t.Error = strconv.ParseFloat(cell.(string), 64)
|
||||
// if t.Error != nil {
|
||||
// val = 0
|
||||
// }
|
||||
// values = append(values, val)
|
||||
// }
|
||||
//
|
||||
// var filename string
|
||||
// // filename = fmt.Sprintf("%s-%s.png", t.filePrefix, strings.ReplaceAll(t.graph.searchName, " ", ""))
|
||||
// filename = fmt.Sprintf("%s.png", t.filePrefix)
|
||||
// t.Error = t.graph.SetFilename(filename)
|
||||
// if t.Error != nil {
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// t.Error = t.graph.SetX("Date", times...)
|
||||
// if t.Error != nil {
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// t.Error = t.graph.SetY(units, values...)
|
||||
// if t.Error != nil {
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// return t.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.RowLength(); row++ {
|
||||
// Get the search column
|
||||
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
|
||||
} else {
|
||||
t.graph.otherSearch[cell.(string)] = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return t.Error
|
||||
}
|
||||
|
||||
func (t *Table) SearchStrings() SearchStrings {
|
||||
return t.graph.otherSearch
|
||||
}
|
||||
// type SearchStrings map[string]int
|
||||
// func (t *Table) FindSearchStrings() error {
|
||||
// for range Only.Once {
|
||||
// t.graph.otherSearch = make(SearchStrings)
|
||||
//
|
||||
// for row := 0; row < t.RowLength(); row++ {
|
||||
// // Get the search column
|
||||
// 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
|
||||
// } else {
|
||||
// t.graph.otherSearch[cell.(string)] = 0
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return t.Error
|
||||
// }
|
||||
//
|
||||
// func (t *Table) SearchStrings() SearchStrings {
|
||||
// return t.graph.otherSearch
|
||||
// }
|
||||
|
||||
func (t *Table) CreateGraph() error {
|
||||
for range Only.Once {
|
||||
if *t.graph.req.SearchString != "" {
|
||||
t.Error = t.graph.Generate()
|
||||
break
|
||||
}
|
||||
|
||||
t.Error = t.FindSearchStrings()
|
||||
t.Error = t.SetGraphFromJson(Json(t.graphFilter))
|
||||
if t.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
for s := range t.graph.otherSearch {
|
||||
t.graph.req.SearchString = &s
|
||||
t.Error = t.ProcessGraphData()
|
||||
if t.Error != nil {
|
||||
continue
|
||||
}
|
||||
t.Error = t.graph.Generate()
|
||||
if t.Error != nil {
|
||||
continue
|
||||
}
|
||||
}
|
||||
t.Error = t.graph.Generate()
|
||||
|
||||
// if t.graph.req.SearchString == nil {
|
||||
// break
|
||||
// }
|
||||
// if *t.graph.req.SearchString != "" {
|
||||
// t.Error = t.graph.Generate()
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// t.Error = t.FindSearchStrings()
|
||||
// if t.Error != nil {
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// for s := range t.graph.otherSearch {
|
||||
// t.graph.req.SearchString = &s
|
||||
// t.Error = t.ProcessGraphData()
|
||||
// if t.Error != nil {
|
||||
// continue
|
||||
// }
|
||||
// t.Error = t.graph.Generate()
|
||||
// if t.Error != nil {
|
||||
// continue
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
return t.Error
|
||||
@ -287,13 +319,17 @@ func (t *Table) CreateGraph() error {
|
||||
type Chart struct {
|
||||
Error error `json:"-"`
|
||||
|
||||
searchName string
|
||||
otherSearch SearchStrings
|
||||
req GraphRequest
|
||||
filename string
|
||||
// otherSearch SearchStrings
|
||||
searchName string
|
||||
title string
|
||||
req GraphRequest
|
||||
filename string
|
||||
timeSeries1 chart.TimeSeries
|
||||
timeSeries2 chart.TimeSeries
|
||||
graph chart.Chart
|
||||
annotation chart.AnnotationSeries
|
||||
minSeries *chart.MinSeries
|
||||
maxSeries *chart.MaxSeries
|
||||
graph chart.Chart
|
||||
}
|
||||
|
||||
|
||||
@ -333,7 +369,7 @@ type Chart struct {
|
||||
// }
|
||||
|
||||
|
||||
func New(title string) *Chart {
|
||||
func New() *Chart {
|
||||
var c Chart
|
||||
|
||||
for range Only.Once {
|
||||
@ -344,7 +380,7 @@ func New(title string) *Chart {
|
||||
XValues: []time.Time{},
|
||||
YValues: []float64{},
|
||||
}
|
||||
c.timeSeries2 = chart.TimeSeries{
|
||||
c.timeSeries2 = chart.TimeSeries {
|
||||
Name: "",
|
||||
Style: chart.Style{},
|
||||
YAxis: chart.YAxisSecondary,
|
||||
@ -352,20 +388,33 @@ func New(title string) *Chart {
|
||||
YValues: []float64{},
|
||||
}
|
||||
|
||||
c.annotation = chart.AnnotationSeries {
|
||||
Annotations: []chart.Value2 {
|
||||
},
|
||||
}
|
||||
|
||||
c.graph = chart.Chart {
|
||||
Title: title,
|
||||
Title: "",
|
||||
TitleStyle: chart.Style{},
|
||||
ColorPalette: nil,
|
||||
Width: 0,
|
||||
Height: 0,
|
||||
DPI: 0,
|
||||
Background: chart.Style{},
|
||||
Background: chart.Style {
|
||||
Padding: chart.Box {
|
||||
Top: 50,
|
||||
Left: 25,
|
||||
Right: 25,
|
||||
Bottom: 10,
|
||||
},
|
||||
FillColor: drawing.ColorFromHex("efefef"),
|
||||
},
|
||||
Canvas: chart.Style{},
|
||||
XAxis: chart.XAxis{},
|
||||
YAxis: chart.YAxis{},
|
||||
YAxisSecondary: chart.YAxis{},
|
||||
Font: nil,
|
||||
Series: []chart.Series{c.timeSeries1}, // , c.timeSeries2},
|
||||
Series: []chart.Series{}, // c.timeSeries1, c.annotation }, // , c.timeSeries2},
|
||||
Elements: nil,
|
||||
Log: nil,
|
||||
}
|
||||
@ -375,6 +424,208 @@ func New(title string) *Chart {
|
||||
}
|
||||
|
||||
|
||||
func (c *Chart) ProcessGraphData(table *Table) error {
|
||||
for range Only.Once {
|
||||
// req := c.req
|
||||
|
||||
c.searchName = ""
|
||||
// var units string
|
||||
var times []time.Time
|
||||
var values []float64
|
||||
|
||||
// if c.req.DataUnit != nil {
|
||||
// units = *c.req.DataUnit
|
||||
// }
|
||||
for row := 0; row < table.RowLength(); row++ {
|
||||
var cell interface{}
|
||||
var cellType string
|
||||
|
||||
// Get the search column
|
||||
// cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.SearchColumn})
|
||||
// cell, t.Error = t.GetCell(row, *req.DataColumn)
|
||||
// if t.Error != nil {
|
||||
// continue
|
||||
// }
|
||||
// if !strings.Contains(cell.String(), *req.SearchString) {
|
||||
// continue
|
||||
// }
|
||||
|
||||
|
||||
// if req.Title == "" {
|
||||
// req.Title = cell.(string)
|
||||
// c.SetTitle(cell.(string))
|
||||
// }
|
||||
|
||||
|
||||
// if t.graph.searchName == "" {
|
||||
if c.req.NameColumn != nil {
|
||||
// cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.NameColumn})
|
||||
cellType, cell, c.Error = table.GetCell(row, *c.req.NameColumn)
|
||||
if c.Error != nil {
|
||||
continue
|
||||
}
|
||||
val, isNil, ok := valueTypes.AnyToUnitValue(cell, "", *c.req.DataUnit, "", "")
|
||||
if isNil {
|
||||
continue
|
||||
}
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
units := val.String()
|
||||
c.req.NameColumn = &units
|
||||
|
||||
// switch cellType {
|
||||
// case "string":
|
||||
// c.searchName = cell.(string)
|
||||
// case valueTypes.TypeUnitValue:
|
||||
// c.searchName = cell.(valueTypes.UnitValue).String()
|
||||
// default:
|
||||
// c.searchName = fmt.Sprintf("%s", cell)
|
||||
// }
|
||||
}
|
||||
// }
|
||||
|
||||
|
||||
// Get units
|
||||
if c.req.DataUnit == nil {
|
||||
if c.req.UnitsColumn != nil {
|
||||
// cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.UnitsColumn})
|
||||
cellType, cell, c.Error = table.GetCell(row, *c.req.UnitsColumn)
|
||||
if c.Error != nil {
|
||||
continue
|
||||
}
|
||||
val, isNil, ok := valueTypes.AnyToUnitValue(cell, "", *c.req.DataUnit, "", "")
|
||||
if isNil {
|
||||
continue
|
||||
}
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
units := val.String()
|
||||
c.req.DataUnit = &units
|
||||
|
||||
// switch cellType {
|
||||
// case "string":
|
||||
// units := cell.(string)
|
||||
// c.req.DataUnit = &units
|
||||
// case valueTypes.TypeUnitValue:
|
||||
// units := cell.(valueTypes.UnitValue).String()
|
||||
// c.req.DataUnit = &units
|
||||
// default:
|
||||
// units := fmt.Sprintf("%s", cell)
|
||||
// c.req.DataUnit = &units
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.TimeColumn})
|
||||
cellType, cell, c.Error = table.GetCell(row, *c.req.TimeColumn)
|
||||
if c.Error != nil {
|
||||
continue
|
||||
}
|
||||
// val, isNil, ok := valueTypes.AnyToUnitValue(cell, "", *c.req.DataUnit, "", "")
|
||||
// if isNil {
|
||||
// continue
|
||||
// }
|
||||
// if !ok {
|
||||
// continue
|
||||
// }
|
||||
// if !val.First().IsTypeDateTime() {
|
||||
// continue
|
||||
// }
|
||||
// times = append(times, val.First().IsTypeDateTime())
|
||||
switch cellType {
|
||||
case valueTypes.TypeUnitValue:
|
||||
var tim time.Time
|
||||
tim, c.Error = time.ParseInLocation(DateTimeSearchLayout, cell.(valueTypes.UnitValue).String(), time.Local) // @TODO - May have to revisit this!
|
||||
if c.Error != nil {
|
||||
continue
|
||||
}
|
||||
times = append(times, tim)
|
||||
case "string":
|
||||
var tim time.Time
|
||||
tim, c.Error = time.ParseInLocation(DateTimeSearchLayout, cell.(string), time.Local) // @TODO - May have to revisit this!
|
||||
if c.Error != nil {
|
||||
continue
|
||||
}
|
||||
times = append(times, tim)
|
||||
case valueTypes.TypeDateTime:
|
||||
times = append(times, cell.(valueTypes.DateTime).Time)
|
||||
default:
|
||||
var tim time.Time
|
||||
tim, c.Error = time.ParseInLocation(DateTimeSearchLayout, fmt.Sprintf("%s", cell), time.Local) // @TODO - May have to revisit this!
|
||||
if c.Error != nil {
|
||||
continue
|
||||
}
|
||||
times = append(times, tim)
|
||||
}
|
||||
|
||||
// cell, t.Error = t.table.CellAt(tabular.CellLocation{Row: row, Column: *req.ValueColumn})
|
||||
cellType, cell, c.Error = table.GetCell(row, *c.req.DataColumn)
|
||||
if c.Error != nil {
|
||||
continue
|
||||
}
|
||||
u := ""
|
||||
if c.req.DataUnit != nil {
|
||||
u = *c.req.DataUnit
|
||||
}
|
||||
val, isNil, ok := valueTypes.AnyToUnitValue(cell, "", u, "", "")
|
||||
if isNil {
|
||||
continue
|
||||
}
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
values = append(values, val.First().Value())
|
||||
|
||||
// switch cellType {
|
||||
// case "string":
|
||||
// var val float64
|
||||
// val, c.Error = strconv.ParseFloat(cell.(string), 64)
|
||||
// if c.Error != nil {
|
||||
// val = 0
|
||||
// }
|
||||
// values = append(values, val)
|
||||
// case "float32":
|
||||
// values = append(values, float64(cell.(float32)))
|
||||
// case "float64":
|
||||
// values = append(values, cell.(float64))
|
||||
// case valueTypes.TypeUnitValue:
|
||||
// units := cell.(valueTypes.UnitValue).String()
|
||||
// c.req.DataUnit = &units
|
||||
// default:
|
||||
// units := fmt.Sprintf("%s", cell)
|
||||
// c.req.DataUnit = &units
|
||||
// }
|
||||
}
|
||||
|
||||
var filename string
|
||||
// filename = fmt.Sprintf("%s-%s.png", t.filePrefix, strings.ReplaceAll(t.graph.searchName, " ", ""))
|
||||
filename = fmt.Sprintf("%s.png", table.filePrefix)
|
||||
c.Error = c.SetFilename(filename)
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
c.Error = c.SetX("Date", times...)
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
var unit string
|
||||
if c.req.DataUnit != nil {
|
||||
unit = *c.req.DataUnit
|
||||
}
|
||||
c.Error = c.SetY(unit, values...)
|
||||
if c.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return c.Error
|
||||
}
|
||||
|
||||
func (c *Chart) SetWidth(v *int) {
|
||||
for range Only.Once {
|
||||
if v == nil {
|
||||
@ -417,21 +668,23 @@ func (c *Chart) SetFilename(fn string) error {
|
||||
return c.Error
|
||||
}
|
||||
|
||||
func (c *Chart) SetTitle(fn string) error {
|
||||
c.graph.Title = fn
|
||||
c.req.Title = fn
|
||||
func (c *Chart) SetTitle(title string) error {
|
||||
c.graph.Title = title
|
||||
// c.req.Title = title
|
||||
return c.Error
|
||||
}
|
||||
|
||||
// var zero = float64(0)
|
||||
|
||||
func (c *Chart) SetRangeY(min *float64, max *float64) bool {
|
||||
var changed bool
|
||||
for range Only.Once {
|
||||
if min == nil {
|
||||
min = c.req.MinLeftAxis
|
||||
min = c.req.DataMin
|
||||
}
|
||||
|
||||
if max == nil {
|
||||
max = c.req.MaxLeftAxis
|
||||
max = c.req.DataMax
|
||||
}
|
||||
|
||||
c.graph.YAxis.Range = &chart.ContinuousRange {
|
||||
@ -447,21 +700,21 @@ func (c *Chart) SetRangeY(min *float64, max *float64) bool {
|
||||
return changed
|
||||
}
|
||||
|
||||
func (c *Chart) SetGraphSearch(req GraphRequest) bool {
|
||||
func (c *Chart) SetColumns(req GraphRequest) bool {
|
||||
var changed bool
|
||||
for range Only.Once {
|
||||
if req.SearchString != nil {
|
||||
c.req.SearchString = req.SearchString
|
||||
changed = true
|
||||
}
|
||||
// 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
|
||||
if req.DataColumn != nil {
|
||||
c.req.DataColumn = req.DataColumn
|
||||
changed = true
|
||||
}
|
||||
|
||||
@ -470,10 +723,10 @@ func (c *Chart) SetGraphSearch(req GraphRequest) bool {
|
||||
changed = true
|
||||
}
|
||||
|
||||
if req.SearchColumn != nil {
|
||||
c.req.SearchColumn = req.SearchColumn
|
||||
changed = true
|
||||
}
|
||||
// if req.DataColumn != nil {
|
||||
// c.req.DataColumn = req.DataColumn
|
||||
// changed = true
|
||||
// }
|
||||
}
|
||||
|
||||
return changed
|
||||
@ -561,18 +814,56 @@ func (c *Chart) SetY(name string, values ...float64) error {
|
||||
// GridMinorStyle: chart.Style{},
|
||||
// }
|
||||
|
||||
// var minX float64
|
||||
// var maxX float64
|
||||
var minY float64
|
||||
var maxY float64
|
||||
for _, value := range values {
|
||||
if value > maxY {
|
||||
maxY = value
|
||||
// maxX = c.timeSeries1.XValues[index].
|
||||
// maxX = 0.0
|
||||
}
|
||||
if value < minY {
|
||||
minY = value
|
||||
// minX = index
|
||||
// minX = 50.0
|
||||
}
|
||||
}
|
||||
|
||||
if (c.req.DataMin == nil) && (c.req.DataMax == nil) {
|
||||
rng := ((maxY - minY) / 2) * 1.1
|
||||
nMin := minY - rng
|
||||
if (nMin < 0.0) && (minY >= 0.0) {
|
||||
// If the subtraction has sent us negative.
|
||||
nMin = 0.0
|
||||
}
|
||||
nMax := maxY + rng
|
||||
c.SetRangeY(&nMin, &nMax)
|
||||
}
|
||||
|
||||
// c.annotation.Annotations = append(c.annotation.Annotations, chart.Value2 {
|
||||
// Style: chart.Style {
|
||||
// StrokeColor: drawing.ColorGreen,
|
||||
// FillColor: drawing.ColorGreen.WithAlpha(64),
|
||||
// },
|
||||
// Label: "Min " + strconv.FormatFloat(minY, 'f', -1, 64),
|
||||
// XValue: minX,
|
||||
// YValue: minY,
|
||||
// })
|
||||
//
|
||||
// c.annotation.Annotations = append(c.annotation.Annotations, chart.Value2 {
|
||||
// Style: chart.Style {
|
||||
// StrokeColor: drawing.ColorGreen,
|
||||
// FillColor: drawing.ColorGreen.WithAlpha(64),
|
||||
// },
|
||||
// Label: "Max " + strconv.FormatFloat(maxY, 'f', -1, 64),
|
||||
// XValue: maxX,
|
||||
// YValue: maxY,
|
||||
// })
|
||||
|
||||
c.graph.YAxis.Name = name
|
||||
|
||||
c.timeSeries1.YValues = values
|
||||
// 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
|
||||
}
|
||||
@ -633,19 +924,54 @@ func (c *Chart) Generate() error {
|
||||
FillColor: drawing.ColorBlue.WithAlpha(64),
|
||||
}
|
||||
|
||||
c.minSeries = &chart.MinSeries {
|
||||
Name: "Min",
|
||||
Style: chart.Style {
|
||||
// StrokeColor: chart.ColorAlternateGray,
|
||||
// StrokeColor: drawing.ColorBlue,
|
||||
// FillColor: drawing.ColorBlue.WithAlpha(50),
|
||||
StrokeColor: drawing.ColorBlue,
|
||||
StrokeDashArray: []float64{5.0, 5.0},
|
||||
DotWidth: 0.5,
|
||||
},
|
||||
InnerSeries: c.timeSeries1,
|
||||
}
|
||||
|
||||
c.maxSeries = &chart.MaxSeries {
|
||||
Name: "Max",
|
||||
Style: chart.Style {
|
||||
// StrokeColor: chart.ColorAlternateGray,
|
||||
// StrokeColor: drawing.ColorGreen,
|
||||
// FillColor: drawing.ColorGreen.WithAlpha(64),
|
||||
StrokeColor: drawing.ColorBlue,
|
||||
StrokeDashArray: []float64{5.0, 5.0},
|
||||
DotWidth: 1.0,
|
||||
},
|
||||
InnerSeries: c.timeSeries1,
|
||||
}
|
||||
|
||||
c.graph.Series = []chart.Series {
|
||||
c.timeSeries1,
|
||||
// c.annotation,
|
||||
c.minSeries,
|
||||
c.maxSeries,
|
||||
chart.LastValueAnnotationSeries(c.minSeries),
|
||||
chart.LastValueAnnotationSeries(c.maxSeries),
|
||||
// c.timeSeries2,
|
||||
}
|
||||
|
||||
c.graph.DPI = 150
|
||||
c.graph.Elements = []chart.Renderable{chart.Legend(&c.graph)}
|
||||
|
||||
for range Only.Once {
|
||||
if c.req.Title != "" {
|
||||
c.graph.Title = c.req.Title
|
||||
break
|
||||
}
|
||||
c.graph.Title = c.searchName
|
||||
if c.title != "" {
|
||||
c.graph.Title = c.title
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("Creating graph file '%s'\n", c.filename)
|
||||
|
@ -1,12 +1,13 @@
|
||||
package output
|
||||
|
||||
import (
|
||||
"github.com/MickMake/GoUnify/Only"
|
||||
"GoSungrow/iSolarCloud/api/GoStruct/reflection"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/MickMake/GoUnify/Only"
|
||||
)
|
||||
|
||||
|
||||
type Json string
|
||||
|
||||
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"github.com/MickMake/GoUnify/Only"
|
||||
tabular "github.com/agrison/go-tablib"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
@ -132,8 +133,9 @@ func (t *Table) RowLength() int {
|
||||
return t.table.Height()
|
||||
}
|
||||
|
||||
func (t *Table) GetCell(row int, colName string) (interface{}, error) {
|
||||
func (t *Table) GetCell(row int, colName string) (string, interface{}, error) {
|
||||
var ret interface{}
|
||||
var retType string
|
||||
for range Only.Once {
|
||||
var r map[string]interface{}
|
||||
r, t.Error = t.table.Row(row)
|
||||
@ -141,8 +143,10 @@ func (t *Table) GetCell(row int, colName string) (interface{}, error) {
|
||||
break
|
||||
}
|
||||
ret = r[colName]
|
||||
// retType = reflect.TypeOf(ret).String()
|
||||
retType = reflect.TypeOf(ret).Name()
|
||||
}
|
||||
return ret, t.Error
|
||||
return retType, ret, t.Error
|
||||
}
|
||||
|
||||
func (t *Table) AddRow(row ...interface{}) error {
|
||||
@ -167,6 +171,10 @@ func (t *Table) SetTitle(title string, args ...interface{}) {
|
||||
t.title = fmt.Sprintf(title, args...)
|
||||
}
|
||||
|
||||
func (t *Table) AppendTitle(title string, args ...interface{}) {
|
||||
t.title += fmt.Sprintf(title, args...)
|
||||
}
|
||||
|
||||
func (t *Table) GetTitle() string {
|
||||
return t.title
|
||||
}
|
||||
@ -237,6 +245,7 @@ func (t *Table) GetName() string {
|
||||
return t.name
|
||||
}
|
||||
|
||||
|
||||
func (t *Table) Output() error {
|
||||
for range Only.Once {
|
||||
if t == nil {
|
||||
@ -268,14 +277,7 @@ func (t *Table) Output() error {
|
||||
t.Error = t.WriteJson()
|
||||
|
||||
case t.OutputType.IsGraph():
|
||||
t.Error = t.SetGraphFromJson(Json(t.graphFilter))
|
||||
if t.Error != nil {
|
||||
break
|
||||
}
|
||||
t.Error = t.CreateGraph()
|
||||
if t.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
case t.OutputType.IsStruct():
|
||||
t.Error = t.WriteStruct()
|
||||
@ -287,23 +289,29 @@ func (t *Table) Output() error {
|
||||
return t.Error
|
||||
}
|
||||
|
||||
|
||||
func (t *Table) GetTable() string {
|
||||
func (t *Table) AsTable() string {
|
||||
return t.String()
|
||||
}
|
||||
|
||||
func (t *Table) WriteTable() error {
|
||||
for range Only.Once {
|
||||
if t.IsNotValid() {
|
||||
msg := fmt.Sprintf("# %s - has no data.", t.name)
|
||||
if t.saveAsFile {
|
||||
fmt.Println(msg)
|
||||
} else {
|
||||
_, _ = fmt.Fprintln(os.Stderr, msg)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
fmt.Printf("# %s\n", t.title)
|
||||
if t.saveAsFile {
|
||||
t.filePrefix += "." + StringTypeTable
|
||||
t.Error = t.writeFile(t.String(), DefaultFileMode)
|
||||
break
|
||||
}
|
||||
fmt.Printf("# %s\n", t.title)
|
||||
|
||||
fmt.Print(t.String())
|
||||
}
|
||||
return t.Error
|
||||
@ -312,22 +320,29 @@ func (t *Table) WriteTable() error {
|
||||
func (t *Table) WriteList() error {
|
||||
for range Only.Once {
|
||||
if t.IsNotValid() {
|
||||
msg := fmt.Sprintf("# %s - has no data.", t.name)
|
||||
if t.saveAsFile {
|
||||
fmt.Println(msg)
|
||||
} else {
|
||||
_, _ = fmt.Fprintln(os.Stderr, msg)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
fmt.Printf("# %s\n", t.title)
|
||||
if t.saveAsFile {
|
||||
t.filePrefix += "." + StringTypeList
|
||||
t.Error = t.writeFile(t.String(), DefaultFileMode)
|
||||
break
|
||||
}
|
||||
fmt.Printf("# %s\n", t.title)
|
||||
|
||||
fmt.Print(t.String())
|
||||
}
|
||||
return t.Error
|
||||
}
|
||||
|
||||
|
||||
func (t *Table) GetCsv() string {
|
||||
func (t *Table) AsCsv() string {
|
||||
var ret string
|
||||
for range Only.Once {
|
||||
if t.IsNotValid() {
|
||||
@ -347,21 +362,29 @@ func (t *Table) GetCsv() string {
|
||||
func (t *Table) WriteCsv() error {
|
||||
for range Only.Once {
|
||||
if t.IsNotValid() {
|
||||
msg := fmt.Sprintf("# %s - has no data.", t.name)
|
||||
if t.saveAsFile {
|
||||
fmt.Println(msg)
|
||||
} else {
|
||||
_, _ = fmt.Fprintln(os.Stderr, msg)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if t.saveAsFile {
|
||||
fmt.Printf("# %s\n", t.title)
|
||||
t.filePrefix += "." + StringTypeCsv
|
||||
t.Error = t.writeFile(t.GetCsv(), DefaultFileMode)
|
||||
t.Error = t.writeFile(t.AsCsv(), DefaultFileMode)
|
||||
break
|
||||
}
|
||||
fmt.Print(t.GetCsv())
|
||||
|
||||
fmt.Print(t.AsCsv())
|
||||
}
|
||||
return t.Error
|
||||
}
|
||||
|
||||
|
||||
func (t *Table) GetXml() string {
|
||||
func (t *Table) AsXml() string {
|
||||
var ret string
|
||||
for range Only.Once {
|
||||
if t.IsNotValid() {
|
||||
@ -381,21 +404,29 @@ func (t *Table) GetXml() string {
|
||||
func (t *Table) WriteXml() error {
|
||||
for range Only.Once {
|
||||
if t.IsNotValid() {
|
||||
msg := fmt.Sprintf("# %s - has no data.", t.name)
|
||||
if t.saveAsFile {
|
||||
fmt.Println(msg)
|
||||
} else {
|
||||
_, _ = fmt.Fprintln(os.Stderr, msg)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if t.saveAsFile {
|
||||
fmt.Printf("# %s\n", t.title)
|
||||
t.filePrefix += "." + StringTypeXML
|
||||
t.Error = t.writeFile(t.GetXml(), DefaultFileMode)
|
||||
t.Error = t.writeFile(t.AsXml(), DefaultFileMode)
|
||||
break
|
||||
}
|
||||
fmt.Print(t.GetXml())
|
||||
|
||||
fmt.Print(t.AsXml())
|
||||
}
|
||||
return t.Error
|
||||
}
|
||||
|
||||
|
||||
func (t *Table) GetXLSX() string {
|
||||
func (t *Table) AsXLSX() string {
|
||||
var ret string
|
||||
for range Only.Once {
|
||||
if t.IsNotValid() {
|
||||
@ -415,75 +446,81 @@ func (t *Table) GetXLSX() string {
|
||||
func (t *Table) WriteXLSX() error {
|
||||
for range Only.Once {
|
||||
if t.IsNotValid() {
|
||||
msg := fmt.Sprintf("# %s - has no data.", t.name)
|
||||
if t.saveAsFile {
|
||||
fmt.Println(msg)
|
||||
} else {
|
||||
_, _ = fmt.Fprintln(os.Stderr, msg)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
// if t.saveAsFile {
|
||||
if t.saveAsFile {
|
||||
fmt.Printf("# %s\n", t.title)
|
||||
t.filePrefix += "." + StringTypeXLSX
|
||||
t.Error = t.writeFile(t.GetXLSX(), DefaultFileMode)
|
||||
// break
|
||||
// }
|
||||
// fmt.Print(t.GetXml())
|
||||
t.Error = t.writeFile(t.AsXLSX(), DefaultFileMode)
|
||||
break
|
||||
}
|
||||
|
||||
fmt.Print(t.AsXLSX())
|
||||
}
|
||||
return t.Error
|
||||
}
|
||||
|
||||
|
||||
func (t *Table) GetJson() string {
|
||||
func (t *Table) AsJson() string {
|
||||
return string(t.raw)
|
||||
}
|
||||
|
||||
func (t *Table) WriteJson() error {
|
||||
for range Only.Once {
|
||||
if t.IsNotValid() {
|
||||
break
|
||||
}
|
||||
// Don't check for valid table data.
|
||||
|
||||
if t.saveAsFile {
|
||||
fmt.Printf("# %s\n", t.title)
|
||||
t.filePrefix += "." + StringTypeJson
|
||||
t.Error = t.writeFile(string(t.json), DefaultFileMode)
|
||||
break
|
||||
}
|
||||
|
||||
fmt.Printf("%s", t.json)
|
||||
}
|
||||
return t.Error
|
||||
}
|
||||
|
||||
|
||||
func (t *Table) GetRaw() string {
|
||||
func (t *Table) AsRaw() string {
|
||||
return string(t.json)
|
||||
}
|
||||
|
||||
func (t *Table) GetRawBytes() []byte {
|
||||
func (t *Table) AsRawBytes() []byte {
|
||||
return t.json
|
||||
}
|
||||
|
||||
func (t *Table) WriteRaw() error {
|
||||
for range Only.Once {
|
||||
// if t.IsNotValid() {
|
||||
// break
|
||||
// }
|
||||
// Don't check for valid table data.
|
||||
|
||||
if t.saveAsFile {
|
||||
fmt.Printf("# %s\n", t.title)
|
||||
t.filePrefix += "." + StringTypeRaw
|
||||
t.Error = t.writeFile(string(t.raw), DefaultFileMode)
|
||||
break
|
||||
}
|
||||
|
||||
fmt.Printf("%s", t.raw)
|
||||
}
|
||||
return t.Error
|
||||
}
|
||||
|
||||
|
||||
func (t *Table) GetStruct() string {
|
||||
func (t *Table) AsStruct() string {
|
||||
return string(t.json)
|
||||
}
|
||||
|
||||
func (t *Table) WriteStruct() error {
|
||||
for range Only.Once {
|
||||
// if t.IsNotValid() {
|
||||
// break
|
||||
// }
|
||||
// Don't check for valid table data.
|
||||
|
||||
var data string
|
||||
var options gojson.Options
|
||||
@ -501,10 +538,12 @@ func (t *Table) WriteStruct() error {
|
||||
}
|
||||
|
||||
if t.saveAsFile {
|
||||
fmt.Printf("# %s\n", t.title)
|
||||
t.filePrefix += ".go"
|
||||
t.Error = t.writeFile(data, DefaultFileMode)
|
||||
break
|
||||
}
|
||||
|
||||
fmt.Printf("%s", data)
|
||||
}
|
||||
return t.Error
|
||||
|
364
iSolarCloud/api/GoStruct/output/struct_tables.go
Normal file
364
iSolarCloud/api/GoStruct/output/struct_tables.go
Normal file
@ -0,0 +1,364 @@
|
||||
package output
|
||||
|
||||
|
||||
// type StructTable struct {
|
||||
// Name string
|
||||
// Current *Reflect
|
||||
// Reflects ReflectArray
|
||||
// SortOn string
|
||||
// ShowIndex bool
|
||||
// IndexTitle string
|
||||
// IsValid bool
|
||||
// Columns []string
|
||||
// Rows int
|
||||
// Cols int
|
||||
// ActualRows int
|
||||
// ActualCols int
|
||||
// }
|
||||
//
|
||||
//
|
||||
// type ReflectArray []ReflectArrayRow
|
||||
// type ReflectArrayRow []*Reflect
|
||||
//
|
||||
// func (ta *ReflectArray) AddRow(refs ...*Reflect) ReflectArray {
|
||||
// for range Only.Once {
|
||||
// if ta == nil {
|
||||
// *ta = make(ReflectArray, 0)
|
||||
// }
|
||||
//
|
||||
// var row ReflectArrayRow
|
||||
// row = append(row, refs...)
|
||||
// *ta = append(*ta, row)
|
||||
// }
|
||||
// return *ta
|
||||
// }
|
||||
//
|
||||
// func (ta *ReflectArray) GetRow(row int) ReflectArrayRow {
|
||||
// if row >= len(*ta) {
|
||||
// return ReflectArrayRow{}
|
||||
// }
|
||||
// return (*ta)[row]
|
||||
// }
|
||||
//
|
||||
//
|
||||
// type StructTables []StructTable
|
||||
// type StructValuesMap map[string]StructValues
|
||||
// type StructValues []StructValue
|
||||
// type StructValue map[string]valueTypes.UnitValue
|
||||
//
|
||||
// func (ta *StructValues) GetCell(row int, col string) valueTypes.UnitValue {
|
||||
// var ret valueTypes.UnitValue
|
||||
// for range Only.Once {
|
||||
// if row >= len(*ta) {
|
||||
// ret = valueTypes.SetUnitValueString("error", "error", "row > size")
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// if _, ok := (*ta)[row][col]; !ok {
|
||||
// ret = valueTypes.SetUnitValueString("", "", "")
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// ret = (*ta)[row][col]
|
||||
// }
|
||||
// return ret
|
||||
// }
|
||||
//
|
||||
// func (ta *StructTable) AddRow(refs ...*Reflect) {
|
||||
// for range Only.Once {
|
||||
// if ta.Reflects == nil {
|
||||
// ta.Reflects = make(ReflectArray, 0)
|
||||
// }
|
||||
//
|
||||
// // var row ReflectArrayRow
|
||||
// // row = append(row, refs...)
|
||||
// ta.Reflects = append(ta.Reflects, append(ReflectArrayRow{}, refs...))
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func (ta *StructTable) GetRow(row int) ReflectArrayRow {
|
||||
// return ta.Reflects.GetRow(row)
|
||||
// }
|
||||
//
|
||||
// func (ta *StructTable) GetHeaders() []string {
|
||||
// return ta.Columns
|
||||
// }
|
||||
//
|
||||
// func (ta *StructTable) Get() ReflectArray {
|
||||
// return ta.Reflects
|
||||
// }
|
||||
//
|
||||
// func (ta *StructTable) GetValues() StructValues {
|
||||
// ret := make(StructValues, 0)
|
||||
//
|
||||
// for range Only.Once {
|
||||
// if !ta.IsValid {
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// colOrder := make(map[string]int)
|
||||
// var colOrderIndex int
|
||||
//
|
||||
// var addCol = func(name string) {
|
||||
// if _, ok := colOrder[name]; !ok {
|
||||
// colOrder[name] = colOrderIndex
|
||||
// colOrderIndex++
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// var colName = func(sub *Reflect, value *valueTypes.UnitValue, length int) string {
|
||||
// name := sub.DataStructure.PointName
|
||||
// if value.ValueKey() == "" {
|
||||
// if name == "" {
|
||||
// name = "Column " + strconv.Itoa(length)
|
||||
// }
|
||||
// } else {
|
||||
// name += " " + value.ValueKey()
|
||||
// }
|
||||
// switch value.Unit() {
|
||||
// case "--":
|
||||
// case "":
|
||||
// default:
|
||||
// if !sub.DataStructure.PointVariableUnit {
|
||||
// name += " (" + value.Unit() + ")"
|
||||
// }
|
||||
// }
|
||||
// return name
|
||||
// }
|
||||
//
|
||||
// // ta.Reflects - contains the rows.
|
||||
// // ta.Reflects == 0 - something wrong.
|
||||
// // ta.Reflects == 1 - Single row, .
|
||||
//
|
||||
// if len(ta.Reflects) == 0 {
|
||||
// // fmt.Println("len(ta.Reflects) == 0")
|
||||
// // Probs an array of values.
|
||||
// // cm := make(map[string][]valueTypes.UnitValue)
|
||||
// // var length int
|
||||
// //
|
||||
// // if ta.ShowIndex {
|
||||
// // addCol(ta.IndexTitle)
|
||||
// // }
|
||||
// // for _, sub := range ta.Current.Value.Range(true) {
|
||||
// // name := sub.ValueKey()
|
||||
// // if !ta.Current.IsPointVariableUnit() {
|
||||
// // switch sub.Unit() {
|
||||
// // case "--":
|
||||
// // case "":
|
||||
// // default:
|
||||
// // name += " (" + sub.Unit() + ")"
|
||||
// // }
|
||||
// // addCol(name)
|
||||
// // }
|
||||
// //
|
||||
// // cm[name] = sub.Range(valueTypes.SortOrder)
|
||||
// // l := sub.Value.Length()
|
||||
// // if l > length {
|
||||
// // length = l
|
||||
// // }
|
||||
// // }
|
||||
// //
|
||||
// // for index := 0; index < length; index++ {
|
||||
// // data := make(StructValue)
|
||||
// //
|
||||
// // if ta.ShowIndex {
|
||||
// // vi := valueTypes.SetUnitValueInteger(int64(index), ta.IndexTitle, "")
|
||||
// // data[ta.IndexTitle] = vi
|
||||
// // }
|
||||
// //
|
||||
// // for name, value := range cm {
|
||||
// // if index >= len(value) {
|
||||
// // data[name] = valueTypes.UnitValue{}
|
||||
// // }
|
||||
// // data[name] = value[index]
|
||||
// // }
|
||||
// // ret = append(ret, data)
|
||||
// // }
|
||||
// //
|
||||
// // ta.Columns = sortMapByValues(colOrder)
|
||||
//
|
||||
// // cm := make(map[string][]valueTypes.UnitValue)
|
||||
// // cm[ta.Current.DataStructure.PointName] = ta.Current.Value.Range(valueTypes.SortOrder)
|
||||
// // length := ta.Current.Value.Length()
|
||||
// // addCol("Key")
|
||||
// // addCol("Value")
|
||||
// // // data := make(StructValue)
|
||||
// // // data["Key"] = value[name]
|
||||
// // // ret = append(ret, data)
|
||||
// // for index := 0; index < length; index++ {
|
||||
// // data := make(StructValue)
|
||||
// //
|
||||
// // if ta.ShowIndex {
|
||||
// // vi := valueTypes.SetUnitValueInteger(ta.IndexTitle, "", int64(index))
|
||||
// // data[ta.IndexTitle] = vi
|
||||
// // }
|
||||
// //
|
||||
// // for name, value := range cm {
|
||||
// // data[name] = value[index]
|
||||
// // }
|
||||
// // ret = append(ret, data)
|
||||
// // }
|
||||
// break
|
||||
// }
|
||||
//
|
||||
//
|
||||
// if len(ta.Reflects) == 1 {
|
||||
// // Probs an array of values - sw we want to pivot the data.
|
||||
// cm := make(map[string][]valueTypes.UnitValue)
|
||||
// var length int
|
||||
//
|
||||
// if ta.ShowIndex {
|
||||
// addCol(ta.IndexTitle)
|
||||
// }
|
||||
// for _, sub := range ta.Reflects[0] {
|
||||
// name := sub.DataStructure.PointName
|
||||
// if !sub.DataStructure.PointVariableUnit {
|
||||
// switch sub.Value.GetUnit() {
|
||||
// case "--":
|
||||
// case "":
|
||||
// default:
|
||||
// name += " (" + sub.Value.GetUnit() + ")"
|
||||
// }
|
||||
// addCol(name)
|
||||
// } else {
|
||||
// // addCol(name)
|
||||
// // addCol("Units")
|
||||
// // cm[name] = sub.Value.Range(valueTypes.SortOrder)
|
||||
// }
|
||||
//
|
||||
// cm[name] = sub.Value.Range(valueTypes.SortOrder)
|
||||
// l := sub.Value.Length()
|
||||
// if l > length {
|
||||
// length = l
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// tin := ta.Current.GetDataTableIndexNames()
|
||||
// for index := 0; index < length; index++ {
|
||||
// data := make(StructValue)
|
||||
//
|
||||
// if ta.ShowIndex {
|
||||
// var vi valueTypes.UnitValue
|
||||
// if len(tin) > 0 {
|
||||
// vi = valueTypes.SetUnitValueString(ta.IndexTitle, "", tin[index])
|
||||
// } else {
|
||||
// vi = valueTypes.SetUnitValueInteger(ta.IndexTitle, "", int64(index))
|
||||
// }
|
||||
// data[ta.IndexTitle] = vi
|
||||
// }
|
||||
//
|
||||
// for name, value := range cm {
|
||||
// if index >= len(value) {
|
||||
// data[name] = valueTypes.UnitValue{}
|
||||
// continue
|
||||
// // @TODO - potential issue here.
|
||||
// }
|
||||
// data[name] = value[index]
|
||||
// }
|
||||
// ret = append(ret, data)
|
||||
// }
|
||||
//
|
||||
// ta.Columns = sortMapByValues(colOrder)
|
||||
// break
|
||||
// }
|
||||
//
|
||||
//
|
||||
// if ta.ShowIndex {
|
||||
// addCol(ta.IndexTitle)
|
||||
// }
|
||||
//
|
||||
// for rowIndex, _ := range ta.Reflects {
|
||||
// // fmt.Printf("ROW[%d] - size:%d\n", rowIndex, len(ta.Reflects[rowIndex]))
|
||||
// data := make(StructValue)
|
||||
// // fmt.Printf("DEBUG[0].FieldPath == %s\n", row[0].FieldPath.String())
|
||||
//
|
||||
// // size := len(ta.Reflects[rowIndex])
|
||||
// // if size == 1 {
|
||||
// // Current := ta.Reflects[rowIndex][0]
|
||||
// // for _, value := range Current.Value {
|
||||
// // data = append(data, valueTypes.UnitValue{StringValue: ""}) // "Date"
|
||||
// // data = append(data, valueTypes.UnitValue{StringValue: ""}) // "Point Id"
|
||||
// // data = append(data, valueTypes.UnitValue{StringValue: ""}) // "Value"
|
||||
// // data = append(data, valueTypes.UnitValue{StringValue: value.Unit()}) // "Unit"
|
||||
// // data = append(data, valueTypes.UnitValue{StringValue: value.TypeValue}) // "Unit Type"
|
||||
// // data = append(data, valueTypes.UnitValue{StringValue: ""}) // "Group Name"
|
||||
// // data = append(data, valueTypes.UnitValue{StringValue: ""}) // "Description"
|
||||
// // data = append(data, valueTypes.UnitValue{StringValue: ""}) // "Update Freq"
|
||||
// // ret = append(ret, data)
|
||||
// // }
|
||||
// // continue
|
||||
// // }
|
||||
//
|
||||
// if ta.ShowIndex {
|
||||
// var vi valueTypes.UnitValue
|
||||
// vi = valueTypes.SetUnitValueInteger(ta.IndexTitle, "", int64(rowIndex))
|
||||
// data[ta.IndexTitle] = vi
|
||||
// }
|
||||
//
|
||||
// for colIndex, col := range ta.Reflects[rowIndex] {
|
||||
// // It's important that the values are sorted by table header.
|
||||
// // This is so that the headers match with data.
|
||||
// if len(col.ChildReflect) > 0 {
|
||||
// // Handles
|
||||
// for _, sub := range col.ChildReflect {
|
||||
// for _, val := range sub.Value.Range(valueTypes.SortOrder) {
|
||||
// name := colName(sub, &val, len(data))
|
||||
// data[name] = val
|
||||
// addCol(name)
|
||||
// }
|
||||
// }
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
// if col.IsKnown() {
|
||||
// value := ta.Reflects[rowIndex][colIndex].Value
|
||||
// // data = append(data, value.Range(valueTypes.SortOrder)...)
|
||||
// for _, val := range value.Range(valueTypes.SortOrder) {
|
||||
// name := colName(col, &val, len(data))
|
||||
// data[name] = val
|
||||
// addCol(name)
|
||||
// }
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
// dateFormat := col.DataStructure.PointNameDateFormat
|
||||
// if dateFormat == "" {
|
||||
// dateFormat = valueTypes.DateTimeLayout
|
||||
// }
|
||||
// value, _, _ := valueTypes.AnyToUnitValue(col.Value, "", col.DataStructure.PointUnit,
|
||||
// col.DataStructure.PointValueType, dateFormat)
|
||||
//
|
||||
// // data = append(data, value.Range(valueTypes.SortOrder)...)
|
||||
// for _, val := range value.Range(valueTypes.SortOrder) {
|
||||
// name := colName(col, &val, len(data))
|
||||
// data[name] = val
|
||||
// addCol(name)
|
||||
// }
|
||||
// }
|
||||
// ret = append(ret, data)
|
||||
// }
|
||||
//
|
||||
// ta.Columns = sortMapByValues(colOrder)
|
||||
//
|
||||
// // @TODO - Add sorting capability here.
|
||||
// }
|
||||
//
|
||||
// return ret
|
||||
// }
|
||||
//
|
||||
// func sortMapByValues(data map[string]int) []string {
|
||||
// var ret []string
|
||||
// keys := make([]string, 0, len(data))
|
||||
//
|
||||
// for key := range data {
|
||||
// keys = append(keys, key)
|
||||
// }
|
||||
// sort.SliceStable(keys, func(i, j int) bool{
|
||||
// return data[keys[i]] < data[keys[j]]
|
||||
// })
|
||||
//
|
||||
// for _, k := range keys{
|
||||
// ret = append(ret, k)
|
||||
// }
|
||||
// return ret
|
||||
// }
|
622
iSolarCloud/api/GoStruct/struct_table.go
Normal file
622
iSolarCloud/api/GoStruct/struct_table.go
Normal file
@ -0,0 +1,622 @@
|
||||
package GoStruct
|
||||
|
||||
import (
|
||||
"GoSungrow/iSolarCloud/api/GoStruct/output"
|
||||
"GoSungrow/iSolarCloud/api/GoStruct/valueTypes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/MickMake/GoUnify/Only"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
|
||||
type StructTables map[string]*StructTable
|
||||
|
||||
func (sm *StructTables) GetTableNames() []string {
|
||||
var ret []string
|
||||
|
||||
for range Only.Once {
|
||||
for name := range *sm {
|
||||
ret = append(ret, name)
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
type StructTable struct {
|
||||
Area string
|
||||
Name string
|
||||
Current *Reflect
|
||||
|
||||
MapName string
|
||||
Reflects ReflectArray
|
||||
Values StructValues
|
||||
Table output.Table
|
||||
SortOn string
|
||||
ShowIndex bool
|
||||
IndexTitle string
|
||||
IsValid bool
|
||||
Columns []string
|
||||
Rows int
|
||||
Cols int
|
||||
ActualRows int
|
||||
ActualCols int
|
||||
|
||||
Debug bool
|
||||
Error error
|
||||
}
|
||||
|
||||
func (ta *StructTable) PrintDebug(format string, args ...interface{}) {
|
||||
if ta.Debug { _, _ = fmt.Fprintf(os.Stderr, format, args...) }
|
||||
}
|
||||
|
||||
func (ta *StructTable) AddRow(refs ...*Reflect) {
|
||||
for range Only.Once {
|
||||
if ta.Reflects == nil {
|
||||
ta.Reflects = make(ReflectArray, 0)
|
||||
}
|
||||
|
||||
// var row ReflectArrayRow
|
||||
// row = append(row, refs...)
|
||||
ta.Reflects = append(ta.Reflects, append(ReflectArrayRow{}, refs...))
|
||||
}
|
||||
}
|
||||
|
||||
func (ta *StructTable) GetRow(row int) ReflectArrayRow {
|
||||
return ta.Reflects.GetRow(row)
|
||||
}
|
||||
|
||||
func (ta *StructTable) GetHeaders() []string {
|
||||
return ta.Columns
|
||||
}
|
||||
|
||||
func (ta *StructTable) Get() ReflectArray {
|
||||
return ta.Reflects
|
||||
}
|
||||
|
||||
func (ta *StructTable) Process(name string, Current *Reflect) error {
|
||||
|
||||
for range Only.Once {
|
||||
if Current == nil {
|
||||
ta.Error = errors.New("*Reflect is nil")
|
||||
break
|
||||
}
|
||||
|
||||
ta.Current = Current
|
||||
ta.MapName = name
|
||||
ta.Name = ta.Current.Name()
|
||||
ta.IsValid = true
|
||||
|
||||
if ta.Current.DataStructure.DataTableIndex {
|
||||
ta.ShowIndex = ta.Current.DataStructure.DataTableIndex
|
||||
}
|
||||
|
||||
ta.IndexTitle = "Index"
|
||||
if ta.Current.DataStructure.DataTableIndexTitle != "" {
|
||||
ta.IndexTitle = ta.Current.DataStructure.DataTableIndexTitle
|
||||
}
|
||||
|
||||
|
||||
ta.Rows, ta.Cols = ta.Current.CountChildren()
|
||||
var isPivot bool
|
||||
if ta.Current.DataStructure.DataTablePivot {
|
||||
isPivot = true
|
||||
}
|
||||
if ta.Cols <= 1 {
|
||||
isPivot = true
|
||||
}
|
||||
|
||||
// if rows == 0 {
|
||||
// // var refs ReflectArray
|
||||
// for row, Child := range ret.Current.Value.Range(true) {
|
||||
// fmt.Printf("GetTableData() row[%d]: %s - %s == %s\n", row, Child, Child.ValueKey(), Child.StringValue)
|
||||
//
|
||||
// // var refRow ReflectArrayRow
|
||||
// // refRow = append(refRow, ChildStruct)
|
||||
// //
|
||||
// // if len(refRow) > 0 {
|
||||
// // refs = refs.AddRow(refRow...)
|
||||
// // continue
|
||||
// // }
|
||||
//
|
||||
// // Single column.
|
||||
// ret.ShowIndex = true
|
||||
// // refs = refs.AddRow(Child)
|
||||
// }
|
||||
// break
|
||||
// }
|
||||
|
||||
ta.PrintDebug("GetTableData(%s) - path:%s type:%s rows:%d cols:%d\n", name, ta.Current.FieldPath, ta.Current.Kind, ta.Rows, ta.Cols)
|
||||
if ta.Current.IsPointIgnore() {
|
||||
break
|
||||
}
|
||||
|
||||
var refs ReflectArray
|
||||
for row, Child := range ta.Current.ChildReflect {
|
||||
ta.PrintDebug("GetTableData() row[%d]: %s\n", row, Child)
|
||||
if Child.IsPointIgnore() {
|
||||
continue
|
||||
}
|
||||
|
||||
var refRow ReflectArrayRow
|
||||
|
||||
for col, ChildStruct := range Child.ChildReflect {
|
||||
ta.PrintDebug("GetTableData() cell[%d][%d]: %s\n", row, col, Child)
|
||||
if ChildStruct.IsPointIgnore() {
|
||||
continue
|
||||
}
|
||||
|
||||
// Make sure we have a valid sort column name.
|
||||
if ta.Current.DataStructure.DataTableSortOn == ChildStruct.FieldName {
|
||||
ta.SortOn = ChildStruct.DataStructure.PointName
|
||||
}
|
||||
|
||||
if ChildStruct.IsKnown() {
|
||||
refRow = append(refRow, ChildStruct)
|
||||
continue
|
||||
}
|
||||
refRow = append(refRow, ChildStruct)
|
||||
}
|
||||
|
||||
if len(refRow) > 0 {
|
||||
if ta.ActualCols < len(refRow) {
|
||||
ta.ActualCols = len(refRow)
|
||||
}
|
||||
refs = refs.AddRow(refRow...)
|
||||
continue
|
||||
}
|
||||
|
||||
// Single column.
|
||||
ta.ShowIndex = true
|
||||
if Child.IsPointIgnore() {
|
||||
continue
|
||||
}
|
||||
if ta.ActualCols < len(refRow) {
|
||||
ta.ActualCols = len(refRow)
|
||||
}
|
||||
refs = refs.AddRow(Child)
|
||||
}
|
||||
|
||||
if refs == nil {
|
||||
break
|
||||
}
|
||||
|
||||
if !isPivot {
|
||||
ta.Reflects = refs
|
||||
// ret.AddHeader(ret.Reflects[0]...)
|
||||
break
|
||||
}
|
||||
|
||||
// Handle table pivots here.
|
||||
for row := 0; row < len(refs[0]); row++ {
|
||||
var refRow ReflectArrayRow
|
||||
for col := 0; col < len(refs); col++ {
|
||||
refRow = append(refRow, refs[col][row])
|
||||
}
|
||||
if len(refRow) > 0 {
|
||||
ta.Reflects = ta.Reflects.AddRow(refRow...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ta.Error
|
||||
}
|
||||
|
||||
func (ta *StructTable) GetValues() StructValues {
|
||||
|
||||
for range Only.Once {
|
||||
ta.Values = make(StructValues, 0)
|
||||
if !ta.IsValid {
|
||||
break
|
||||
}
|
||||
|
||||
colOrder := make(map[string]int)
|
||||
var colOrderIndex int
|
||||
|
||||
var addCol = func(name string) {
|
||||
if _, ok := colOrder[name]; !ok {
|
||||
colOrder[name] = colOrderIndex
|
||||
colOrderIndex++
|
||||
}
|
||||
}
|
||||
|
||||
var colName = func(sub *Reflect, value *valueTypes.UnitValue, length int) string {
|
||||
name := sub.DataStructure.PointName
|
||||
if value.ValueKey() == "" {
|
||||
if name == "" {
|
||||
name = "Column " + strconv.Itoa(length)
|
||||
}
|
||||
} else {
|
||||
name += " " + value.ValueKey()
|
||||
}
|
||||
switch value.Unit() {
|
||||
case "--":
|
||||
case "":
|
||||
default:
|
||||
if !sub.DataStructure.PointVariableUnit {
|
||||
name += " (" + value.Unit() + ")"
|
||||
}
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
// ta.Reflects - contains the rows.
|
||||
// ta.Reflects == 0 - something wrong.
|
||||
// ta.Reflects == 1 - Single row, .
|
||||
|
||||
if len(ta.Reflects) == 0 {
|
||||
// fmt.Println("len(ta.Reflects) == 0")
|
||||
// Probs an array of values.
|
||||
// cm := make(map[string][]valueTypes.UnitValue)
|
||||
// var length int
|
||||
//
|
||||
// if ta.ShowIndex {
|
||||
// addCol(ta.IndexTitle)
|
||||
// }
|
||||
// for _, sub := range ta.Current.Value.Range(true) {
|
||||
// name := sub.ValueKey()
|
||||
// if !ta.Current.IsPointVariableUnit() {
|
||||
// switch sub.Unit() {
|
||||
// case "--":
|
||||
// case "":
|
||||
// default:
|
||||
// name += " (" + sub.Unit() + ")"
|
||||
// }
|
||||
// addCol(name)
|
||||
// }
|
||||
//
|
||||
// cm[name] = sub.Range(valueTypes.SortOrder)
|
||||
// l := sub.Value.Length()
|
||||
// if l > length {
|
||||
// length = l
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for index := 0; index < length; index++ {
|
||||
// data := make(StructValue)
|
||||
//
|
||||
// if ta.ShowIndex {
|
||||
// vi := valueTypes.SetUnitValueInteger(int64(index), ta.IndexTitle, "")
|
||||
// data[ta.IndexTitle] = vi
|
||||
// }
|
||||
//
|
||||
// for name, value := range cm {
|
||||
// if index >= len(value) {
|
||||
// data[name] = valueTypes.UnitValue{}
|
||||
// }
|
||||
// data[name] = value[index]
|
||||
// }
|
||||
// ret = append(ret, data)
|
||||
// }
|
||||
//
|
||||
// ta.Columns = sortMapByValues(colOrder)
|
||||
|
||||
// cm := make(map[string][]valueTypes.UnitValue)
|
||||
// cm[ta.Current.DataStructure.PointName] = ta.Current.Value.Range(valueTypes.SortOrder)
|
||||
// length := ta.Current.Value.Length()
|
||||
// addCol("Key")
|
||||
// addCol("Value")
|
||||
// // data := make(StructValue)
|
||||
// // data["Key"] = value[name]
|
||||
// // ret = append(ret, data)
|
||||
// for index := 0; index < length; index++ {
|
||||
// data := make(StructValue)
|
||||
//
|
||||
// if ta.ShowIndex {
|
||||
// vi := valueTypes.SetUnitValueInteger(ta.IndexTitle, "", int64(index))
|
||||
// data[ta.IndexTitle] = vi
|
||||
// }
|
||||
//
|
||||
// for name, value := range cm {
|
||||
// data[name] = value[index]
|
||||
// }
|
||||
// ret = append(ret, data)
|
||||
// }
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
if len(ta.Reflects) == 1 {
|
||||
// Probs an array of values - sw we want to pivot the data.
|
||||
cm := make(map[string][]valueTypes.UnitValue)
|
||||
var length int
|
||||
|
||||
if ta.ShowIndex {
|
||||
addCol(ta.IndexTitle)
|
||||
}
|
||||
for _, sub := range ta.Reflects[0] {
|
||||
name := sub.DataStructure.PointName
|
||||
if !sub.DataStructure.PointVariableUnit {
|
||||
switch sub.Value.GetUnit() {
|
||||
case "--":
|
||||
case "":
|
||||
default:
|
||||
name += " (" + sub.Value.GetUnit() + ")"
|
||||
}
|
||||
addCol(name)
|
||||
} else {
|
||||
// addCol(name)
|
||||
// addCol("Units")
|
||||
// cm[name] = sub.Value.Range(valueTypes.SortOrder)
|
||||
}
|
||||
|
||||
cm[name] = sub.Value.Range(valueTypes.SortOrder)
|
||||
l := sub.Value.Length()
|
||||
if l > length {
|
||||
length = l
|
||||
}
|
||||
}
|
||||
|
||||
tin := ta.Current.GetDataTableIndexNames()
|
||||
for index := 0; index < length; index++ {
|
||||
data := make(StructValue)
|
||||
|
||||
if ta.ShowIndex {
|
||||
var vi valueTypes.UnitValue
|
||||
if len(tin) > 0 {
|
||||
vi = valueTypes.SetUnitValueString(ta.IndexTitle, "", tin[index])
|
||||
} else {
|
||||
vi = valueTypes.SetUnitValueInteger(ta.IndexTitle, "", int64(index))
|
||||
}
|
||||
data[ta.IndexTitle] = vi
|
||||
}
|
||||
|
||||
for name, value := range cm {
|
||||
if index >= len(value) {
|
||||
data[name] = valueTypes.UnitValue{}
|
||||
continue
|
||||
// @TODO - potential issue here.
|
||||
}
|
||||
data[name] = value[index]
|
||||
}
|
||||
ta.Values = append(ta.Values, data)
|
||||
}
|
||||
|
||||
ta.Columns = sortMapByValues(colOrder)
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
if ta.ShowIndex {
|
||||
addCol(ta.IndexTitle)
|
||||
}
|
||||
|
||||
for rowIndex, _ := range ta.Reflects {
|
||||
// fmt.Printf("ROW[%d] - size:%d\n", rowIndex, len(ta.Reflects[rowIndex]))
|
||||
data := make(StructValue)
|
||||
// fmt.Printf("DEBUG[0].FieldPath == %s\n", row[0].FieldPath.String())
|
||||
|
||||
// size := len(ta.Reflects[rowIndex])
|
||||
// if size == 1 {
|
||||
// Current := ta.Reflects[rowIndex][0]
|
||||
// for _, value := range Current.Value {
|
||||
// data = append(data, valueTypes.UnitValue{StringValue: ""}) // "Date"
|
||||
// data = append(data, valueTypes.UnitValue{StringValue: ""}) // "Point Id"
|
||||
// data = append(data, valueTypes.UnitValue{StringValue: ""}) // "Value"
|
||||
// data = append(data, valueTypes.UnitValue{StringValue: value.Unit()}) // "Unit"
|
||||
// data = append(data, valueTypes.UnitValue{StringValue: value.TypeValue}) // "Unit Type"
|
||||
// data = append(data, valueTypes.UnitValue{StringValue: ""}) // "Group Name"
|
||||
// data = append(data, valueTypes.UnitValue{StringValue: ""}) // "Description"
|
||||
// data = append(data, valueTypes.UnitValue{StringValue: ""}) // "Update Freq"
|
||||
// ret = append(ret, data)
|
||||
// }
|
||||
// continue
|
||||
// }
|
||||
|
||||
if ta.ShowIndex {
|
||||
var vi valueTypes.UnitValue
|
||||
vi = valueTypes.SetUnitValueInteger(ta.IndexTitle, "", int64(rowIndex))
|
||||
data[ta.IndexTitle] = vi
|
||||
}
|
||||
|
||||
for colIndex, col := range ta.Reflects[rowIndex] {
|
||||
// It's important that the values are sorted by table header.
|
||||
// This is so that the headers match with data.
|
||||
if len(col.ChildReflect) > 0 {
|
||||
// Handles
|
||||
for _, sub := range col.ChildReflect {
|
||||
for _, val := range sub.Value.Range(valueTypes.SortOrder) {
|
||||
name := colName(sub, &val, len(data))
|
||||
data[name] = val
|
||||
addCol(name)
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if col.IsKnown() {
|
||||
value := ta.Reflects[rowIndex][colIndex].Value
|
||||
// data = append(data, value.Range(valueTypes.SortOrder)...)
|
||||
for _, val := range value.Range(valueTypes.SortOrder) {
|
||||
name := colName(col, &val, len(data))
|
||||
data[name] = val
|
||||
addCol(name)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
dateFormat := col.DataStructure.PointNameDateFormat
|
||||
if dateFormat == "" {
|
||||
dateFormat = valueTypes.DateTimeLayout
|
||||
}
|
||||
value, _, _ := valueTypes.AnyToUnitValue(col.Value, "", col.DataStructure.PointUnit,
|
||||
col.DataStructure.PointValueType, dateFormat)
|
||||
|
||||
// data = append(data, value.Range(valueTypes.SortOrder)...)
|
||||
for _, val := range value.Range(valueTypes.SortOrder) {
|
||||
name := colName(col, &val, len(data))
|
||||
data[name] = val
|
||||
addCol(name)
|
||||
}
|
||||
}
|
||||
ta.Values = append(ta.Values, data)
|
||||
}
|
||||
|
||||
ta.Columns = sortMapByValues(colOrder)
|
||||
|
||||
// @TODO - Add sorting capability here.
|
||||
}
|
||||
|
||||
return ta.Values
|
||||
}
|
||||
|
||||
func (ta *StructTable) CreateTable() (output.Table, error) { // (output.Tables, GoStruct.StructValuesMap) {
|
||||
|
||||
for range Only.Once {
|
||||
if ta.Current == nil {
|
||||
ta.Error = errors.New("*Reflect is nil")
|
||||
break
|
||||
}
|
||||
|
||||
values := ta.GetValues()
|
||||
if (values == nil) || (len(values) == 0) {
|
||||
fmt.Printf("No data table results for '%s'\n", ta.MapName)
|
||||
break
|
||||
}
|
||||
|
||||
headers := ta.GetHeaders()
|
||||
ta.Table = output.NewTable(headers...)
|
||||
for row := range values {
|
||||
var items []interface{}
|
||||
for _, col := range ta.Columns {
|
||||
items = append(items, values.GetCell(row, col).String())
|
||||
}
|
||||
ta.Error = ta.Table.AddRow(items...)
|
||||
if ta.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
if ta.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
title := ta.Current.DataStructure.DataTableTitle
|
||||
if title == "" {
|
||||
title = ta.Current.DataStructure.DataTableName
|
||||
}
|
||||
if title == "" {
|
||||
title = valueTypes.PointToName(ta.Current.DataStructure.DataTableId)
|
||||
}
|
||||
// if title == "" {
|
||||
// title = valueTypes.PointToName(ta.Current.DataStructure.PointId)
|
||||
// }
|
||||
// dm.EndPoint.GetRequestArgNames()
|
||||
|
||||
ta.Table.SetName(ta.MapName)
|
||||
if title == "" {
|
||||
ta.Table.SetTitle("DataTable %s.%s", ta.Area, ta.Name)
|
||||
ta.Table.SetFilePrefix("%s.%s", ta.Area, ta.Name)
|
||||
} else {
|
||||
ta.Table.SetTitle("DataTable %s.%s (%s)", ta.Area, ta.Name, title)
|
||||
ta.Table.SetFilePrefix("%s.%s-%s", ta.Area, ta.Name, ta.Current.DataStructure.DataTableId)
|
||||
}
|
||||
|
||||
// table.Sort(td.SortOn)
|
||||
ta.Table.SetJson(nil)
|
||||
ta.Table.SetRaw(nil)
|
||||
|
||||
ta.Table.SetGraphFilter("") // @TODO - Consider setting graph options here instead of iSolarCloud/data.go:487
|
||||
|
||||
// if sgd.Options.GraphRequest.TimeColumn == nil {
|
||||
// for _, col := range table.GetHeaders() {
|
||||
// val := value.GetCell(0, col)
|
||||
// if val.Type() == "DateTime" {
|
||||
// sgd.Options.GraphRequest.TimeColumn = &col
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if sgd.Options.GraphRequest.DataColumn == nil {
|
||||
// for _, col := range table.GetHeaders() {
|
||||
// val := value.GetCell(0, col)
|
||||
// if val.IsNumber() {
|
||||
// sgd.Options.GraphRequest.DataColumn = &col
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if sgd.Options.GraphRequest.ValueColumn == nil {
|
||||
// for _, col := range table.GetHeaders() {
|
||||
// val := value.GetCell(0, col)
|
||||
// if val.IsNumber() {
|
||||
// sgd.Options.GraphRequest.ValueColumn = &col
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
return ta.Table, ta.Error
|
||||
}
|
||||
|
||||
|
||||
type ReflectArray []ReflectArrayRow
|
||||
type ReflectArrayRow []*Reflect
|
||||
|
||||
func (ta *ReflectArray) AddRow(refs ...*Reflect) ReflectArray {
|
||||
for range Only.Once {
|
||||
if ta == nil {
|
||||
*ta = make(ReflectArray, 0)
|
||||
}
|
||||
|
||||
var row ReflectArrayRow
|
||||
row = append(row, refs...)
|
||||
*ta = append(*ta, row)
|
||||
}
|
||||
return *ta
|
||||
}
|
||||
|
||||
func (ta *ReflectArray) GetRow(row int) ReflectArrayRow {
|
||||
if row >= len(*ta) {
|
||||
return ReflectArrayRow{}
|
||||
}
|
||||
return (*ta)[row]
|
||||
}
|
||||
|
||||
|
||||
type StructValuesMap map[string]StructValues
|
||||
type StructValue map[string]valueTypes.UnitValue
|
||||
|
||||
type StructValues []StructValue
|
||||
|
||||
func (ta *StructValues) GetCell(row int, col string) valueTypes.UnitValue {
|
||||
var ret valueTypes.UnitValue
|
||||
for range Only.Once {
|
||||
if row >= len(*ta) {
|
||||
ret = valueTypes.SetUnitValueString("error", "error", "row > size")
|
||||
break
|
||||
}
|
||||
|
||||
if _, ok := (*ta)[row][col]; !ok {
|
||||
ret = valueTypes.SetUnitValueString("", "", "")
|
||||
break
|
||||
}
|
||||
|
||||
ret = (*ta)[row][col]
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
func sortMapByValues(data map[string]int) []string {
|
||||
var ret []string
|
||||
keys := make([]string, 0, len(data))
|
||||
|
||||
for key := range data {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.SliceStable(keys, func(i, j int) bool{
|
||||
return data[keys[i]] < data[keys[j]]
|
||||
})
|
||||
|
||||
for _, k := range keys{
|
||||
ret = append(ret, k)
|
||||
}
|
||||
return ret
|
||||
}
|
@ -7,8 +7,6 @@ import (
|
||||
"github.com/MickMake/GoUnify/Only"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@ -29,12 +27,14 @@ type StructMapOptions struct {
|
||||
type StructMap struct {
|
||||
StructMapOptions
|
||||
|
||||
SortOn string
|
||||
Start *Reflect
|
||||
Map map[string]*Reflect
|
||||
TableMap map[string]*Reflect
|
||||
VirtualMap map[string]*Reflect
|
||||
_Timestamp valueTypes.DateTime
|
||||
SortOn string
|
||||
Start *Reflect
|
||||
Map map[string]*Reflect
|
||||
TableMap map[string]*Reflect
|
||||
VirtualMap map[string]*Reflect
|
||||
_Timestamp valueTypes.DateTime
|
||||
|
||||
Error error
|
||||
}
|
||||
|
||||
func (sm *StructMap) PrintDebug(format string, args ...interface{}) {
|
||||
@ -729,607 +729,6 @@ func (sm *StructMap) IsPointSplitOn(Current *Reflect) bool {
|
||||
}
|
||||
|
||||
|
||||
func (sm *StructMap) GetTables() StructTables {
|
||||
var ret StructTables
|
||||
|
||||
for range Only.Once {
|
||||
st := sm.GetResultTableData()
|
||||
ret = append(ret, st)
|
||||
|
||||
names := sm.GetTableNames()
|
||||
for _, name := range names {
|
||||
st = sm.GetTableData(name)
|
||||
if !st.IsValid {
|
||||
continue
|
||||
}
|
||||
ret = append(ret, st)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (sm *StructMap) GetTableNames() []string {
|
||||
var ret []string
|
||||
|
||||
for range Only.Once {
|
||||
for name := range sm.TableMap {
|
||||
ret = append(ret, name)
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (sm *StructMap) GetTableData(name string) StructTable {
|
||||
var ret StructTable
|
||||
|
||||
for range Only.Once {
|
||||
var ok bool
|
||||
if ret.Current, ok = sm.TableMap[name]; !ok {
|
||||
break
|
||||
}
|
||||
|
||||
ret.Name = ret.Current.Name()
|
||||
ret.IsValid = true
|
||||
|
||||
if ret.Current.DataStructure.DataTableIndex {
|
||||
ret.ShowIndex = ret.Current.DataStructure.DataTableIndex
|
||||
}
|
||||
|
||||
ret.IndexTitle = "Index"
|
||||
if ret.Current.DataStructure.DataTableIndexTitle != "" {
|
||||
ret.IndexTitle = ret.Current.DataStructure.DataTableIndexTitle
|
||||
}
|
||||
|
||||
|
||||
ret.Rows, ret.Cols = ret.Current.CountChildren()
|
||||
var isPivot bool
|
||||
if ret.Current.DataStructure.DataTablePivot {
|
||||
isPivot = true
|
||||
}
|
||||
if ret.Cols <= 1 {
|
||||
isPivot = true
|
||||
}
|
||||
|
||||
// if rows == 0 {
|
||||
// // var refs ReflectArray
|
||||
// for row, Child := range ret.Current.Value.Range(true) {
|
||||
// fmt.Printf("GetTableData() row[%d]: %s - %s == %s\n", row, Child, Child.ValueKey(), Child.StringValue)
|
||||
//
|
||||
// // var refRow ReflectArrayRow
|
||||
// // refRow = append(refRow, ChildStruct)
|
||||
// //
|
||||
// // if len(refRow) > 0 {
|
||||
// // refs = refs.AddRow(refRow...)
|
||||
// // continue
|
||||
// // }
|
||||
//
|
||||
// // Single column.
|
||||
// ret.ShowIndex = true
|
||||
// // refs = refs.AddRow(Child)
|
||||
// }
|
||||
// break
|
||||
// }
|
||||
|
||||
sm.PrintDebug("GetTableData(%s) - path:%s type:%s rows:%d cols:%d\n", name, ret.Current.FieldPath, ret.Current.Kind, ret.Rows, ret.Cols)
|
||||
if ret.Current.IsPointIgnore() {
|
||||
break
|
||||
}
|
||||
|
||||
var refs ReflectArray
|
||||
for row, Child := range ret.Current.ChildReflect {
|
||||
sm.PrintDebug("GetTableData() row[%d]: %s\n", row, Child)
|
||||
if Child.IsPointIgnore() {
|
||||
continue
|
||||
}
|
||||
|
||||
var refRow ReflectArrayRow
|
||||
|
||||
for col, ChildStruct := range Child.ChildReflect {
|
||||
sm.PrintDebug("GetTableData() cell[%d][%d]: %s\n", row, col, Child)
|
||||
if ChildStruct.IsPointIgnore() {
|
||||
continue
|
||||
}
|
||||
|
||||
// Make sure we have a valid sort column name.
|
||||
if ret.Current.DataStructure.DataTableSortOn == ChildStruct.FieldName {
|
||||
ret.SortOn = ChildStruct.DataStructure.PointName
|
||||
}
|
||||
|
||||
if ChildStruct.IsKnown() {
|
||||
refRow = append(refRow, ChildStruct)
|
||||
continue
|
||||
}
|
||||
refRow = append(refRow, ChildStruct)
|
||||
}
|
||||
|
||||
if len(refRow) > 0 {
|
||||
if ret.ActualCols < len(refRow) {
|
||||
ret.ActualCols = len(refRow)
|
||||
}
|
||||
refs = refs.AddRow(refRow...)
|
||||
continue
|
||||
}
|
||||
|
||||
// Single column.
|
||||
ret.ShowIndex = true
|
||||
if Child.IsPointIgnore() {
|
||||
continue
|
||||
}
|
||||
if ret.ActualCols < len(refRow) {
|
||||
ret.ActualCols = len(refRow)
|
||||
}
|
||||
refs = refs.AddRow(Child)
|
||||
}
|
||||
|
||||
if refs == nil {
|
||||
break
|
||||
}
|
||||
|
||||
if !isPivot {
|
||||
ret.Reflects = refs
|
||||
// ret.AddHeader(ret.Reflects[0]...)
|
||||
break
|
||||
}
|
||||
|
||||
// Handle table pivots here.
|
||||
for row := 0; row < len(refs[0]); row++ {
|
||||
var refRow ReflectArrayRow
|
||||
for col := 0; col < len(refs); col++ {
|
||||
refRow = append(refRow, refs[col][row])
|
||||
}
|
||||
if len(refRow) > 0 {
|
||||
ret.Reflects = ret.Reflects.AddRow(refRow...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (sm *StructMap) GetResultTableData() StructTable {
|
||||
var ret StructTable
|
||||
|
||||
fmt.Printf("NOT IMPLEMENTED YET.\n")
|
||||
// for range Only.Once {
|
||||
// var sorted []string
|
||||
// // @TODO - Add in other column sorting options here.
|
||||
// for name := range sm.Map {
|
||||
// sorted = append(sorted, name)
|
||||
// }
|
||||
//
|
||||
// ret.Name = "Results"
|
||||
// ret.IsValid = true
|
||||
//
|
||||
// for _, name := range sorted {
|
||||
// Current := sm.Map[name]
|
||||
//
|
||||
// rows, cols := Current.CountChildren()
|
||||
// // fmt.Printf("GetTableData(%s) - path:%s type:%s rows:%d cols:%d\n", name, ret.Current.FieldPath, ret.Current.Kind, rows, cols)
|
||||
// sm.PrintDebug("GetResultTableData(%s) - path:%s type:%s rows:%d cols:%d\n", name, Current.FieldPath, Current.Kind, rows, cols)
|
||||
// if Current.IsPointIgnore() {
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// // if len(refs) > 0 {
|
||||
// // ret.AddRow(refs...)
|
||||
// // }
|
||||
//
|
||||
// // for row, Child := range Current.ChildReflect {
|
||||
// // fmt.Printf("[%s]%s - Known:%t Current:%d / Child:%d\n", Child.FieldPath, ret.Current.Kind,
|
||||
// // Child.IsKnown(),
|
||||
// // len(ret.Current.ChildReflect),
|
||||
// // len(Child.ChildReflect))
|
||||
// // if sm.Debug {
|
||||
// // _, _ = fmt.Fprintf(os.Stderr, "GetResultTableData() row[%d]: %s\n", row, Child)
|
||||
// // }
|
||||
// // if Child.IsPointIgnore() {
|
||||
// // continue
|
||||
// // }
|
||||
// //
|
||||
// // var refs []*Reflect
|
||||
// //
|
||||
// // for col, ChildStruct := range Child.ChildReflect {
|
||||
// // // fmt.Printf("[%s]%s - Known:%t Current:%d / Child:%d / ChildStruct:%d\n", ChildStruct.FieldPath, ret.Current.Kind,
|
||||
// // // ChildStruct.IsKnown(),
|
||||
// // // len(ret.Current.ChildReflect),
|
||||
// // // len(Child.ChildReflect),
|
||||
// // // len(ChildStruct.ChildReflect))
|
||||
// // if sm.Debug {
|
||||
// // _, _ = fmt.Fprintf(os.Stderr, "GetResultTableData() cell[%d][%d]: %s\n", row, col, Child)
|
||||
// // }
|
||||
// // if ChildStruct.IsPointIgnore() {
|
||||
// // continue
|
||||
// // }
|
||||
// //
|
||||
// // // Make sure we have a valid sort column name.
|
||||
// // if Current.DataStructure.DataTableSortOn != "" {
|
||||
// // if Current.DataStructure.DataTableSortOn == ChildStruct.FieldName {
|
||||
// // ret.SortOn = ChildStruct.DataStructure.PointName
|
||||
// // }
|
||||
// // }
|
||||
// //
|
||||
// // if ChildStruct.IsKnown() {
|
||||
// // refs = append(refs, ChildStruct)
|
||||
// // continue
|
||||
// // }
|
||||
// // refs = append(refs, ChildStruct)
|
||||
// // }
|
||||
// //
|
||||
// // if len(refs) > 0 {
|
||||
// // ret.AddRow(refs...)
|
||||
// // }
|
||||
// }
|
||||
// }
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
type StructTable struct {
|
||||
Name string
|
||||
Current *Reflect
|
||||
Reflects ReflectArray
|
||||
SortOn string
|
||||
ShowIndex bool
|
||||
IndexTitle string
|
||||
IsValid bool
|
||||
Columns []string
|
||||
Rows int
|
||||
Cols int
|
||||
ActualRows int
|
||||
ActualCols int
|
||||
}
|
||||
|
||||
|
||||
type ReflectArray []ReflectArrayRow
|
||||
type ReflectArrayRow []*Reflect
|
||||
|
||||
func (ta *ReflectArray) AddRow(refs ...*Reflect) ReflectArray {
|
||||
for range Only.Once {
|
||||
if ta == nil {
|
||||
*ta = make(ReflectArray, 0)
|
||||
}
|
||||
|
||||
var row ReflectArrayRow
|
||||
row = append(row, refs...)
|
||||
*ta = append(*ta, row)
|
||||
}
|
||||
return *ta
|
||||
}
|
||||
|
||||
func (ta *ReflectArray) GetRow(row int) ReflectArrayRow {
|
||||
if row >= len(*ta) {
|
||||
return ReflectArrayRow{}
|
||||
}
|
||||
return (*ta)[row]
|
||||
}
|
||||
|
||||
|
||||
type StructTables []StructTable
|
||||
type StructValues []StructValue
|
||||
type StructValue map[string]valueTypes.UnitValue
|
||||
|
||||
func (ta *StructValues) GetCell(row int, col string) string {
|
||||
var ret string
|
||||
for range Only.Once {
|
||||
if row >= len(*ta) {
|
||||
ret = "row > size"
|
||||
break
|
||||
}
|
||||
|
||||
if _, ok := (*ta)[row][col]; !ok {
|
||||
ret = ""
|
||||
break
|
||||
}
|
||||
|
||||
ret = (*ta)[row][col].String()
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (ta *StructTable) AddRow(refs ...*Reflect) {
|
||||
for range Only.Once {
|
||||
if ta.Reflects == nil {
|
||||
ta.Reflects = make(ReflectArray, 0)
|
||||
}
|
||||
|
||||
// var row ReflectArrayRow
|
||||
// row = append(row, refs...)
|
||||
ta.Reflects = append(ta.Reflects, append(ReflectArrayRow{}, refs...))
|
||||
}
|
||||
}
|
||||
|
||||
func (ta *StructTable) GetRow(row int) ReflectArrayRow {
|
||||
return ta.Reflects.GetRow(row)
|
||||
}
|
||||
|
||||
func (ta *StructTable) GetHeaders() []string {
|
||||
return ta.Columns
|
||||
}
|
||||
|
||||
func (ta *StructTable) Get() ReflectArray {
|
||||
return ta.Reflects
|
||||
}
|
||||
|
||||
func (ta *StructTable) GetValues() StructValues {
|
||||
ret := make(StructValues, 0)
|
||||
|
||||
for range Only.Once {
|
||||
if !ta.IsValid {
|
||||
break
|
||||
}
|
||||
|
||||
colOrder := make(map[string]int)
|
||||
var colOrderIndex int
|
||||
|
||||
var addCol = func(name string) {
|
||||
if _, ok := colOrder[name]; !ok {
|
||||
colOrder[name] = colOrderIndex
|
||||
colOrderIndex++
|
||||
}
|
||||
}
|
||||
|
||||
var colName = func(sub *Reflect, value *valueTypes.UnitValue, length int) string {
|
||||
name := sub.DataStructure.PointName
|
||||
if value.ValueKey() == "" {
|
||||
if name == "" {
|
||||
name = "Column " + strconv.Itoa(length)
|
||||
}
|
||||
} else {
|
||||
name += " " + value.ValueKey()
|
||||
}
|
||||
switch value.Unit() {
|
||||
case "--":
|
||||
case "":
|
||||
default:
|
||||
if !sub.DataStructure.PointVariableUnit {
|
||||
name += " (" + value.Unit() + ")"
|
||||
}
|
||||
}
|
||||
return name
|
||||
}
|
||||
|
||||
// ta.Reflects - contains the rows.
|
||||
// ta.Reflects == 0 - something wrong.
|
||||
// ta.Reflects == 1 - Single row, .
|
||||
|
||||
if len(ta.Reflects) == 0 {
|
||||
// fmt.Println("len(ta.Reflects) == 0")
|
||||
// Probs an array of values.
|
||||
// cm := make(map[string][]valueTypes.UnitValue)
|
||||
// var length int
|
||||
//
|
||||
// if ta.ShowIndex {
|
||||
// addCol(ta.IndexTitle)
|
||||
// }
|
||||
// for _, sub := range ta.Current.Value.Range(true) {
|
||||
// name := sub.ValueKey()
|
||||
// if !ta.Current.IsPointVariableUnit() {
|
||||
// switch sub.Unit() {
|
||||
// case "--":
|
||||
// case "":
|
||||
// default:
|
||||
// name += " (" + sub.Unit() + ")"
|
||||
// }
|
||||
// addCol(name)
|
||||
// }
|
||||
//
|
||||
// cm[name] = sub.Range(valueTypes.SortOrder)
|
||||
// l := sub.Value.Length()
|
||||
// if l > length {
|
||||
// length = l
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// for index := 0; index < length; index++ {
|
||||
// data := make(StructValue)
|
||||
//
|
||||
// if ta.ShowIndex {
|
||||
// vi := valueTypes.SetUnitValueInteger(int64(index), ta.IndexTitle, "")
|
||||
// data[ta.IndexTitle] = vi
|
||||
// }
|
||||
//
|
||||
// for name, value := range cm {
|
||||
// if index >= len(value) {
|
||||
// data[name] = valueTypes.UnitValue{}
|
||||
// }
|
||||
// data[name] = value[index]
|
||||
// }
|
||||
// ret = append(ret, data)
|
||||
// }
|
||||
//
|
||||
// ta.Columns = sortMapByValues(colOrder)
|
||||
|
||||
// cm := make(map[string][]valueTypes.UnitValue)
|
||||
// cm[ta.Current.DataStructure.PointName] = ta.Current.Value.Range(valueTypes.SortOrder)
|
||||
// length := ta.Current.Value.Length()
|
||||
// addCol("Key")
|
||||
// addCol("Value")
|
||||
// // data := make(StructValue)
|
||||
// // data["Key"] = value[name]
|
||||
// // ret = append(ret, data)
|
||||
// for index := 0; index < length; index++ {
|
||||
// data := make(StructValue)
|
||||
//
|
||||
// if ta.ShowIndex {
|
||||
// vi := valueTypes.SetUnitValueInteger(ta.IndexTitle, "", int64(index))
|
||||
// data[ta.IndexTitle] = vi
|
||||
// }
|
||||
//
|
||||
// for name, value := range cm {
|
||||
// data[name] = value[index]
|
||||
// }
|
||||
// ret = append(ret, data)
|
||||
// }
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
if len(ta.Reflects) == 1 {
|
||||
// Probs an array of values - sw we want to pivot the data.
|
||||
cm := make(map[string][]valueTypes.UnitValue)
|
||||
var length int
|
||||
|
||||
if ta.ShowIndex {
|
||||
addCol(ta.IndexTitle)
|
||||
}
|
||||
for _, sub := range ta.Reflects[0] {
|
||||
name := sub.DataStructure.PointName
|
||||
if !sub.DataStructure.PointVariableUnit {
|
||||
switch sub.Value.GetUnit() {
|
||||
case "--":
|
||||
case "":
|
||||
default:
|
||||
name += " (" + sub.Value.GetUnit() + ")"
|
||||
}
|
||||
addCol(name)
|
||||
} else {
|
||||
// addCol(name)
|
||||
// addCol("Units")
|
||||
// cm[name] = sub.Value.Range(valueTypes.SortOrder)
|
||||
}
|
||||
|
||||
cm[name] = sub.Value.Range(valueTypes.SortOrder)
|
||||
l := sub.Value.Length()
|
||||
if l > length {
|
||||
length = l
|
||||
}
|
||||
}
|
||||
|
||||
tin := ta.Current.GetDataTableIndexNames()
|
||||
for index := 0; index < length; index++ {
|
||||
data := make(StructValue)
|
||||
|
||||
if ta.ShowIndex {
|
||||
var vi valueTypes.UnitValue
|
||||
if len(tin) > 0 {
|
||||
vi = valueTypes.SetUnitValueString(ta.IndexTitle, "", tin[index])
|
||||
} else {
|
||||
vi = valueTypes.SetUnitValueInteger(ta.IndexTitle, "", int64(index))
|
||||
}
|
||||
data[ta.IndexTitle] = vi
|
||||
}
|
||||
|
||||
for name, value := range cm {
|
||||
if index >= len(value) {
|
||||
data[name] = valueTypes.UnitValue{}
|
||||
continue
|
||||
// @TODO - potential issue here.
|
||||
}
|
||||
data[name] = value[index]
|
||||
}
|
||||
ret = append(ret, data)
|
||||
}
|
||||
|
||||
ta.Columns = sortMapByValues(colOrder)
|
||||
break
|
||||
}
|
||||
|
||||
|
||||
if ta.ShowIndex {
|
||||
addCol(ta.IndexTitle)
|
||||
}
|
||||
|
||||
for rowIndex, _ := range ta.Reflects {
|
||||
// fmt.Printf("ROW[%d] - size:%d\n", rowIndex, len(ta.Reflects[rowIndex]))
|
||||
data := make(StructValue)
|
||||
// fmt.Printf("DEBUG[0].FieldPath == %s\n", row[0].FieldPath.String())
|
||||
|
||||
// size := len(ta.Reflects[rowIndex])
|
||||
// if size == 1 {
|
||||
// Current := ta.Reflects[rowIndex][0]
|
||||
// for _, value := range Current.Value {
|
||||
// data = append(data, valueTypes.UnitValue{StringValue: ""}) // "Date"
|
||||
// data = append(data, valueTypes.UnitValue{StringValue: ""}) // "Point Id"
|
||||
// data = append(data, valueTypes.UnitValue{StringValue: ""}) // "Value"
|
||||
// data = append(data, valueTypes.UnitValue{StringValue: value.Unit()}) // "Unit"
|
||||
// data = append(data, valueTypes.UnitValue{StringValue: value.TypeValue}) // "Unit Type"
|
||||
// data = append(data, valueTypes.UnitValue{StringValue: ""}) // "Group Name"
|
||||
// data = append(data, valueTypes.UnitValue{StringValue: ""}) // "Description"
|
||||
// data = append(data, valueTypes.UnitValue{StringValue: ""}) // "Update Freq"
|
||||
// ret = append(ret, data)
|
||||
// }
|
||||
// continue
|
||||
// }
|
||||
|
||||
if ta.ShowIndex {
|
||||
var vi valueTypes.UnitValue
|
||||
vi = valueTypes.SetUnitValueInteger(ta.IndexTitle, "", int64(rowIndex))
|
||||
data[ta.IndexTitle] = vi
|
||||
}
|
||||
|
||||
for colIndex, col := range ta.Reflects[rowIndex] {
|
||||
// It's important that the values are sorted by table header.
|
||||
// This is so that the headers match with data.
|
||||
if len(col.ChildReflect) > 0 {
|
||||
// Handles
|
||||
for _, sub := range col.ChildReflect {
|
||||
for _, val := range sub.Value.Range(valueTypes.SortOrder) {
|
||||
name := colName(sub, &val, len(data))
|
||||
data[name] = val
|
||||
addCol(name)
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if col.IsKnown() {
|
||||
value := ta.Reflects[rowIndex][colIndex].Value
|
||||
// data = append(data, value.Range(valueTypes.SortOrder)...)
|
||||
for _, val := range value.Range(valueTypes.SortOrder) {
|
||||
name := colName(col, &val, len(data))
|
||||
data[name] = val
|
||||
addCol(name)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
dateFormat := col.DataStructure.PointNameDateFormat
|
||||
if dateFormat == "" {
|
||||
dateFormat = valueTypes.DateTimeLayout
|
||||
}
|
||||
value, _, _ := valueTypes.AnyToUnitValue(col.Value, "", col.DataStructure.PointUnit,
|
||||
col.DataStructure.PointValueType, dateFormat)
|
||||
|
||||
// data = append(data, value.Range(valueTypes.SortOrder)...)
|
||||
for _, val := range value.Range(valueTypes.SortOrder) {
|
||||
name := colName(col, &val, len(data))
|
||||
data[name] = val
|
||||
addCol(name)
|
||||
}
|
||||
}
|
||||
ret = append(ret, data)
|
||||
}
|
||||
|
||||
ta.Columns = sortMapByValues(colOrder)
|
||||
|
||||
// @TODO - Add sorting capability here.
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func sortMapByValues(data map[string]int) []string {
|
||||
var ret []string
|
||||
keys := make([]string, 0, len(data))
|
||||
|
||||
for key := range data {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.SliceStable(keys, func(i, j int) bool{
|
||||
return data[keys[i]] < data[keys[j]]
|
||||
})
|
||||
|
||||
for _, k := range keys{
|
||||
ret = append(ret, k)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
|
||||
// func (sm *StructMap) SaveGoStructOptions(Child *Reflect) bool {
|
||||
// var yes bool
|
||||
//
|
||||
|
@ -284,8 +284,9 @@ func SizeOfArrayLength(ref interface{}) int {
|
||||
|
||||
func AnyToUnitValue(ref interface{}, key string, unit string, typeString string, dateFormat string) (UnitValues, bool, bool) {
|
||||
var uvs UnitValues
|
||||
ok := true
|
||||
isNil := false
|
||||
ok := true
|
||||
|
||||
for range Only.Once {
|
||||
if IsNil(ref) {
|
||||
// fmt.Println("DEBUG: AnyToUnitValue(): NIL")
|
||||
@ -499,6 +500,7 @@ func AnyToUnitValue(ref interface{}, key string, unit string, typeString string,
|
||||
ok = false
|
||||
}
|
||||
}
|
||||
|
||||
return uvs, isNil, ok
|
||||
}
|
||||
|
||||
|
@ -16,13 +16,13 @@ type UnitValue struct {
|
||||
|
||||
TypeValue string `json:"type_value"`
|
||||
|
||||
*float64 `json:"value_float,omitempty"`
|
||||
*int64 `json:"value_int,omitempty"`
|
||||
*bool `json:"value_bool,omitempty"`
|
||||
*float64 `json:"value_float,omitempty"`
|
||||
*int64 `json:"value_int,omitempty"`
|
||||
*bool `json:"value_bool,omitempty"`
|
||||
|
||||
key string
|
||||
deviceId string
|
||||
Valid bool `json:"valid"`
|
||||
Valid bool `json:"valid"`
|
||||
Error error `json:"-"`
|
||||
}
|
||||
|
||||
@ -293,6 +293,37 @@ func (t *UnitValue) ValueKey() string {
|
||||
return t.key
|
||||
}
|
||||
|
||||
func (t *UnitValue) IsFloat() bool {
|
||||
if t.float64 != nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *UnitValue) IsInt() bool {
|
||||
if t.int64 != nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *UnitValue) IsNumber() bool {
|
||||
if t.float64 != nil {
|
||||
return true
|
||||
}
|
||||
if t.int64 != nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *UnitValue) IsBool() bool {
|
||||
if t.float64 != nil {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (t UnitValue) String() string {
|
||||
var ret string
|
||||
for range Only.Once {
|
||||
@ -350,6 +381,13 @@ func (t *UnitValue) Type() string {
|
||||
return t.TypeValue
|
||||
}
|
||||
|
||||
func (t *UnitValue) IsTypeDateTime() bool {
|
||||
if t.TypeValue == "DateTime" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (t *UnitValue) DeviceId() string {
|
||||
return t.deviceId
|
||||
}
|
||||
|
@ -1,5 +1,106 @@
|
||||
package api
|
||||
|
||||
// -------------------------------------------------------------------------------- //
|
||||
// From struct_data.go
|
||||
//
|
||||
// func (dm *DataMap) CopyDataEntries(dep DataEntries, endpoint string, pointId string, name string) *DataEntries {
|
||||
// var ret *DataEntries
|
||||
// for range Only.Once {
|
||||
// var des DataEntries
|
||||
// des = dep.Copy()
|
||||
// for i := range des.Entries {
|
||||
// des.Entries[i].SetEndpoint(endpoint, pointId)
|
||||
// des.Entries[i].SetPointName(name)
|
||||
// dm.Add(des.Entries[i])
|
||||
// }
|
||||
//
|
||||
// if len(des.Entries) == 0 {
|
||||
// fmt.Printf("OOOPS\n")
|
||||
// }
|
||||
// epn := des.Entries[0].EndPoint
|
||||
// ret = dm.Map[epn]
|
||||
// }
|
||||
// return ret
|
||||
// }
|
||||
//
|
||||
// func (dm *DataMap) TableSort() []string {
|
||||
// var sorted []string
|
||||
//
|
||||
// for range Only.Once {
|
||||
// for p := range dm.DataTables {
|
||||
// sorted = append(sorted, p)
|
||||
// }
|
||||
// sort.Strings(sorted)
|
||||
// }
|
||||
// return sorted
|
||||
// }
|
||||
//
|
||||
// func (dm *DataMap) AddAny(endpoint string, parentDeviceId string, pid valueTypes.PointId, name string, groupName string, date valueTypes.DateTime, value interface{}, unit string, Type string, timeSpan string) {
|
||||
//
|
||||
// for range Only.Once {
|
||||
// var point Point
|
||||
// p := GetPoint(parentDeviceId + "." + pid.String())
|
||||
// if p == nil {
|
||||
// // No point found. Create one.
|
||||
// point = CreatePoint(parentDeviceId, pid, name, groupName, unit, Type, timeSpan)
|
||||
// } else {
|
||||
// point = *p
|
||||
// }
|
||||
//
|
||||
// uvs, isNil, ok := valueTypes.AnyToUnitValue(value, unit, Type, valueTypes.DateTimeLayout)
|
||||
// if !ok {
|
||||
// fmt.Printf("ERROR: AddAny(endpoint '%s', parentId '%s', pid '%s', name '%s', date '%s', value '%v')",
|
||||
// endpoint, parentDeviceId, pid, name, date, value)
|
||||
// break
|
||||
// }
|
||||
// if isNil {
|
||||
// point.ValueType += "(NIL)"
|
||||
// }
|
||||
//
|
||||
// for _, uv := range uvs {
|
||||
// if uv.GetUnit() != point.Unit {
|
||||
// fmt.Printf("OOOPS: Unit mismatch - %f %s != %f %s\n", value, point.Unit, uv.ValueFloat(), uv.GetUnit())
|
||||
// point.Unit = uv.GetUnit()
|
||||
// }
|
||||
//
|
||||
// var parent ParentDevice
|
||||
// parent.Set(parentDeviceId)
|
||||
// point.Parents.Add(parent)
|
||||
//
|
||||
// de := CreatePointDataEntry(endpoint, parentDeviceId, point, date, uv)
|
||||
// de.Point = &point
|
||||
// dm.Add(de)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// func (dm *DataMap) AddUnitValue(endpoint string, parentDeviceId string, pid valueTypes.PointId, name string, groupName string, date valueTypes.DateTime, uv valueTypes.UnitValue, timeSpan string) {
|
||||
//
|
||||
// for range Only.Once {
|
||||
// var point Point
|
||||
// p := GetPoint(parentDeviceId + "." + pid.String())
|
||||
// if p == nil {
|
||||
// // No point found. Create one.
|
||||
// point = CreatePoint(parentDeviceId, pid, name, groupName, uv.GetUnit(), uv.Type(), timeSpan)
|
||||
// } else {
|
||||
// point = *p
|
||||
// }
|
||||
//
|
||||
// if uv.GetUnit() != point.Unit {
|
||||
// fmt.Printf("OOOPS: Unit mismatch - %s %s != %f %s\n", uv.String(), point.Unit, uv.ValueFloat(), uv.GetUnit())
|
||||
// point.Unit = uv.GetUnit()
|
||||
// }
|
||||
//
|
||||
// var parent ParentDevice
|
||||
// parent.Set(parentDeviceId)
|
||||
// point.Parents.Add(parent)
|
||||
//
|
||||
// de := CreatePointDataEntry(endpoint, parentDeviceId, point, date, uv)
|
||||
// de.Point = &point
|
||||
// dm.Add(de)
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------- //
|
||||
// From struct_de.go
|
||||
@ -197,6 +298,109 @@ package api
|
||||
// }
|
||||
// return de
|
||||
// }
|
||||
//
|
||||
// func (dm *DataMap) CreateDataTables() Tables {
|
||||
// tables := make(Tables, 0)
|
||||
//
|
||||
// for range Only.Once {
|
||||
// for name := range dm.StructMap.TableMap {
|
||||
// // values = make(GoStruct.StructValuesMap)
|
||||
//
|
||||
// td := dm.StructMap.GetTableData(name)
|
||||
// if !td.IsValid {
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
// values := td.GetValues()
|
||||
// if (values == nil) || (len(values) == 0) {
|
||||
// fmt.Printf("No data table results for '%s'\n", name)
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// headers := td.GetHeaders()
|
||||
// table := output.NewTable(headers...)
|
||||
// for row := range values {
|
||||
// var items []interface{}
|
||||
// for _, col := range td.Columns {
|
||||
// items = append(items, values.GetCell(row, col))
|
||||
// }
|
||||
// dm.Error = table.AddRow(items...)
|
||||
// if dm.Error != nil {
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// if dm.Error != nil {
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// title := td.Current.DataStructure.DataTableTitle
|
||||
// if title == "" {
|
||||
// title = td.Current.DataStructure.DataTableName
|
||||
// }
|
||||
// if title == "" {
|
||||
// title = valueTypes.PointToName(td.Current.DataStructure.DataTableId)
|
||||
// }
|
||||
// // if title == "" {
|
||||
// // title = valueTypes.PointToName(td.Current.DataStructure.PointId)
|
||||
// // }
|
||||
// // dm.EndPoint.GetRequestArgNames()
|
||||
//
|
||||
// table.SetName(name)
|
||||
// if title == "" {
|
||||
// table.SetTitle("DataTable %s.%s", dm.EndPoint.GetArea(), td.Name)
|
||||
// table.SetFilePrefix("%s.%s", dm.EndPoint.GetArea(), td.Name)
|
||||
// } else {
|
||||
// table.SetTitle("DataTable %s.%s (%s)", dm.EndPoint.GetArea(), td.Name, title)
|
||||
// table.SetFilePrefix("%s.%s-%s", dm.EndPoint.GetArea(), td.Name, td.Current.DataStructure.DataTableId)
|
||||
// }
|
||||
//
|
||||
// // table.Sort(td.SortOn)
|
||||
// table.SetJson(nil)
|
||||
// table.SetRaw(nil)
|
||||
//
|
||||
// table.SetGraphFilter("") // @TODO - Consider setting graph options here instead of iSolarCloud/data.go:487
|
||||
//
|
||||
// // if sgd.Options.GraphRequest.TimeColumn == nil {
|
||||
// // for _, col := range table.GetHeaders() {
|
||||
// // val := value.GetCell(0, col)
|
||||
// // if val.Type() == "DateTime" {
|
||||
// // sgd.Options.GraphRequest.TimeColumn = &col
|
||||
// // break
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
// //
|
||||
// // if sgd.Options.GraphRequest.DataColumn == nil {
|
||||
// // for _, col := range table.GetHeaders() {
|
||||
// // val := value.GetCell(0, col)
|
||||
// // if val.IsNumber() {
|
||||
// // sgd.Options.GraphRequest.DataColumn = &col
|
||||
// // break
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
// //
|
||||
// // if sgd.Options.GraphRequest.ValueColumn == nil {
|
||||
// // for _, col := range table.GetHeaders() {
|
||||
// // val := value.GetCell(0, col)
|
||||
// // if val.IsNumber() {
|
||||
// // sgd.Options.GraphRequest.ValueColumn = &col
|
||||
// // break
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
//
|
||||
// tables[name] = Table {
|
||||
// Values: values,
|
||||
// Table: table,
|
||||
// }
|
||||
// // values[name] = vals
|
||||
// // tables[name] = table
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return tables
|
||||
// }
|
||||
|
||||
|
||||
// -------------------------------------------------------------------------------- //
|
||||
|
@ -17,7 +17,7 @@ import (
|
||||
|
||||
|
||||
type DataMap struct {
|
||||
Map map[string]*DataEntries
|
||||
Map map[string]*DataEntries
|
||||
|
||||
parentDeviceId string
|
||||
TimeStamp time.Time
|
||||
@ -34,314 +34,6 @@ func NewDataMap() DataMap {
|
||||
}
|
||||
}
|
||||
|
||||
func (dm *DataMap) ProcessMap() {
|
||||
for range Only.Once {
|
||||
// Convert Struct.Map to DataMap
|
||||
for _, Child := range dm.StructMap.Map {
|
||||
if Child.IsPointIgnore() {
|
||||
continue
|
||||
}
|
||||
|
||||
var when valueTypes.DateTime
|
||||
if Child.IsPointTimestampNotZero() {
|
||||
when = valueTypes.SetDateTimeValue(Child.DataStructure.PointTimestamp)
|
||||
} else {
|
||||
when = valueTypes.SetDateTimeValue(dm.TimeStamp)
|
||||
}
|
||||
|
||||
pdi := dm.parentDeviceId
|
||||
if Child.DataStructure.PointDevice != "" {
|
||||
pdi = Child.DataStructure.PointDevice
|
||||
}
|
||||
|
||||
dm.AddPointUnitValues(Child, pdi, when)
|
||||
}
|
||||
|
||||
// Convert Struct.VirtualMap to DataMap
|
||||
for _, Child := range dm.StructMap.VirtualMap {
|
||||
if Child.IsPointIgnore() {
|
||||
continue
|
||||
}
|
||||
|
||||
var when valueTypes.DateTime
|
||||
if Child.IsPointTimestampNotZero() {
|
||||
when = valueTypes.SetDateTimeValue(Child.DataStructure.PointTimestamp)
|
||||
} else {
|
||||
when = valueTypes.SetDateTimeValue(dm.TimeStamp)
|
||||
}
|
||||
|
||||
pdi := dm.parentDeviceId
|
||||
if Child.DataStructure.PointDevice != "" {
|
||||
pdi = Child.DataStructure.PointDevice
|
||||
}
|
||||
|
||||
if Child.DataStructure.PointVirtualShift > 0 {
|
||||
Child.DataStructure.Endpoint.ShiftLeft(Child.DataStructure.PointVirtualShift)
|
||||
Child.DataStructure.Endpoint.InsertFirst("virtual")
|
||||
} else {
|
||||
Child.DataStructure.Endpoint.ReplaceFirst("virtual")
|
||||
}
|
||||
dm.AddPointUnitValues(Child, pdi, when)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (dm *DataMap) ProcessMapForMqtt() {
|
||||
for range Only.Once {
|
||||
// Convert StructMap to DataMap
|
||||
for _, Child := range dm.StructMap.Map {
|
||||
if Child.IsPointIgnore() {
|
||||
fmt.Printf("[%s] - IGNORE\n", Child.FieldPath.String())
|
||||
continue
|
||||
}
|
||||
|
||||
if Child.CurrentReflect.IsPointListFlatten() {
|
||||
// fmt.Printf("[%s] - PointListFlatten", Child.FieldPath.String())
|
||||
// if len(de.Current.ChildReflect) > 0 {
|
||||
// continue // We already have the children.
|
||||
// }
|
||||
if len(Child.ChildReflect) == 0 {
|
||||
// fmt.Printf(" - IGNORE\n")
|
||||
// fmt.Printf(" - ignore\n")
|
||||
continue // Ignore points with no children.
|
||||
}
|
||||
// fmt.Println("")
|
||||
}
|
||||
|
||||
if Child.DataStructure.DataTable {
|
||||
continue // We are a datatable parent.
|
||||
}
|
||||
|
||||
var when valueTypes.DateTime
|
||||
if Child.IsPointTimestampNotZero() {
|
||||
when = valueTypes.SetDateTimeValue(Child.DataStructure.PointTimestamp)
|
||||
} else {
|
||||
when = valueTypes.SetDateTimeValue(dm.TimeStamp)
|
||||
}
|
||||
|
||||
pdi := dm.parentDeviceId
|
||||
if Child.DataStructure.PointDevice != "" {
|
||||
pdi = Child.DataStructure.PointDevice
|
||||
}
|
||||
|
||||
dm.AddPointUnitValues(Child, pdi, when)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (dm *DataMap) CreateDataTables() output.Tables {
|
||||
ret := make(output.Tables)
|
||||
|
||||
for range Only.Once {
|
||||
ret = output.NewTables()
|
||||
|
||||
names := dm.StructMap.GetTableNames()
|
||||
for _, name := range names {
|
||||
td := dm.StructMap.GetTableData(name)
|
||||
if !td.IsValid {
|
||||
continue
|
||||
}
|
||||
|
||||
values := td.GetValues()
|
||||
if (values == nil) || (len(values) == 0) {
|
||||
fmt.Printf("No data table results for '%s'\n", name)
|
||||
break
|
||||
}
|
||||
|
||||
headers := td.GetHeaders()
|
||||
table := output.NewTable(headers...)
|
||||
for row := range values {
|
||||
var items []interface{}
|
||||
for _, col := range td.Columns {
|
||||
items = append(items, values.GetCell(row, col))
|
||||
}
|
||||
dm.Error = table.AddRow(items...)
|
||||
if dm.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
if dm.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
title := td.Current.DataStructure.DataTableTitle
|
||||
if title == "" {
|
||||
title = td.Current.DataStructure.DataTableName
|
||||
}
|
||||
if title == "" {
|
||||
title = valueTypes.PointToName(td.Current.DataStructure.DataTableId)
|
||||
}
|
||||
// if title == "" {
|
||||
// title = valueTypes.PointToName(td.Current.DataStructure.PointId)
|
||||
// }
|
||||
|
||||
table.SetName(name)
|
||||
table.SetTitle("Data Table %s - %s", td.Name, title)
|
||||
if td.Current.DataStructure.DataTableId == "" {
|
||||
table.SetFilePrefix(td.Name)
|
||||
} else {
|
||||
table.SetFilePrefix("%s-%s", td.Name, td.Current.DataStructure.DataTableId)
|
||||
}
|
||||
table.SetGraphFilter("")
|
||||
table.Sort(td.SortOn)
|
||||
table.SetJson(nil)
|
||||
table.SetRaw(nil)
|
||||
|
||||
ret[name] = table
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (dm *DataMap) CreateResultTable(full bool) output.Table {
|
||||
var ret output.Table
|
||||
|
||||
for range Only.Once {
|
||||
ret = output.NewTable(
|
||||
"Date",
|
||||
"Point Id",
|
||||
"Value",
|
||||
"Unit",
|
||||
"Unit Type",
|
||||
"Group Name",
|
||||
"Description",
|
||||
"Update Freq",
|
||||
)
|
||||
|
||||
for _, p := range dm.Sort() {
|
||||
entries := dm.Map[p].Entries
|
||||
for _, de := range entries {
|
||||
if full {
|
||||
if de.Current.DataStructure.DataTable {
|
||||
continue // We are a datatable parent.
|
||||
}
|
||||
|
||||
if de.Current.CurrentReflect.IsPointListFlatten() {
|
||||
// if len(de.Current.ChildReflect) > 0 {
|
||||
// continue // We already have the children.
|
||||
// }
|
||||
if len(de.Current.ChildReflect) == 0 {
|
||||
continue // Ignore points with no children.
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if de.Hide {
|
||||
continue // Ignore hidden entries.
|
||||
}
|
||||
if de.Current.DataStructure.DataTableChild {
|
||||
continue // Ignore data table children.
|
||||
}
|
||||
// child, i := de.Current.IsTableChild()
|
||||
// fmt.Printf("%t[%d]\n", child, i)
|
||||
// if child {
|
||||
// if !de.Current.IsTable() {
|
||||
// continue
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
v := de.Value.String()
|
||||
if de.Current.IsTable() {
|
||||
v = "See table: " + de.Current.Name()
|
||||
}
|
||||
dm.Error = ret.AddRow(
|
||||
de.Date.Format(valueTypes.DateTimeLayout),
|
||||
p,
|
||||
v,
|
||||
// de.Value.String(),
|
||||
de.Point.Unit,
|
||||
de.Point.ValueType,
|
||||
de.Point.GroupName,
|
||||
de.Point.Description,
|
||||
de.Point.UpdateFreq,
|
||||
)
|
||||
if dm.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
ret.SetTitle("EndPoint Data %s", dm.StructMap.Name.String()) // endpoint.GetArea(), endpoint.GetName()
|
||||
if dm.StructMap.Start.DataStructure.DataTableName != "" {
|
||||
ret.SetTitle("EndPoint Data %s - %s", dm.StructMap.Name.String(), dm.StructMap.Start.DataStructure.DataTableName) // endpoint.GetArea(), endpoint.GetName()
|
||||
}
|
||||
ret.SetFilePrefix(dm.StructMap.Name.String())
|
||||
ret.SetGraphFilter("")
|
||||
ret.Sort("Point Id")
|
||||
if full {
|
||||
ret.SetJson([]byte(dm.EndPoint.GetJsonData(false)))
|
||||
ret.SetRaw([]byte(dm.EndPoint.GetJsonData(true)))
|
||||
}
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (dm *DataMap) Print() {
|
||||
for range Only.Once {
|
||||
table := datatable.New("utf8-heavy")
|
||||
table.AddHeaders(
|
||||
"Index",
|
||||
"EndPoint",
|
||||
|
||||
"Id",
|
||||
"Name",
|
||||
"Unit",
|
||||
"Type",
|
||||
"Value",
|
||||
"(Value)",
|
||||
"Valid",
|
||||
|
||||
"GroupName",
|
||||
"Parent Ids",
|
||||
"Parent Types",
|
||||
"Parent Codes",
|
||||
)
|
||||
|
||||
// dm.Order - Produces double the amount of entries for some reason.
|
||||
i := 0
|
||||
for k := range dm.Map {
|
||||
for _, v := range dm.Map[k].Entries {
|
||||
i++
|
||||
|
||||
table.AddRowItems(
|
||||
i,
|
||||
v.EndPoint,
|
||||
|
||||
v.Point.Id,
|
||||
v.Point.Description,
|
||||
v.Point.Unit,
|
||||
v.Point.UpdateFreq,
|
||||
v.Value,
|
||||
v.Current.Value.First(),
|
||||
v.Point.Valid,
|
||||
|
||||
v.Point.GroupName,
|
||||
v.Point.Parents.PsIds(),
|
||||
v.Point.Parents.Types(),
|
||||
v.Point.Parents.Codes(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
ret, _ := table.Render()
|
||||
fmt.Println(ret)
|
||||
}
|
||||
}
|
||||
|
||||
func (dm *DataMap) Sort() []string {
|
||||
var sorted []string
|
||||
|
||||
for range Only.Once {
|
||||
for p := range dm.Map {
|
||||
sorted = append(sorted, p)
|
||||
}
|
||||
sort.Strings(sorted)
|
||||
}
|
||||
return sorted
|
||||
}
|
||||
|
||||
|
||||
func (dm *DataMap) StructToDataMap(endpoint EndPoint, parentDeviceId string, name GoStruct.EndPointPath) DataMap {
|
||||
for range Only.Once {
|
||||
epName := GoStruct.NewEndPointPath(reflection.GetName("", endpoint))
|
||||
@ -513,26 +205,6 @@ func (dm *DataMap) MakeState(refEndpoint *GoStruct.Reflect, endpoint GoStruct.En
|
||||
return Current
|
||||
}
|
||||
|
||||
// func (dm *DataMap) CopyDataEntries(dep DataEntries, endpoint string, pointId string, name string) *DataEntries {
|
||||
// var ret *DataEntries
|
||||
// for range Only.Once {
|
||||
// var des DataEntries
|
||||
// des = dep.Copy()
|
||||
// for i := range des.Entries {
|
||||
// des.Entries[i].SetEndpoint(endpoint, pointId)
|
||||
// des.Entries[i].SetPointName(name)
|
||||
// dm.Add(des.Entries[i])
|
||||
// }
|
||||
//
|
||||
// if len(des.Entries) == 0 {
|
||||
// fmt.Printf("OOOPS\n")
|
||||
// }
|
||||
// epn := des.Entries[0].EndPoint
|
||||
// ret = dm.Map[epn]
|
||||
// }
|
||||
// return ret
|
||||
// }
|
||||
|
||||
func (dm *DataMap) LowerUpper(lowerEntry *GoStruct.Reflect, upperEntry *GoStruct.Reflect) float64 {
|
||||
var ret float64
|
||||
for range Only.Once {
|
||||
@ -599,83 +271,359 @@ func (dm *DataMap) Add(des ...DataEntry) {
|
||||
}
|
||||
}
|
||||
|
||||
// func (dm *DataMap) TableSort() []string {
|
||||
// var sorted []string
|
||||
//
|
||||
// for range Only.Once {
|
||||
// for p := range dm.DataTables {
|
||||
// sorted = append(sorted, p)
|
||||
// }
|
||||
// sort.Strings(sorted)
|
||||
// }
|
||||
// return sorted
|
||||
// }
|
||||
func (dm *DataMap) ProcessMap() {
|
||||
for range Only.Once {
|
||||
// Convert Struct.Map to DataMap
|
||||
for _, Child := range dm.StructMap.Map {
|
||||
if Child.IsPointIgnore() {
|
||||
continue
|
||||
}
|
||||
|
||||
// func (dm *DataMap) AddAny(endpoint string, parentDeviceId string, pid valueTypes.PointId, name string, groupName string, date valueTypes.DateTime, value interface{}, unit string, Type string, timeSpan string) {
|
||||
//
|
||||
// for range Only.Once {
|
||||
// var point Point
|
||||
// p := GetPoint(parentDeviceId + "." + pid.String())
|
||||
// if p == nil {
|
||||
// // No point found. Create one.
|
||||
// point = CreatePoint(parentDeviceId, pid, name, groupName, unit, Type, timeSpan)
|
||||
// } else {
|
||||
// point = *p
|
||||
// }
|
||||
//
|
||||
// uvs, isNil, ok := valueTypes.AnyToUnitValue(value, unit, Type, valueTypes.DateTimeLayout)
|
||||
// if !ok {
|
||||
// fmt.Printf("ERROR: AddAny(endpoint '%s', parentId '%s', pid '%s', name '%s', date '%s', value '%v')",
|
||||
// endpoint, parentDeviceId, pid, name, date, value)
|
||||
// break
|
||||
// }
|
||||
// if isNil {
|
||||
// point.ValueType += "(NIL)"
|
||||
// }
|
||||
//
|
||||
// for _, uv := range uvs {
|
||||
// if uv.GetUnit() != point.Unit {
|
||||
// fmt.Printf("OOOPS: Unit mismatch - %f %s != %f %s\n", value, point.Unit, uv.ValueFloat(), uv.GetUnit())
|
||||
// point.Unit = uv.GetUnit()
|
||||
// }
|
||||
//
|
||||
// var parent ParentDevice
|
||||
// parent.Set(parentDeviceId)
|
||||
// point.Parents.Add(parent)
|
||||
//
|
||||
// de := CreatePointDataEntry(endpoint, parentDeviceId, point, date, uv)
|
||||
// de.Point = &point
|
||||
// dm.Add(de)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
var when valueTypes.DateTime
|
||||
if Child.IsPointTimestampNotZero() {
|
||||
when = valueTypes.SetDateTimeValue(Child.DataStructure.PointTimestamp)
|
||||
} else {
|
||||
when = valueTypes.SetDateTimeValue(dm.TimeStamp)
|
||||
}
|
||||
|
||||
// func (dm *DataMap) AddUnitValue(endpoint string, parentDeviceId string, pid valueTypes.PointId, name string, groupName string, date valueTypes.DateTime, uv valueTypes.UnitValue, timeSpan string) {
|
||||
//
|
||||
// for range Only.Once {
|
||||
// var point Point
|
||||
// p := GetPoint(parentDeviceId + "." + pid.String())
|
||||
// if p == nil {
|
||||
// // No point found. Create one.
|
||||
// point = CreatePoint(parentDeviceId, pid, name, groupName, uv.GetUnit(), uv.Type(), timeSpan)
|
||||
// } else {
|
||||
// point = *p
|
||||
// }
|
||||
//
|
||||
// if uv.GetUnit() != point.Unit {
|
||||
// fmt.Printf("OOOPS: Unit mismatch - %s %s != %f %s\n", uv.String(), point.Unit, uv.ValueFloat(), uv.GetUnit())
|
||||
// point.Unit = uv.GetUnit()
|
||||
// }
|
||||
//
|
||||
// var parent ParentDevice
|
||||
// parent.Set(parentDeviceId)
|
||||
// point.Parents.Add(parent)
|
||||
//
|
||||
// de := CreatePointDataEntry(endpoint, parentDeviceId, point, date, uv)
|
||||
// de.Point = &point
|
||||
// dm.Add(de)
|
||||
// }
|
||||
// }
|
||||
pdi := dm.parentDeviceId
|
||||
if Child.DataStructure.PointDevice != "" {
|
||||
pdi = Child.DataStructure.PointDevice
|
||||
}
|
||||
|
||||
dm.AddPointUnitValues(Child, pdi, when)
|
||||
}
|
||||
|
||||
// Convert Struct.VirtualMap to DataMap
|
||||
for _, Child := range dm.StructMap.VirtualMap {
|
||||
if Child.IsPointIgnore() {
|
||||
continue
|
||||
}
|
||||
|
||||
var when valueTypes.DateTime
|
||||
if Child.IsPointTimestampNotZero() {
|
||||
when = valueTypes.SetDateTimeValue(Child.DataStructure.PointTimestamp)
|
||||
} else {
|
||||
when = valueTypes.SetDateTimeValue(dm.TimeStamp)
|
||||
}
|
||||
|
||||
pdi := dm.parentDeviceId
|
||||
if Child.DataStructure.PointDevice != "" {
|
||||
pdi = Child.DataStructure.PointDevice
|
||||
}
|
||||
|
||||
if Child.DataStructure.PointVirtualShift > 0 {
|
||||
Child.DataStructure.Endpoint.ShiftLeft(Child.DataStructure.PointVirtualShift)
|
||||
Child.DataStructure.Endpoint.InsertFirst("virtual")
|
||||
} else {
|
||||
Child.DataStructure.Endpoint.ReplaceFirst("virtual")
|
||||
}
|
||||
dm.AddPointUnitValues(Child, pdi, when)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (dm *DataMap) ProcessMapForMqtt() {
|
||||
for range Only.Once {
|
||||
// Convert StructMap to DataMap
|
||||
for _, Child := range dm.StructMap.Map {
|
||||
if Child.IsPointIgnore() {
|
||||
fmt.Printf("[%s] - IGNORE\n", Child.FieldPath.String())
|
||||
continue
|
||||
}
|
||||
|
||||
if Child.CurrentReflect.IsPointListFlatten() {
|
||||
// fmt.Printf("[%s] - PointListFlatten", Child.FieldPath.String())
|
||||
// if len(de.Current.ChildReflect) > 0 {
|
||||
// continue // We already have the children.
|
||||
// }
|
||||
if len(Child.ChildReflect) == 0 {
|
||||
// fmt.Printf(" - IGNORE\n")
|
||||
// fmt.Printf(" - ignore\n")
|
||||
continue // Ignore points with no children.
|
||||
}
|
||||
// fmt.Println("")
|
||||
}
|
||||
|
||||
if Child.DataStructure.DataTable {
|
||||
continue // We are a datatable parent.
|
||||
}
|
||||
|
||||
var when valueTypes.DateTime
|
||||
if Child.IsPointTimestampNotZero() {
|
||||
when = valueTypes.SetDateTimeValue(Child.DataStructure.PointTimestamp)
|
||||
} else {
|
||||
when = valueTypes.SetDateTimeValue(dm.TimeStamp)
|
||||
}
|
||||
|
||||
pdi := dm.parentDeviceId
|
||||
if Child.DataStructure.PointDevice != "" {
|
||||
pdi = Child.DataStructure.PointDevice
|
||||
}
|
||||
|
||||
dm.AddPointUnitValues(Child, pdi, when)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
type Tables GoStruct.StructTables
|
||||
|
||||
func (dm *DataMap) CreateDataTables() Tables {
|
||||
tables := make(Tables, 0)
|
||||
|
||||
for range Only.Once {
|
||||
for name := range dm.StructMap.TableMap {
|
||||
var ret GoStruct.StructTable
|
||||
dm.Error = ret.Process(name, dm.StructMap.TableMap[name])
|
||||
_, dm.Error = ret.CreateTable()
|
||||
tables[name] = &ret
|
||||
// tables[name] = dm.StructMap.GetTableData(name)
|
||||
|
||||
// // values = make(GoStruct.StructValuesMap)
|
||||
//
|
||||
// td := dm.StructMap.GetTableData(name)
|
||||
// if !td.IsValid {
|
||||
// continue
|
||||
// }
|
||||
//
|
||||
// values := td.GetValues()
|
||||
// if (values == nil) || (len(values) == 0) {
|
||||
// fmt.Printf("No data table results for '%s'\n", name)
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// headers := td.GetHeaders()
|
||||
// table := output.NewTable(headers...)
|
||||
// for row := range values {
|
||||
// var items []interface{}
|
||||
// for _, col := range td.Columns {
|
||||
// items = append(items, values.GetCell(row, col))
|
||||
// }
|
||||
// dm.Error = table.AddRow(items...)
|
||||
// if dm.Error != nil {
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// if dm.Error != nil {
|
||||
// break
|
||||
// }
|
||||
//
|
||||
// title := td.Current.DataStructure.DataTableTitle
|
||||
// if title == "" {
|
||||
// title = td.Current.DataStructure.DataTableName
|
||||
// }
|
||||
// if title == "" {
|
||||
// title = valueTypes.PointToName(td.Current.DataStructure.DataTableId)
|
||||
// }
|
||||
// // if title == "" {
|
||||
// // title = valueTypes.PointToName(td.Current.DataStructure.PointId)
|
||||
// // }
|
||||
// // dm.EndPoint.GetRequestArgNames()
|
||||
//
|
||||
// table.SetName(name)
|
||||
// if title == "" {
|
||||
// table.SetTitle("DataTable %s.%s", dm.EndPoint.GetArea(), td.Name)
|
||||
// table.SetFilePrefix("%s.%s", dm.EndPoint.GetArea(), td.Name)
|
||||
// } else {
|
||||
// table.SetTitle("DataTable %s.%s (%s)", dm.EndPoint.GetArea(), td.Name, title)
|
||||
// table.SetFilePrefix("%s.%s-%s", dm.EndPoint.GetArea(), td.Name, td.Current.DataStructure.DataTableId)
|
||||
// }
|
||||
//
|
||||
// // table.Sort(td.SortOn)
|
||||
// table.SetJson(nil)
|
||||
// table.SetRaw(nil)
|
||||
//
|
||||
// table.SetGraphFilter("") // @TODO - Consider setting graph options here instead of iSolarCloud/data.go:487
|
||||
//
|
||||
// // if sgd.Options.GraphRequest.TimeColumn == nil {
|
||||
// // for _, col := range table.GetHeaders() {
|
||||
// // val := value.GetCell(0, col)
|
||||
// // if val.Type() == "DateTime" {
|
||||
// // sgd.Options.GraphRequest.TimeColumn = &col
|
||||
// // break
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
// //
|
||||
// // if sgd.Options.GraphRequest.DataColumn == nil {
|
||||
// // for _, col := range table.GetHeaders() {
|
||||
// // val := value.GetCell(0, col)
|
||||
// // if val.IsNumber() {
|
||||
// // sgd.Options.GraphRequest.DataColumn = &col
|
||||
// // break
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
// //
|
||||
// // if sgd.Options.GraphRequest.ValueColumn == nil {
|
||||
// // for _, col := range table.GetHeaders() {
|
||||
// // val := value.GetCell(0, col)
|
||||
// // if val.IsNumber() {
|
||||
// // sgd.Options.GraphRequest.ValueColumn = &col
|
||||
// // break
|
||||
// // }
|
||||
// // }
|
||||
// // }
|
||||
//
|
||||
// tables[name] = Table {
|
||||
// Values: values,
|
||||
// Table: table,
|
||||
// }
|
||||
// // values[name] = vals
|
||||
// // tables[name] = table
|
||||
}
|
||||
}
|
||||
|
||||
return tables
|
||||
}
|
||||
|
||||
func (dm *DataMap) CreateResultTable(full bool) output.Table {
|
||||
var table output.Table
|
||||
|
||||
for range Only.Once {
|
||||
table = output.NewTable(
|
||||
"Date",
|
||||
"Point Id",
|
||||
"Value",
|
||||
"Unit",
|
||||
"Unit Type",
|
||||
"Group Name",
|
||||
"Description",
|
||||
"Update Freq",
|
||||
)
|
||||
|
||||
for _, p := range dm.Sort() {
|
||||
entries := dm.Map[p].Entries
|
||||
for _, de := range entries {
|
||||
if full {
|
||||
if de.Current.DataStructure.DataTable {
|
||||
continue // We are a datatable parent.
|
||||
}
|
||||
|
||||
if de.Current.CurrentReflect.IsPointListFlatten() {
|
||||
// if len(de.Current.ChildReflect) > 0 {
|
||||
// continue // We already have the children.
|
||||
// }
|
||||
if len(de.Current.ChildReflect) == 0 {
|
||||
continue // Ignore points with no children.
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if de.Hide {
|
||||
continue // Ignore hidden entries.
|
||||
}
|
||||
if de.Current.DataStructure.DataTableChild {
|
||||
continue // Ignore data table children.
|
||||
}
|
||||
// child, i := de.Current.IsTableChild()
|
||||
// fmt.Printf("%t[%d]\n", child, i)
|
||||
// if child {
|
||||
// if !de.Current.IsTable() {
|
||||
// continue
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
v := de.Value.String()
|
||||
if de.Current.IsTable() {
|
||||
v = "See table: " + de.Current.Name()
|
||||
}
|
||||
dm.Error = table.AddRow(
|
||||
de.Date.Format(valueTypes.DateTimeLayout),
|
||||
p,
|
||||
v,
|
||||
// de.Value.String(),
|
||||
de.Point.Unit,
|
||||
de.Point.ValueType,
|
||||
de.Point.GroupName,
|
||||
de.Point.Description,
|
||||
de.Point.UpdateFreq,
|
||||
)
|
||||
if dm.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
table.SetTitle("EndPoint Data %s.%s", dm.EndPoint.GetArea(), dm.StructMap.Name.String()) // endpoint.GetArea(), endpoint.GetName()
|
||||
if dm.StructMap.Start.DataStructure.DataTableName != "" {
|
||||
table.AppendTitle(" - %s", dm.StructMap.Start.DataStructure.DataTableName)
|
||||
}
|
||||
table.SetFilePrefix("%s.%s", dm.EndPoint.GetArea(), dm.StructMap.Name.String())
|
||||
table.SetGraphFilter("")
|
||||
table.Sort("Point Id")
|
||||
if full {
|
||||
table.SetJson([]byte(dm.EndPoint.GetJsonData(false)))
|
||||
table.SetRaw([]byte(dm.EndPoint.GetJsonData(true)))
|
||||
}
|
||||
}
|
||||
|
||||
return table
|
||||
}
|
||||
|
||||
func (dm *DataMap) Print() {
|
||||
for range Only.Once {
|
||||
table := datatable.New("utf8-heavy")
|
||||
table.AddHeaders(
|
||||
"Index",
|
||||
"EndPoint",
|
||||
|
||||
"Id",
|
||||
"Name",
|
||||
"Unit",
|
||||
"Type",
|
||||
"Value",
|
||||
"(Value)",
|
||||
"Valid",
|
||||
|
||||
"GroupName",
|
||||
"Parent Ids",
|
||||
"Parent Types",
|
||||
"Parent Codes",
|
||||
)
|
||||
|
||||
// dm.Order - Produces double the amount of entries for some reason.
|
||||
i := 0
|
||||
for k := range dm.Map {
|
||||
for _, v := range dm.Map[k].Entries {
|
||||
i++
|
||||
|
||||
table.AddRowItems(
|
||||
i,
|
||||
v.EndPoint,
|
||||
|
||||
v.Point.Id,
|
||||
v.Point.Description,
|
||||
v.Point.Unit,
|
||||
v.Point.UpdateFreq,
|
||||
v.Value,
|
||||
v.Current.Value.First(),
|
||||
v.Point.Valid,
|
||||
|
||||
v.Point.GroupName,
|
||||
v.Point.Parents.PsIds(),
|
||||
v.Point.Parents.Types(),
|
||||
v.Point.Parents.Codes(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
ret, _ := table.Render()
|
||||
fmt.Println(ret)
|
||||
}
|
||||
}
|
||||
|
||||
func (dm *DataMap) Sort() []string {
|
||||
var sorted []string
|
||||
|
||||
for range Only.Once {
|
||||
for p := range dm.Map {
|
||||
sorted = append(sorted, p)
|
||||
}
|
||||
sort.Strings(sorted)
|
||||
}
|
||||
return sorted
|
||||
}
|
||||
|
||||
|
||||
func CreatePointDataEntry(Current *GoStruct.Reflect, parentDeviceId string, point Point, dateTime valueTypes.DateTime, uv valueTypes.UnitValue) DataEntry {
|
||||
|
@ -191,12 +191,29 @@ func (sgd *SunGrowData) CallEndpoint(endpoint api.EndPoint, request SunGrowDataR
|
||||
}
|
||||
|
||||
response.Data = endpoint.GetEndPointData()
|
||||
response.Name = endpoint.GetName().String()
|
||||
// response.Data.Table.AppendFilePrefix(request.RequestAsFilePrefix()) // request.GetFilename(endpoint.GetName().String()))
|
||||
// response.Data.Table.SetSaveFile(sgd.saveAsFile)
|
||||
// response.Data.Table.OutputType = sgd.outputType
|
||||
// response.Title = response.Data.Table.GetTitle()
|
||||
// response.Filename = response.Data.Table.GetFilePrefix()
|
||||
args := request.GetArgs(response.Data.EndPoint)
|
||||
name := endpoint.GetArea().String() + "." + endpoint.GetName().String()
|
||||
|
||||
response.Options = OutputOptions {
|
||||
Name: endpoint.GetName().String(),
|
||||
OutputType: sgd.sunGrow.OutputType,
|
||||
FileSuffix: request.GetPrimaryArg(), // + " - " + request.RequestAsFilePrefix(),
|
||||
SaveAsFile: sgd.sunGrow.SaveAsFile,
|
||||
TitleSuffix: args,
|
||||
GraphRequest: output.GraphRequest {
|
||||
Title: name + " - " + args,
|
||||
TimeColumn: nil,
|
||||
DataColumn: nil,
|
||||
UnitsColumn: nil,
|
||||
NameColumn: nil,
|
||||
// DataColumn: nil,
|
||||
DataMin: nil,
|
||||
DataMax: nil,
|
||||
Width: nil,
|
||||
Height: nil,
|
||||
Error: nil,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return response
|
||||
@ -223,6 +240,7 @@ func (sgd *SunGrowData) GetData() error {
|
||||
if sgd.Request.IsPsIdNotRequired() {
|
||||
var result SunGrowDataResult
|
||||
|
||||
result.EndPointArea = ep.GetArea()
|
||||
result.EndPointName = ep.GetName()
|
||||
result.EndPoint = ep
|
||||
result.Request = sgd.Request
|
||||
@ -242,10 +260,10 @@ func (sgd *SunGrowData) GetData() error {
|
||||
// PsId required.
|
||||
for _, psId := range sgd.Request.aPsId {
|
||||
var result SunGrowDataResult
|
||||
|
||||
result.Request = sgd.Request
|
||||
result.Request.SetPsId(psId.String())
|
||||
|
||||
result.EndPointArea = ep.GetArea()
|
||||
result.EndPointName = ep.GetName()
|
||||
result.EndPoint = ep
|
||||
result.Response = sgd.CallEndpoint(ep, result.Request)
|
||||
@ -264,7 +282,6 @@ func (sgd *SunGrowData) GetData() error {
|
||||
return sgd.Error
|
||||
}
|
||||
|
||||
|
||||
func (sgd *SunGrowData) Process() error {
|
||||
for range Only.Once {
|
||||
if len(sgd.Results) == 0 {
|
||||
@ -291,10 +308,7 @@ func (sgd *SunGrowData) Output() error {
|
||||
}
|
||||
|
||||
for _, result := range sgd.Results {
|
||||
args := result.Request.GetArgs(result.EndPoint)
|
||||
result.Response.Filename = result.Request.RequestAsFilePrefix()
|
||||
result.Response.Title = result.EndPoint.GetArea().String() + "." + result.EndPoint.GetName().String() + " - " + args
|
||||
sgd.Error = result.Response.Output(sgd.sunGrow.OutputType, sgd.sunGrow.SaveAsFile)
|
||||
sgd.Error = result.Response.Output()
|
||||
if sgd.Error != nil {
|
||||
break
|
||||
}
|
||||
@ -303,43 +317,6 @@ func (sgd *SunGrowData) Output() error {
|
||||
|
||||
return sgd.Error
|
||||
}
|
||||
func (sgd *SunGrowDataResult) Output(outputType output.OutputType, saveAsFile bool, filePrefix string) error {
|
||||
sgd.Response.Filename = filePrefix
|
||||
sgd.Error = sgd.Response.Output(outputType, saveAsFile)
|
||||
return sgd.Error
|
||||
}
|
||||
func (sgd *SunGrowDataResponse) Output(outputType output.OutputType, saveAsFile bool) error {
|
||||
for range Only.Once {
|
||||
// Outputs that don't drop through.
|
||||
if outputType.IsStruct() || outputType.IsList() || outputType.IsRaw() || outputType.IsJson() {
|
||||
table := sgd.Data.CreateResultTable(true)
|
||||
table.OutputType = outputType
|
||||
table.SetSaveFile(saveAsFile)
|
||||
table.AppendFilePrefix(sgd.Filename)
|
||||
table.SetTitle(table.GetName() + " - " + sgd.Title)
|
||||
sgd.Error = table.Output()
|
||||
break
|
||||
}
|
||||
|
||||
// Outputs that can drop through to DataTables.
|
||||
if outputType.IsTable() || outputType.IsXLSX() || outputType.IsCsv() || outputType.IsXML() {
|
||||
table := sgd.Data.CreateResultTable(false)
|
||||
table.OutputType = outputType
|
||||
table.SetSaveFile(saveAsFile)
|
||||
table.AppendFilePrefix(sgd.Filename)
|
||||
table.SetTitle(table.GetName() + " - " + sgd.Title)
|
||||
sgd.Error = table.Output()
|
||||
if sgd.Error != nil {
|
||||
break
|
||||
}
|
||||
// break
|
||||
}
|
||||
|
||||
sgd.Error = sgd.OutputDataTables(outputType, saveAsFile)
|
||||
}
|
||||
|
||||
return sgd.Error
|
||||
}
|
||||
|
||||
func (sgd *SunGrowData) OutputDataTables() error {
|
||||
for range Only.Once {
|
||||
@ -349,10 +326,7 @@ func (sgd *SunGrowData) OutputDataTables() error {
|
||||
}
|
||||
|
||||
for _, result := range sgd.Results {
|
||||
args := result.Request.GetArgs(result.EndPoint)
|
||||
result.Response.Filename = result.Request.RequestAsFilePrefix()
|
||||
result.Response.Title = result.EndPoint.GetArea().String() + "." + result.EndPoint.GetName().String() + " - " + args
|
||||
sgd.Error = result.OutputDataTables(sgd.sunGrow.OutputType, sgd.sunGrow.SaveAsFile)
|
||||
sgd.Error = result.Response.OutputDataTables()
|
||||
if sgd.Error != nil {
|
||||
break
|
||||
}
|
||||
@ -361,40 +335,11 @@ func (sgd *SunGrowData) OutputDataTables() error {
|
||||
|
||||
return sgd.Error
|
||||
}
|
||||
func (sgd *SunGrowDataResult) OutputDataTables(outputType output.OutputType, saveAsFile bool) error {
|
||||
sgd.Error = sgd.Response.OutputDataTables(outputType, saveAsFile)
|
||||
return sgd.Error
|
||||
}
|
||||
func (sgd *SunGrowDataResponse) OutputDataTables(outputType output.OutputType, saveAsFile bool) error {
|
||||
for range Only.Once {
|
||||
tables := sgd.Data.CreateDataTables()
|
||||
if len(tables) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
for _, table := range tables {
|
||||
fmt.Println()
|
||||
table.OutputType = outputType
|
||||
table.SetSaveFile(saveAsFile)
|
||||
table.AppendFilePrefix(sgd.Filename)
|
||||
table.SetTitle(table.GetName() + " - " + sgd.Title)
|
||||
sgd.Error = table.Output()
|
||||
if sgd.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sgd.Error
|
||||
}
|
||||
|
||||
// func (sgd *SunGrowData) GetResults() SunGrowDataResults {
|
||||
// return sgd.Results
|
||||
// }
|
||||
|
||||
|
||||
type SunGrowDataResults map[string]SunGrowDataResult
|
||||
type SunGrowDataResult struct {
|
||||
EndPointArea api.AreaName
|
||||
EndPointName api.EndPointName
|
||||
EndPoint api.EndPoint
|
||||
Request SunGrowDataRequest
|
||||
@ -420,21 +365,11 @@ func (sgd *SunGrowDataResult) CreateResultTable(full bool) output.Table {
|
||||
sgd.Error = sgd.Response.Data.Error
|
||||
return ret
|
||||
}
|
||||
func (sgd *SunGrowDataResponse) CreateResultTable(full bool) output.Table {
|
||||
ret := sgd.Data.CreateResultTable(full)
|
||||
sgd.Error = sgd.Data.Error
|
||||
return ret
|
||||
}
|
||||
|
||||
func (sgd *SunGrowDataResult) CreateDataTables() output.Tables {
|
||||
ret := sgd.Response.Data.CreateDataTables()
|
||||
func (sgd *SunGrowDataResult) CreateDataTables() api.Tables {
|
||||
tables := sgd.Response.CreateDataTables()
|
||||
sgd.Error = sgd.Response.Data.Error
|
||||
return ret
|
||||
}
|
||||
func (sgd *SunGrowDataResponse) CreateDataTables() output.Tables {
|
||||
ret := sgd.Data.CreateDataTables()
|
||||
sgd.Error = sgd.Data.Error
|
||||
return ret
|
||||
return tables
|
||||
}
|
||||
|
||||
func (sgd *SunGrowDataResult) Sort() []string {
|
||||
@ -444,17 +379,204 @@ func (sgd *SunGrowDataResult) Sort() []string {
|
||||
func (sgd *SunGrowDataResult) Print() {
|
||||
sgd.Response.Data.Print()
|
||||
}
|
||||
|
||||
|
||||
type OutputOptions struct {
|
||||
Name string
|
||||
TitleSuffix string
|
||||
OutputType output.OutputType
|
||||
FileSuffix string
|
||||
SaveAsFile bool
|
||||
GraphRequest output.GraphRequest
|
||||
|
||||
// table.InitGraph(output.GraphRequest {
|
||||
// Title: "",
|
||||
// TimeColumn: output.SetString("Date/Time"),
|
||||
// SearchColumn: output.SetString("Point Id"),
|
||||
// NameColumn: output.SetString("Point Name"),
|
||||
// ValueColumn: output.SetString("Value"),
|
||||
// UnitsColumn: output.SetString("Units"),
|
||||
// SearchString: output.SetString(""),
|
||||
// MinLeftAxis: output.SetFloat(0),
|
||||
// MaxLeftAxis: output.SetFloat(0),
|
||||
// })
|
||||
}
|
||||
|
||||
type SunGrowDataResponses map[string]SunGrowDataResponse
|
||||
type SunGrowDataFunction func(request SunGrowDataRequest) SunGrowDataResponse
|
||||
type SunGrowDataResponse struct {
|
||||
Data api.DataMap
|
||||
Options OutputOptions
|
||||
Error error
|
||||
}
|
||||
|
||||
func (sgd *SunGrowDataResponse) CreateResultTable(full bool) output.Table {
|
||||
ret := sgd.Data.CreateResultTable(full)
|
||||
sgd.Error = sgd.Data.Error
|
||||
return ret
|
||||
}
|
||||
|
||||
func (sgd *SunGrowDataResponse) CreateDataTables() api.Tables {
|
||||
tables := sgd.Data.CreateDataTables()
|
||||
sgd.Error = sgd.Data.Error
|
||||
return tables
|
||||
}
|
||||
|
||||
func (sgd *SunGrowDataResponse) Output() error {
|
||||
for range Only.Once {
|
||||
// Outputs that don't drop through.
|
||||
if sgd.Options.OutputType.IsStruct() || sgd.Options.OutputType.IsList() || sgd.Options.OutputType.IsRaw() || sgd.Options.OutputType.IsJson() {
|
||||
table := sgd.Data.CreateResultTable(true)
|
||||
table.OutputType = sgd.Options.OutputType
|
||||
table.SetSaveFile(sgd.Options.SaveAsFile)
|
||||
table.AppendTitle(" - %s", sgd.Options.TitleSuffix)
|
||||
table.AppendFilePrefix(sgd.Options.FileSuffix)
|
||||
sgd.Error = table.Output()
|
||||
break
|
||||
}
|
||||
|
||||
// Outputs that can drop through to DataTables.
|
||||
if sgd.Options.OutputType.IsTable() || sgd.Options.OutputType.IsXLSX() || sgd.Options.OutputType.IsCsv() || sgd.Options.OutputType.IsXML() {
|
||||
table := sgd.Data.CreateResultTable(false)
|
||||
table.OutputType = sgd.Options.OutputType
|
||||
table.SetSaveFile(sgd.Options.SaveAsFile)
|
||||
table.AppendTitle(" - %s", sgd.Options.TitleSuffix)
|
||||
table.AppendFilePrefix(sgd.Options.FileSuffix)
|
||||
sgd.Error = table.Output()
|
||||
if sgd.Error != nil {
|
||||
break
|
||||
}
|
||||
// break
|
||||
}
|
||||
|
||||
sgd.Error = sgd.OutputDataTables()
|
||||
}
|
||||
|
||||
return sgd.Error
|
||||
}
|
||||
|
||||
func (sgd *SunGrowDataResponse) OutputDataTables() error {
|
||||
for range Only.Once {
|
||||
tables := sgd.Data.CreateDataTables()
|
||||
if len(tables) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
// @iSolarCloud/api/struct_data.go:420
|
||||
if sgd.Options.OutputType.IsGraph() {
|
||||
for _, data := range tables {
|
||||
// table := tables[name]
|
||||
// table.OutputType = sgd.Options.OutputType
|
||||
// table.SetSaveFile(sgd.Options.SaveAsFile)
|
||||
// table.SetFilePrefix("%s", sgd.Options.Filename)
|
||||
|
||||
// value := values[name]
|
||||
// fmt.Printf("Writing (%d)\n", len(value))
|
||||
// fmt.Printf("%v\n", table.GetHeaders())
|
||||
|
||||
if sgd.Options.TitleSuffix == "" {
|
||||
sgd.Options.TitleSuffix = data.Table.GetTitle()
|
||||
}
|
||||
data.Table.OutputType = sgd.Options.OutputType
|
||||
data.Table.SetSaveFile(true)
|
||||
data.Table.AppendTitle(" - %s", sgd.Options.TitleSuffix)
|
||||
data.Table.AppendFilePrefix(sgd.Options.FileSuffix)
|
||||
|
||||
if sgd.Options.GraphRequest.TimeColumn == nil {
|
||||
for _, col := range data.Table.GetHeaders() {
|
||||
val := data.Values.GetCell(0, col)
|
||||
if val.IsTypeDateTime() {
|
||||
sgd.Options.GraphRequest.TimeColumn = &col
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if sgd.Options.GraphRequest.DataColumn == nil {
|
||||
// for _, col := range data.Table.GetHeaders() {
|
||||
// val := data.Values.GetCell(0, col)
|
||||
// if val.IsNumber() {
|
||||
// sgd.Options.GraphRequest.DataColumn = &col
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
if sgd.Options.GraphRequest.DataColumn == nil {
|
||||
for _, col := range data.Table.GetHeaders() {
|
||||
val := data.Values.GetCell(0, col)
|
||||
if val.IsNumber() {
|
||||
sgd.Options.GraphRequest.DataColumn = &col
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if sgd.Options.GraphRequest.UnitsColumn != nil {
|
||||
for _, col := range data.Table.GetHeaders() {
|
||||
if *sgd.Options.GraphRequest.UnitsColumn != col {
|
||||
continue
|
||||
}
|
||||
val := data.Values.GetCell(0, col)
|
||||
unit := val.Unit()
|
||||
if unit != "" {
|
||||
continue
|
||||
}
|
||||
sgd.Options.GraphRequest.UnitsColumn = &col
|
||||
sgd.Options.GraphRequest.DataUnit = &unit
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if sgd.Options.GraphRequest.NameColumn == nil {
|
||||
}
|
||||
|
||||
if sgd.Options.GraphRequest.DataMin == nil {
|
||||
zero := 0.0
|
||||
sgd.Options.GraphRequest.DataMin = &zero
|
||||
}
|
||||
|
||||
if sgd.Options.GraphRequest.DataMax == nil {
|
||||
zero := 0.0
|
||||
sgd.Options.GraphRequest.DataMax = &zero
|
||||
}
|
||||
|
||||
if sgd.Options.GraphRequest.Width == nil {
|
||||
}
|
||||
|
||||
if sgd.Options.GraphRequest.Height == nil {
|
||||
}
|
||||
|
||||
sgd.Error = data.Table.SetGraph(sgd.Options.GraphRequest)
|
||||
if sgd.Error != nil {
|
||||
break
|
||||
}
|
||||
|
||||
sgd.Error = data.Table.Output()
|
||||
if sgd.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
for _, data := range tables {
|
||||
fmt.Println()
|
||||
data.Table.OutputType = sgd.Options.OutputType
|
||||
data.Table.SetSaveFile(sgd.Options.SaveAsFile)
|
||||
data.Table.AppendTitle(" - %s", sgd.Options.TitleSuffix)
|
||||
data.Table.AppendFilePrefix(sgd.Options.FileSuffix)
|
||||
|
||||
sgd.Error = data.Table.Output()
|
||||
if sgd.Error != nil {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sgd.Error
|
||||
}
|
||||
|
||||
func (sgd *SunGrowDataResponse) Print() {
|
||||
sgd.Data.Print()
|
||||
}
|
||||
|
||||
|
||||
type SunGrowDataResponse struct {
|
||||
Data api.DataMap
|
||||
Name string
|
||||
Filename string
|
||||
Title string
|
||||
Error error
|
||||
}
|
||||
type SunGrowDataResponses map[string]SunGrowDataResponse
|
||||
type SunGrowDataFunction func(request SunGrowDataRequest) SunGrowDataResponse
|
||||
|
@ -962,12 +962,15 @@ func (sgd *SunGrowDataRequest) IsRequiredAndNotSet(arg string) bool {
|
||||
var yes bool
|
||||
for range Only.Once {
|
||||
if _, ok := sgd.Required[arg]; !ok {
|
||||
yes = false
|
||||
break
|
||||
}
|
||||
if sgd.IsNotRequired(arg) {
|
||||
yes = false
|
||||
break
|
||||
}
|
||||
if sgd.IsSet(arg) {
|
||||
yes = false
|
||||
break
|
||||
}
|
||||
yes = true
|
||||
@ -976,7 +979,59 @@ func (sgd *SunGrowDataRequest) IsRequiredAndNotSet(arg string) bool {
|
||||
}
|
||||
|
||||
func (sgd *SunGrowDataRequest) IsRequiredAndSet(arg string) bool {
|
||||
return !sgd.IsRequiredAndNotSet(arg)
|
||||
var yes bool
|
||||
for range Only.Once {
|
||||
if _, ok := sgd.Required[arg]; !ok {
|
||||
yes = false
|
||||
break
|
||||
}
|
||||
if sgd.IsNotRequired(arg) {
|
||||
yes = false
|
||||
break
|
||||
}
|
||||
if sgd.IsNotSet(arg) {
|
||||
yes = false
|
||||
break
|
||||
}
|
||||
yes = true
|
||||
}
|
||||
return yes
|
||||
}
|
||||
|
||||
// GetPrimaryArg - Fetch the primary arg that's set. Typically used in filename generation.
|
||||
func (sgd *SunGrowDataRequest) GetPrimaryArg() string {
|
||||
var yes string
|
||||
for range Only.Once {
|
||||
switch {
|
||||
case sgd.IsRequiredAndSet(NamePsKey):
|
||||
yes = sgd.Get(NamePsKey)
|
||||
case sgd.IsRequiredAndSet(NamePsId):
|
||||
yes = sgd.Get(NamePsId)
|
||||
case sgd.IsRequiredAndSet(NamePsId2):
|
||||
yes = sgd.Get(NamePsId2)
|
||||
case sgd.IsRequiredAndSet(NamePsId3):
|
||||
yes = sgd.Get(NamePsId3)
|
||||
case sgd.IsRequiredAndSet(NameUuid):
|
||||
yes = sgd.Get(NameUuid)
|
||||
case sgd.IsRequiredAndSet(NameFaultCode):
|
||||
yes = sgd.Get(NameFaultCode)
|
||||
case sgd.IsRequiredAndSet(NameDeviceType):
|
||||
yes = sgd.Get(NameDeviceType)
|
||||
case sgd.IsRequiredAndSet(NameOrgId):
|
||||
yes = sgd.Get(NameOrgId)
|
||||
case sgd.IsRequiredAndSet(NameTaskId):
|
||||
yes = sgd.Get(NameTaskId)
|
||||
case sgd.IsRequiredAndSet(NameSn):
|
||||
yes = sgd.Get(NameSn)
|
||||
case sgd.IsRequiredAndSet(NameCodeType):
|
||||
yes = sgd.Get(NameCodeType)
|
||||
case sgd.IsRequiredAndSet(NameReportType):
|
||||
yes = sgd.Get(NameReportType)
|
||||
case sgd.IsRequiredAndSet(NameUserId):
|
||||
yes = sgd.Get(NameUserId)
|
||||
}
|
||||
}
|
||||
return yes
|
||||
}
|
||||
|
||||
func (sgd *SunGrowDataRequest) SetIfRequired(arg string, value string) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user