v3.0.0-alpha - more bug fixes

This commit is contained in:
MickMake 2022-11-19 11:18:35 +11:00
parent 8d52bac8ff
commit cd52de490f
23 changed files with 2095 additions and 843 deletions

369
.idea/workspace.xml generated
View File

@ -6,36 +6,27 @@
<component name="ChangeListManager">
<list default="true" id="76adadc9-ae71-42a6-82a1-66dbc8ecb14c" name="Changes" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getHistoryInfo/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getHistoryInfo/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getHouseholdStoragePsReport/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getHouseholdStoragePsReport/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getInstallerInfoByDealerOrgCodeOrId/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getInstallerInfoByDealerOrgCodeOrId/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getKpiInfo/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getKpiInfo/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getModuleLogTaskList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getModuleLogTaskList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getPowerDevicePointNames/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPowerDevicePointNames/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getPowerStationData/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPowerStationData/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getPsReport/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getPsReport/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getRegionalTree/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getRegionalTree/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getDevicePointMinuteDataList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getDevicePointMinuteDataList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getReportData/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getReportData/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/getUpTimePoint/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/getUpTimePoint/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/psHourPointsValue/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/psHourPointsValue/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceListForApp/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/queryDeviceListForApp/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/queryMutiPointDataList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/queryMutiPointDataList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/queryPsProfit/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/queryPsProfit/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/queryUnitList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/queryUnitList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/AppService/reportList/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/AppService/reportList/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/MttvScreenService/getPsKpiForHoursByPsId/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/MttvScreenService/getPsKpiForHoursByPsId/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/MttvScreenService/getPsKpiForHoursByPsId/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/MttvScreenService/getPsKpiForHoursByPsId/struct.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/WebAppService/queryUserCurveTemplateData/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/WebAppService/queryUserCurveTemplateData/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/WebIscmAppService/viewDeviceParameter/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/WebIscmAppService/viewDeviceParameter/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/WebIscmAppService/modelPointsPage/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/WebIscmAppService/modelPointsPage/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/const.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/const.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_table.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_table.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/datetime.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/datetime.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/float.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/float.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/integers.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/integers.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/types.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/types.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/help.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/help.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/struct_areas.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/struct_areas.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/api/struct_data.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/api/struct_data.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/data_request.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/data_request.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/highlevel.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/highlevel.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/iSolarCloud/struct.go" beforeDir="false" afterPath="$PROJECT_DIR$/iSolarCloud/struct.go" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -109,7 +100,7 @@
<configuration name="GoSungrow" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="GoSungrow" />
<working_directory value="$PROJECT_DIR$" />
<parameters value="data table psHourPointsValue PsId:1171348" />
<parameters value="data table AppService.getPowerDevicePointNames DeviceType:14" />
<envs>
<env name="GOCACHE" value="/Volumes/Media/GoCache" />
</envs>
@ -348,12 +339,12 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/output/struct_table.go</url>
<line>51</line>
<line>52</line>
<option name="timeStamp" value="3787" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>382</line>
<line>410</line>
<option name="timeStamp" value="3848" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -388,7 +379,7 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/AppService/queryMutiPointDataList/data.go</url>
<line>190</line>
<line>191</line>
<option name="timeStamp" value="4111" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -403,32 +394,32 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/types.go</url>
<line>565</line>
<line>539</line>
<option name="timeStamp" value="4193" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/types.go</url>
<line>575</line>
<line>549</line>
<option name="timeStamp" value="4194" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/types.go</url>
<line>586</line>
<line>560</line>
<option name="timeStamp" value="4195" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/types.go</url>
<line>596</line>
<line>570</line>
<option name="timeStamp" value="4196" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/types.go</url>
<line>606</line>
<line>580</line>
<option name="timeStamp" value="4197" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/types.go</url>
<line>641</line>
<line>615</line>
<option name="timeStamp" value="4201" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -438,7 +429,7 @@
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>126</line>
<line>127</line>
<option name="timeStamp" value="4518" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -466,79 +457,24 @@
<line>423</line>
<option name="timeStamp" value="4695" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>228</line>
<option name="timeStamp" value="4775" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/AppService/getPsList/data.go</url>
<line>161</line>
<option name="timeStamp" value="5177" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/reflection/funcs.go</url>
<line>139</line>
<option name="timeStamp" value="5204" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>517</line>
<option name="timeStamp" value="5449" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>532</line>
<option name="timeStamp" value="5452" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>544</line>
<option name="timeStamp" value="5453" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>537</line>
<option name="timeStamp" value="5454" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>524</line>
<option name="timeStamp" value="5458" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>527</line>
<option name="timeStamp" value="5459" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>540</line>
<option name="timeStamp" value="5460" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>1062</line>
<option name="timeStamp" value="5473" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>1108</line>
<option name="timeStamp" value="5475" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>115</line>
<line>116</line>
<option name="timeStamp" value="5494" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>119</line>
<line>120</line>
<option name="timeStamp" value="5495" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>111</line>
<line>112</line>
<option name="timeStamp" value="5496" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
@ -546,16 +482,6 @@
<line>367</line>
<option name="timeStamp" value="5610" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>904</line>
<option name="timeStamp" value="5626" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/data.go</url>
<line>250</line>
<option name="timeStamp" value="5694" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/data_request.go</url>
<line>522</line>
@ -566,110 +492,200 @@
<line>245</line>
<option name="timeStamp" value="5709" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/data.go</url>
<line>239</line>
<option name="timeStamp" value="5711" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>951</line>
<option name="timeStamp" value="5726" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>999</line>
<option name="timeStamp" value="5731" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>110</line>
<line>111</line>
<option name="timeStamp" value="5732" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>98</line>
<option name="timeStamp" value="5733" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>59</line>
<option name="timeStamp" value="5739" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>1168</line>
<option name="timeStamp" value="5753" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>1178</line>
<option name="timeStamp" value="5757" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>763</line>
<option name="timeStamp" value="5770" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>827</line>
<option name="timeStamp" value="5783" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>836</line>
<option name="timeStamp" value="5784" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>852</line>
<line>855</line>
<option name="timeStamp" value="5785" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>861</line>
<line>864</line>
<option name="timeStamp" value="5786" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>814</line>
<option name="timeStamp" value="5791" />
<url>file://$PROJECT_DIR$/iSolarCloud/data.go</url>
<line>81</line>
<option name="timeStamp" value="5861" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>78</line>
<option name="timeStamp" value="5873" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>94</line>
<option name="timeStamp" value="5875" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>101</line>
<option name="timeStamp" value="5886" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>812</line>
<option name="timeStamp" value="5792" />
<line>817</line>
<option name="timeStamp" value="5907" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>147</line>
<option name="timeStamp" value="5911" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/types.go</url>
<line>57</line>
<option name="timeStamp" value="5927" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>143</line>
<option name="timeStamp" value="5931" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/data.go</url>
<line>260</line>
<option name="timeStamp" value="5954" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/data.go</url>
<line>316</line>
<option name="timeStamp" value="5956" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/data.go</url>
<line>250</line>
<option name="timeStamp" value="5957" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/types.go</url>
<line>250</line>
<option name="timeStamp" value="5999" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>414</line>
<option name="timeStamp" value="6019" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>1002</line>
<option name="timeStamp" value="6037" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>776</line>
<option name="timeStamp" value="6064" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>770</line>
<option name="timeStamp" value="6071" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>772</line>
<option name="timeStamp" value="6072" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/uv.go</url>
<line>620</line>
<option name="timeStamp" value="6085" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>612</line>
<option name="timeStamp" value="6096" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>632</line>
<option name="timeStamp" value="6097" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>807</line>
<option name="timeStamp" value="6101" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>830</line>
<option name="timeStamp" value="6102" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>846</line>
<option name="timeStamp" value="6103" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/types.go</url>
<line>261</line>
<option name="timeStamp" value="6110" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/valueTypes/types.go</url>
<line>291</line>
<option name="timeStamp" value="6115" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>388</line>
<option name="timeStamp" value="6121" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>995</line>
<option name="timeStamp" value="6127" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>108</line>
<option name="timeStamp" value="6132" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>106</line>
<option name="timeStamp" value="6134" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>921</line>
<option name="timeStamp" value="6142" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>926</line>
<option name="timeStamp" value="6143" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>100</line>
<option name="timeStamp" value="6161" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>908</line>
<option name="timeStamp" value="5805" />
<option name="timeStamp" value="6166" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>745</line>
<option name="timeStamp" value="5813" />
<line>606</line>
<option name="timeStamp" value="6186" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>732</line>
<option name="timeStamp" value="5817" />
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>173</line>
<option name="timeStamp" value="6198" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/struct_reflect.go</url>
<line>763</line>
<option name="timeStamp" value="5821" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>980</line>
<option name="timeStamp" value="5822" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/iSolarCloud/api/GoStruct/structmap.go</url>
<line>726</line>
<option name="timeStamp" value="5823" />
<url>file://$PROJECT_DIR$/iSolarCloud/api/struct_data.go</url>
<line>166</line>
<option name="timeStamp" value="6200" />
</line-breakpoint>
</breakpoints>
<default-breakpoints>
@ -678,7 +694,8 @@
</breakpoint-manager>
<watches-manager>
<configuration name="GoApplicationRunConfiguration">
<watch expression="refs[col][row]" language="go" />
<watch expression="de.Current.DataStructure.DataTable" language="go" />
<watch expression="de.Current.DataStructure.DataTableChild" language="go" />
</configuration>
</watches-manager>
</component>

View File

@ -4,6 +4,7 @@ import (
"GoSungrow/iSolarCloud/api"
"GoSungrow/iSolarCloud/api/GoStruct"
"GoSungrow/iSolarCloud/api/GoStruct/valueTypes"
"encoding/json"
"fmt"
"github.com/MickMake/GoUnify/Only"
)
@ -12,8 +13,10 @@ const Url = "/v1/commonService/getDevicePointMinuteDataList"
const Disabled = false
type RequestData struct {
PsKey valueTypes.PsKey `json:"ps_key" required:"true"`
Points valueTypes.String `json:"points" required:"true"`
PsKey valueTypes.PsKey `json:"ps_key" required:"true"`
Points valueTypes.String `json:"points" required:"true"`
StartTimeStamp valueTypes.String `json:"start_time_stamp" required:"true"`
EndTimeStamp valueTypes.String `json:"end_time_stamp" required:"true"`
}
func (rd RequestData) IsValid() error {
@ -27,9 +30,85 @@ func (rd RequestData) Help() string {
type ResultData struct {
Dummy valueTypes.String `json:"dummy"`
Data []DataPoint `json:"data" PointIdReplace:"false" DataTable:"true" DataTableSortOn:"TimeStamp"`
}
func (e *ResultData) UnmarshalJSON(data []byte) error {
var err error
for range Only.Once {
if len(data) == 0 {
break
}
err = json.Unmarshal(data, &e.Data)
if err != nil {
break
}
}
return err
}
type DataPoint struct {
GoStruct GoStruct.GoStruct `json:"-" PointIdReplace:"true" PointIdFrom:"TimeStamp" PointNameDateFormat:"20060102-150405" PointTimestampFrom:"TimeStamp"`
TimeStamp valueTypes.DateTime `json:"time_stamp"`
Points map[string]valueTypes.UnitValue `json:"points"`
// P13148 valueTypes.Integer `json:"p13148"`
IsPlatformDefaultUnit valueTypes.Bool `json:"is_platform_default_unit"`
}
func (e *DataPoint) UnmarshalJSON(data []byte) error {
var err error
for range Only.Once {
if len(data) == 0 {
break
}
type decode DataPoint
var d decode
// Store DataPoint
err = json.Unmarshal(data, &d)
if err != nil {
break
}
mp := map[string]interface{}{}
err = json.Unmarshal(data, &mp)
if err != nil {
break
}
d.Points = make(map[string]valueTypes.UnitValue) // @TODO - change to UVS
for k, v := range mp {
if k == "is_platform_default_unit" {
continue
}
if k == "time_stamp" {
continue
}
// key := valueTypes.SetPointIdString(k)
// value, ok, _ := valueTypes.AnyToUnitValue(v, "", "", "")
// value, _, _ := valueTypes.AnyToUnitValue(v, "", "", "")
// d.Points[k] = valueTypes.SetFloatValue(value.First().Value())
value, _, _ := valueTypes.AnyToUnitValue(v, "", "", "", "")
d.Points[k] = *value.First()
}
*e = DataPoint(d)
}
return err
}
func (e *ResultData) IsValid() error {
var err error
return err
@ -39,7 +118,7 @@ func (e *EndPoint) GetData() api.DataMap {
entries := api.NewDataMap()
for range Only.Once {
entries.StructToDataMap(*e, "", GoStruct.EndPointPath{})
entries.StructToDataMap(*e, e.Request.PsKey.String(), GoStruct.NewEndPointPath(e.Request.PsKey.String()))
}
return entries

View File

@ -25,7 +25,7 @@ func (rd RequestData) Help() string {
}
type ResultData struct {
DataList []DataList `json:"dataList" PointId:"data_list" PointIgnoreChildIfFromNil:"UpdateTime" PointIdFromChild:"DateId" PointNameDateFormat:"20060102" PointIdReplace:"false" PointArrayFlatten:"false" DataTable:"true"`
DataList []DataList `json:"dataList" PointId:"data_list" PointIgnoreIfChildFromNil:"UpdateTime" PointIdFromChild:"DateId" PointNameDateFormat:"20060102" PointIdReplace:"false" PointArrayFlatten:"false" DataTable:"true"`
Info []struct {
DesignCapacity valueTypes.Float `json:"design_capacity" PointUnit:"W"`
InstallerPsFaultStatus valueTypes.Integer `json:"installer_ps_fault_status"`
@ -41,7 +41,7 @@ type ResultData struct {
ValidFlag valueTypes.Bool `json:"valid_flag"`
} `json:"info" PointArrayFlatten:"false" DataTable:"true"`
MinDateId interface{} `json:"min_date_id"`
Total []DataList `json:"total" PointId:"total" PointIgnoreChildIfFromNil:"UpdateTime" PointIdFromChild:"DateId" PointNameDateFormat:"20060102" PointIdReplace:"false" PointArrayFlatten:"false" DataTable:"true"`
Total []DataList `json:"total" PointId:"total" PointIgnoreIfChildFromNil:"UpdateTime" PointIdFromChild:"DateId" PointNameDateFormat:"20060102" PointIdReplace:"false" PointArrayFlatten:"false" DataTable:"true"`
}
type DataList struct {
DateId valueTypes.DateTime `json:"date_id"`

View File

@ -24,15 +24,14 @@ func (rd RequestData) Help() string {
return ret
}
type ResultData struct {
PointTimeRelation []struct {
Is24Hour valueTypes.Bool `json:"is_24_hour"`
UpTimePointId valueTypes.Integer `json:"up_time_point_id"`
PointList []struct {
PointId valueTypes.Integer `json:"point_id"`
TimeType valueTypes.Integer `json:"time_type"`
} `json:"point_list"` // DataTable:"true" DataTablePivot:"true"`
UpTimePointId valueTypes.Integer `json:"up_time_point_id"`
Is24Hour valueTypes.Bool `json:"is_24_hour"`
} `json:"point_time_relation" DataTable:"true"`
}

View File

@ -145,7 +145,7 @@ type ResultData struct {
// } `json:"dev_type_definition"`
type PointStruct struct {
GoStruct GoStruct.GoStruct `json:"GoStruct" PointDeviceFromParent:"PsKey"`
GoStruct GoStruct.GoStruct `json:"-" PointDeviceFromParent:"PsKey"`
PointId valueTypes.PointId `json:"point_id" PointIgnore:"true" PointUpdateFreq:"UpdateFreqBoot"`
PointGroupName valueTypes.String `json:"point_group_name" PointIgnore:"true" PointUpdateFreq:"UpdateFreqBoot"`

View File

@ -26,7 +26,7 @@ func (rd RequestData) Help() string {
type ResultData struct {
PageList []struct {
GoStruct GoStruct.GoStruct `json:"GoStruct" PointDeviceFrom:"PsKey"`
GoStruct GoStruct.GoStruct `json:"-" PointDeviceFrom:"PsKey"`
AttrId valueTypes.Integer `json:"attr_id"`
ChannelId valueTypes.Integer `json:"chnnl_id" PointId:"channel_id"`

View File

@ -37,33 +37,6 @@ type ResultData struct {
Devices Devices `json:"devices"`
}
type Devices map[string]Device
type Device struct {
Points Points `json:"points"`
}
type Points map[valueTypes.PointId]Point
type Point struct {
Name valueTypes.String `json:"name"`
Units valueTypes.String `json:"units"`
Times Times `json:"times"`
}
type Times []Time
type Time struct {
Key valueTypes.DateTime `json:"key"`
Value string `json:"value"`
}
func (e *ResultData) IsValid() error {
var err error
return err
}
type dDevices map[string]dPoints
type dPoints map[string]dTimes
type dTimes map[string]string
type DecodeResultData ResultData
func (e *ResultData) UnmarshalJSON(data []byte) error {
var err error
@ -111,6 +84,11 @@ func (e *ResultData) UnmarshalJSON(data []byte) error {
return err
}
func (e *ResultData) IsValid() error {
var err error
return err
}
func (e *ResultData) String() string {
var ret string
@ -160,6 +138,29 @@ func (e *ResultData) String() string {
return ret
}
type Devices map[string]Device
type Device struct {
Points Points `json:"points"`
}
type Points map[valueTypes.PointId]Point
type Point struct {
Name valueTypes.String `json:"name"`
Units valueTypes.String `json:"units"`
Times Times `json:"times"`
}
type Times []Time
type Time struct {
Key valueTypes.DateTime `json:"key"`
Value string `json:"value"`
}
type dDevices map[string]dPoints
type dPoints map[string]dTimes
type dTimes map[string]string
type DecodeResultData ResultData
func (e *EndPoint) GetPointDataTable(points api.TemplatePoints) output.Table {
var table output.Table

View File

@ -52,7 +52,7 @@ type ResultData struct {
ValleyNetPowerQuantity interface{} `json:"valley_net_power_quantity"`
ValleyPowerQuantity interface{} `json:"valley_power_quantity"`
ValleyUsePowerQuantity interface{} `json:"valley_use_power_quantity"`
} `json:"actual_list" PointId:"actual" PointIdFromChild:"DateId" PointNameDateFormat:"20060102" PointArrayFlatten:"false"` // PointIgnoreChildIfFromNil:"UpdateTime" DataTable:"true"`
} `json:"actual_list" PointId:"actual" PointIdFromChild:"DateId" PointNameDateFormat:"20060102" PointArrayFlatten:"false"` // PointIgnoreIfChildFromNil:"UpdateTime" DataTable:"true"`
// Need to fix this output - PointIdFromChild:"DateId" isn't working.
PlanList []interface{} `json:"plan_list" PointArrayFlatten:"false"`
}

View File

@ -24,7 +24,7 @@ func (rd RequestData) Help() string {
}
type ResultData []struct {
GoStructParent GoStruct.GoStructParent `json:"GoStruct" DataTable:"true" DataTableSortOn:"UnitConvertId"`
GoStructParent GoStruct.GoStructParent `json:"-" DataTable:"true" DataTableSortOn:"UnitConvertId"`
UnitConvertId valueTypes.Integer `json:"unit_conver_id" PointId:"unit_convert_id"`
UnitName valueTypes.String `json:"unit_name"`

View File

@ -27,9 +27,9 @@ func (rd RequestData) Help() string {
type ResultData struct {
Info Common.ReportInfo `json:"info" PointArrayFlatten:"false"`
DataList []DataList `json:"dataList" PointId:"data_list" DataTable:"true" PointIgnoreChildIfFromNil:"UpdateTime" PointIdFromChild:"UpdateTime" PointNameDateFormat:"20060102" PointIdReplace:"false"`
DataList []DataList `json:"dataList" PointId:"data_list" DataTable:"true" PointIgnoreIfChildFromNil:"UpdateTime" PointIdFromChild:"UpdateTime" PointNameDateFormat:"20060102" PointIdReplace:"false"`
MinDateId interface{} `json:"min_date_id"`
Total []DataList `json:"total" PointId:"total" DataTable:"true" PointIgnoreChildIfFromNil:"UpdateTime" PointIdFromChild:"UpdateTime" PointNameDateFormat:"20060102" PointIdReplace:"false" PointArrayFlatten:"false"`
Total []DataList `json:"total" PointId:"total" DataTable:"true" PointIgnoreIfChildFromNil:"UpdateTime" PointIdFromChild:"UpdateTime" PointNameDateFormat:"20060102" PointIdReplace:"false" PointArrayFlatten:"false"`
}
type DataList struct {

View File

@ -27,7 +27,7 @@ func (rd RequestData) Help() string {
type ResultData struct {
PointList []struct {
GoStructParent GoStruct.GoStructParent `json:"-" DataTable:"true" DataTableSortOn:"PointId" PointIdFromChild:"PointId" PointIdReplace:"false"`
GoStructParent GoStruct.GoStructParent `json:"-" PointIdFromChild:"PointId" PointIdReplace:"false"`
PointId valueTypes.Integer `json:"point_id"`
PointName valueTypes.String `json:"point_name"`
@ -36,14 +36,14 @@ type ResultData struct {
IsShow valueTypes.Bool `json:"is_show"`
IsSupportSecondData valueTypes.Bool `json:"is_support_second_data"`
OrderNum valueTypes.Integer `json:"order_num"`
} `json:"pointList" PointId:"point_list"` // DataTable:"true" DataTableSortOn:"PointId" PointIdFromChild:"PointId" PointIdReplace:"false"`
} `json:"pointList" PointId:"point_list" DataTable:"true" DataTableSortOn:"PointId"`
ModelList []struct {
GoStruct GoStruct.GoStructParent `json:"GoStruct" DataTable:"true" DataTableSortOn:"DeviceModelId" PointIdFromChild:"DeviceModelId" PointIdReplace:"false"`
GoStruct GoStruct.GoStructParent `json:"GoStruct" PointIdFromChild:"DeviceModelId" PointIdReplace:"false"`
DeviceModelId valueTypes.Integer `json:"device_model_id"`
DeviceModel valueTypes.String `json:"device_model"`
DeviceModelCode valueTypes.String `json:"device_model_code"`
} `json:"modelList" PointId:"model_list"` // DataTable:"true" DataTableSortOn:"DeviceModelId" PointIdFromChild:"DeviceModelId" PointIdReplace:"false"`
} `json:"modelList" PointId:"model_list" DataTable:"true" DataTableSortOn:"DeviceModelId"`
}
func (e *ResultData) IsValid() error {

View File

@ -1,3 +1,4 @@
// Package GoStruct - A framework for type agnostic and recursive data.
package GoStruct
// These are tags that can be added to a Go structure that GoStruct uses to process the structure.
@ -57,8 +58,8 @@ const (
PointIgnore = "PointIgnore"
// PointIgnoreIfNil - Ignore this point if a child is nil or empty.
PointIgnoreIfNil = "PointIgnoreIfNil"
// PointIgnoreChildIfFromNil - Ignore this point if a child is nil or empty.
PointIgnoreChildIfFromNil = "PointIgnoreChildIfFromNil"
// PointIgnoreIfChildFromNil - Ignore this point if a child is nil or empty.
PointIgnoreIfChildFromNil = "PointIgnoreIfChildFromNil"
// PointIgnoreZero - Ignore arrays with zero size, (default true).
PointIgnoreZero = "PointIgnoreZero"

View File

@ -6,6 +6,7 @@ import (
"fmt"
tabular "github.com/agrison/go-tablib"
"os"
"sort"
"strings"
)
// "github.com/agrison/go-tablib"
@ -61,6 +62,18 @@ func (t *Table) GetHeaders() []string {
return t.table.Headers()
}
func (t *Table) GetSortedHeaders() []string {
var sorted []string
for range Only.Once {
for _, h := range t.table.Headers() {
sorted = append(sorted, h)
}
sort.Strings(sorted)
}
return sorted
}
func (t *Table) RowLength() int {
return t.table.Height()
}

View File

@ -50,7 +50,7 @@ type DataTags struct {
PointIgnore bool `json:"point_ignore,omitempty"`
PointIgnoreZero bool `json:"point_ignore_zero,omitempty"`
PointIgnoreIfNil string `json:"point_ignore_if_nil,omitempty"`
PointIgnoreChildIfFromNil string `json:"point_ignore_if_child_nil,omitempty"`
PointIgnoreIfChildFromNil string `json:"point_ignore_if_child_nil,omitempty"`
PointGroupName string `json:"point_group_name,omitempty"`
PointGroupNameFrom string `json:"point_group_name_from,omitempty"`
@ -158,7 +158,7 @@ func (ds *DataTags) GetTags(fieldTo reflect.StructField, fieldVo reflect.Value)
PointAliasTo: fieldTo.Tag.Get(PointAliasTo),
PointIgnoreIfNil: fieldTo.Tag.Get(PointIgnoreIfNil),
PointIgnoreChildIfFromNil: fieldTo.Tag.Get(PointIgnoreChildIfFromNil),
PointIgnoreIfChildFromNil: fieldTo.Tag.Get(PointIgnoreIfChildFromNil),
PointSplitOn: fieldTo.Tag.Get(PointSplitOn),
PointSplitOnType: fieldTo.Tag.Get(PointSplitOnType),
@ -269,7 +269,9 @@ func (ds *DataTags) UpdateTags(parent *Reflect, current *Reflect) *DataTags {
ds.PointGroupName = reflection.GetStringFrom(current.Interface, current.Index, ds.PointGroupNameFrom)
}
ds.PointTimestamp = time.Now()
// if ds.PointTimestamp.IsZero() {
// ds.PointTimestamp = time.Now()
// }
if ds.PointTimestampFrom != "" {
ds.PointTimestamp = reflection.GetTimestampFrom(current.Interface, ds.PointTimestampFrom, valueTypes.DateTimeLayout)
}
@ -285,9 +287,9 @@ func (ds *DataTags) UpdateTags(parent *Reflect, current *Reflect) *DataTags {
ds.PointName = valueTypes.PointToName(ds.PointId)
}
if parent.DataStructure.PointIgnoreChildIfFromNil != "" {
if parent.DataStructure.PointIgnoreIfChildFromNil != "" {
// Ignore a child if it has a zero/empty value.
ret := reflection.GetStringFrom(current.Interface, current.Index, parent.DataStructure.PointIgnoreChildIfFromNil)
ret := reflection.GetStringFrom(current.Interface, current.Index, parent.DataStructure.PointIgnoreIfChildFromNil)
if ret != "" {
ds.PointIgnore = true
}
@ -543,7 +545,7 @@ func (r *Reflect) Init(parent interface{}, current interface{}, name EndPointPat
IsExported: true,
isUnknown: false,
IsOk: true,
Value: nil,
Value: valueTypes.UnitValues{},
InterfaceValue: parent,
Index: 0,
Length: 0,
@ -584,12 +586,12 @@ func (r *Reflect) Init(parent interface{}, current interface{}, name EndPointPat
r.FieldName = r.FieldTo.Name
r.DataStructure.GetTags(reflect.StructField{}, reflect.Value{}) // , r.FieldTo, r.FieldVo)
r.SetGoStructOptions()
r.SetGoStructOptions(1)
r.DataStructure.UpdateTags(r.ParentReflect, r.CurrentReflect)
r.InterfaceValue = current
r.Value, r.IsNil, r.IsOk = valueTypes.AnyToUnitValue(
r.InterfaceValue, r.DataStructure.PointUnit,
r.InterfaceValue, "", r.DataStructure.PointUnit,
r.DataStructure.PointValueType, r.DataStructure.PointNameDateFormat)
case reflect.Slice:
@ -601,18 +603,17 @@ func (r *Reflect) Init(parent interface{}, current interface{}, name EndPointPat
r.IsExported = true
r.FieldName = r.FieldTo.Name
r.DataStructure.GetTags(reflect.StructField{}, reflect.Value{}) // , r.FieldTo, r.FieldVo)
r.SetGoStructOptions()
r.SetGoStructOptions(2)
r.DataStructure.UpdateTags(r.ParentReflect, r.CurrentReflect)
r.InterfaceValue = r.FieldVo.Interface()
r.Value, r.IsNil, r.IsOk = valueTypes.AnyToUnitValue(
r.InterfaceValue, r.DataStructure.PointUnit,
r.DataStructure.PointValueType, r.DataStructure.PointNameDateFormat)
if r.Length == 0 {
r.DataStructure.PointIdReplace = true
}
r.InterfaceValue = r.FieldVo.Interface()
r.Value, r.IsNil, r.IsOk = valueTypes.AnyToUnitValue(
r.InterfaceValue, "", r.DataStructure.PointUnit,
r.DataStructure.PointValueType, r.DataStructure.PointNameDateFormat)
case reflect.Map:
r.Length = len(r.ValueOf.MapKeys())
r.FieldTo = reflect.StructField{}
@ -625,17 +626,17 @@ func (r *Reflect) Init(parent interface{}, current interface{}, name EndPointPat
// r.FieldName = current.FieldName // mk[index].String()
r.DataStructure.GetTags(reflect.StructField{}, reflect.Value{}) // , r.FieldTo, r.FieldVo)
r.SetGoStructOptions()
r.SetGoStructOptions(1)
r.DataStructure.UpdateTags(r.ParentReflect, r.CurrentReflect)
r.InterfaceValue = r.FieldVo.Interface()
r.Value, r.IsNil, r.IsOk = valueTypes.AnyToUnitValue(
r.InterfaceValue, r.DataStructure.PointUnit,
r.InterfaceValue, "", r.DataStructure.PointUnit,
r.DataStructure.PointValueType, r.DataStructure.PointNameDateFormat)
}
r.SetGoStructOptions()
r.DataStructure.UpdateTags(r.ParentReflect, r.CurrentReflect)
// r.SetGoStructOptions()
// r.DataStructure.UpdateTags(r.ParentReflect, r.CurrentReflect)
r.SetPointId()
}
}
@ -701,13 +702,13 @@ func (r *Reflect) SetByIndex(parent *Reflect, current *Reflect, index int, index
// DataStructure
r.DataStructure.GetTags(r.FieldTo, r.FieldVo)
r.SetGoStructOptions()
r.SetGoStructOptions(1)
r.DataStructure.UpdateTags(parent, current)
// Value
r.InterfaceValue = r.FieldVo.Interface()
r.Value, r.IsNil, r.IsOk = valueTypes.AnyToUnitValue(
r.InterfaceValue, r.DataStructure.PointUnit,
r.InterfaceValue, "", r.DataStructure.PointUnit,
r.DataStructure.PointValueType, r.DataStructure.PointNameDateFormat)
switch {
case r.DataStructure.PointUnit == "":
@ -743,7 +744,7 @@ func (r *Reflect) SetByIndex(parent *Reflect, current *Reflect, index int, index
r.DataStructure.PointUnitFromParent = current.DataStructure.PointUnitFrom
}
}
r.SetGoStructOptions()
r.SetGoStructOptions(2)
r.DataStructure.UpdateTags(parent, current)
if r.Length == 0 {
r.DataStructure.PointIdReplace = true
@ -763,7 +764,7 @@ func (r *Reflect) SetByIndex(parent *Reflect, current *Reflect, index int, index
// Value
r.InterfaceValue = r.FieldVo.Interface()
r.Value, r.IsNil, r.IsOk = valueTypes.AnyToUnitValue(
r.InterfaceValue, r.DataStructure.PointUnit,
r.InterfaceValue, "", r.DataStructure.PointUnit,
r.DataStructure.PointValueType, r.DataStructure.PointNameDateFormat)
switch {
case r.DataStructure.PointUnit == "":
@ -797,16 +798,16 @@ func (r *Reflect) SetByIndex(parent *Reflect, current *Reflect, index int, index
r.DataStructure.PointUnitFromParent = current.DataStructure.PointUnitFrom
}
}
r.SetGoStructOptions()
r.DataStructure.UpdateTags(parent, current)
r.SetGoStructOptions(1)
r.DataStructure.Json = indexName.String() // current.ValueOf.MapIndex(indexName).String() || r.FieldVo.String()
r.DataStructure.PointId = indexName.String() // current.ValueOf.MapIndex(indexName).String() || r.FieldVo.String()
r.DataStructure.UpdateTags(parent, current)
// Value
r.InterfaceValue = r.FieldVo.Interface()
r.Value, r.IsNil, r.IsOk = valueTypes.AnyToUnitValue(
// map[string]interface{}{ indexName.String(): r.InterfaceValue }, r.DataStructure.PointUnit,
r.InterfaceValue, r.DataStructure.PointUnit,
r.InterfaceValue, "", r.DataStructure.PointUnit,
r.DataStructure.PointValueType, r.DataStructure.PointNameDateFormat)
switch {
case r.DataStructure.PointUnit == "":
@ -814,7 +815,7 @@ func (r *Reflect) SetByIndex(parent *Reflect, current *Reflect, index int, index
case r.Value.Unit() == "":
r.Value.SetUnit(r.DataStructure.PointUnit)
}
r.Value.First().SetKey(indexName.String())
// r.Value.First().SetKey(indexName.String())
default:
r.Interface = current.Interface
@ -828,11 +829,15 @@ func (r *Reflect) SetValue(value interface{}) {
for range Only.Once {
r.InterfaceValue = value
r.Value, r.IsNil, r.IsOk = valueTypes.AnyToUnitValue(
value, r.DataStructure.PointUnit,
value, "", r.DataStructure.PointUnit,
r.DataStructure.PointValueType, r.DataStructure.PointNameDateFormat)
}
}
func (r *Reflect) ValuesRange() []valueTypes.UnitValue {
return r.Value.Range(valueTypes.SortOrder)
}
func (r *Reflect) SetValues(values ...interface{}) {
for range Only.Once {
r.InterfaceValue = values
@ -840,11 +845,9 @@ func (r *Reflect) SetValues(values ...interface{}) {
for _, value := range values {
var uvs2 valueTypes.UnitValues
uvs2, r.IsNil, r.IsOk = valueTypes.AnyToUnitValue(
value, r.DataStructure.PointUnit,
value, "", r.DataStructure.PointUnit,
r.DataStructure.PointValueType, r.DataStructure.PointNameDateFormat)
for _, uv := range uvs2 {
uvs = append(uvs, uv)
}
uvs.Append(uvs2)
}
}
}
@ -853,7 +856,7 @@ func (r *Reflect) SetUnitValue(value valueTypes.UnitValue) {
for range Only.Once {
r.InterfaceValue = value
r.Value, r.IsNil, r.IsOk = valueTypes.AnyToUnitValue(
value, r.DataStructure.PointUnit,
value, "", r.DataStructure.PointUnit,
r.DataStructure.PointValueType, r.DataStructure.PointNameDateFormat)
}
}
@ -862,7 +865,7 @@ func (r *Reflect) SetUnitValues(value valueTypes.UnitValues) {
for range Only.Once {
r.InterfaceValue = value
r.Value, r.IsNil, r.IsOk = valueTypes.AnyToUnitValue(
value, r.DataStructure.PointUnit,
value, "", r.DataStructure.PointUnit,
r.DataStructure.PointValueType, r.DataStructure.PointNameDateFormat)
}
}
@ -871,6 +874,7 @@ func (r *Reflect) SetUnitValues(value valueTypes.UnitValues) {
func (r *Reflect) SetPointId() EndPointPath {
for range Only.Once {
r.DataStructure.Endpoint = r.CurrentReflect.CopyEndPointPath()
// fmt.Printf("EPP(BEFORE): %s\n", r.DataStructure.Endpoint.String())
// fmt.Printf("[ ] EPP: %s - FP: %s\n", r.DataStructure.Endpoint, r.FieldPath)
var pn string
@ -920,7 +924,9 @@ func (r *Reflect) SetPointId() EndPointPath {
}
if r.DataStructure.PointId != "" {
pns = append(pns, r.DataStructure.PointId)
if !r.DataStructure.PointIdReplace {
pns = append(pns, r.DataStructure.PointId)
}
}
pn = strings.Join(pns, ".")
r.DataStructure.Endpoint.Append(r.DataStructure.PointId)
@ -999,6 +1005,7 @@ func (r *Reflect) SetPointId() EndPointPath {
}
}
// fmt.Printf("EPP(AFTER): %s\n", r.DataStructure.Endpoint.String())
return r.DataStructure.Endpoint
}
@ -1116,12 +1123,12 @@ func (r *Reflect) AsJson() string {
}
// SetGoStructOptions - Copies and updates DataTags from a GoStruct object.
func (r *Reflect) SetGoStructOptions() bool {
func (r *Reflect) SetGoStructOptions(limit int) bool {
var yes bool
// fmt.Printf("Current(enter): %s\n", r.DataStructure)
for range Only.Once {
r.GoStructs.Parent, r.GoStructs.Current = GetChildGoStruct(r.Interface, 1)
r.GoStructs.Parent, r.GoStructs.Current = GetChildGoStruct(r.Interface, limit)
if r.GoStructs.Current == nil {
r.GoStructs.Current = r.GetGoStruct()
}
@ -1294,6 +1301,11 @@ func GetChildGoStruct(ref interface{}, limit int) (*DataTags, *DataTags) {
}
if (vo.Kind() == reflect.Slice) || (vo.Kind() == reflect.Array) {
if limit < 0 {
break // Count a recurse as one extra.
}
limit--
// Iterate over all available fields, looking for the field name.
for i := 0; i < vo.Len(); i++ {
parent, current = GetChildGoStruct(vo.Index(i).Interface(), limit)
@ -1384,16 +1396,16 @@ func (r *Reflect) IsGoStructForParent() bool {
return yes
}
func (r *Reflect) PointIgnoreChildIfFromNil() bool {
func (r *Reflect) PointIgnoreIfChildFromNil() bool {
var yes bool
for range Only.Once {
if r.ParentReflect.DataStructure.PointIgnoreChildIfFromNil == "" {
if r.ParentReflect.DataStructure.PointIgnoreIfChildFromNil == "" {
// If parent doesn't care about a zero value.
yes = false
break
}
ret := reflection.GetStringFrom(r.Interface, r.Index, r.ParentReflect.DataStructure.PointIgnoreChildIfFromNil)
ret := reflection.GetStringFrom(r.Interface, r.Index, r.ParentReflect.DataStructure.PointIgnoreIfChildFromNil)
if ret == "" {
yes = false
break

View File

@ -7,6 +7,7 @@ import (
"github.com/MickMake/GoUnify/Only"
"os"
"reflect"
"sort"
"strings"
"time"
)
@ -144,6 +145,8 @@ func (sm *StructMap) ScanMap(Parent *Reflect, Current *Reflect) bool {
break
}
ok = Current.IsKnown()
ok = true
for index, key := range Current.FieldVo.MapKeys() {
var Child Reflect
@ -261,8 +264,13 @@ func (sm *StructMap) Process(Child *Reflect) bool {
sm.Start = Child
sm.StructMapOptions.StartAt = ""
sm.PrintDebug("DEBUG: sm.Start.EndPointPath(): %s\n", sm.Start.EndPointPath())
if Child.Kind == reflect.Array || Child.Kind == reflect.Slice {
Child.SetGoStructOptions(2)
Child.DataStructure.UpdateTags(Child.CurrentReflect, Child)
}
// @TODO - FIX THIS UP - need to check if the point_id is not this...
if sm.Start.EndPointPath().Last() == "result_data" {
// if sm.Start.FieldPath.Last() == sm.StructMapOptions.StartAt {
sm.Start.EndPointPath().PopLast() // Remove "ResultData" from end.
sm.PrintDebug("DEBUG: sm.Start.EndPointPath().PopLast(): %s\n", sm.Start.EndPointPath())
}
@ -273,6 +281,14 @@ func (sm *StructMap) Process(Child *Reflect) bool {
break
}
if Child.DataStructure.PointTimestamp.IsZero() {
if sm._Timestamp.IsZero() {
Child.DataStructure.PointTimestamp = time.Now()
} else {
Child.DataStructure.PointTimestamp = sm.TimeStamp
}
}
if sm.Start == nil {
ok = Child.IsKnown()
break // Wait until we've started.
@ -345,6 +361,10 @@ func (sm *StructMap) Add(Current *Reflect) {
sm.Map = make(map[string]*Reflect)
}
name := Current.EndPointPath().String()
if _, ok := sm.Map[name]; ok {
sm.PrintDebug("\t- Add() Current: %s\n", Current)
break
}
sm.Map[name] = Current
sm.PrintDebug("\t- Add() Current: %s\n", Current)
}
@ -365,6 +385,10 @@ func (sm *StructMap) AddTable(Current *Reflect) {
sm.TableMap = make(map[string]*Reflect)
}
name := Current.Name()
if _, ok := sm.TableMap[name]; ok {
sm.PrintDebug("\t- Add() Current: %s\n", Current)
break
}
sm.TableMap[name] = Current
sm.PrintDebug("\t- Add() Current: %s\n", Current)
}
@ -373,7 +397,7 @@ func (sm *StructMap) AddTable(Current *Reflect) {
func (sm *StructMap) IsNil(Current *Reflect) bool {
var yes bool
for range Only.Once {
yes = Current.PointIgnoreChildIfFromNil() // true - Current is nil.
yes = Current.PointIgnoreIfChildFromNil() // true - Current is nil.
if sm.AddNil {
sm.Add(Current)
@ -477,13 +501,14 @@ func (sm *StructMap) IsTable(Current *Reflect) bool {
// We want to flatten a slice down to EG "[1, 2, 3]"
uv := valueTypes.AnyToValueString(Current.InterfaceValue, 0, Current.DataStructure.PointNameDateFormat)
// uv = Current.AsJson()
Current.Value.Set(valueTypes.SetUnitValueString(uv, Current.DataStructure.PointUnit, Current.DataStructure.PointValueType))
Current.Value.Set(uv, "", Current.DataStructure.PointUnit, Current.DataStructure.PointValueType)
sm.Add(Current)
break
}
// Check for a table child.
ok, iterate := Current.IsTableChild()
// ok, iterate := Current.IsTableChild()
ok, _ := Current.IsTableChild()
if !ok {
break
}
@ -507,44 +532,47 @@ func (sm *StructMap) IsTable(Current *Reflect) bool {
// We want to flatten a slice down to EG "[1, 2, 3]"
yes = Current.IsKnown()
sm.Add(Current)
// First order types get flattened.
switch Current.Kind {
case reflect.Struct:
if yes {
break
}
if iterate == 1 {
sm.Add(Current)
break
}
case reflect.Array:
fallthrough
case reflect.Slice:
if yes {
break
}
if iterate == 1 {
if Current.Length <= 1 {
uv := valueTypes.AnyToValueString(Current.InterfaceValue, 0, Current.DataStructure.PointNameDateFormat)
Current.Value.Set(valueTypes.SetUnitValueString(uv, Current.DataStructure.PointUnit, Current.DataStructure.PointValueType))
}
sm.Add(Current)
break
}
case reflect.Map:
if yes {
break
}
if iterate == 1 {
if Current.Length <= 1 {
uv := valueTypes.AnyToValueString(Current.InterfaceValue, 0, Current.DataStructure.PointNameDateFormat)
Current.Value.Set(valueTypes.SetUnitValueString(uv, Current.DataStructure.PointUnit, Current.DataStructure.PointValueType)) }
sm.Add(Current)
break
}
}
// switch Current.Kind {
// case reflect.Struct:
// if yes {
// break
// }
// if iterate == 1 {
// sm.Add(Current)
// break
// }
//
// case reflect.Array:
// fallthrough
// case reflect.Slice:
// if yes {
// break
// }
// if iterate == 1 {
// if Current.Length <= 1 {
// uv := valueTypes.AnyToValueString(Current.InterfaceValue, 0, Current.DataStructure.PointNameDateFormat)
// Current.Value.AddString(uv, "", Current.DataStructure.PointUnit, Current.DataStructure.PointValueType)
// }
// sm.Add(Current)
// break
// }
//
// case reflect.Map:
// if yes {
// break
// }
// if iterate == 1 {
// if Current.Length <= 1 {
// uv := valueTypes.AnyToValueString(Current.InterfaceValue, 0, Current.DataStructure.PointNameDateFormat)
// Current.Value.AddString(uv, "", Current.DataStructure.PointUnit, Current.DataStructure.PointValueType)
// }
// sm.Add(Current)
// break
// }
// }
}
return yes
}
@ -600,7 +628,7 @@ func (sm *StructMap) IsPointArrayFlatten(Current *Reflect) bool {
// Current.InterfaceValue, Current.DataStructure.PointUnit,
// Current.DataStructure.PointValueType, Current.DataStructure.PointNameDateFormat)
uv := valueTypes.AnyToValueString(Current.InterfaceValue, 0, Current.DataStructure.PointNameDateFormat)
Current.Value.Set(valueTypes.SetUnitValueString(uv, Current.DataStructure.PointUnit, Current.DataStructure.PointValueType))
Current.Value.AddString(uv, "", Current.DataStructure.PointUnit, Current.DataStructure.PointValueType)
sm.Add(Current)
}
return yes
@ -747,7 +775,7 @@ func (sm *StructMap) GetTableData(name string) StructTable {
if !ret.Current.DataStructure.DataTablePivot {
ret.Reflects = refs
ret.AddHeader(ret.Reflects[0]...)
// ret.AddHeader(ret.Reflects[0]...)
break
}
@ -761,7 +789,7 @@ func (sm *StructMap) GetTableData(name string) StructTable {
ret.Reflects = ret.Reflects.AddRow(refRow...)
}
}
ret.AddHeader(ret.Reflects[0]...)
// ret.AddHeader(ret.Reflects[0]...)
}
return ret
@ -770,92 +798,91 @@ func (sm *StructMap) GetTableData(name string) StructTable {
func (sm *StructMap) GetResultTableData() StructTable {
var ret StructTable
for range Only.Once {
fmt.Printf("NOT IMPLEMENTED YET.\n")
break
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...)
// }
}
}
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
Headers []string
Reflects ReflectArray
SortOn string
ShowIndex bool
Name string
Current *Reflect
Reflects ReflectArray
SortOn string
ShowIndex bool
IndexTitle string
IsValid bool
IsValid bool
Columns []string
}
@ -884,31 +911,25 @@ func (ta *ReflectArray) GetRow(row int) ReflectArrayRow {
type StructTables []StructTable
type StructValues [][]valueTypes.UnitValue
type StructValues []StructValue
type StructValue map[string]valueTypes.UnitValue
func (ta *StructTable) AddHeader(headers ...*Reflect) {
func (ta *StructValues) GetCell(row int, col string) string {
var ret string
for range Only.Once {
for index, header := range headers {
if header == nil {
name := fmt.Sprintf("Column %d", index)
ta.Headers = append(ta.Headers, name)
continue
}
name := valueTypes.PointToName(header.DataStructure.PointId)
switch header.Value.Unit() { // header.DataStructure.PointUnit {
case "--":
//
case "":
//
default:
// name += " (" + header.DataStructure.PointUnit + ")"
name += " (" + header.Value.Unit() + ")"
}
ta.Headers = append(ta.Headers, name)
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) {
@ -928,13 +949,67 @@ func (ta *StructTable) GetRow(row int) ReflectArrayRow {
}
func (ta *StructTable) GetHeaders() []string {
var ret []string
if ta.ShowIndex {
ret := []string{ta.IndexTitle}
ret = append(ret, ta.Headers...)
return ret
for range Only.Once {
if !ta.IsValid {
break
}
for colIndex := range ta.Columns {
header := ta.Reflects[0][colIndex]
if header == nil {
name := fmt.Sprintf("Column %d", colIndex)
ret = append(ret, name)
continue
}
if len(header.ChildReflect) > 0 {
for _, sub := range header.ChildReflect {
name := header.DataStructure.PointName + " " + sub.DataStructure.PointName
switch header.Value.Unit() {
case "--":
case "":
default:
name += " (" + sub.Value.Unit() + ")"
}
// ret = append(ret, sub.Value.KeysSorted()...)
ret = append(ret, name)
}
continue
}
if header.IsKnown() {
name := header.DataStructure.PointName
unit := header.Value.Unit()
for _, n := range header.Value.KeysSorted() {
if unit == "" {
ret = append(ret, name + " " + n)
continue
}
ret = append(ret, name + " " + n + " (" + unit + ")")
}
continue
}
name := header.DataStructure.PointName
switch header.Value.Unit() {
case "--":
case "":
default:
name += " (" + header.Value.Unit() + ")"
}
ret = append(ret, name)
}
}
return ta.Headers
// if ta.ShowIndex {
// ret := []string{ta.IndexTitle}
// ret = append(ret, ta.Headers...)
// return ret
// }
// return ta.Headers
return ret
}
func (ta *StructTable) Get() ReflectArray {
@ -949,9 +1024,18 @@ func (ta *StructTable) GetValues() StructValues {
break
}
colOrder := make(map[string]int)
var colOrderIndex int
var addCol = func(name string) {
if _, ok := colOrder[name]; !ok {
colOrder[name] = colOrderIndex
colOrderIndex++
}
}
for rowIndex := range ta.Reflects {
// fmt.Printf("ROW[%d] - size:%d\n", rowIndex, len(ta.Reflects[rowIndex]))
var data []valueTypes.UnitValue
data := make(StructValue)
// size := len(ta.Reflects[rowIndex])
// if size == 1 {
@ -972,189 +1056,82 @@ func (ta *StructTable) GetValues() StructValues {
if ta.ShowIndex {
vi := valueTypes.SetUnitValueInteger(int64(rowIndex), ta.IndexTitle, "")
data = append(data, vi)
data[ta.IndexTitle] = vi
addCol(ta.IndexTitle)
}
for colIndex, col := range ta.Reflects[rowIndex] {
value := ta.Reflects[rowIndex][colIndex].Value
if col.IsUnknown() {
dateFormat := col.DataStructure.PointNameDateFormat
if dateFormat == "" {
dateFormat = valueTypes.DateTimeLayout
// 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 {
// data = append(data, sub.Value.Range(valueTypes.SortOrder)...)
for _, val := range sub.Value.Range(valueTypes.LoadOrder) {
name := val.ValueKey()
data[name] = val
addCol(name)
}
}
value, _, _ = valueTypes.AnyToUnitValue(col.Value, col.DataStructure.PointUnit,
col.DataStructure.PointValueType, dateFormat)
continue
}
for _, v := range value {
data = append(data, v)
if col.IsKnown() {
value := ta.Reflects[rowIndex][colIndex].Value
// data = append(data, value.Range(valueTypes.SortOrder)...)
for _, val := range value.Range(valueTypes.LoadOrder) {
name := val.ValueKey()
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.LoadOrder) {
name := val.ValueKey()
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) GetMergedTableData(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.Kind == reflect.Struct {
// if sm.Debug {
// _, _ = fmt.Fprintf(os.Stderr,"GetTableArray(%s) - STRUCT\n", name)
// }
//
// if ret.Current.IsPointIgnore() {
// continue
// }
//
// fmt.Printf("[%s]STRUCT - Current:%d\n", ret.Current.FieldPath,
// len(ret.Current.ChildReflect),
// )
//
// var refs []*Reflect
// for _, Child := range ret.Current.ChildReflect {
// if Child.IsPointIgnore() {
// continue
// }
//
// if ret.Current.DataStructure.DataTableSortOn != "" {
// // fmt.Printf("\tChildStruct> %s / %s\n", ChildStruct.FieldName, dt.Reflect.DataStructure.DataTableSortOn)
// if ret.Current.DataStructure.DataTableSortOn == Child.FieldName {
// ret.SortOn = Child.DataStructure.PointName
// // dt.Reflect.DataStructure.DataTableSortOn = ""
// }
// }
//
// fmt.Printf("[%s]STRUCT - Known:%t Current:%d / Child:%d\n", Child.FieldPath,
// Child.IsKnown(),
// len(ret.Current.ChildReflect),
// len(Child.ChildReflect),
// )
// if Child.IsKnown() {
// refs = append(refs, Child)
// continue
// }
//
// refs = append(refs, Child)
// }
//
// if len(refs) > 0 {
// ret.AddRow(refs...)
// }
// break
// }
//
// if ret.Current.Kind == reflect.Map {
// if sm.Debug {
// _, _ = fmt.Fprintf(os.Stderr,"GetTableArray(%s) - MAP\n", name)
// }
//
// if ret.Current.IsPointIgnore() {
// continue
// }
//
// fmt.Printf("[%s]STRUCT - Current:%d\n", ret.Current.FieldPath,
// len(ret.Current.ChildReflect),
// )
//
// var refs []*Reflect
// for _, Child := range ret.Current.ChildReflect {
// if Child.IsPointIgnore() {
// continue
// }
//
// if ret.Current.DataStructure.DataTableSortOn != "" {
// // fmt.Printf("\tChildStruct> %s / %s\n", ChildStruct.FieldName, dt.Reflect.DataStructure.DataTableSortOn)
// if ret.Current.DataStructure.DataTableSortOn == Child.FieldName {
// ret.SortOn = Child.DataStructure.PointName
// // dt.Reflect.DataStructure.DataTableSortOn = ""
// }
// }
//
// fmt.Printf("[%s]STRUCT - Known:%t Current:%d / Child:%d\n", Child.FieldPath,
// Child.IsKnown(),
// len(ret.Current.ChildReflect),
// len(Child.ChildReflect),
// )
// if Child.IsKnown() {
// refs = append(refs, Child)
// continue
// }
// refs = append(refs, Child)
// }
//
// if len(refs) > 0 {
// ret.AddRow(refs...)
// }
// break
// }
//
// _, _ = fmt.Fprintf(os.Stderr,"GetTableArray(%s) - ARRAY\n", name)
// for row, Child := range ret.Current.ChildReflect {
// if sm.Debug {
// _, _ = fmt.Fprintf(os.Stderr,"GetTableArray() Child[%d]: %s\n", row, Child)
// }
// if Child.IsPointIgnore() {
// continue
// }
//
// fmt.Printf("[%s]SLICE - Current:%d / Child:%d\n", Child.FieldPath,
// len(ret.Current.ChildReflect),
// len(Child.ChildReflect),
// )
//
// var refs []*Reflect
// for _, ChildStruct := range Child.ChildReflect {
// if ChildStruct.IsPointIgnore() {
// continue
// }
//
// if ret.Current.DataStructure.DataTableSortOn != "" {
// // fmt.Printf("\tChildStruct> %s / %s\n", ChildStruct.FieldName, dt.Reflect.DataStructure.DataTableSortOn)
// if ret.Current.DataStructure.DataTableSortOn == ChildStruct.FieldName {
// ret.SortOn = ChildStruct.DataStructure.PointName
// // dt.Reflect.DataStructure.DataTableSortOn = ""
// }
// }
//
// fmt.Printf("[%s]STRUCT - Known:%t Current:%d / Child:%d / ChildStruct:%d\n", Child.FieldPath,
// Child.IsKnown(),
// len(ret.Current.ChildReflect),
// len(Child.ChildReflect),
// len(ChildStruct.ChildReflect),
// )
// if ChildStruct.IsKnown() {
// refs = append(refs, ChildStruct)
// continue
// }
//
// refs = append(refs, ChildStruct)
// }
//
// if len(refs) > 0 {
// ret.AddRow(refs...)
// }
// break
// }
// }
//
// return ret
// }
// func (sm *StructMap) SaveGoStructOptions(Child *Reflect) bool {
// var yes bool

View File

@ -53,6 +53,7 @@ type DateTime struct {
string `json:"string,omitempty"`
time.Time `json:"time,omitempty"`
DateType string
format string
Error error `json:"-"`
}
@ -80,6 +81,7 @@ func (dt *DateTime) UnmarshalJSON(data []byte) error {
for _, f := range inputDateLayout {
dt.Time, dt.Error = time.Parse(f, string(data))
if dt.Error == nil {
dt.format = f
dt.string = dt.Time.Format(DateTimeLayout)
dt.SetDateType(string(data))
break
@ -101,7 +103,8 @@ func (dt DateTime) MarshalJSON() ([]byte, error) {
for range Only.Once {
// data = []byte("\"" + dt.Time.Format(DateTimeLayout) + "\"")
// data = []byte("\"" + dt.string + "\"")
data = []byte("\"" + dt.Original() + "\"")
// data = []byte("\"" + dt.Original() + "\"")
data = []byte("\"" + dt.Time.Format(dt.format) + "\"")
}
return data, dt.Error
@ -143,6 +146,7 @@ func (dt *DateTime) SetString(value string) DateTime {
for _, f := range inputDateLayout {
dt.Time, dt.Error = time.Parse(f, value)
if dt.Error == nil {
dt.format = f
dt.string = dt.Time.Format(f)
dt.SetDateType(value)
break
@ -167,6 +171,7 @@ func (dt *DateTime) SetValue(value time.Time) DateTime {
}
dt.string = value.Format(DateTimeLayout)
dt.format = DateTimeLayout
dt.DateType = "3"
}
@ -251,6 +256,7 @@ func NewDateTime(value string) DateTime {
for _, f := range inputDateLayout {
ret.Time, ret.Error = time.Parse(f, value)
if ret.Error == nil {
ret.format = f
ret.SetValue(ret.Time)
ret.SetDateType(value)
break

View File

@ -114,6 +114,10 @@ func (t *Float) SetValue(value float64) Float {
return *t
}
func (t *Float) ToUnitValue() UnitValue {
return SetUnitValueFloat(t.float64, "", "")
}
func SetFloatString(value string) Float {
var t Float
return t.SetString(value)

View File

@ -113,6 +113,10 @@ func (t *Integer) SetValue(value int64) Integer {
return *t
}
func (t *Integer) ToUnitValue() UnitValue {
return SetUnitValueInteger(t.int64, "", "")
}
func SetIntegerString(value string) Integer {
var t Integer
return t.SetString(value)
@ -229,6 +233,10 @@ func (t *Count) SetValue(value int64) Count {
return *t
}
func (t *Count) ToUnitValue() UnitValue {
return SetUnitValueInteger(t.int64, "--", "Count")
}
func SetCountString(value string) Count {
var t Count
return t.SetString(value)

View File

@ -52,68 +52,85 @@ func IsUnknownStruct(ref interface{}) bool {
// fmt.Printf("fieldTo.Kind().String(): %s\n", fieldTo.Kind().String())
kindy := fieldVo.Kind()
// fmt.Printf("DEBUYg: K:%s / T:%v\n", kindy.String(), fieldVo)
// fmt.Printf("DEBUG: K:%s / T:%v\n", kindy.String(), fieldVo)
if kindy == reflect.Interface {
ok = false
break
}
if kindy == reflect.Slice {
// if fieldVo.Len() > 0 {
// ok = IsUnknownStruct(fieldVo.Index(0).Interface())
// }
ok = true
if fieldVo.Len() > 0 {
fieldVo = reflect.ValueOf(fieldVo.Index(0).Interface())
ok = IsTypeUnknown(fieldVo)
}
// ok = true
break
}
if kindy == reflect.Array {
// if fieldVo.Len() > 0 {
// ok = IsUnknownStruct(fieldVo.Index(0).Interface())
// }
ok = true
if fieldVo.Len() > 0 {
fieldVo = reflect.ValueOf(fieldVo.Index(0).Interface())
ok = IsTypeUnknown(fieldVo)
}
// ok = true
break
}
if kindy == reflect.Map {
// mk := fieldVo.MapKeys()
// if len(mk) > 0 {
// ok = IsUnknownStruct(fieldVo.MapIndex(mk[0]).Interface())
// }
ok = true
mk := fieldVo.MapKeys()
if len(mk) > 0 {
// ok = IsUnknownStruct(fieldVo.MapIndex(mk[0]).Interface())
fieldVo = reflect.ValueOf(fieldVo.MapIndex(mk[0]).Interface())
ok = IsTypeUnknown(fieldVo)
}
break
}
if kindy == reflect.Struct {
Type := fieldVo.Type().String()
Type = strings.ReplaceAll(Type, "valueTypes.", "")
switch Type {
case TypeBool:
case TypeCount:
case TypeDateTime:
case TypeFloat:
case TypeInteger:
case TypePointId:
case TypePsId:
case TypePsKey:
case TypeString:
case TypeTime:
case TypeUnitValue:
case TypeArrayBool:
case TypeArrayCount:
case TypeArrayDateTime:
case TypeArrayFloat:
case TypeArrayInteger:
case TypeArrayPointId:
case TypeArrayPsId:
case TypeArrayPsKey:
case TypeArrayString:
case TypeArrayTime:
case TypeArrayUnitValue:
case TypeUnitValues:
ok = IsTypeUnknown(fieldVo)
}
}
default:
ok = true
}
return ok
}
func IsKnownStruct(ref interface{}) bool {
return !IsUnknownStruct(ref)
}
func IsTypeUnknown(fieldVo reflect.Value) bool {
var ok bool
for range Only.Once {
Type := fieldVo.Type().String()
Type = strings.ReplaceAll(Type, "valueTypes.", "")
switch Type {
case TypeBool:
case TypeCount:
case TypeDateTime:
case TypeFloat:
case TypeInteger:
case TypePointId:
case TypePsId:
case TypePsKey:
case TypeString:
case TypeTime:
case TypeUnitValue:
case TypeArrayBool:
case TypeArrayCount:
case TypeArrayDateTime:
case TypeArrayFloat:
case TypeArrayInteger:
case TypeArrayPointId:
case TypeArrayPsId:
case TypeArrayPsKey:
case TypeArrayString:
case TypeArrayTime:
case TypeArrayUnitValue:
case TypeUnitValues:
default:
ok = true
}
}
@ -229,18 +246,20 @@ func ArrayLength(i interface{}) int {
return reflect.ValueOf(i).Len()
}
func SizeOfArrayLength(i interface{}) int {
return SizeOfInt(reflect.ValueOf(i).Len())
func SizeOfArrayLength(ref interface{}) int {
ValueOf := reflect.ValueOf(ref)
Len := ValueOf.Len()
return SizeOfInt(Len)
}
func AnyToUnitValue(ref interface{}, unit string, typeString string, dateFormat string) (UnitValues, bool, bool) {
var uv UnitValues
func AnyToUnitValue(ref interface{}, key string, unit string, typeString string, dateFormat string) (UnitValues, bool, bool) {
var uvs UnitValues
ok := true
isNil := false
for range Only.Once {
if IsNil(ref) {
// fmt.Println("DEBUG: AnyToUnitValue(): NIL")
uv = append(uv, SetUnitValueString("", unit, typeString + "(unknown)"))
uvs.AddString("", key, unit, typeString + "(unknown)")
isNil = true
break
}
@ -250,231 +269,186 @@ func AnyToUnitValue(ref interface{}, unit string, typeString string, dateFormat
dateFormat = DateTimeAltLayout
}
ValueOf := reflect.ValueOf(ref)
Kind := ValueOf.Kind()
if IsKnownStruct(ref) {
if Kind == reflect.Map {
for _, mk := range ValueOf.MapKeys() {
var uv UnitValues
// fmt.Printf("Map[%s]\n", key)
val := ValueOf.MapIndex(mk).Interface()
uv, isNil, ok = AnyToUnitValue(val, mk.String(), unit, typeString, dateFormat) // uvs.AddUnitValue(ref.(UnitValue))
uvs.Append(uv)
}
break
}
if Kind == reflect.Slice || Kind == reflect.Array {
for index := 0; index < ValueOf.Len(); index++ {
var uv UnitValues
// fmt.Printf("Slice[%d]\n", index)
val := ValueOf.Index(index).Interface()
uv, isNil, ok = AnyToUnitValue(val, key, unit, typeString, dateFormat)
uvs.Append(uv)
}
break
}
}
Type := reflect.TypeOf(ref).String()
Type = strings.ReplaceAll(Type, "valueTypes.", "")
if typeString == "" {
typeString = Type
}
switch Type {
case "int":
if typeString == "" {
typeString = "--"
}
uv = append(uv, SetUnitValueInteger(int64(ref.(int)), unit, typeString))
uvs.AddInteger(int64(ref.(int)), key, unit, typeString)
case "int32":
if typeString == "" {
typeString = "--"
}
uv = append(uv, SetUnitValueInteger(int64(ref.(int32)), unit, typeString))
uvs.AddInteger(int64(ref.(int32)), key, unit, typeString)
case "int64":
if typeString == "" {
typeString = "--"
}
uv = append(uv, SetUnitValueInteger(ref.(int64), unit, typeString))
uvs.AddInteger(ref.(int64), key, unit, typeString)
case "float32":
if typeString == "" {
typeString = "--"
}
uv = append(uv, SetUnitValueFloat(float64(ref.(float32)), unit, typeString))
uvs.AddFloat(float64(ref.(float32)), key, unit, typeString)
case "float64":
if typeString == "" {
typeString = "--"
}
uv = append(uv, SetUnitValueFloat(ref.(float64), unit, typeString))
uvs.AddFloat(ref.(float64), key, unit, typeString)
case "string":
if typeString == "" {
typeString = "--"
}
uv = append(uv, SetUnitValueString(ref.(string), unit, typeString))
uvs.AddString(ref.(string), key, unit, typeString)
case "[]string":
// v := strings.Join(e.([]string), ",")
if typeString == "" {
typeString = "--"
}
j, err := json.Marshal(ref.([]string))
if err != nil {
j = []byte(fmt.Sprintf("%v", ref.([]string)))
}
uv = append(uv, SetUnitValueString(string(j), unit, typeString))
// j, err := json.Marshal(ref.([]string))
// if err != nil {
// j = []byte(fmt.Sprintf("%v", ref.([]string)))
// }
uvs.AddStrings(ref.([]string), key, unit, typeString)
case "bool":
if typeString == "" {
typeString = "--"
}
uv = append(uv, SetUnitValueBool(ref.(bool)))
uvs.AddBool(ref.(bool), key)
case TypeUnitValue:
if typeString == "" {
typeString = "--"
}
uv = append(uv, ref.(UnitValue))
// uv = uv.UnitValueFix()
val := ref.(UnitValue)
val.SetKey(key)
uvs.AddUnitValue(val)
case TypeUnitValues:
fallthrough
case TypeArrayUnitValue:
for _, val := range ref.(UnitValues) {
uv = append(uv, val)
vals := ref.(UnitValues)
for _, val := range vals.values {
val.SetKey(key)
}
uvs.Append(vals)
case TypeFloat:
if typeString == "" {
typeString = TypeFloat
}
v := ref.(Float)
uv = append(uv, SetUnitValueFloat(v.Value(), unit, typeString))
uvs.AddFloat(v.Value(), key, unit, typeString)
case TypeArrayFloat:
if typeString == "" {
typeString = TypeFloat
}
v := ref.([]Float)
for _, val := range v {
uv = append(uv, SetUnitValueFloat(val.Value(), unit, typeString))
uvs.AddFloat(val.Value(), key, unit, typeString)
}
case TypeInteger:
if typeString == "" {
typeString = TypeInteger
}
v := ref.(Integer)
uv = append(uv, SetUnitValueInteger(v.Value(), unit, typeString))
uvs.AddInteger(v.Value(), key, unit, typeString)
case TypeArrayInteger:
if typeString == "" {
typeString = TypeInteger
}
v := ref.([]Integer)
for _, val := range v {
uv = append(uv, SetUnitValueInteger(val.Value(), unit, typeString))
uvs.AddInteger(val.Value(), key, unit, typeString)
}
// HERE IS THE PROBLEM - need to return SOMETHING, even if it's null!
case TypeCount:
if typeString == "" {
typeString = TypeCount
}
v := ref.(Count)
uv = append(uv, SetUnitValueInteger(v.Value(), unit, typeString))
uvs.AddInteger(v.Value(), key, unit, typeString)
case TypeArrayCount:
if typeString == "" {
typeString = TypeCount
}
v := ref.([]Count)
for _, val := range v {
uv = append(uv, SetUnitValueInteger(val.Value(), unit, typeString))
uvs.AddInteger(val.Value(), key, unit, typeString)
}
case TypeBool:
if typeString == "" {
typeString = TypeBool
}
v := ref.(Bool)
uv = append(uv, SetUnitValueBool(v.Value()))
uvs.AddBool(v.Value(), key)
case TypeArrayBool:
if typeString == "" {
typeString = TypeBool
}
v := ref.([]Bool)
for _, val := range v {
uv = append(uv, SetUnitValueBool(val.Value()))
uvs.AddBool(val.Value(), key)
}
case TypeString:
if typeString == "" {
typeString = TypeString
}
v := ref.(String)
uv = append(uv, SetUnitValueString(v.String(), unit, typeString))
uvs.AddString(v.String(), key, unit, typeString)
case TypeArrayString:
if typeString == "" {
typeString = TypeString
}
v := ref.([]String)
for _, val := range v {
uv = append(uv, SetUnitValueString(val.Value(), unit, typeString))
uvs.AddString(val.String(), key, unit, typeString)
}
case TypePsId:
if typeString == "" {
typeString = TypePsId
}
v := ref.(PsId)
uv = append(uv, SetUnitValueString(v.String(), unit, typeString))
uvs.AddString(v.String(), key, unit, typeString)
case TypeArrayPsId:
if typeString == "" {
typeString = TypePsId
}
v := ref.([]PsId)
for _, val := range v {
uv = append(uv, SetUnitValueString(val.String(), unit, typeString))
uvs.AddString(val.String(), key, unit, typeString)
}
case TypePsKey:
if typeString == "" {
typeString = TypePsKey
}
v := ref.(PsKey)
uv = append(uv, SetUnitValueString(v.Value(), unit, typeString))
uvs.AddString(v.String(), key, unit, typeString)
case TypeArrayPsKey:
if typeString == "" {
typeString = TypePsKey
}
v := ref.([]PsKey)
for _, val := range v {
uv = append(uv, SetUnitValueString(val.Value(), unit, typeString))
uvs.AddString(val.String(), key, unit, typeString)
}
case TypePointId:
if typeString == "" {
typeString = TypePointId
}
v := ref.(PointId)
uv = append(uv, SetUnitValueString(v.String(), unit, typeString))
uvs.AddString(v.String(), key, unit, typeString)
case TypeArrayPointId:
if typeString == "" {
typeString = TypePointId
}
v := ref.([]PointId)
for _, val := range v {
uv = append(uv, SetUnitValueString(val.String(), unit, typeString))
uvs.AddString(val.String(), key, unit, typeString)
}
case TypeDateTime:
if typeString == "" {
typeString = TypeDateTime
}
v := ref.(DateTime)
uv = append(uv, SetUnitValueString(v.Format(dateFormat), unit, typeString))
uvs.AddString(v.Format(dateFormat), key, unit, typeString)
case TypeArrayDateTime:
if typeString == "" {
typeString = TypeDateTime
}
v := ref.([]DateTime)
for _, val := range v {
uv = append(uv, SetUnitValueString(val.Format(dateFormat), unit, typeString))
uvs.AddString(val.Format(dateFormat), key, unit, typeString)
}
case TypeTime:
if typeString == "" {
typeString = TypeTime
}
v := ref.(Time)
uv = append(uv, SetUnitValueString(v.Format(TimeLayout), unit, typeString))
uvs.AddString(v.Format(TimeLayout), key, unit, typeString)
case TypeArrayTime:
if typeString == "" {
typeString = TypeTime
}
v := ref.([]Time)
for _, val := range v {
uv = append(uv, SetUnitValueString(val.Format(TimeLayout), unit, typeString))
uvs.AddString(val.Format(TimeLayout), key, unit, typeString)
}
default:
typeString = ""
j, err := json.Marshal(ref)
if err != nil {
j = []byte(typeString + "(unknown)")
j = []byte(Type + "(unknown)")
}
uv = append(uv, SetUnitValueString(string(j), unit, typeString))
uvs.AddString(string(j), key, unit, typeString)
ok = false
}
}
return uv, isNil, ok
return uvs, isNil, ok
}
func AnyToValueString(ref interface{}, intSize int, dateFormat string) string {

View File

@ -292,7 +292,15 @@ func (t *UnitValue) ValueBool() bool {
}
func (t *UnitValue) ValueKey() string {
return t.key
switch {
case t.key != "":
return t.key
case t.UnitValue != "":
return t.UnitValue
case t.TypeValue != "":
return t.TypeValue
}
return "nokey"
}
func (t UnitValue) String() string {
@ -311,9 +319,9 @@ func (t UnitValue) String() string {
ret = t.StringValue
}
if t.key != "" {
ret = fmt.Sprintf(`"%s": "%s"`, t.key, ret)
}
// if t.key != "" {
// ret = fmt.Sprintf(`"%s": "%s"`, t.key, ret)
// }
}
return ret
}
@ -569,66 +577,254 @@ func (u *UnitValueMap) Sort() []string {
}
type UnitValues []UnitValue
type UnitValues struct {
// array []UnitValue // We're just saving everything as a map.
values map[string]UnitValue
order []*UnitValue
UnitValue string `json:"unit"`
TypeValue string `json:"type_value"`
}
func (t UnitValues) String() string {
var ret string
for range Only.Once {
if len(t) == 0 {
for k, v := range t.values {
ret += fmt.Sprintf("%s: %s\n", k, v.String())
}
}
return ret
}
func (t UnitValues) firstKey() string {
var ret string
for range Only.Once {
if len(t.values) == 0 {
break
}
if len(t) == 1 {
ret = t[0].String()
for k := range t.values {
ret = k
break
}
for i, v := range t {
ret += fmt.Sprintf("%d: %s\n", i, v.String())
}
}
return ret
}
func (t *UnitValues) Unit() string {
var ret string
for _, v := range *t {
ret = v.Unit()
break
for _, v := range t.values {
return v.Unit()
}
return ""
}
func (t *UnitValues) Map() map[string]UnitValue {
return t.values
}
const SortOrder = false
const LoadOrder = true
func (t *UnitValues) Range(loadOrder bool) []UnitValue {
var ret []UnitValue
for range Only.Once {
var keys []string
if loadOrder {
for _, k := range t.order {
ret = append(ret, *k)
}
break
}
for k := range t.values {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
ret = append(ret, t.values[k])
}
}
return ret
}
func (t *UnitValues) Keys() []string {
var ret []string
for key, v := range t.values {
if v.key != "" {
key = v.key
}
ret = append(ret, key)
}
return ret
}
func (t *UnitValues) KeysSorted() []string {
ret := t.Keys()
sort.Strings(ret)
return ret
}
func (t *UnitValues) Type() string {
var ret string
for _, v := range *t {
ret = v.Type()
break
for _, v := range t.values {
return v.Type()
}
return ret
return ""
}
func (t *UnitValues) SetUnit(unit string) *UnitValue {
return &(*t)[0]
}
// func (t *UnitValues) SetKey(key string) *UnitValues {
// for i := range t.values {
// t.values[i].SetKey(key)
// }
// return t
// }
func (t *UnitValues) First() *UnitValue {
if len(*t) == 0 {
return &UnitValue{}
func (t *UnitValues) SetType(Type string) *UnitValues {
t.TypeValue = Type
for i := range t.values {
uv := t.values[i]
uv.SetType(Type)
}
return &(*t)[0]
}
func (t *UnitValues) Set(uv UnitValue) *UnitValues {
*t = UnitValues{uv}
return t
}
func (t *UnitValues) Append(uv UnitValue) *UnitValues {
*t = append(*t, uv)
func (t *UnitValues) SetUnit(unit string) *UnitValues {
t.UnitValue = unit
for i := range t.values {
uv := t.values[i]
uv.SetUnit(unit)
}
return t
}
func (t *UnitValues) First() *UnitValue {
if len(t.order) == 0 {
return &UnitValue{}
}
return t.order[0]
}
func (t *UnitValues) Last() *UnitValue {
if len(t.order) == 0 {
return &UnitValue{}
}
last := len(t.values) - 1
return t.order[last]
}
func (t *UnitValues) nextKey() string {
return strconv.Itoa(len(t.values))
}
// add - Simulate an array, but we're storing everything as a map.
// Makes it easier to code, not having to deal with either array or map.
func (t *UnitValues) add(value UnitValue) *UnitValues {
key := value.key
if key == "" {
key = t.nextKey()
}
t.order = append(t.order, &value) // Keep track of the order.
if t.values == nil {
t.values = make(map[string]UnitValue)
}
t.values[key] = value
return t
}
func (t *UnitValues) Append(uvs ...UnitValues) *UnitValues {
for _, uv := range uvs {
for key, v := range uv.values {
v.key = key
t.add(v)
// if key == "" {
// key = t.nextKey()
// }
// t.values[key] = v
}
}
return t
}
func (t *UnitValues) AddUnitValue(value UnitValue) *UnitValues {
return t.add(value)
}
func (t *UnitValues) Set(value string, key string, unit string, Type string) *UnitValues {
uv := SetUnitValueString(value, unit, Type)
uv.SetKey(key)
t.values = make(map[string]UnitValue)
t.order = []*UnitValue{}
t.UnitValue = unit
t.TypeValue = Type
return t.add(uv)
}
func (t *UnitValues) AddString(value string, key string, unit string, Type string) *UnitValues {
uv := SetUnitValueString(value, unit, Type)
uv.SetKey(key)
return t.add(uv)
}
func (t *UnitValues) AddBool(value bool, key string) *UnitValues {
uv := SetUnitValueBool(value)
uv.SetKey(key)
return t.add(uv)
}
func (t *UnitValues) AddFloat(value float64, key string, unit string, Type string) *UnitValues {
uv := SetUnitValueFloat(value, unit, Type)
uv.SetKey(key)
return t.add(uv)
}
func (t *UnitValues) AddInteger(value int64, key string, unit string, Type string) *UnitValues {
uv := SetUnitValueInteger(value, unit, Type)
uv.SetKey(key)
return t.add(uv)
}
func (t *UnitValues) AddStrings(value []string, key string, unit string, Type string) *UnitValues {
for _, v := range value {
uv := SetUnitValueString(v, unit, Type)
uv.SetKey(key)
t.add(uv)
}
return t
}
func (t *UnitValues) AddBools(value []bool, key string) *UnitValues {
for _, v := range value {
uv := SetUnitValueBool(v)
uv.SetKey(key)
t.add(uv)
}
return t
}
func (t *UnitValues) AddFloats(value []float64, key string, unit string, Type string) *UnitValues {
for _, v := range value {
uv := SetUnitValueFloat(v, unit, Type)
uv.SetKey(key)
t.add(uv)
}
return t
}
func (t *UnitValues) AddIntegers(value []int64, key string, unit string, Type string) *UnitValues {
for _, v := range value {
uv := SetUnitValueInteger(v, unit, Type)
uv.SetKey(key)
t.add(uv)
}
return t
}
func (t *UnitValues) Length() int {
return len(*t)
return len(t.values)
}

View File

@ -0,0 +1,899 @@
package valueTypes
import (
"encoding/json"
"fmt"
"github.com/MickMake/GoUnify/Only"
"sort"
"strconv"
"strings"
)
type UnitValue struct {
UnitValue string `json:"unit"` // Primary iSolarCloud entity.
StringValue string `json:"value"` // Primary iSolarCloud entity.
TypeValue string `json:"type_value"`
*float64 `json:"value_float,omitempty"`
*int64 `json:"value_int,omitempty"`
*bool `json:"value_bool,omitempty"`
key string
deviceId string
Valid bool `json:"valid"`
Error error `json:"-"`
}
var zero = int64(0)
func (t *UnitValue) UnitValueFix() UnitValue {
switch t.UnitValue {
case "w":
t.UnitValue = "W"
}
switch t.UnitValue {
case "g":
fallthrough
case "Wp":
fallthrough
case "Wh":
fallthrough
case "W":
if t.float64 == nil {
// Only if we have a float.
break
}
fv := t.Value() / 1000
t.SetFloat(fv)
t.SetUnit("k" + t.UnitValue)
// fv, dt.Error := strconv.ParseFloat(value, 64)
// if dt.Error == nil {
// fv = fv / 1000
// value, _ = DivideByThousand(value)
// UnitValue = "k" + UnitValue
// }
}
return *t
}
func UnitValueType(unit string) string {
var ret string
switch unit {
case "Wh":
fallthrough
case "kWh":
fallthrough
case "MWh":
ret = "Energy"
case "kWp":
fallthrough
case "W":
fallthrough
case "kW":
fallthrough
case "MW":
ret = "Power"
case "AUD":
ret = "Currency"
case "g":
fallthrough
case "kg":
ret = "Weight"
case "mV":
fallthrough
case "V":
ret = "Voltage"
case "mA":
fallthrough
case "A":
ret = "Current"
case "Hz":
ret = "Frequency"
case "kvar":
ret = "Reactive Power"
case "Ω":
fallthrough
case "kΩ":
ret = "Resistance"
case "%":
ret = "Percent"
case "F":
fallthrough
case "°F":
fallthrough
case "℉":
fallthrough
case "C":
fallthrough
case "°C":
fallthrough
case "℃":
ret = "Temperature"
}
return ret
}
// UnmarshalJSON - Convert JSON to value
func (t *UnitValue) UnmarshalJSON(data []byte) error {
for range Only.Once {
t.Valid = false
if len(data) == 0 {
break
}
var resString struct {
Unit string `json:"unit"`
Value string `json:"value"`
}
// Store result from JSON string
t.Error = json.Unmarshal(data, &resString)
if t.Error == nil {
t.SetString(resString.Value)
t.SetUnit(resString.Unit)
t.UnitValueFix()
break
}
var resInteger struct {
Unit string `json:"unit"`
Value int64 `json:"value"`
}
// Store result from JSON string
t.Error = json.Unmarshal(data, &resInteger)
if t.Error == nil {
t.SetInteger(resInteger.Value)
t.SetUnit(resInteger.Unit)
t.UnitValueFix()
break
}
var resFloat struct {
Unit string `json:"unit"`
Value float64 `json:"value"`
}
// Store result from JSON string
t.Error = json.Unmarshal(data, &resFloat)
if t.Error == nil {
t.SetFloat(resFloat.Value)
t.SetUnit(resFloat.Unit)
t.UnitValueFix()
break
}
t.Error = nil
}
return t.Error
}
// MarshalJSON - Convert value to JSON
func (t UnitValue) MarshalJSON() ([]byte, error) {
var data []byte
for range Only.Once {
t.Valid = false
if t.float64 != nil {
// Store result to JSON string
data, t.Error = json.Marshal(&struct {
Unit string `json:"unit"`
Value float64 `json:"value"`
}{
Unit: t.UnitValue,
Value: *t.float64,
})
if t.Error != nil {
break
}
t.Valid = true
break
}
if t.int64 != nil {
// Store result to JSON string
data, t.Error = json.Marshal(&struct {
Unit string `json:"unit"`
Value int64 `json:"value"`
}{
Unit: t.UnitValue,
Value: *t.int64,
})
if t.Error != nil {
break
}
}
if t.bool != nil {
// Store result to JSON string
data, t.Error = json.Marshal(&struct {
Unit string `json:"unit"`
Value bool `json:"value"`
}{
Unit: t.UnitValue,
Value: *t.bool,
})
if t.Error != nil {
break
}
}
// t = t.UnitValueFix()
data = []byte(fmt.Sprintf(`{"unit":"%s","value":"--","key":"%s"}`, t.UnitValue, t.key))
t.Error = nil
t.Valid = true
}
return data, t.Error
}
func (t *UnitValue) Value() float64 {
var ret float64
for range Only.Once {
if t.float64 != nil {
ret = *t.float64
break
}
if t.int64 != nil {
ret = float64(*t.int64)
break
}
if t.bool != nil {
if *t.bool {
ret = 1
break
}
ret = 0
break
}
}
return ret
}
func (t *UnitValue) ValueFloat() float64 {
if t.float64 == nil {
return 0
}
return *t.float64
}
func (t *UnitValue) ValueInt() int64 {
if t.int64 == nil {
return 0
}
return *t.int64
}
func (t *UnitValue) ValueBool() bool {
if t.float64 == nil {
return false
}
return *t.bool
}
func (t *UnitValue) ValueKey() string {
return t.key
}
func (t UnitValue) String() string {
var ret string
for range Only.Once {
switch {
case t.float64 != nil:
ret = strconv.FormatFloat(*t.float64, 'f', -1, 64)
case t.int64 != nil:
ret = strconv.FormatInt(*t.int64, 10)
case t.bool != nil:
ret = strconv.FormatBool(*t.bool)
default:
ret = t.StringValue
}
// if t.key != "" {
// ret = fmt.Sprintf(`"%s": "%s"`, t.key, ret)
// }
}
return ret
}
func (t *UnitValue) MatchFloat(comp float64) bool {
if t.float64 == nil {
return false
}
if *t.float64 == comp {
return true
}
return false
}
func (t *UnitValue) MatchInt(comp int64) bool {
if t.int64 == nil {
return false
}
if *t.int64 == comp {
return true
}
return false
}
func (t *UnitValue) MatchBool(comp bool) bool {
if t.bool == nil {
return false
}
if *t.bool == comp {
return true
}
return false
}
func (t *UnitValue) Unit() string {
return t.UnitValue
}
func (t *UnitValue) Type() string {
return t.TypeValue
}
func (t *UnitValue) DeviceId() string {
return t.deviceId
}
var varTrue = true
var varFalse = false
func (t *UnitValue) SetString(value string) UnitValue {
for range Only.Once {
t.StringValue = value
t.float64 = nil
t.int64 = nil
t.bool = nil
t.Valid = false
if value == "" {
break
}
if value == "--" {
// value = ""
break
}
if value == "true" {
t.SetBool(true)
break
}
if value == "false" {
t.SetBool(false)
break
}
if strings.Contains(value, ".") {
var v float64
v, t.Error = strconv.ParseFloat(t.StringValue, 64)
if t.Error != nil {
t.Error = nil // Less than useful.
break
}
t.SetFloat(v)
break
}
var v int
v, t.Error = strconv.Atoi(t.StringValue)
if t.Error != nil {
t.Error = nil // Less than useful.
break
}
t.SetInteger(int64(v))
}
return *t
}
func (t *UnitValue) SetInteger(value int64) UnitValue {
for range Only.Once {
t.int64 = &value
// fv := float64(value); t.float64 = &fv
t.float64 = nil
t.bool = nil
t.Valid = true
t.StringValue = strconv.FormatInt(*t.int64, 10)
}
return *t
}
func (t *UnitValue) SetFloat(value float64) UnitValue {
for range Only.Once {
// iv := int64(value)
// t.int64 = &iv
t.int64 = nil
t.float64 = &value
t.bool = nil
t.Valid = true
// t.String = strconv.FormatFloat(t.float64, 'f', 12, 64)
// t.String = strings.TrimRight(t.String, "0")
t.StringValue = strconv.FormatFloat(*t.float64, 'f', -1, 64)
}
return *t
}
func (t *UnitValue) SetBool(value bool) UnitValue {
for range Only.Once {
t.Valid = true
t.float64 = nil
t.int64 = nil
t.bool = &value
t.StringValue = strconv.FormatBool(value)
}
return *t
}
func (t *UnitValue) SetBoolString(value string) UnitValue {
for range Only.Once {
t.Valid = true
t.float64 = nil
t.int64 = nil
// t.StringValue = strconv.FormatBool(value)
switch strings.ToLower(value) {
case "false":
fallthrough
case "no":
fallthrough
case "off":
fallthrough
case "0":
fallthrough
case "":
// fallthrough
// case "--":
t.bool = &varFalse
t.StringValue = "false"
t.Valid = true
case "true":
fallthrough
case "yes":
fallthrough
case "on":
fallthrough
case "1":
t.bool = &varTrue
t.StringValue = "true"
t.Valid = true
}
}
return *t
}
func (t *UnitValue) SetUnit(unit string) UnitValue {
for range Only.Once {
t.UnitValue = unit
t.TypeValue = UnitValueType(unit)
}
return *t
}
func (t *UnitValue) SetType(Type string) UnitValue {
for range Only.Once {
t.TypeValue = Type
}
return *t
}
func (t *UnitValue) SetDeviceId(deviceId string) UnitValue {
for range Only.Once {
t.deviceId = deviceId
}
return *t
}
func (t *UnitValue) SetKey(key string) UnitValue {
for range Only.Once {
t.key = key
}
return *t
}
func SetUnitValueString(value string, unit string, Type string) UnitValue {
var t UnitValue
t = t.SetString(value)
t = t.SetUnit(unit)
t = t.SetType(Type)
return t.UnitValueFix()
}
func SetUnitValueInteger(value int64, unit string, Type string) UnitValue {
var t UnitValue
t = t.SetInteger(value)
t = t.SetUnit(unit)
t = t.SetType(Type)
return t.UnitValueFix()
}
func SetUnitValueFloat(value float64, unit string, Type string) UnitValue {
var t UnitValue
t = t.SetFloat(value)
t = t.SetUnit(unit)
t = t.SetType(Type)
return t.UnitValueFix()
}
func SetUnitValueBool(value bool) UnitValue {
var t UnitValue
t = t.SetBool(value)
t = t.SetUnit("")
t = t.SetType("Bool")
return t
}
type UnitValueMap map[PointId]UnitValue
func (u *UnitValueMap) Sort() []string {
var ret []string
for n := range *u {
ret = append(ret, n.String())
}
sort.Strings(ret)
return ret
}
type UnitValues struct {
// array []UnitValue // We're just saving everything as a map.
values map[string]UnitValue
UnitValue string `json:"unit"`
TypeValue string `json:"type_value"`
}
func (t UnitValues) String() string {
var ret string
for range Only.Once {
if len(t.array) > 0 {
if len(t.array) == 1 {
ret = t.array[0].String()
break
}
for i, v := range t.array {
ret += fmt.Sprintf("%d: %s\n", i, v.String())
}
break
}
if len(t.values) > 0 {
for k, v := range t.values {
ret += fmt.Sprintf("%s: %s\n", k, v.String())
}
}
}
return ret
}
func (t UnitValues) firstKey() string {
var ret string
for range Only.Once {
if len(t.values) == 0 {
break
}
for k := range t.values {
ret = k
break
}
}
return ret
}
func (t *UnitValues) Unit() string {
for _, v := range t.array {
return v.Unit()
}
for _, v := range t.values {
return v.Unit()
}
return ""
}
func (t *UnitValues) Range() map[string]UnitValue {
ret := make(map[string]UnitValue)
for i, v := range t.array {
key := strconv.Itoa(i)
if v.key != "" {
key = v.key
}
ret[key] = v
}
for key, v := range t.values {
if v.key != "" {
key = v.key
}
ret[key] = v
}
return ret
}
func (t *UnitValues) RangeSorted() []UnitValue {
var ret []UnitValue
rm := t.Range()
var keys []string
for k := range rm {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
ret = append(ret, rm[k])
}
return ret
}
func (t *UnitValues) Keys() []string {
var ret []string
for i, v := range t.array {
key := strconv.Itoa(i)
if v.key != "" {
key = v.key
}
ret = append(ret, key)
}
for key, v := range t.values {
if v.key != "" {
key = v.key
}
ret = append(ret, key)
}
return ret
}
func (t *UnitValues) KeysSorted() []string {
ret := t.Keys()
sort.Strings(ret)
return ret
}
func (t *UnitValues) RangeArray() []UnitValue {
return t.array
}
func (t *UnitValues) RangeMap() map[string]UnitValue {
return t.values
}
func (t *UnitValues) Type() string {
for _, v := range t.array {
return v.Type()
}
for _, v := range t.values {
return v.Type()
}
return ""
}
func (t *UnitValues) SetKey(key string) *UnitValues {
for range Only.Once {
for i := range t.array {
t.array[i].SetKey(key)
}
for i := range t.values {
uv := t.values[i]
uv.SetKey(key)
}
}
return t
}
func (t *UnitValues) SetType(Type string) *UnitValues {
for range Only.Once {
t.TypeValue = Type
for i := range t.array {
t.array[i].SetType(Type)
}
for i := range t.values {
uv := t.values[i]
uv.SetType(Type)
}
}
return t
}
func (t *UnitValues) SetUnit(unit string) *UnitValues {
for range Only.Once {
t.UnitValue = unit
for i := range t.array {
t.array[i].SetUnit(unit)
}
for i := range t.values {
uv := t.values[i]
uv.SetUnit(unit)
}
}
return t
}
func (t *UnitValues) IsMap() bool {
if len(t.values) > 0 {
return true
}
return false
}
func (t *UnitValues) IsArray() bool {
if len(t.array) > 0 {
return true
}
return false
}
func (t *UnitValues) First() *UnitValue {
ret := &UnitValue{}
for range Only.Once {
if t.IsArray() {
ret = &(t.array[0])
break
}
if t.IsMap() {
// key := t.firstKey()
// if key == "" {
// break
// }
// *ret, _ = t.mapmap[key]
for _, v := range t.values {
ret = &v
break
}
}
}
return ret
}
func (t *UnitValues) Last() *UnitValue {
ret := &UnitValue{}
for range Only.Once {
if t.IsArray() {
ret = &(t.array)[len(t.array)-1]
break
}
if t.IsMap() {
for _, v := range t.values {
ret = &v
}
}
}
return ret
}
// func (t *UnitValues) Set(uv UnitValue) *UnitValues {
// *t = UnitValues{uv}
// return t
// }
func (t *UnitValues) Append(uvs ...UnitValues) *UnitValues {
for _, uv := range uvs {
t.array = append(t.array, uv.array...)
}
return t
}
func (t *UnitValues) MapAppend(uvs ...UnitValues) *UnitValues {
if t.values == nil {
t.values = make(map[string]UnitValue)
}
for _, uv := range uvs {
for k, v := range uv.values {
t.values[k] = v
}
for _, v := range uv.array {
t.values[v.key] = v
}
}
return t
}
func (t *UnitValues) AddUnitValue(value UnitValue) *UnitValues {
t.array = append(t.array, value)
return t
}
func (t *UnitValues) AddString(value string, unit string, Type string) *UnitValues {
t.array = append(t.array, SetUnitValueString(value, unit, Type))
return t
}
func (t *UnitValues) AddBool(value bool) *UnitValues {
t.array = append(t.array, SetUnitValueBool(value))
return t
}
func (t *UnitValues) AddFloat(value float64, unit string, Type string) *UnitValues {
t.array = append(t.array, SetUnitValueFloat(value, unit, Type))
return t
}
func (t *UnitValues) AddInteger(value int64, unit string, Type string) *UnitValues {
t.array = append(t.array, SetUnitValueInteger(value, unit, Type))
return t
}
func (t *UnitValues) AddStrings(value []string, unit string, Type string) *UnitValues {
for _, v := range value {
t.array = append(t.array, SetUnitValueString(v, unit, Type))
}
return t
}
func (t *UnitValues) AddBools(value []bool) *UnitValues {
for _, v := range value {
t.array = append(t.array, SetUnitValueBool(v))
}
return t
}
func (t *UnitValues) AddFloats(value []float64, unit string, Type string) *UnitValues {
for _, v := range value {
t.array = append(t.array, SetUnitValueFloat(v, unit, Type))
}
return t
}
func (t *UnitValues) AddIntegers(value []int64, unit string, Type string) *UnitValues {
for _, v := range value {
t.array = append(t.array, SetUnitValueInteger(v, unit, Type))
}
return t
}
func (t *UnitValues) Length() int {
var ret int
for range Only.Once {
if t.IsArray() {
ret = len(t.array)
break
}
if t.IsMap() {
ret = len(t.values)
}
}
return ret
}

View File

@ -96,12 +96,13 @@ func (dm *DataMap) CreateDataTables(sm GoStruct.StructMap) error {
continue
}
table := output.NewTable(td.GetHeaders()...)
values := td.GetValues()
headers := td.GetHeaders()
table := output.NewTable(headers...)
for row := range values {
var items []interface{}
for col := range values[row] {
items = append(items, values[row][col].String())
for _, col := range td.Columns {
items = append(items, values.GetCell(row, col))
}
dm.Error = table.AddRow(items...)
if dm.Error != nil {
@ -161,27 +162,58 @@ func (dm *DataMap) CreateResultTable(endpoint EndPoint, sm GoStruct.StructMap) e
if de.Hide {
continue
}
for _, value := range de.Current.Value {
v := value.String()
if de.Current.IsTable() {
v = "See table: " + de.Current.Name()
}
dm.Error = dm.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
}
if de.Current.DataStructure.DataTableChild {
continue
}
// 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 = dm.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
}
// values := de.Current.ValuesRange()
// for _, key := range de.Current.Value.KeysSorted() {
// value := values[key]
// v := value.String()
// if de.Current.IsTable() {
// v = "See table: " + de.Current.Name()
// }
// dm.Error = dm.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
// }
// }
}
}
@ -224,17 +256,14 @@ func (dm *DataMap) AddPointUnitValues(Current *GoStruct.Reflect, parentDeviceId
point.SetName(Current.DataStructure.PointName)
if Current.Value.Unit() != point.Unit {
fmt.Printf("OOOPS: Unit mismatch - %s %s != %f %s\n",
Current.Value.First().String(), point.Unit, Current.Value.First().ValueFloat(), Current.Value.Unit())
fmt.Printf("OOOPS: Unit mismatch - %s != %f %s\n", point.Unit, Current.Value.First().ValueFloat(), Current.Value.Unit())
point.Unit = Current.Value.Unit()
}
// Add arrays as multiple entries.
if Current.Value.Length() > 1 {
entries := CreatePointDataEntries(Current, parentDeviceId, point, date)
for _, de := range entries.Entries {
dm.Add(de)
}
dm.Add(entries.Entries...)
break
}
@ -335,25 +364,27 @@ func (dm *DataMap) AppendMap(add DataMap) {
}
}
func (dm *DataMap) Add(de DataEntry) {
func (dm *DataMap) Add(des ...DataEntry) {
for range Only.Once {
// fmt.Printf("DEBUG DataMap.Add() %s - Value(%s):'%s' Parent:'%s'\n", de.FullId(), de.Point.ValueType, de.Value, de.Parent)
endpoint := de.FullId()
// de.Index = len(dm.Order)
for _, de := range des {
// fmt.Printf("DEBUG DataMap.Add() %s - Value(%s):'%s' Parent:'%s'\n", de.FullId(), de.Point.ValueType, de.Value, de.Parent)
endpoint := de.FullId()
// de.Index = len(dm.Order)
if dm.Map[endpoint] == nil {
dm.Map[endpoint] = &DataEntries{ Entries: []DataEntry{} }
}
entries := dm.Map[endpoint]
if entries.Add(de) == nil {
break
}
// dm.Order = append(dm.Order, endpoint)
if dm.Map[endpoint] == nil {
dm.Map[endpoint] = &DataEntries{Entries: []DataEntry{}}
}
entries := dm.Map[endpoint]
if entries.Add(de) == nil {
continue
}
// dm.Order = append(dm.Order, endpoint)
if Points.Exists(endpoint) {
fmt.Printf("EXISTS: %s\n", endpoint)
if Points.Exists(endpoint) {
fmt.Printf("EXISTS: %s\n", endpoint)
}
Points.Add(*de.Point)
}
Points.Add(*de.Point)
}
}
@ -527,18 +558,21 @@ func CreatePointDataEntries(Current *GoStruct.Reflect, parentDeviceId string, po
break
}
res := valueTypes.SizeOfArrayLength(Current.Value.Length())
for i, uv := range Current.Value {
// res := valueTypes.SizeOfArrayLength(Current.Value.Length())
// res := Current.Value.Length()
sorted := Current.Value.Range(valueTypes.SortOrder)
res := len(sorted)
for i, uv := range sorted {
epn := JoinWithDots(res, valueTypes.DateTimeLayoutDay, Current.EndPointPath().String(), i)
ret.Entries = append(ret.Entries, DataEntry {
Current: Current,
EndPoint: epn, // Current.EndPointPath().String(),
Point: &point,
Parent: NewParentDevice(parentDeviceId),
Date: dateTime,
Value: uv,
Valid: true,
Hide: false,
ret.Entries = append(ret.Entries, DataEntry{
Current: Current,
EndPoint: epn, // Current.EndPointPath().String(),
Point: &point,
Parent: NewParentDevice(parentDeviceId),
Date: dateTime,
Value: uv,
Valid: true,
Hide: false,
// Index: 0,
})
}

View File

@ -544,6 +544,38 @@ func (sgd *SunGrowDataRequest) SetDay(date string) {
}
}
func (sgd *SunGrowDataRequest) SetStartTimeStamp(date string) {
for range Only.Once {
// if sgd.IsNotRequired(NameDay) {
// break
// }
did := valueTypes.SetDateTimeString(date)
sgd.args.StartTimeStamp = &did
if sgd.args.StartTimeStamp.IsZero() {
now := time.Now().Format(valueTypes.DateTimeLayoutSecond)
did = valueTypes.NewDateTime(now)
sgd.args.StartTimeStamp = &did
// Use valueTypes.GetDayStartTimestamp
}
}
}
func (sgd *SunGrowDataRequest) SetEndTimeStamp(date string) {
for range Only.Once {
// if sgd.IsNotRequired(NameDay) {
// break
// }
did := valueTypes.SetDateTimeString(date)
sgd.args.EndTimeStamp = &did
if sgd.args.EndTimeStamp.IsZero() {
now := time.Now().Format(valueTypes.DateTimeLayoutSecond)
did = valueTypes.NewDateTime(now)
sgd.args.EndTimeStamp = &did
// Use valueTypes.GetDayEndTimestamp
}
}
}
func (sgd *SunGrowDataRequest) SetFaultTypeCode(ftc string) {
for range Only.Once {
// if sgd.IsNotRequired(NameFaultTypeCode) {